Ejemplo n.º 1
0
  private boolean calc(final boolean signalError) {
    if (currentFormat == coordInputFormatEnum.Plain) {
      try {
        gp = new Geopoint(eLat.getText().toString(), eLon.getText().toString());
      } catch (Geopoint.ParseException e) {
        if (signalError) {
          context.showToast(context.getResources().getString(R.string.err_parse_lat_lon));
        }
        return false;
      }
      return true;
    }

    String latDir = bLat.getText().toString();
    String lonDir = bLon.getText().toString();
    String latDeg = eLatDeg.getText().toString();
    String lonDeg = eLonDeg.getText().toString();
    String latDegFrac = eLatMin.getText().toString();
    String lonDegFrac = eLonMin.getText().toString();
    String latMin = eLatMin.getText().toString();
    String lonMin = eLonMin.getText().toString();
    String latMinFrac = eLatSec.getText().toString();
    String lonMinFrac = eLonSec.getText().toString();
    String latSec = eLatSec.getText().toString();
    String lonSec = eLonSec.getText().toString();
    String latSecFrac = eLatSub.getText().toString();
    String lonSecFrac = eLonSub.getText().toString();

    switch (currentFormat) {
      case Deg:
        gp = new Geopoint(latDir, latDeg, latDegFrac, lonDir, lonDeg, lonDegFrac);
        break;
      case Min:
        gp = new Geopoint(latDir, latDeg, latMin, latMinFrac, lonDir, lonDeg, lonMin, lonMinFrac);
        break;
      case Sec:
        gp =
            new Geopoint(
                latDir,
                latDeg,
                latMin,
                latSec,
                latSecFrac,
                lonDir,
                lonDeg,
                lonMin,
                lonSec,
                lonSecFrac);
        break;
      case Plain:
        // This case has been handled above
      default:
        throw new IllegalArgumentException();
    }

    return true;
  }
Ejemplo n.º 2
0
 public static void restartActivity(AbstractActivity activity) {
   final Intent intent = activity.getIntent();
   if (isLevel5) {
     overridePendingTransition(activity, 0, 0);
     intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
   }
   activity.finish();
   if (isLevel5) {
     overridePendingTransition(activity, 0, 0);
   }
   activity.startActivity(intent);
 }
  /** Opens a dialog to do actions on an user name */
  protected static void showUserActionsDialog(final CharSequence name, final View view) {
    final AbstractActivity context = (AbstractActivity) view.getContext();
    final Resources res = context.getResources();
    final CharSequence[] items = {
      res.getString(R.string.user_menu_view_hidden),
      res.getString(R.string.user_menu_view_found),
      res.getString(R.string.user_menu_open_browser),
      res.getString(R.string.user_menu_send_message)
    };

    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(res.getString(R.string.user_menu_title) + " " + name);
    builder.setItems(
        items,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            switch (item) {
              case 0:
                cgeocaches.startActivityOwner(context, name.toString());
                return;
              case 1:
                cgeocaches.startActivityUserName(context, name.toString());
                return;
              case 2:
                context.startActivity(
                    new Intent(
                        Intent.ACTION_VIEW,
                        Uri.parse(
                            "http://www.geocaching.com/profile/?u="
                                + Network.encode(name.toString()))));
                return;
              case 3:
                context.startActivity(
                    new Intent(
                        Intent.ACTION_VIEW,
                        Uri.parse(
                            "http://www.geocaching.com/email/?u="
                                + Network.encode(name.toString()))));
                return;
              default:
                break;
            }
          }
        });
    final AlertDialog alert = builder.create();
    alert.show();
  }
Ejemplo n.º 4
0
  @Override
  public void onResume() {
    super.onResume();

    settings.load();

    if (StringUtils.isNotBlank(title)) {
      app.setAction(title);
    } else if (StringUtils.isNotBlank(name)) {
      app.setAction(name);
    }

    // sensor & geolocation manager
    if (geo == null) {
      geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
    }
    if (settings.useCompass == 1 && dir == null) {
      dir = app.startDir(this, dirUpdate);
    }

    // keep backlight on
    if (pm == null) {
      pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    }

    // updater thread
    if (updater == null) {
      updater = new updaterThread(updaterHandler);
      updater.start();
    }
  }
