public void setSearchEngines(JSONArray engines) {
   mSearchEngines = engines;
   GeckoAppShell.getMainHandler()
       .post(
           new Runnable() {
             public void run() {
               mAllPagesCursorAdapter.notifyDataSetChanged();
             }
           });
 }
Example #2
0
 @Override
 public void handleMessage(String event, final JSONObject message) {
   if (event.equals("SearchEngines:Data")) {
     GeckoAppShell.getMainHandler()
         .post(
             new Runnable() {
               @Override
               public void run() {
                 setSearchEngines(message);
               }
             });
   }
 }
 public void handleMessage(String event, JSONObject message) {
   try {
     if (event.equals("Preferences:Data")) {
       JSONArray jsonPrefs = message.getJSONArray("preferences");
       refresh(jsonPrefs);
     } else if (event.equals("Sanitize:Finished")) {
       boolean success = message.getBoolean("success");
       final int stringRes = success ? R.string.private_data_success : R.string.private_data_fail;
       final Context context = this;
       GeckoAppShell.getMainHandler()
           .post(
               new Runnable() {
                 public void run() {
                   Toast.makeText(context, stringRes, Toast.LENGTH_SHORT).show();
                 }
               });
     }
   } catch (Exception e) {
     Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
   }
 }
  private void refresh(JSONArray jsonPrefs) {
    // enable all preferences once we have them from gecko
    GeckoAppShell.getMainHandler()
        .post(
            new Runnable() {
              public void run() {
                mPreferenceScreen.setEnabled(true);
              }
            });

    try {
      if (mPreferenceScreen == null) return;

      final int length = jsonPrefs.length();
      for (int i = 0; i < length; i++) {
        JSONObject jPref = jsonPrefs.getJSONObject(i);
        final String prefName = jPref.getString("name");
        final String prefType = jPref.getString("type");
        final Preference pref = mPreferenceScreen.findPreference(prefName);

        if (pref instanceof CheckBoxPreference && "bool".equals(prefType)) {
          final boolean value = jPref.getBoolean("value");
          GeckoAppShell.getMainHandler()
              .post(
                  new Runnable() {
                    public void run() {
                      if (((CheckBoxPreference) pref).isChecked() != value)
                        ((CheckBoxPreference) pref).setChecked(value);
                    }
                  });
        } else if (pref instanceof EditTextPreference && "string".equals(prefType)) {
          final String value = jPref.getString("value");
          GeckoAppShell.getMainHandler()
              .post(
                  new Runnable() {
                    public void run() {
                      ((EditTextPreference) pref).setText(value);
                    }
                  });
        } else if (pref instanceof ListPreference && "string".equals(prefType)) {
          final String value = jPref.getString("value");
          GeckoAppShell.getMainHandler()
              .post(
                  new Runnable() {
                    public void run() {
                      ((ListPreference) pref).setValue(value);
                      // Set the summary string to the current entry
                      CharSequence selectedEntry = ((ListPreference) pref).getEntry();
                      ((ListPreference) pref).setSummary(selectedEntry);
                    }
                  });
        } else if (pref instanceof FontSizePreference) {
          final FontSizePreference fontSizePref = (FontSizePreference) pref;
          final String twipValue = jPref.getString("value");
          fontSizePref.setSavedFontSize(twipValue);
          final String fontSizeName = fontSizePref.getSavedFontSizeName();
          GeckoAppShell.getMainHandler()
              .post(
                  new Runnable() {
                    public void run() {
                      fontSizePref.setSummary(fontSizeName); // Ex: "Small".
                    }
                  });
        }
      }
    } catch (JSONException e) {
      Log.e(LOGTAG, "Problem parsing preferences response: ", e);
    }
  }