2011-11-18 10:28:17 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-11-13 09:47:05 -08:00
|
|
|
import org.mozilla.gecko.background.announcements.AnnouncementsConstants;
|
2012-08-02 17:13:40 -07:00
|
|
|
import org.mozilla.gecko.util.GeckoEventListener;
|
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONObject;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-21 13:08:01 -08:00
|
|
|
import android.app.AlertDialog;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.app.Dialog;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.content.Context;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.content.DialogInterface;
|
2012-10-11 10:10:49 -07:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2012-11-02 12:31:02 -07:00
|
|
|
import android.os.Build;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.os.Bundle;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.preference.CheckBoxPreference;
|
|
|
|
import android.preference.EditTextPreference;
|
|
|
|
import android.preference.ListPreference;
|
|
|
|
import android.preference.Preference;
|
|
|
|
import android.preference.Preference.OnPreferenceChangeListener;
|
|
|
|
import android.preference.PreferenceActivity;
|
|
|
|
import android.preference.PreferenceGroup;
|
2012-10-11 10:10:49 -07:00
|
|
|
import android.preference.PreferenceManager;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.preference.PreferenceScreen;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.text.Editable;
|
2011-12-21 13:08:01 -08:00
|
|
|
import android.text.InputType;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.util.Log;
|
2011-11-23 11:04:47 -08:00
|
|
|
import android.view.MenuItem;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.view.View;
|
2011-12-21 13:08:01 -08:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.LinearLayout;
|
2012-06-26 23:15:24 -07:00
|
|
|
import android.widget.Toast;
|
2011-12-01 17:27:11 -08:00
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import java.util.ArrayList;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public class GeckoPreferences
|
2011-11-18 10:28:17 -08:00
|
|
|
extends PreferenceActivity
|
2013-01-29 13:59:42 -08:00
|
|
|
implements OnPreferenceChangeListener, GeckoEventListener, GeckoActivityStatus
|
2011-11-18 10:28:17 -08:00
|
|
|
{
|
|
|
|
private static final String LOGTAG = "GeckoPreferences";
|
|
|
|
|
2012-02-14 16:20:07 -08:00
|
|
|
private ArrayList<String> mPreferencesList;
|
2011-11-18 10:28:17 -08:00
|
|
|
private PreferenceScreen mPreferenceScreen;
|
2012-01-23 13:47:48 -08:00
|
|
|
private static boolean sIsCharEncodingEnabled = false;
|
2012-06-26 23:15:24 -07:00
|
|
|
private static final String NON_PREF_PREFIX = "android.not_a_preference.";
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-10-04 12:05:05 -07:00
|
|
|
// These match keys in resources/xml/preferences.xml.in.
|
|
|
|
public static String PREFS_MP_ENABLED = "privacy.masterpassword.enabled";
|
|
|
|
public static String PREFS_MENU_CHAR_ENCODING = "browser.menu.showCharacterEncoding";
|
2012-10-11 10:10:49 -07:00
|
|
|
public static String PREFS_ANNOUNCEMENTS_ENABLED = NON_PREF_PREFIX + "privacy.announcements.enabled";
|
2012-10-15 06:56:42 -07:00
|
|
|
public static String PREFS_UPDATER_AUTODOWNLOAD = "app.update.autodownload";
|
2012-10-04 12:05:05 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
2012-08-02 18:38:45 -07:00
|
|
|
registerEventListener("Sanitize:Finished");
|
2012-11-02 12:31:02 -07:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 14)
|
|
|
|
getActionBar().setHomeButtonEnabled(true);
|
2012-09-17 11:22:28 -07:00
|
|
|
}
|
2012-02-14 16:20:07 -08:00
|
|
|
|
2012-09-17 11:22:28 -07:00
|
|
|
@Override
|
|
|
|
public void onWindowFocusChanged(boolean hasFocus) {
|
2012-02-14 16:20:07 -08:00
|
|
|
if (!hasFocus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mPreferencesList = new ArrayList<String>();
|
|
|
|
mPreferenceScreen = getPreferenceScreen();
|
2011-11-18 10:28:17 -08:00
|
|
|
initGroups(mPreferenceScreen);
|
2011-12-01 17:27:11 -08:00
|
|
|
initValues();
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-01 17:27:11 -08:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
2012-08-02 18:38:45 -07:00
|
|
|
unregisterEventListener("Sanitize:Finished");
|
2011-12-01 17:27:11 -08:00
|
|
|
}
|
|
|
|
|
2013-01-29 13:59:42 -08:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
|
|
|
|
if (getApplication() instanceof GeckoApplication) {
|
|
|
|
((GeckoApplication) getApplication()).onActivityPause(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
if (getApplication() instanceof GeckoApplication) {
|
|
|
|
((GeckoApplication) getApplication()).onActivityResume(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-01 17:27:11 -08:00
|
|
|
public void handleMessage(String event, JSONObject message) {
|
|
|
|
try {
|
2012-09-17 11:22:28 -07:00
|
|
|
if (event.equals("Sanitize:Finished")) {
|
2012-06-26 23:15:24 -07:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2011-12-01 17:27:11 -08:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
private void initGroups(PreferenceGroup preferences) {
|
|
|
|
final int count = preferences.getPreferenceCount();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
Preference pref = preferences.getPreference(i);
|
|
|
|
if (pref instanceof PreferenceGroup)
|
|
|
|
initGroups((PreferenceGroup)pref);
|
|
|
|
else {
|
|
|
|
pref.setOnPreferenceChangeListener(this);
|
2012-06-26 23:15:24 -07:00
|
|
|
|
|
|
|
// Some Preference UI elements are not actually preferences,
|
|
|
|
// but they require a key to work correctly. For example,
|
|
|
|
// "Clear private data" requires a key for its state to be
|
|
|
|
// saved when the orientation changes. It uses the
|
|
|
|
// "android.not_a_preference.privacy.clear" key - which doesn't
|
|
|
|
// exist in Gecko - to satisfy this requirement.
|
|
|
|
String key = pref.getKey();
|
2012-07-19 18:08:40 -07:00
|
|
|
if (key != null && !key.startsWith(NON_PREF_PREFIX)) {
|
2012-04-25 16:31:14 -07:00
|
|
|
mPreferencesList.add(pref.getKey());
|
2012-07-19 18:08:40 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-08 09:37:57 -08:00
|
|
|
|
2011-11-23 11:04:47 -08:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-21 13:08:01 -08:00
|
|
|
final private int DIALOG_CREATE_MASTER_PASSWORD = 0;
|
|
|
|
final private int DIALOG_REMOVE_MASTER_PASSWORD = 1;
|
|
|
|
|
2012-01-23 13:47:48 -08:00
|
|
|
public static void setCharEncodingState(boolean enabled) {
|
|
|
|
sIsCharEncodingEnabled = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean getCharEncodingState() {
|
|
|
|
return sIsCharEncodingEnabled;
|
|
|
|
}
|
|
|
|
|
2012-10-11 10:10:49 -07:00
|
|
|
/**
|
|
|
|
* Broadcast an intent with <code>pref</code>, <code>branch</code>, and
|
|
|
|
* <code>enabled</code> extras. This is intended to represent the
|
|
|
|
* notification of a preference value to observers.
|
|
|
|
*/
|
|
|
|
public static void broadcastPrefAction(final Context context,
|
|
|
|
final String action,
|
|
|
|
final String pref,
|
|
|
|
final boolean value) {
|
|
|
|
final Intent intent = new Intent(action);
|
|
|
|
intent.setAction(action);
|
|
|
|
intent.putExtra("pref", pref);
|
|
|
|
intent.putExtra("branch", GeckoApp.PREFS_NAME);
|
|
|
|
intent.putExtra("enabled", value);
|
|
|
|
Log.d(LOGTAG, "Broadcast: " + action + ", " + pref + ", " + GeckoApp.PREFS_NAME + ", " + value);
|
|
|
|
context.sendBroadcast(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Broadcast the provided value as the value of the
|
|
|
|
* <code>PREFS_ANNOUNCEMENTS_ENABLED</code> pref.
|
|
|
|
*/
|
|
|
|
public static void broadcastAnnouncementsPref(final Context context, final boolean value) {
|
|
|
|
broadcastPrefAction(context,
|
2012-11-13 09:47:05 -08:00
|
|
|
AnnouncementsConstants.ACTION_ANNOUNCEMENTS_PREF,
|
2012-10-11 10:10:49 -07:00
|
|
|
PREFS_ANNOUNCEMENTS_ENABLED,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Broadcast the current value of the
|
|
|
|
* <code>PREFS_ANNOUNCEMENTS_ENABLED</code> pref.
|
|
|
|
*/
|
|
|
|
public static void broadcastAnnouncementsPref(final Context context) {
|
2012-11-13 09:47:05 -08:00
|
|
|
final boolean value = getBooleanPref(context, PREFS_ANNOUNCEMENTS_ENABLED, true);
|
|
|
|
broadcastAnnouncementsPref(context, value);
|
2012-10-11 10:10:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the value of the named preference in the default preferences file.
|
|
|
|
*
|
|
|
|
* This corresponds to the storage that backs preferences.xml.
|
|
|
|
* @param context a <code>Context</code>; the
|
|
|
|
* <code>PreferenceActivity</code> will suffice, but this
|
|
|
|
* method is intended to be called from other contexts
|
|
|
|
* within the application, not just this <code>Activity</code>.
|
|
|
|
* @param name the name of the preference to retrieve.
|
|
|
|
* @param def the default value to return if the preference is not present.
|
|
|
|
* @return the value of the preference, or the default.
|
|
|
|
*/
|
|
|
|
public static boolean getBooleanPref(final Context context, final String name, boolean def) {
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
return prefs.getBoolean(name, def);
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
String prefName = preference.getKey();
|
2012-10-04 12:05:05 -07:00
|
|
|
if (prefName != null && prefName.equals(PREFS_MP_ENABLED)) {
|
|
|
|
showDialog((Boolean) newValue ? DIALOG_CREATE_MASTER_PASSWORD : DIALOG_REMOVE_MASTER_PASSWORD);
|
2011-12-21 13:08:01 -08:00
|
|
|
return false;
|
2012-10-04 12:05:05 -07:00
|
|
|
} else if (prefName != null && prefName.equals(PREFS_MENU_CHAR_ENCODING)) {
|
2012-01-23 13:47:48 -08:00
|
|
|
setCharEncodingState(((String) newValue).equals("true"));
|
2012-10-11 10:10:49 -07:00
|
|
|
} else if (prefName != null && prefName.equals(PREFS_ANNOUNCEMENTS_ENABLED)) {
|
|
|
|
// Send a broadcast intent to the product announcements service, either to start or
|
|
|
|
// to stop the repeated background checks.
|
|
|
|
broadcastAnnouncementsPref(GeckoApp.mAppContext, ((Boolean) newValue).booleanValue());
|
2012-10-15 06:56:42 -07:00
|
|
|
} else if (prefName != null && prefName.equals(PREFS_UPDATER_AUTODOWNLOAD)) {
|
|
|
|
org.mozilla.gecko.updater.UpdateServiceHelper.registerForUpdates(GeckoApp.mAppContext, (String)newValue);
|
2011-12-21 13:08:01 -08:00
|
|
|
}
|
|
|
|
|
2012-09-17 11:22:28 -07:00
|
|
|
if (!TextUtils.isEmpty(prefName)) {
|
|
|
|
PrefsHelper.setPref(prefName, newValue);
|
|
|
|
}
|
2011-12-13 14:28:45 -08:00
|
|
|
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);
|
2012-07-19 18:08:40 -07:00
|
|
|
} else if (preference instanceof LinkPreference) {
|
2011-12-08 09:37:57 -08:00
|
|
|
finish();
|
2012-07-19 18:08:40 -07:00
|
|
|
} else if (preference instanceof FontSizePreference) {
|
|
|
|
final FontSizePreference fontSizePref = (FontSizePreference) preference;
|
|
|
|
fontSizePref.setSummary(fontSizePref.getSavedFontSizeName());
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-12-21 13:08:01 -08:00
|
|
|
private EditText getTextBox(int aHintText) {
|
|
|
|
EditText input = new EditText(GeckoApp.mAppContext);
|
|
|
|
int inputtype = InputType.TYPE_CLASS_TEXT;
|
|
|
|
inputtype |= InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
|
|
|
|
input.setInputType(inputtype);
|
|
|
|
|
|
|
|
String hint = getResources().getString(aHintText);
|
|
|
|
input.setHint(aHintText);
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
private class PasswordTextWatcher implements TextWatcher {
|
2011-12-21 13:08:01 -08:00
|
|
|
EditText input1 = null;
|
|
|
|
EditText input2 = null;
|
2012-01-03 15:53:29 -08:00
|
|
|
AlertDialog dialog = null;
|
2011-12-21 13:08:01 -08:00
|
|
|
|
2012-01-03 15:53:29 -08:00
|
|
|
PasswordTextWatcher(EditText aInput1, EditText aInput2, AlertDialog aDialog) {
|
2011-12-21 13:08:01 -08:00
|
|
|
input1 = aInput1;
|
|
|
|
input2 = aInput2;
|
2012-01-03 15:53:29 -08:00
|
|
|
dialog = aDialog;
|
2011-12-21 13:08:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void afterTextChanged(Editable s) {
|
2012-01-03 15:53:29 -08:00
|
|
|
if (dialog == null)
|
2011-12-21 13:08:01 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
String text1 = input1.getText().toString();
|
|
|
|
String text2 = input2.getText().toString();
|
2012-01-18 08:50:11 -08:00
|
|
|
boolean disabled = TextUtils.isEmpty(text1) || TextUtils.isEmpty(text2) || !text1.equals(text2);
|
|
|
|
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(!disabled);
|
2011-12-21 13:08:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) { }
|
|
|
|
}
|
|
|
|
|
2012-12-03 12:22:05 -08:00
|
|
|
private class EmptyTextWatcher implements TextWatcher {
|
|
|
|
EditText input = null;
|
|
|
|
AlertDialog dialog = null;
|
|
|
|
|
|
|
|
EmptyTextWatcher(EditText aInput, AlertDialog aDialog) {
|
|
|
|
input = aInput;
|
|
|
|
dialog = aDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
if (dialog == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
String text = input.getText().toString();
|
|
|
|
boolean disabled = TextUtils.isEmpty(text);
|
|
|
|
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(!disabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) { }
|
|
|
|
}
|
|
|
|
|
2011-12-21 13:08:01 -08:00
|
|
|
protected Dialog onCreateDialog(int id) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
LinearLayout linearLayout = new LinearLayout(this);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
2012-01-03 15:53:29 -08:00
|
|
|
AlertDialog dialog = null;
|
2011-12-21 13:08:01 -08:00
|
|
|
switch(id) {
|
|
|
|
case DIALOG_CREATE_MASTER_PASSWORD:
|
|
|
|
final EditText input1 = getTextBox(R.string.masterpassword_password);
|
|
|
|
final EditText input2 = getTextBox(R.string.masterpassword_confirm);
|
|
|
|
linearLayout.addView(input1);
|
|
|
|
linearLayout.addView(input2);
|
|
|
|
|
|
|
|
builder.setTitle(R.string.masterpassword_create_title)
|
|
|
|
.setView((View)linearLayout)
|
|
|
|
.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
JSONObject jsonPref = new JSONObject();
|
|
|
|
try {
|
2012-10-04 12:05:05 -07:00
|
|
|
jsonPref.put("name", PREFS_MP_ENABLED);
|
2011-12-21 13:08:01 -08:00
|
|
|
jsonPref.put("type", "string");
|
|
|
|
jsonPref.put("value", input1.getText().toString());
|
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent event = GeckoEvent.createBroadcastEvent("Preferences:Set", jsonPref.toString());
|
2011-12-21 13:08:01 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(event);
|
|
|
|
} catch(Exception ex) {
|
2012-10-04 12:05:05 -07:00
|
|
|
Log.e(LOGTAG, "Error setting master password", ex);
|
2011-12-21 13:08:01 -08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2012-01-03 15:53:29 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialog = builder.create();
|
2012-01-18 08:50:11 -08:00
|
|
|
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
|
|
|
public void onShow(DialogInterface dialog) {
|
2011-12-21 13:08:01 -08:00
|
|
|
input1.setText("");
|
|
|
|
input2.setText("");
|
2012-01-03 15:53:29 -08:00
|
|
|
input1.requestFocus();
|
2011-12-21 13:08:01 -08:00
|
|
|
}
|
|
|
|
});
|
2012-01-03 15:53:29 -08:00
|
|
|
|
|
|
|
PasswordTextWatcher watcher = new PasswordTextWatcher(input1, input2, dialog);
|
|
|
|
input1.addTextChangedListener((TextWatcher)watcher);
|
|
|
|
input2.addTextChangedListener((TextWatcher)watcher);
|
|
|
|
|
2011-12-21 13:08:01 -08:00
|
|
|
break;
|
|
|
|
case DIALOG_REMOVE_MASTER_PASSWORD:
|
|
|
|
final EditText input = getTextBox(R.string.masterpassword_password);
|
|
|
|
linearLayout.addView(input);
|
|
|
|
|
|
|
|
builder.setTitle(R.string.masterpassword_remove_title)
|
|
|
|
.setView((View)linearLayout)
|
|
|
|
.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2012-10-04 12:05:05 -07:00
|
|
|
PrefsHelper.setPref(PREFS_MP_ENABLED, input.getText().toString());
|
2011-12-21 13:08:01 -08:00
|
|
|
}
|
|
|
|
})
|
2012-01-03 15:53:29 -08:00
|
|
|
.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
|
2011-12-21 13:08:01 -08:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
2012-01-03 15:53:29 -08:00
|
|
|
dialog = builder.create();
|
|
|
|
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
input.setText("");
|
|
|
|
}
|
|
|
|
});
|
2012-12-03 12:22:05 -08:00
|
|
|
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
|
|
|
public void onShow(DialogInterface dialog) {
|
|
|
|
input.setText("");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
input.addTextChangedListener(new EmptyTextWatcher(input, dialog));
|
2011-12-21 13:08:01 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
2012-01-03 15:53:29 -08:00
|
|
|
|
|
|
|
return dialog;
|
2011-12-21 13:08:01 -08:00
|
|
|
}
|
|
|
|
|
2012-09-17 11:22:28 -07:00
|
|
|
// Initialize preferences by requesting the preference values from Gecko
|
|
|
|
private void initValues() {
|
|
|
|
JSONArray jsonPrefs = new JSONArray(mPreferencesList);
|
|
|
|
PrefsHelper.getPrefs(jsonPrefs, new PrefsHelper.PrefHandlerBase() {
|
|
|
|
private Preference getField(String prefName) {
|
|
|
|
return (mPreferenceScreen == null ? null : mPreferenceScreen.findPreference(prefName));
|
2011-12-01 17:27:11 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-09-17 11:22:28 -07:00
|
|
|
@Override public void prefValue(String prefName, final boolean value) {
|
|
|
|
final Preference pref = getField(prefName);
|
|
|
|
if (pref instanceof CheckBoxPreference) {
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.getMainHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (((CheckBoxPreference)pref).isChecked() != value)
|
|
|
|
((CheckBoxPreference)pref).setChecked(value);
|
|
|
|
}
|
|
|
|
});
|
2012-09-17 11:22:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override public void prefValue(String prefName, final String value) {
|
|
|
|
final Preference pref = getField(prefName);
|
|
|
|
if (pref instanceof EditTextPreference) {
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.getMainHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
((EditTextPreference)pref).setText(value);
|
|
|
|
}
|
|
|
|
});
|
2012-09-17 11:22:28 -07:00
|
|
|
} else if (pref instanceof ListPreference) {
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.getMainHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
((ListPreference)pref).setValue(value);
|
2011-12-13 14:28:45 -08:00
|
|
|
// Set the summary string to the current entry
|
|
|
|
CharSequence selectedEntry = ((ListPreference)pref).getEntry();
|
|
|
|
((ListPreference)pref).setSummary(selectedEntry);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
2012-07-19 18:08:40 -07:00
|
|
|
} else if (pref instanceof FontSizePreference) {
|
2012-07-19 18:08:40 -07:00
|
|
|
final FontSizePreference fontSizePref = (FontSizePreference) pref;
|
2012-09-17 11:22:28 -07:00
|
|
|
fontSizePref.setSavedFontSize(value);
|
2012-07-19 18:08:40 -07:00
|
|
|
final String fontSizeName = fontSizePref.getSavedFontSizeName();
|
|
|
|
GeckoAppShell.getMainHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
2012-07-19 18:08:40 -07:00
|
|
|
fontSizePref.setSummary(fontSizeName); // Ex: "Small".
|
2012-07-19 18:08:40 -07:00
|
|
|
}
|
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
2011-12-14 13:36:27 -08:00
|
|
|
|
2012-09-17 11:22:28 -07:00
|
|
|
@Override public void finish() {
|
|
|
|
// enable all preferences once we have them from gecko
|
|
|
|
GeckoAppShell.getMainHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mPreferenceScreen.setEnabled(true);
|
|
|
|
}
|
|
|
|
});
|
2011-12-01 17:27:11 -08:00
|
|
|
}
|
2012-09-17 11:22:28 -07:00
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-08-02 18:38:45 -07:00
|
|
|
|
|
|
|
private void registerEventListener(String event) {
|
|
|
|
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void unregisterEventListener(String event) {
|
|
|
|
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
|
|
|
|
}
|
2013-01-29 13:59:42 -08:00
|
|
|
|
|
|
|
public boolean isGeckoActivityOpened() {
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|