Ejemplo n.º 5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTheme();
    setContentView(R.layout.waypoint);
    setTitle(R.string.waypoint_title);

    // get parameters
    Bundle extras = getIntent().getExtras();

    // try to get data from extras
    if (extras != null) {
      id = extras.getInt("waypoint");
      geocode = extras.getString("geocode");
    }

    if (id <= 0) {
      showToast(res.getString(R.string.err_waypoint_unknown));
      finish();
      return;
    }

    if (geo == null) {
      geo = app.startGeo(geoUpdate);
    }

    waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true);
    waitDialog.setCancelable(true);

    (new loadWaypoint()).start();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTheme();
    setContentView(R.layout.waypoint_new);
    setTitle("waypoint");

    if (geo == null) {
      geo = app.startGeo(geoUpdate);
    }

    // get parameters
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      geocode = extras.getString("geocode");
      wpCount = extras.getInt("count", 0);
      id = extras.getInt("waypoint");
    }

    if (StringUtils.isBlank(geocode) && id <= 0) {
      showToast(res.getString(R.string.err_waypoint_cache_unknown));

      finish();
      return;
    }

    if (id <= 0) {
      setTitle(res.getString(R.string.waypoint_add_title));
    } else {
      setTitle(res.getString(R.string.waypoint_edit_title));
    }

    if (geocode != null) {
      app.setAction(geocode);
    }

    Button buttonLat = (Button) findViewById(R.id.buttonLatitude);
    buttonLat.setOnClickListener(new coordDialogListener());
    Button buttonLon = (Button) findViewById(R.id.buttonLongitude);
    buttonLon.setOnClickListener(new coordDialogListener());

    Button addWaypoint = (Button) findViewById(R.id.add_waypoint);
    addWaypoint.setOnClickListener(new coordsListener());

    List<String> wayPointNames = new ArrayList<String>(cgBase.waypointTypes.values());
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.name);
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, wayPointNames);
    textView.setAdapter(adapter);

    if (id > 0) {
      waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true);
      waitDialog.setCancelable(true);

      (new loadWaypoint()).start();
    }

    disableSuggestions((EditText) findViewById(R.id.distance));
  }
  @Override
  public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo info) {
    super.onCreateContextMenu(menu, view, info);
    final int viewId = view.getId();

    if (viewId == R.id.type) {
      for (final LogType typeOne : possibleLogTypes) {
        menu.add(viewId, typeOne.id, 0, typeOne.getL10n());
        Log.w("Adding " + typeOne + " " + typeOne.getL10n());
      }
    } else if (viewId == R.id.changebutton) {
      final int textId = ((TextView) findViewById(viewId)).getId();

      menu.setHeaderTitle(res.getString(R.string.log_tb_changeall));
      for (LogTypeTrackable logType : LogTypeTrackable.values()) {
        menu.add(textId, logType.id, 0, res.getString(logType.resourceId));
      }
    } else {
      final int realViewId = ((LinearLayout) findViewById(viewId)).getId();

      for (final cgTrackableLog tb : trackables) {
        if (tb.id == realViewId) {
          menu.setHeaderTitle(tb.name);
        }
      }
      for (LogTypeTrackable logType : LogTypeTrackable.values()) {
        menu.add(realViewId, logType.id, 0, res.getString(logType.resourceId));
      }
    }
  }
Ejemplo n.º 8
0
  @Override
  public void onResume() {
    super.onResume();

    setGo4CacheAction();

    // sensor & geolocation manager
    if (geo == null) {
      geo = app.startGeo(geoUpdate);
    }
    if (Settings.isUseCompass() && dir == null) {
      dir = app.startDir(this, dirUpdate);
    }

    // keep backlight on
    if (pm == null) {
      pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    }

    // updater thread
    if (updater == null) {
      updater = new updaterThread(updaterHandler);
      updater.start();
    }
  }
