コード例 #1
0
  // send the Preferences:Set message to Gecko
  public static void setPreference(String pref, Object value) {
    if (pref == null || pref.length() == 0) return;

    try {
      JSONObject jsonPref = new JSONObject();
      jsonPref.put("name", pref);
      if (value instanceof Boolean) {
        jsonPref.put("type", "bool");
        jsonPref.put("value", ((Boolean) value).booleanValue());
      } else if (value instanceof Integer) {
        jsonPref.put("type", "int");
        jsonPref.put("value", ((Integer) value).intValue());
      } else {
        jsonPref.put("type", "string");
        jsonPref.put("value", String.valueOf(value));
      }

      GeckoEvent event = GeckoEvent.createBroadcastEvent("Preferences:Set", jsonPref.toString());
      GeckoAppShell.sendEventToGecko(event);
    } catch (JSONException e) {
      Log.e(LOGTAG, "JSON exception: ", e);
    }
  }
コード例 #2
0
  // Initialize preferences by sending the "Preferences:Get" command to Gecko
  private void initValues() {
    JSONArray jsonPrefs = new JSONArray(mPreferencesList);

    GeckoEvent event = GeckoEvent.createBroadcastEvent("Preferences:Get", jsonPrefs.toString());
    GeckoAppShell.sendEventToGecko(event);
  }