@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String prefName = preference.getKey(); if (prefName != null && prefName.equals("privacy.masterpassword.enabled")) { showDialog( (Boolean) newValue ? DIALOG_CREATE_MASTER_PASSWORD : DIALOG_REMOVE_MASTER_PASSWORD); return false; } else if (prefName != null && prefName.equals("browser.menu.showCharacterEncoding")) { setCharEncodingState(((String) newValue).equals("true")); } setPreference(prefName, newValue); if (preference instanceof ListPreference) { // We need to find the entry for the new value int newIndex = ((ListPreference) preference).findIndexOfValue((String) newValue); CharSequence newEntry = ((ListPreference) preference).getEntries()[newIndex]; ((ListPreference) preference).setSummary(newEntry); } else if (preference instanceof LinkPreference) { finish(); } else if (preference instanceof FontSizePreference) { final FontSizePreference fontSizePref = (FontSizePreference) preference; fontSizePref.setSummary(fontSizePref.getSavedFontSizeName()); } return true; }
@Override public void handleMessage(String event, JSONObject message) { try { if (event.equals("Menu:Add")) { MenuItemInfo info = new MenuItemInfo(); info.label = message.getString("name"); info.id = message.getInt("id") + ADDON_MENU_OFFSET; info.checkable = false; info.checked = false; info.enabled = true; info.visible = true; String iconRes = null; try { // icon is optional iconRes = message.getString("icon"); } catch (Exception ex) { } info.icon = iconRes; info.checkable = false; try { info.checkable = message.getBoolean("checkable"); } catch (Exception ex) { } try { // parent is optional info.parent = message.getInt("parent") + ADDON_MENU_OFFSET; } catch (Exception ex) { } final MenuItemInfo menuItemInfo = info; mMainHandler.post( new Runnable() { public void run() { addAddonMenuItem(menuItemInfo); } }); } else if (event.equals("Menu:Remove")) { final int id = message.getInt("id") + ADDON_MENU_OFFSET; mMainHandler.post( new Runnable() { public void run() { removeAddonMenuItem(id); } }); } else if (event.equals("Menu:Update")) { final int id = message.getInt("id") + ADDON_MENU_OFFSET; final JSONObject options = message.getJSONObject("options"); mMainHandler.post( new Runnable() { public void run() { updateAddonMenuItem(id, options); } }); } else if (event.equals("CharEncoding:Data")) { final JSONArray charsets = message.getJSONArray("charsets"); int selected = message.getInt("selected"); final int len = charsets.length(); final String[] titleArray = new String[len]; for (int i = 0; i < len; i++) { JSONObject charset = charsets.getJSONObject(i); titleArray[i] = charset.getString("title"); } final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setSingleChoiceItems( titleArray, selected, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { try { JSONObject charset = charsets.getJSONObject(which); GeckoAppShell.sendEventToGecko( GeckoEvent.createBroadcastEvent( "CharEncoding:Set", charset.getString("code"))); dialog.dismiss(); } catch (JSONException e) { Log.e(LOGTAG, "error parsing json", e); } } }); dialogBuilder.setNegativeButton( R.string.button_cancel, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); mMainHandler.post( new Runnable() { public void run() { dialogBuilder.show(); } }); } else if (event.equals("CharEncoding:State")) { final boolean visible = message.getString("visible").equals("true"); GeckoPreferences.setCharEncodingState(visible); final Menu menu = mMenu; mMainHandler.post( new Runnable() { public void run() { if (menu != null) menu.findItem(R.id.char_encoding).setVisible(visible); } }); } else if (event.equals("Feedback:OpenPlayStore")) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=" + getPackageName())); startActivity(intent); } else if (event.equals("Feedback:MaybeLater")) { resetFeedbackLaunchCount(); } else if (event.equals("Feedback:LastUrl")) { getLastUrl(); } else if (event.equals("Gecko:Ready")) { // Handle this message in GeckoApp, but also enable the Settings // menuitem, which is specific to BrowserApp. super.handleMessage(event, message); final Menu menu = mMenu; mMainHandler.post( new Runnable() { public void run() { if (menu != null) menu.findItem(R.id.settings).setEnabled(true); } }); } else if (event.equals("Telemetry:Gather")) { Telemetry.HistogramAdd( "PLACES_PAGES_COUNT", BrowserDB.getCount(getContentResolver(), "history")); Telemetry.HistogramAdd( "PLACES_BOOKMARKS_COUNT", BrowserDB.getCount(getContentResolver(), "bookmarks")); Telemetry.HistogramAdd( "FENNEC_FAVICONS_COUNT", BrowserDB.getCount(getContentResolver(), "favicons")); Telemetry.HistogramAdd( "FENNEC_THUMBNAILS_COUNT", BrowserDB.getCount(getContentResolver(), "thumbnails")); } else if (event.equals("Dex:Load")) { String zipFile = message.getString("zipfile"); String implClass = message.getString("impl"); Log.d( LOGTAG, "Attempting to load classes.dex file from " + zipFile + " and instantiate " + implClass); try { File tmpDir = getDir("dex", 0); DexClassLoader loader = new DexClassLoader( zipFile, tmpDir.getAbsolutePath(), null, ClassLoader.getSystemClassLoader()); Class<?> c = loader.loadClass(implClass); c.newInstance(); } catch (Exception e) { Log.e(LOGTAG, "Unable to initialize addon", e); } } else { super.handleMessage(event, message); } } catch (Exception e) { Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e); } }