@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;
  }
Exemplo n.º 2
0
 public static RepeaterUtil get() {
   Application app = Application.get();
   RepeaterUtil util = app.getMetaData(REPEATER_UTIL_KEY);
   if (util != null) {
     return util;
   }
   util = new RepeaterUtil(app); // this registers too
   return util;
 }
 /**
  * Changes the summary of a preference based on a given preference key
  *
  * @param preferenceKey preference key that triggers a change in summary
  */
 private void changePreferenceSummary(String preferenceKey) {
   // Change the current region summary and server API URL summary
   if (preferenceKey.equalsIgnoreCase(getString(R.string.preference_key_region))
       || preferenceKey.equalsIgnoreCase(getString(R.string.preference_key_oba_api_url))) {
     if (Application.get().getCurrentRegion() != null) {
       regionPref.setSummary(
           getString(
               R.string.preferences_region_summary,
               Application.get().getCurrentRegion().getName()));
       customApiUrlPref.setSummary(getString(R.string.preferences_oba_api_servername_summary));
     } else {
       regionPref.setSummary(getString(R.string.preferences_region_summary_custom_api));
       customApiUrlPref.setSummary(Application.get().getCustomApiUrl());
     }
   } else if (preferenceKey.equalsIgnoreCase(getString(R.string.preference_key_preferred_units))) {
     preferredUnits.setSummary(preferredUnits.getValue());
   }
 }
 @Override
 public void actionPerformed(final ActionEvent e) {
   final Window window = (Window) Application.get().getMainPane();
   try {
     window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
     actionInvoked(e);
   } finally {
     window.setCursor(Cursor.getDefaultCursor());
   }
 }
  @Override
  public void ok() {
    if (assertNull(nameField, urlField)) {
      return;
    }

    final ModelerSettings settings = ModelerSettings.get();
    final Vector<String> connections = new Vector<>(settings.getConnections());
    final NodeConnection connection = (NodeConnection) params[0];
    final String name = nameField.getText();
    if (connections.contains(name)) {
      if (connection == null || !name.equals(connection.getName())) {
        SwingUtils.showError($m("ConnectionDialog.2"));
        return;
      }
    }

    super.ok();

    final NavigationTree tree = Application.get().getMainPane().getNavigationTree();
    final String url = urlField.getText();
    final String login = loginField.getText();
    final String password = passwordField.getText();
    if (connection != null) {
      final String old = connection.getName();
      final int p = connections.indexOf(old);
      if (p > -1) {
        connections.set(p, name);
        connection.setName(name);
        connection.setUrl(url);
        connection.setLogin(login);
        connection.setPassword(password);

        settings.setConnectionUrl(old, null);
        settings.setConnectionLogin(old, null);
        settings.setConnectionPassword(old, null);
      }
    } else {
      connections.add(name);
    }

    settings.setConnections(connections);
    settings.setConnectionUrl(name, url);
    settings.setConnectionLogin(name, login);
    settings.setConnectionPassword(name, password);
    settings.save();

    if (null == connection) {
      final NodeRoot root = tree.getModel().getRoot();
      root.add(new NodeConnection(name, url, login, password));
    }
    tree.updateUI();
  }
  //
  // 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);
    }
  }
Exemplo n.º 7
0
  protected static CursorLoader newRecentQuery(
      final Context context,
      final Uri uri,
      final String[] projection,
      final String accessTime,
      final String useCount) {
    // "Recently" means seven days in the past
    final long last = System.currentTimeMillis() - 7 * DateUtils.DAY_IN_MILLIS;
    Uri limit = uri.buildUpon().appendQueryParameter("limit", "20").build();

    String regionWhere = "";
    if (Application.get().getCurrentRegion() != null) {
      if (projection.equals(QueryUtils.StopList.Columns.PROJECTION)) {
        regionWhere = " AND " + StopList.getRegionWhere();
      } else if (projection.equals(QueryUtils.RouteList.Columns.PROJECTION)) {
        regionWhere = " AND " + RouteList.getRegionWhere();
      }
    }

    return new CursorLoader(
        context,
        limit,
        projection,
        "(("
            + accessTime
            + " IS NOT NULL AND "
            + accessTime
            + " > "
            + last
            + ") OR ("
            + useCount
            + " > 0))"
            + regionWhere,
        null,
        accessTime + " desc, " + useCount + " desc");
  }
  @Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    SharedPreferences settings = Application.getPrefs();
    // Listening to changes to a custom Preference doesn't seem to work, so we can listen to changes
    // to the shared pref value instead
    if (key.equals(getString(R.string.preference_key_experimental_regions))) {
      boolean experimentalServers =
          settings.getBoolean(getString(R.string.preference_key_experimental_regions), false);
      if (BuildConfig.DEBUG) {
        Log.d(TAG, "Experimental regions shared preference changed to " + experimentalServers);
      }

      /*
      Force a refresh of the regions list, but don't using blocking progress dialog
      inside the ObaRegionsTask AsyncTask.
      We need to use our own Action Bar progress bar here so its linked to this activity,
      which will survive orientation changes.
      */
      setSupportProgressBarIndeterminateVisibility(true);
      ObaRegionsTask task = new ObaRegionsTask(this, this, true, false);
      task.execute();

      // Wait to change the region preference description until the task callback
      // Analytics
      if (experimentalServers) {
        ObaAnalytics.reportEventWithCategory(
            ObaAnalytics.ObaEventCategory.UI_ACTION.toString(),
            getString(R.string.analytics_action_button_press),
            getString(R.string.analytics_label_button_press_experimental_on));
      } else {
        ObaAnalytics.reportEventWithCategory(
            ObaAnalytics.ObaEventCategory.UI_ACTION.toString(),
            getString(R.string.analytics_action_button_press),
            getString(R.string.analytics_label_button_press_experimental_off));
      }
    } else if (key.equals(getString(R.string.preference_key_oba_api_url))) {
      // Change the region preference description to show we're not using a region
      changePreferenceSummary(key);
    } else if (key.equalsIgnoreCase(getString(R.string.preference_key_preferred_units))) {
      // Change the preferred units description
      changePreferenceSummary(key);
    } else if (key.equalsIgnoreCase(getString(R.string.preference_key_auto_select_region))) {
      // Analytics
      boolean autoSelect =
          settings.getBoolean(getString(R.string.preference_key_auto_select_region), false);
      if (autoSelect) {
        ObaAnalytics.reportEventWithCategory(
            ObaAnalytics.ObaEventCategory.UI_ACTION.toString(),
            getString(R.string.analytics_action_button_press),
            getString(R.string.analytics_label_button_press_auto));
      } else {
        ObaAnalytics.reportEventWithCategory(
            ObaAnalytics.ObaEventCategory.UI_ACTION.toString(),
            getString(R.string.analytics_action_button_press),
            getString(R.string.analytics_label_button_press_manual));
      }
    } else if (key.equalsIgnoreCase(getString(R.string.preferences_key_analytics))) {
      Boolean isAnalyticsActive =
          settings.getBoolean(
              Application.get().getString(R.string.preferences_key_analytics), Boolean.FALSE);
      // Report if the analytics turns on, just after 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"));
    }
  }
Exemplo n.º 9
0
 protected static String getRegionWhere() {
   return Application.get().getCurrentRegion() == null
       ? ""
       : QueryUtils.getRegionWhere(
           ObaContract.Stops.REGION_ID, Application.get().getCurrentRegion().getId());
 }