diff options
| author | John Reck <jreck@google.com> | 2011-01-18 15:26:28 -0800 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-01-18 15:26:28 -0800 |
| commit | a2137d089f004f237c53c97bc780db8669c1bd59 (patch) | |
| tree | c6c9a106a073e275e1ab5f39e9e42673f3667753 /src | |
| parent | a7deb60a5b0b65bb6d66e5e4f71aa86a633b0b79 (diff) | |
| parent | 812d2d690ffa918a6e9f43da0967e43657ef817c (diff) | |
| download | packages_apps_Browser-a2137d089f004f237c53c97bc780db8669c1bd59.tar.gz packages_apps_Browser-a2137d089f004f237c53c97bc780db8669c1bd59.tar.bz2 packages_apps_Browser-a2137d089f004f237c53c97bc780db8669c1bd59.zip | |
Merge "Switch autologin to ListPreference" into honeycomb
Diffstat (limited to 'src')
| -rw-r--r-- | src/com/android/browser/BrowserSettings.java | 25 | ||||
| -rw-r--r-- | src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java | 112 |
2 files changed, 52 insertions, 85 deletions
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index 3393c4fc5..0d3bc482f 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -22,39 +22,28 @@ import com.android.browser.search.SearchEngine; import com.android.browser.search.SearchEngines; import android.app.ActivityManager; -import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; -import android.content.SharedPreferences.OnSharedPreferenceChangeListener; -import android.content.pm.ActivityInfo; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; -import android.database.ContentObserver; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; -import android.os.Handler; import android.os.Message; -import android.preference.PreferenceActivity; import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; import android.provider.Browser; -import android.provider.Settings; import android.util.Log; import android.webkit.CookieManager; import android.webkit.GeolocationPermissions; -import android.webkit.ValueCallback; -import android.webkit.WebView; -import android.webkit.WebViewDatabase; import android.webkit.WebIconDatabase; import android.webkit.WebSettings; import android.webkit.WebSettings.AutoFillProfile; import android.webkit.WebStorage; -import android.widget.Toast; +import android.webkit.WebView; +import android.webkit.WebViewDatabase; import java.util.HashMap; -import java.util.Map; -import java.util.Set; import java.util.Observable; /* @@ -635,6 +624,14 @@ public class BrowserSettings extends Observable implements OnSharedPreferenceCha autoLoginAccount = name; } + public void setAutoLoginEnabled(Context context, boolean enable) { + Editor ed = PreferenceManager. + getDefaultSharedPreferences(context).edit(); + ed.putBoolean(PREF_AUTOLOGIN, enable); + ed.apply(); + autoLoginEnabled = enable; + } + public void setAutoFillProfile(Context ctx, AutoFillProfile profile, Message msg) { if (profile != null) { setActiveAutoFillProfileId(ctx, profile.getUniqueId()); diff --git a/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java b/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java index 20d4f420c..c0cf3cf57 100644 --- a/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java +++ b/src/com/android/browser/preferences/PrivacySecurityPreferencesFragment.java @@ -22,12 +22,9 @@ import com.android.browser.R; import android.accounts.Account; import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.os.Bundle; -import android.preference.CheckBoxPreference; +import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceFragment; @@ -47,19 +44,40 @@ public class PrivacySecurityPreferencesFragment extends PreferenceFragment Preference e = findPreference(BrowserSettings.PREF_CLEAR_HISTORY); e.setOnPreferenceChangeListener(this); - e = findPreference(BrowserSettings.PREF_AUTOLOGIN); - e.setOnPreferenceChangeListener(this); - updateAutoLoginSummary((CheckBoxPreference) e); + setupAutoLoginPreference(); + } + + void setupAutoLoginPreference() { + ListPreference autologinPref = (ListPreference) findPreference( + BrowserSettings.PREF_AUTOLOGIN_ACCOUNT); + autologinPref.setOnPreferenceChangeListener(this); + updateAutoLoginSummary(autologinPref); + Account[] accounts = GoogleAccountLogin.getAccounts(getActivity()); + // +1 for disable + CharSequence[] names = new CharSequence[accounts.length + 1]; + CharSequence[] values = new CharSequence[names.length]; + int i = 0; + int defaultAccount = 0; + for (Account a : accounts) { + values[i] = names[i] = a.name; + i++; + } + names[i] = getResources().getString(R.string.pref_autologin_disable); + values[i] = ""; + autologinPref.setEntries(names); + autologinPref.setEntryValues(values); } - private void updateAutoLoginSummary(CheckBoxPreference pref) { - String account = mSettings.getAutoLoginAccount(getActivity()); - if (account == null) { - pref.setChecked(false); - pref.setEnabled(false); - pref.setSummary(R.string.pref_autologin_no_account); + private void updateAutoLoginSummary(Preference pref) { + if (!mSettings.isAutoLoginEnabled()) { + pref.setSummary(R.string.pref_autologin_disable); } else { - pref.setSummary(getString(R.string.pref_autologin_summary, account)); + String account = mSettings.getAutoLoginAccount(getActivity()); + if (account == null) { + pref.setSummary(R.string.pref_autologin_no_account); + } else { + pref.setSummary(getString(R.string.pref_autologin_summary, account)); + } } } @@ -72,68 +90,20 @@ public class PrivacySecurityPreferencesFragment extends PreferenceFragment getActivity().setResult(Activity.RESULT_OK, (new Intent()).putExtra(Intent.EXTRA_TEXT, pref.getKey())); return true; - } else if (pref.getKey().equals(BrowserSettings.PREF_AUTOLOGIN)) { - boolean val = ((Boolean) objValue).booleanValue(); - if (val) { - selectAccount((CheckBoxPreference) pref); - return false; + } else if (pref.getKey().equals(BrowserSettings.PREF_AUTOLOGIN_ACCOUNT)) { + String account = (String) objValue; + if (account.length() == 0) { + // Disable + mSettings.setAutoLoginEnabled(getActivity(), false); + } else { + mSettings.setAutoLoginEnabled(getActivity(), true); } + mSettings.setAutoLoginAccount(getActivity(), account); + updateAutoLoginSummary(pref); return true; } return false; } - class AccountCallback implements OnClickListener { - private final Account[] mAccounts; - private final CheckBoxPreference mPref; - - public AccountCallback(Account[] accounts, CheckBoxPreference pref) { - mAccounts = accounts; - mPref = pref; - } - - public void onClick(DialogInterface d, int which) { - saveAutoLoginAccount(mPref, mAccounts[which].name); - d.dismiss(); - } - } - - private void saveAutoLoginAccount(CheckBoxPreference pref, String name) { - mSettings.setAutoLoginAccount(getActivity(), name); - pref.setChecked(true); - updateAutoLoginSummary(pref); - } - - private void selectAccount(CheckBoxPreference pref) { - Account[] accounts = GoogleAccountLogin.getAccounts(getActivity()); - if (accounts.length == 0) { - mSettings.setAutoLoginAccount(getActivity(), null); - updateAutoLoginSummary(pref); - return; - } else if (accounts.length == 1) { - // No need for a dialog with one account. - saveAutoLoginAccount(pref, accounts[0].name); - return; - } - - String account = mSettings.getAutoLoginAccount(getActivity()); - CharSequence[] names = new CharSequence[accounts.length]; - int i = 0; - int defaultAccount = 0; - for (Account a : accounts) { - if (a.name.equals(account)) { - defaultAccount = i; - } - names[i++] = a.name; - } - - AccountCallback callback = - new AccountCallback(accounts, pref); - new AlertDialog.Builder(getActivity()) - .setTitle(R.string.pref_autologin_title) - .setSingleChoiceItems(names, defaultAccount, callback) - .setCancelable(true) - .show(); - } } |