Ejemplo n.º 9
0
  @Override
  public void onPause() {
    if (geo != null) {
      geo = app.removeGeo();
    }

    super.onPause();
  }
Ejemplo n.º 10
0
  @Override
  public void onDestroy() {
    if (geo != null) {
      geo = app.removeGeo();
    }

    super.onDestroy();
  }
Ejemplo n.º 11
0
 @Override
 protected void onSaveInstanceState(final Bundle outState) {
   super.onSaveInstanceState(outState);
   syncEditTexts();
   outState.putString(SAVED_STATE_IMAGE_CAPTION, imageCaption);
   outState.putString(SAVED_STATE_IMAGE_DESCRIPTION, imageDescription);
   outState.putString(
       SAVED_STATE_IMAGE_URI, imageUri != null ? imageUri.getPath() : StringUtils.EMPTY);
   outState.putInt(SAVED_STATE_IMAGE_SCALE, scaleChoiceIndex);
 }
Ejemplo n.º 12
0
  @Override
  public void onStop() {
    if (geo != null) {
      geo = app.removeGeo();
    }
    if (dir != null) {
      dir = app.removeDir();
    }

    super.onStop();
  }
Ejemplo n.º 13
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTheme();
    setContentView(R.layout.point);
    setTitle(res.getString(R.string.search_destination));

    createHistoryView();

    init();
  }
Ejemplo n.º 14
0
  @Override
  public void onResume() {
    super.onResume();

    app.addGeoObserver(this);

    if (waitDialog == null) {
      waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true);
      waitDialog.setCancelable(true);

      (new loadWaypoint()).start();
    }
  }
Ejemplo n.º 15
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    MenuItem item;
    item = menu.findItem(1);
    if (settings.useCompass == 1) {
      item.setTitle(res.getString(R.string.use_gps));
    } else {
      item.setTitle(res.getString(R.string.use_compass));
    }

    return true;
  }
Ejemplo n.º 16
0
  @Override
  public void onDestroy() {
    if (geo != null) {
      geo = app.removeGeo();
    }
    if (dir != null) {
      dir = app.removeDir();
    }

    compassView.destroyDrawingCache();
    compassView = null;

    super.onDestroy();
  }
 @Override
 public void onResume() {
   super.onResume();
   final Uri uri = getIntent().getData();
   if (uri != null) {
     final String verifier = uri.getQueryParameter("oauth_verifier");
     if (StringUtils.isNotBlank(verifier)) {
       exchangeTokens(verifier);
     } else {
       // We can shortcut the whole verification process if we do not have a token at all.
       changeTokensHandler.sendEmptyMessage(NOT_AUTHENTICATED);
     }
   }
 }
Ejemplo n.º 18
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

    this.setTheme(ActivityMixin.getDialogTheme());

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
      waypointId = extras.getInt(Intents.EXTRA_WAYPOINT_ID);
      geocode = extras.getString(Intents.EXTRA_GEOCODE);
    }
    showDialog();
  }
Ejemplo n.º 19
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    try {
      boolean visible = waypoint != null && waypoint.getCoords() != null;
      menu.findItem(MENU_ID_NAVIGATION).setVisible(visible);
      menu.findItem(MENU_ID_COMPASS).setVisible(visible);
      menu.findItem(MENU_ID_CACHES_AROUND).setVisible(visible);
    } catch (Exception e) {
      // nothing
    }

    return true;
  }
  @Override
  public void onResume() {
    super.onResume();

    if (geo == null) {
      geo = app.startGeo(geoUpdate);
    }

    if (id > 0) {
      if (waitDialog == null) {
        waitDialog =
            ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true);
        waitDialog.setCancelable(true);

        (new loadWaypoint()).start();
      }
    }
  }
