Example #1
0
  // OVERRIDABLE
  @Override
  @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
      value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD",
      justification = "Make some context visible statically (no matter which one)")
  public void onCreate() {
    super.onCreate();
    Application.mApplication = this;

    SettingsActivity.setDefaultSharedPreferences(getApplicationContext());

    setLanguage();
    setExceptionHandler();

    // Initialize special classes
    try {
      mApplicationSettings =
          (ApplicationSettings)
              Class.forName(getResourceString(R.string.class_application_settings))
                  .getDeclaredMethod("getInstance", new Class<?>[0])
                  .invoke(null, new Object[0]);
    } catch (Exception e) {
      Log.e(TAG, "Error in getting PrivateConstants and ApplicationSettings", e);
    }

    // Set statistics
    int initialVersion =
        PreferenceUtil.getSharedPreferenceInt(R.string.key_statistics_initialversion, -1);
    if (initialVersion == -1) {
      PreferenceUtil.setSharedPreferenceInt(R.string.key_statistics_initialversion, getVersion());
    }

    long firstStartTime =
        PreferenceUtil.getSharedPreferenceLong(R.string.key_statistics_firststarttime, -1);
    if (firstStartTime == -1) {
      PreferenceUtil.setSharedPreferenceLong(
          R.string.key_statistics_firststarttime, System.currentTimeMillis());
    }

    PreferenceUtil.incrementCounter(R.string.key_statistics_countstarts);
  }
Example #2
0
  /** Set the language. */
  public static void setLanguage() {
    String languageString = PreferenceUtil.getSharedPreferenceString(R.string.key_language);
    if (languageString == null || languageString.length() == 0) {
      PreferenceUtil.setSharedPreferenceString(R.string.key_language, "0");
      return;
    }

    int languageSetting = Integer.parseInt(languageString);

    if (languageSetting != 0) {
      switch (languageSetting) {
        case 1:
          setLocale(Locale.ENGLISH);
          break;
        case 2:
          setLocale(Locale.GERMAN);
          break;
        case 3: // MAGIC_NUMBER
          setLocale(new Locale("es"));
          break;
        default:
      }
    }
  }