Beispiel #1
0
 private static void switchToEnglish(String previousPage) {
   if (previousPage != null && previousPage.contains(ENGLISH)) {
     Log.i("Geocaching.com language already set to English");
     // get find count
     getLoginStatus(
         Network.getResponseData(Network.getRequest("http://www.geocaching.com/email/")));
   } else {
     final String page = Network.getResponseData(Network.getRequest(LANGUAGE_CHANGE_URI));
     getLoginStatus(page);
     if (page == null) {
       Log.e("Failed to read viewstates to set geocaching.com language");
     }
     final Parameters params =
         new Parameters(
             "__EVENTTARGET",
                 "ctl00$uxLocaleList$uxLocaleList$ctl00$uxLocaleItem", // switch to english
             "__EVENTARGUMENT", "");
     Login.transferViewstates(page, params);
     final HttpResponse response =
         Network.postRequest(
             LANGUAGE_CHANGE_URI, params, new Parameters("Referer", LANGUAGE_CHANGE_URI));
     if (Network.isSuccess(response)) {
       Log.i("changed language on geocaching.com to English");
     } else {
       Log.e("Failed to set geocaching.com language to English");
     }
   }
 }
Beispiel #2
0
  @Override
  public void onCreate() {
    try {
      final ViewConfiguration config = ViewConfiguration.get(this);
      final Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
      menuKeyField.setAccessible(true);
      menuKeyField.setBoolean(config, false);
    } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException ignored) {
    }

    // Set language to English if the user decided so.
    initApplicationLocale(Settings.useEnglish());

    // ensure initialization of lists
    DataStore.getLists();

    // Check if Google Play services is available
    if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this)
        == ConnectionResult.SUCCESS) {
      isGooglePlayServicesAvailable = true;
    }
    Log.i(
        "Google Play services are " + (isGooglePlayServicesAvailable ? "" : "not ") + "available");
    final Sensors sensors = Sensors.getInstance();
    sensors.setupGeoDataObservables(Settings.useGooglePlayServices(), Settings.useLowPowerMode());
    sensors.setupDirectionObservable(Settings.useLowPowerMode());

    // Attempt to acquire an initial location before any real activity happens.
    sensors
        .geoDataObservable(true)
        .subscribeOn(RxUtils.looperCallbacksScheduler)
        .first()
        .subscribe();
  }
Beispiel #3
0
 @Override
 public void onTrimMemory(final int level) {
   if (level >= TRIM_MEMORY_MODERATE) {
     Log.i("Cleaning applications cache to trim memory");
     DataStore.removeAllFromCache();
   }
 }
Beispiel #4
0
    @Override
    public void run() {
      if (app == null) {
        return;
      }
      if (cleanupRunning) {
        return;
      }

      boolean more = false;
      if (version != Settings.getVersion()) {
        Log.i(
            "Initializing hard cleanup - version changed from "
                + Settings.getVersion()
                + " to "
                + version
                + ".");

        more = true;
      }

      cleanupRunning = true;
      DataStore.clean(more);
      cleanupRunning = false;

      if (version > 0) {
        Settings.setVersion(version);
      }
    }
Beispiel #5
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    // don't call the super implementation with the layout argument, as that would set the wrong
    // theme
    super.onCreate(savedInstanceState);

    // Disable the up navigation for this activity
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);

    setContentView(R.layout.main_activity);
    ButterKnife.inject(this);

    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
      // If we had been open already, start from the last used activity.
      finish();
      return;
    }

    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); // type to search

    version = Version.getVersionCode(this);
    Log.i(
        "Starting " + getPackageName() + ' ' + version + " a.k.a " + Version.getVersionName(this));

    init();

    checkShowChangelog();
  }
 public ImportGpxZipAttachmentThread(
     final Uri uri,
     final ContentResolver contentResolver,
     final int listId,
     final Handler importStepHandler,
     final CancellableHandler progressHandler) {
   super(listId, importStepHandler, progressHandler);
   this.uri = uri;
   this.contentResolver = contentResolver;
   Log.i("Import zipped GPX from uri: " + uri);
 }
Beispiel #7
0
  private void loadImagePreview() {
    if (imageUri == null) {
      return;
    }
    if (!new File(imageUri.getPath()).exists()) {
      Log.i("Image does not exist");
      return;
    }

    final Bitmap bitmap = ImageUtils.readAndScaleImageToFitDisplay(imageUri.getPath());
    imagePreview.setImageBitmap(bitmap);
    imagePreview.setVisibility(View.VISIBLE);
  }
