@Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (preference.equals(customApiUrlPref) && newValue instanceof String) {
      String apiUrl = (String) newValue;

      if (!TextUtils.isEmpty(apiUrl)) {
        // User entered a custom API Url, so set the region info to null
        Application.get().setCurrentRegion(null);
        if (BuildConfig.DEBUG) {
          Log.d(TAG, "User entered new API URL, set region to null.");
        }
      } else {
        // User cleared the API URL preference value, so re-initialize regions
        if (BuildConfig.DEBUG) {
          Log.d(TAG, "User entered blank API URL, re-initializing regions...");
        }
        NavHelp.goHome(this);
      }
    } else if (preference.equals(analyticsPref) && newValue instanceof Boolean) {
      Boolean isAnalyticsActive = (Boolean) newValue;
      // Report if the analytics turns off, just before shared preference changed
      if (!isAnalyticsActive) {
        ObaAnalytics.reportEventWithCategory(
            ObaAnalytics.ObaEventCategory.APP_SETTINGS.toString(),
            getString(R.string.analytics_action_edit_general),
            getString(R.string.analytics_label_analytic_preference)
                + (isAnalyticsActive ? "YES" : "NO"));
        GoogleAnalytics.getInstance(getBaseContext()).dispatchLocalHits();
      }
    }
    return true;
  }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   if (item.getItemId() == android.R.id.home) {
     NavHelp.goHome(this, false);
     return true;
   }
   return false;
 }
  @Override
  protected void onDestroy() {
    SharedPreferences settings = Application.getPrefs();
    boolean currentValue =
        settings.getBoolean(getString(R.string.preference_key_auto_select_region), true);

    // If the use has selected to auto-select region, and the previous state of the setting was
    // false,
    // then run the auto-select by going to HomeActivity
    if (currentValue && !autoSelectInitialValue) {
      if (BuildConfig.DEBUG) {
        Log.d(TAG, "User re-enabled auto-select regions pref, auto-selecting via Home Activity...");
      }
      NavHelp.goHome(this);
    }
    super.onDestroy();
  }
  //
  // Region Task Callback
  //
  public void onTaskFinished(boolean currentRegionChanged) {
    setSupportProgressBarIndeterminateVisibility(false);

    if (currentRegionChanged) {
      // If region was auto-selected, show user the region we're using
      if (Application.getPrefs()
              .getBoolean(getString(R.string.preference_key_auto_select_region), true)
          && Application.get().getCurrentRegion() != null) {
        Toast.makeText(
                this,
                getString(
                    R.string.region_region_found, Application.get().getCurrentRegion().getName()),
                Toast.LENGTH_LONG)
            .show();
      }

      // Update the preference summary to show the newly selected region
      changePreferenceSummary(getString(R.string.preference_key_region));

      // Since the current region was updated as a result of enabling/disabling experimental
      // servers, go home
      NavHelp.goHome(this);
    }
  }