Ejemplo n.º 21
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    try {
      boolean visible = waypoint != null && waypoint.getCoords() != null;
      menu.findItem(MENU_ID_NAVIGATION).setVisible(visible);
      menu.findItem(MENU_ID_DEFAULT_NAVIGATION).setVisible(visible);
      menu.findItem(MENU_ID_CACHES_AROUND).setVisible(visible);

      boolean openGeocache = waypoint != null && StringUtils.isNotEmpty(waypoint.getGeocode());
      menu.findItem(MENU_ID_OPEN_GEOCACHE).setVisible(openGeocache);
    } catch (Exception e) {
      // nothing
    }

    return true;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.authorization_activity, true);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      host = BundleUtils.getString(extras, Intents.EXTRA_OAUTH_HOST, host);
      pathRequest = BundleUtils.getString(extras, Intents.EXTRA_OAUTH_PATH_REQUEST, pathRequest);
      pathAuthorize =
          BundleUtils.getString(extras, Intents.EXTRA_OAUTH_PATH_AUTHORIZE, pathAuthorize);
      pathAccess = BundleUtils.getString(extras, Intents.EXTRA_OAUTH_PATH_ACCESS, pathAccess);
      https = extras.getBoolean(Intents.EXTRA_OAUTH_HTTPS, https);
      consumerKey = BundleUtils.getString(extras, Intents.EXTRA_OAUTH_CONSUMER_KEY, consumerKey);
      consumerSecret =
          BundleUtils.getString(extras, Intents.EXTRA_OAUTH_CONSUMER_SECRET, consumerSecret);
      callback = BundleUtils.getString(extras, Intents.EXTRA_OAUTH_CALLBACK, callback);
    }

    setTitle(getAuthTitle());

    auth_1.setText(getAuthExplainShort());
    auth_2.setText(getAuthExplainLong());

    ImmutablePair<String, String> tempToken = getTempTokens();
    OAtoken = tempToken.left;
    OAtokenSecret = tempToken.right;

    startButton.setText(getAuthAuthorize());
    startButton.setEnabled(true);
    startButton.setOnClickListener(new StartListener());

    if (StringUtils.isBlank(OAtoken) && StringUtils.isBlank(OAtokenSecret)) {
      // start authorization process
      startButton.setText(getAuthStart());
    } else {
      // already have temporary tokens, continue from pin
      startButton.setText(getAuthAgain());
    }
  }
Ejemplo n.º 23
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTheme();
    setContentView(R.layout.waypoint);
    setTitle(R.string.waypoint_title);

    // get parameters
    Bundle extras = getIntent().getExtras();

    // try to get data from extras
    if (extras != null) {
      id = extras.getInt("waypoint");
    }

    if (id <= 0) {
      showToast(res.getString(R.string.err_waypoint_unknown));
      finish();
      return;
    }

    waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true);
    waitDialog.setCancelable(true);

    (new loadWaypoint()).start();

    ImageView defaultNavigationImageView = (ImageView) findViewById(R.id.defaultNavigation);
    defaultNavigationImageView.setOnLongClickListener(
        new OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            startDefaultNavigation2();
            return true;
          }
        });
  }
Ejemplo n.º 24
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    try {
      final Geopoint coords = getDestination();

      if (coords != null) {
        menu.findItem(MENU_NAVIGATE).setVisible(true);
        menu.findItem(MENU_COMPASS).setVisible(true);
        menu.findItem(MENU_CACHES_AROUND).setVisible(true);
      } else {
        menu.findItem(MENU_NAVIGATE).setVisible(false);
        menu.findItem(MENU_COMPASS).setVisible(false);
        menu.findItem(MENU_CACHES_AROUND).setVisible(false);
      }

      menu.findItem(MENU_CLEAR_HISTORY).setEnabled(!getHistoryOfSearchedLocations().isEmpty());
    } catch (Exception e) {
      // nothing
    }

    return true;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTheme();
    setContentView(R.layout.visit);
    setTitle(res.getString(R.string.log_new_log));

    // get parameters
    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
      cacheid = extras.getString(EXTRAS_ID);
      geocode = extras.getString(EXTRAS_GEOCODE);
      text = extras.getString(EXTRAS_TEXT);
      alreadyFound = extras.getBoolean(EXTRAS_FOUND);
    }

    if ((StringUtils.isBlank(cacheid)) && StringUtils.isNotBlank(geocode)) {
      cacheid = app.getCacheid(geocode);
    }
    if (StringUtils.isBlank(geocode) && StringUtils.isNotBlank(cacheid)) {
      geocode = app.getGeocode(cacheid);
    }

    cache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);

    if (StringUtils.isNotBlank(cache.getName())) {
      setTitle(res.getString(R.string.log_new_log) + ": " + cache.getName());
    } else {
      setTitle(res.getString(R.string.log_new_log) + ": " + cache.getGeocode().toUpperCase());
    }

    app.setAction(geocode);

    init();
  }