Beispiel #8
0
  /**
   * POST HTTP request. Do the request a second time if the user is not logged in
   *
   * @param uri
   * @return
   */
  public static String postRequestLogged(final String uri, final Parameters params) {
    HttpResponse response = Network.postRequest(uri, params);
    String data = Network.getResponseData(response);

    if (!getLoginStatus(data)) {
      if (login() == StatusCode.NO_ERROR) {
        response = Network.postRequest(uri, params);
        data = Network.getResponseData(response);
      } else {
        Log.i("Working as guest.");
      }
    }
    return data;
  }
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    final int group = item.getGroupId();
    final int id = item.getItemId();

    if (group == R.id.type) {
      setType(LogType.getById(id));

      return true;
    } else if (group == R.id.changebutton) {
      try {
        final LogTypeTrackable logType = LogTypeTrackable.findById(id);
        if (logType != null) {
          final LinearLayout inventView = (LinearLayout) findViewById(R.id.inventory);
          for (int count = 0; count < inventView.getChildCount(); count++) {
            final LinearLayout tbView = (LinearLayout) inventView.getChildAt(count);
            if (tbView == null) {
              return false;
            }

            final TextView tbText = (TextView) tbView.findViewById(R.id.action);
            if (tbText == null) {
              return false;
            }
            tbText.setText(res.getString(logType.resourceId) + " ▼");
          }
          for (cgTrackableLog tb : trackables) {
            tb.action = logType;
          }
          tbChanged = true;
          return true;
        }
      } catch (Exception e) {
        Log.e("cgeovisit.onContextItemSelected: " + e.toString());
      }
    } else {
      try {
        final LogTypeTrackable logType = LogTypeTrackable.findById(id);
        if (logType != null) {
          final LinearLayout tbView = (LinearLayout) findViewById(group);
          if (tbView == null) {
            return false;
          }

          final TextView tbText = (TextView) tbView.findViewById(R.id.action);
          if (tbText == null) {
            return false;
          }

          for (cgTrackableLog tb : trackables) {
            if (tb.id == group) {
              tbChanged = true;

              tb.action = logType;
              tbText.setText(res.getString(logType.resourceId) + " ▼");

              Log.i("Trackable " + tb.trackCode + " (" + tb.name + ") has new action: #" + id);
            }
          }

          return true;
        }
      } catch (Exception e) {
        Log.e("cgeovisit.onContextItemSelected: " + e.toString());
      }
    }

    return false;
  }
Beispiel #10
0
  private static StatusCode login(boolean retry) {
    final ImmutablePair<String, String> login = Settings.getLogin();

    if (login == null || StringUtils.isEmpty(login.left) || StringUtils.isEmpty(login.right)) {
      Login.setActualStatus(cgeoapplication.getInstance().getString(R.string.err_login));
      Log.e("Login.login: No login information stored");
      return StatusCode.NO_LOGIN_INFO_STORED;
    }

    Login.setActualStatus(
        cgeoapplication.getInstance().getString(R.string.init_login_popup_working));
    HttpResponse loginResponse =
        Network.getRequest("https://www.geocaching.com/login/default.aspx");
    String loginData = Network.getResponseData(loginResponse);
    if (loginResponse != null
        && loginResponse.getStatusLine().getStatusCode() == 503
        && BaseUtils.matches(loginData, GCConstants.PATTERN_MAINTENANCE)) {
      return StatusCode.MAINTENANCE;
    }

    if (StringUtils.isBlank(loginData)) {
      Log.e("Login.login: Failed to retrieve login page (1st)");
      return StatusCode.CONNECTION_FAILED; // no loginpage
    }

    if (Login.getLoginStatus(loginData)) {
      Log.i(
          "Already logged in Geocaching.com as "
              + login.left
              + " ("
              + Settings.getMemberStatus()
              + ')');
      Login.switchToEnglish(loginData);
      return StatusCode.NO_ERROR; // logged in
    }

    Cookies.clearCookies();
    Settings.setCookieStore(null);

    final Parameters params =
        new Parameters(
            "__EVENTTARGET", "",
            "__EVENTARGUMENT", "",
            "ctl00$ContentBody$tbUsername", login.left,
            "ctl00$ContentBody$tbPassword", login.right,
            "ctl00$ContentBody$cbRememberMe", "on",
            "ctl00$ContentBody$btnSignIn", "Login");
    final String[] viewstates = Login.getViewstates(loginData);
    if (isEmpty(viewstates)) {
      Log.e("Login.login: Failed to find viewstates");
      return StatusCode.LOGIN_PARSE_ERROR; // no viewstates
    }
    Login.putViewstates(params, viewstates);

    loginResponse = Network.postRequest("https://www.geocaching.com/login/default.aspx", params);
    loginData = Network.getResponseData(loginResponse);

    if (StringUtils.isBlank(loginData)) {
      Log.e("Login.login: Failed to retrieve login page (2nd)");
      // FIXME: should it be CONNECTION_FAILED to match the first attempt?
      return StatusCode.COMMUNICATION_ERROR; // no login page
    }

    if (Login.getLoginStatus(loginData)) {
      Log.i(
          "Successfully logged in Geocaching.com as "
              + login.left
              + " ("
              + Settings.getMemberStatus()
              + ')');

      Login.switchToEnglish(loginData);
      Settings.setCookieStore(Cookies.dumpCookieStore());

      return StatusCode.NO_ERROR; // logged in
    }

    if (loginData.contains("Your username/password combination does not match.")) {
      Log.i(
          "Failed to log in Geocaching.com as "
              + login.left
              + " because of wrong username/password");
      return StatusCode.WRONG_LOGIN_DATA; // wrong login
    }

    Log.i("Failed to log in Geocaching.com as " + login.left + " for some unknown reason");
    if (retry) {
      Login.switchToEnglish(loginData);
      return login(false);
    }

    return StatusCode.UNKNOWN_ERROR; // can't login
  }