From e0d934fcb1f6e82c813f74cf5ea10d4d734e63d3 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Tue, 1 Oct 2013 12:32:27 -0700 Subject: [PATCH] Back out of Home settings when penultimate home app is uninstalled When the user deletes the last-but-one, there's nothing more that they can do in Home settings (and we'll be suppressing it from the top level of the Settings UI as well), so we now back out with a dialog explaining the situation. Bug 10918801 Change-Id: Id03169dace976f7de639e3b3ab3d50ed161258d8 --- res/values/strings.xml | 2 + src/com/android/settings/HomeSettings.java | 18 ++++++++ src/com/android/settings/Settings.java | 49 ++++++++++++++++++---- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 9c5d0398b21..960f1c90db3 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4768,6 +4768,8 @@ Uninstall this application + + Home settings will be hidden until you install another home application. This setting affects all users on this tablet. diff --git a/src/com/android/settings/HomeSettings.java b/src/com/android/settings/HomeSettings.java index bac94d69e3a..14e1d9fe367 100644 --- a/src/com/android/settings/HomeSettings.java +++ b/src/com/android/settings/HomeSettings.java @@ -23,6 +23,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; @@ -50,6 +51,8 @@ public class HomeSettings extends SettingsPreferenceFragment { public static final String CURRENT_HOME = "current_home"; + public static final String HOME_SHOW_NOTICE = "show"; + PreferenceGroup mPrefGroup; PackageManager mPm; @@ -57,6 +60,7 @@ public class HomeSettings extends SettingsPreferenceFragment { ArrayList mPrefs; HomeAppPreference mCurrentHome = null; final IntentFilter mHomeFilter; + boolean mShowNotice; public HomeSettings() { mHomeFilter = new IntentFilter(Intent.ACTION_MAIN); @@ -126,6 +130,17 @@ public class HomeSettings extends SettingsPreferenceFragment { } } } + + // If we're down to just one possible home app, back out of this settings + // fragment and show a dialog explaining to the user that they won't see + // 'Home' settings now until such time as there are multiple available. + if (mPrefs.size() < 2) { + if (mShowNotice) { + mShowNotice = false; + Settings.requestHomeNotice(); + } + finishFragment(); + } } void buildHomeActivitiesList() { @@ -176,6 +191,9 @@ public class HomeSettings extends SettingsPreferenceFragment { mPm = getPackageManager(); mPrefGroup = (PreferenceGroup) findPreference("home"); + + Bundle args = getArguments(); + mShowNotice = (args != null) && args.getBoolean(HOME_SHOW_NOTICE, false); } @Override diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 87d34c69553..87feab79dc6 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -19,6 +19,10 @@ package com.android.settings; import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.OnAccountsUpdateListener; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -27,7 +31,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; -import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; @@ -117,6 +120,10 @@ public class Settings extends PreferenceActivity private static final String SAVE_KEY_CURRENT_HEADER = "com.android.settings.CURRENT_HEADER"; private static final String SAVE_KEY_PARENT_HEADER = "com.android.settings.PARENT_HEADER"; + static final int DIALOG_ONLY_ONE_HOME = 1; + + private static boolean sShowNoHomeNotice = false; + private String mFragmentClass; private int mTopLevelHeaderId; private Header mFirstHeader; @@ -681,8 +688,22 @@ public class Settings extends PreferenceActivity getPackageManager().getHomeActivities(homeApps); if (homeApps.size() < 2) { // When there's only one available home app, omit this settings - // category entirely at the top level UI. + // category entirely at the top level UI. If the user just + // uninstalled the penultimate home app candidiate, we also + // now tell them about why they aren't seeing 'Home' in the list. + if (sShowNoHomeNotice) { + sShowNoHomeNotice = false; + NoHomeDialogFragment.show(this); + } return false; + } else { + // Okay, we're allowing the Home settings category. Tell it, when + // invoked via this front door, that we'll need to be told about the + // case when the user uninstalls all but one home app. + if (header.fragmentArguments == null) { + header.fragmentArguments = new Bundle(); + } + header.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true); } } catch (Exception e) { // Can't look up the home activity; bail on configuring the icon @@ -724,6 +745,21 @@ public class Settings extends PreferenceActivity return super.getNextButton(); } + public static class NoHomeDialogFragment extends DialogFragment { + public static void show(Activity parent) { + final NoHomeDialogFragment dialog = new NoHomeDialogFragment(); + dialog.show(parent.getFragmentManager(), null); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + return new AlertDialog.Builder(getActivity()) + .setMessage(R.string.only_one_home_message) + .setPositiveButton(android.R.string.ok, null) + .create(); + } + } + private static class HeaderAdapter extends ArrayAdapter
{ static final int HEADER_TYPE_CATEGORY = 0; static final int HEADER_TYPE_NORMAL = 1; @@ -915,11 +951,6 @@ public class Settings extends PreferenceActivity ManageAccountsSettings.KEY_ACCOUNT_TYPE); Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType); setHeaderIcon(holder, icon); - } else if (header.extras != null && - header.extras.containsKey(HomeSettings.CURRENT_HOME)) { - ActivityInfo ai = header.extras.getParcelable(HomeSettings.CURRENT_HOME); - Drawable icon = ai.loadIcon(getContext().getPackageManager()); - setHeaderIcon(holder, icon); } else { holder.icon.setImageResource(header.iconRes); } @@ -1012,6 +1043,10 @@ public class Settings extends PreferenceActivity invalidateHeaders(); } + public static void requestHomeNotice() { + sShowNoHomeNotice = true; + } + /* * Settings subclasses for launching independently. */