Ejemplo n.º 26
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // set layout
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setTheme();
    setContentView(R.layout.navigate);
    setTitle(res.getString(R.string.compass_title));

    // sensor & geolocation manager
    if (geo == null) {
      geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
    }
    if (settings.useCompass == 1 && dir == null) {
      dir = app.startDir(this, dirUpdate);
    }

    // get parameters
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      title = extras.getString("geocode");
      name = extras.getString("name");
      dstCoords = new Geopoint(extras.getDouble("latitude"), extras.getDouble("longitude"));

      if (StringUtils.isNotBlank(name)) {
        if (StringUtils.isNotBlank(title)) {
          title = title + ": " + name;
        } else {
          title = name;
        }
      }
    } else {
      Intent pointIntent = new Intent(this, cgeopoint.class);
      startActivity(pointIntent);

      finish();
      return;
    }

    if (StringUtils.isNotBlank(title)) {
      app.setAction(title);
    } else if (StringUtils.isNotBlank(name)) {
      app.setAction(name);
    }

    // set header
    setTitle();
    setDestCoords();

    // get textviews once
    compassView = (cgCompass) findViewById(R.id.rose);

    // start updater thread
    updater = new updaterThread(updaterHandler);
    updater.start();

    if (geo != null) {
      geoUpdate.updateLoc(geo);
    }
    if (dir != null) {
      dirUpdate.updateDir(dir);
    }
  }
Ejemplo n.º 27
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.imageselect_activity);
    Views.inject(this);

    scaleChoiceIndex = Settings.getLogImageScale();
    imageCaption = "";
    imageDescription = "";
    imageUri = Uri.EMPTY;

    // Get parameters from intent and basic cache information from database
    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
      imageCaption = extras.getString(EXTRAS_CAPTION);
      imageDescription = extras.getString(EXTRAS_DESCRIPTION);
      imageUri = Uri.parse(extras.getString(EXTRAS_URI_AS_STRING));
      scaleChoiceIndex = extras.getInt(EXTRAS_SCALE, scaleChoiceIndex);
    }

    // Restore previous state
    if (savedInstanceState != null) {
      imageCaption = savedInstanceState.getString(SAVED_STATE_IMAGE_CAPTION);
      imageDescription = savedInstanceState.getString(SAVED_STATE_IMAGE_DESCRIPTION);
      imageUri = Uri.parse(savedInstanceState.getString(SAVED_STATE_IMAGE_URI));
      scaleChoiceIndex = savedInstanceState.getInt(SAVED_STATE_IMAGE_SCALE);
    }

    cameraButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View view) {
            selectImageFromCamera();
          }
        });

    storedButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View view) {
            selectImageFromStorage();
          }
        });

    if (StringUtils.isNotBlank(imageCaption)) {
      captionView.setText(imageCaption);
    }

    if (StringUtils.isNotBlank(imageDescription)) {
      descriptionView.setText(imageDescription);
    }

    scaleView.setSelection(scaleChoiceIndex);
    scaleView.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            scaleChoiceIndex = scaleView.getSelectedItemPosition();
            Settings.setLogImageScale(scaleChoiceIndex);
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    saveButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            saveImageInfo(true);
          }
        });

    clearButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            saveImageInfo(false);
          }
        });

    loadImagePreview();
  }
 @Override
 public void onResume() {
   super.onResume();
 }
 @Override
 public void onStop() {
   super.onStop();
   saveLog(false);
 }
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    init();
  }