diff options
author | Lifu Tang <lifu@google.com> | 2013-08-16 12:44:54 -0700 |
---|---|---|
committer | Lifu Tang <lifu@google.com> | 2013-08-19 18:42:56 -0700 |
commit | d3dbc6e3a187b9de69b83915400425032d287dec (patch) | |
tree | d6f33e89be625a55f79802a103d757e00be47287 /src | |
parent | b9ab196bb520fed9b23aa9a259fab08084646c2c (diff) | |
download | packages_apps_Settings-d3dbc6e3a187b9de69b83915400425032d287dec.zip packages_apps_Settings-d3dbc6e3a187b9de69b83915400425032d287dec.tar.gz packages_apps_Settings-d3dbc6e3a187b9de69b83915400425032d287dec.tar.bz2 |
Launches the Location setting as fragment
Change-Id: I0fb04a346236676ce9483a0c4d1fc3b2b590b08c
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/accounts/ManageAccountsSettings.java | 78 |
1 files changed, 62 insertions, 16 deletions
diff --git a/src/com/android/settings/accounts/ManageAccountsSettings.java b/src/com/android/settings/accounts/ManageAccountsSettings.java index 8a093ca..a7f0f30 100644 --- a/src/com/android/settings/accounts/ManageAccountsSettings.java +++ b/src/com/android/settings/accounts/ManageAccountsSettings.java @@ -21,10 +21,7 @@ import android.accounts.AccountManager; import android.accounts.OnAccountsUpdateListener; import android.app.ActionBar; import android.app.Activity; -import android.app.ActivityManager; -import android.app.ActivityManagerNative; import android.content.ContentResolver; -import android.content.Context; import android.content.Intent; import android.content.SyncAdapterType; import android.content.SyncInfo; @@ -36,29 +33,26 @@ import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; -import android.text.format.DateFormat; import android.util.Log; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.CompoundButton; import android.widget.ListView; -import android.widget.Switch; import android.widget.TextView; import com.android.settings.AccountPreference; import com.android.settings.R; -import com.android.settings.Settings; import com.android.settings.Utils; +import com.android.settings.location.LocationSettings; import java.util.ArrayList; import java.util.Date; import java.util.HashSet; +/** Manages settings for Google Account. */ public class ManageAccountsSettings extends AccountPreferenceBase implements OnAccountsUpdateListener { @@ -74,7 +68,6 @@ public class ManageAccountsSettings extends AccountPreferenceBase private String[] mAuthorities; private TextView mErrorInfoView; - private SettingsDialogFragment mDialogFragment; // If an account type is set, then show only accounts of that type private String mAccountType; // Temporary hack, to deal with backward compatibility @@ -354,18 +347,71 @@ public class ManageAccountsSettings extends AccountPreferenceBase } } + /** Listens to a preference click event and starts a fragment */ + private class FragmentStarter + implements Preference.OnPreferenceClickListener { + private final String mClass; + private final int mTitleRes; + + /** + * @param className the class name of the fragment to be started. + * @param title the title resource id of the started preference panel. + */ + public FragmentStarter(String className, int title) { + mClass = className; + mTitleRes = title; + } + + @Override + public boolean onPreferenceClick(Preference preference) { + ((PreferenceActivity) getActivity()).startPreferencePanel( + mClass, null, mTitleRes, null, null, 0); + return true; + } + } + + /** + * Filters through the preference list provided by GoogleLoginService. + * + * This method removes all the invalid intent from the list, adds account name as extra into the + * intent, and hack the location settings to start it as a fragment. + */ private void updatePreferenceIntents(PreferenceScreen prefs) { PackageManager pm = getActivity().getPackageManager(); for (int i = 0; i < prefs.getPreferenceCount();) { - Intent intent = prefs.getPreference(i).getIntent(); + Preference pref = prefs.getPreference(i); + Intent intent = pref.getIntent(); if (intent != null) { - ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); - if (ri == null) { - prefs.removePreference(prefs.getPreference(i)); - continue; + // Hack. Launch "Location" as fragment instead of as activity. + // + // When "Location" is launched as activity via Intent, there's no "Up" button at the + // top left, and if there's another running instance of "Location" activity, the + // back stack would usually point to some other place so the user won't be able to + // go back to the previous page by "back" key. Using fragment is a much easier + // solution to those problems. + // + // If we set Intent to null and assign a fragment to the PreferenceScreen item here, + // in order to make it work as expected, we still need to modify the container + // PreferenceActivity, override onPreferenceStartFragment() and call + // startPreferencePanel() there. In order to inject the title string there, more + // dirty further hack is still needed. It's much easier and cleaner to listen to + // preference click event here directly. + if (intent.getAction().equals( + android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)) { + // The OnPreferenceClickListener overrides the click event completely. No intent + // will get fired. + pref.setOnPreferenceClickListener(new FragmentStarter( + LocationSettings.class.getName(), + R.string.location_settings_title)); } else { - intent.putExtra(ACCOUNT_KEY, mFirstAccount); - intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); + ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); + if (ri == null) { + prefs.removePreference(pref); + continue; + } else { + intent.putExtra(ACCOUNT_KEY, mFirstAccount); + intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); + } } } i++; |