Merge "Back out of Home settings when penultimate home app is uninstalled" into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e7358028d1
@@ -4768,6 +4768,8 @@
|
|||||||
|
|
||||||
<!-- Home application selection - uninstall button [CHAR LIMIT=80] -->
|
<!-- Home application selection - uninstall button [CHAR LIMIT=80] -->
|
||||||
<string name="home_app_uninstall_button">Uninstall this application</string>
|
<string name="home_app_uninstall_button">Uninstall this application</string>
|
||||||
|
<!-- Message to user that Home Settings will be hidden because there is now only one available home application -->
|
||||||
|
<string name="only_one_home_message">Home settings will be hidden until you install another home application.</string>
|
||||||
|
|
||||||
<!-- Warning message when changing a global setting for a tablet.[CHAR LIMIT=none] -->
|
<!-- Warning message when changing a global setting for a tablet.[CHAR LIMIT=none] -->
|
||||||
<string name="global_change_warning" product="tablet">This setting affects all users on this tablet.</string>
|
<string name="global_change_warning" product="tablet">This setting affects all users on this tablet.</string>
|
||||||
|
@@ -23,6 +23,7 @@ import android.content.ComponentName;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
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 CURRENT_HOME = "current_home";
|
||||||
|
|
||||||
|
public static final String HOME_SHOW_NOTICE = "show";
|
||||||
|
|
||||||
PreferenceGroup mPrefGroup;
|
PreferenceGroup mPrefGroup;
|
||||||
|
|
||||||
PackageManager mPm;
|
PackageManager mPm;
|
||||||
@@ -57,6 +60,7 @@ public class HomeSettings extends SettingsPreferenceFragment {
|
|||||||
ArrayList<HomeAppPreference> mPrefs;
|
ArrayList<HomeAppPreference> mPrefs;
|
||||||
HomeAppPreference mCurrentHome = null;
|
HomeAppPreference mCurrentHome = null;
|
||||||
final IntentFilter mHomeFilter;
|
final IntentFilter mHomeFilter;
|
||||||
|
boolean mShowNotice;
|
||||||
|
|
||||||
public HomeSettings() {
|
public HomeSettings() {
|
||||||
mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
|
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() {
|
void buildHomeActivitiesList() {
|
||||||
@@ -176,6 +191,9 @@ public class HomeSettings extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
mPm = getPackageManager();
|
mPm = getPackageManager();
|
||||||
mPrefGroup = (PreferenceGroup) findPreference("home");
|
mPrefGroup = (PreferenceGroup) findPreference("home");
|
||||||
|
|
||||||
|
Bundle args = getArguments();
|
||||||
|
mShowNotice = (args != null) && args.getBoolean(HOME_SHOW_NOTICE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -19,6 +19,10 @@ package com.android.settings;
|
|||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.accounts.OnAccountsUpdateListener;
|
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.app.admin.DevicePolicyManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
@@ -27,7 +31,6 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.pm.ResolveInfo;
|
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_CURRENT_HEADER = "com.android.settings.CURRENT_HEADER";
|
||||||
private static final String SAVE_KEY_PARENT_HEADER = "com.android.settings.PARENT_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 String mFragmentClass;
|
||||||
private int mTopLevelHeaderId;
|
private int mTopLevelHeaderId;
|
||||||
private Header mFirstHeader;
|
private Header mFirstHeader;
|
||||||
@@ -684,8 +691,22 @@ public class Settings extends PreferenceActivity
|
|||||||
getPackageManager().getHomeActivities(homeApps);
|
getPackageManager().getHomeActivities(homeApps);
|
||||||
if (homeApps.size() < 2) {
|
if (homeApps.size() < 2) {
|
||||||
// When there's only one available home app, omit this settings
|
// 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;
|
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) {
|
} catch (Exception e) {
|
||||||
// Can't look up the home activity; bail on configuring the icon
|
// Can't look up the home activity; bail on configuring the icon
|
||||||
@@ -727,6 +748,21 @@ public class Settings extends PreferenceActivity
|
|||||||
return super.getNextButton();
|
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<Header> {
|
private static class HeaderAdapter extends ArrayAdapter<Header> {
|
||||||
static final int HEADER_TYPE_CATEGORY = 0;
|
static final int HEADER_TYPE_CATEGORY = 0;
|
||||||
static final int HEADER_TYPE_NORMAL = 1;
|
static final int HEADER_TYPE_NORMAL = 1;
|
||||||
@@ -918,11 +954,6 @@ public class Settings extends PreferenceActivity
|
|||||||
ManageAccountsSettings.KEY_ACCOUNT_TYPE);
|
ManageAccountsSettings.KEY_ACCOUNT_TYPE);
|
||||||
Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType);
|
Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType);
|
||||||
setHeaderIcon(holder, icon);
|
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 {
|
} else {
|
||||||
holder.icon.setImageResource(header.iconRes);
|
holder.icon.setImageResource(header.iconRes);
|
||||||
}
|
}
|
||||||
@@ -1015,6 +1046,10 @@ public class Settings extends PreferenceActivity
|
|||||||
invalidateHeaders();
|
invalidateHeaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void requestHomeNotice() {
|
||||||
|
sShowNoHomeNotice = true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Settings subclasses for launching independently.
|
* Settings subclasses for launching independently.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user