Loading src/com/android/settings/SettingsActivity.java +22 −1 Original line number Diff line number Diff line Loading @@ -184,6 +184,11 @@ public class SettingsActivity extends Activity * that fragment. */ public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; /** * The package name used to resolve the title resource id. */ public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME = ":settings:show_fragment_title_res_package_name"; public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = ":settings:show_fragment_title_resid"; public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = Loading Loading @@ -657,7 +662,23 @@ public class SettingsActivity extends Activity if (initialTitleResId > 0) { mInitialTitle = null; mInitialTitleResId = initialTitleResId; final String initialTitleResPackageName = intent.getStringExtra( EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME); if (initialTitleResPackageName != null) { try { Context authContext = createPackageContextAsUser(initialTitleResPackageName, 0 /* flags */, new UserHandle(UserHandle.myUserId())); mInitialTitle = authContext.getResources().getText(mInitialTitleResId); setTitle(mInitialTitle); mInitialTitleResId = -1; return; } catch (NameNotFoundException e) { Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName); } } else { setTitle(mInitialTitleResId); } } else { mInitialTitleResId = -1; final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); Loading src/com/android/settings/Utils.java +61 −10 Original line number Diff line number Diff line Loading @@ -590,16 +590,40 @@ public final class Utils { * @param title String to display for the title of this set of preferences. */ public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title) { Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title) { startWithFragment(context, fragmentName, args, resultTo, resultRequestCode, titleResId, title, false /* not a shortcut */); null /* titleResPackageName */, titleResId, title, false /* not a shortcut */); } /** * Start a new instance of the activity, showing only the given fragment. * When launched in this mode, the given preference fragment will be instantiated and fill the * entire activity. * * @param context The context. * @param fragmentName The name of the fragment to display. * @param args Optional arguments to supply to the fragment. * @param resultTo Option fragment that should receive the result of the activity launch. * @param resultRequestCode If resultTo is non-null, this is the request code in which * to report the result. * @param titleResPackageName Optional package name for the resource id of the title. * @param titleResId resource id for the String to display for the title of this set * of preferences. * @param title String to display for the title of this set of preferences. */ public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title, boolean isShortcut) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResId, title, isShortcut); Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId, CharSequence title) { startWithFragment(context, fragmentName, args, resultTo, resultRequestCode, titleResPackageName, titleResId, title, false /* not a shortcut */); } public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title, boolean isShortcut) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, null /* titleResPackageName */, titleResId, title, isShortcut); if (resultTo == null) { context.startActivity(intent); } else { Loading @@ -607,10 +631,33 @@ public final class Utils { } } public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName, titleResId, title, isShortcut); if (resultTo == null) { context.startActivity(intent); } else { resultTo.startActivityForResult(intent, resultRequestCode); } } public static void startWithFragmentAsUser(Context context, String fragmentName, Bundle args, int titleResId, CharSequence title, boolean isShortcut, UserHandle userHandle) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, null /* titleResPackageName */, titleResId, title, isShortcut); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivityAsUser(intent, userHandle); } public static void startWithFragmentAsUser(Context context, String fragmentName, Bundle args, int titleResId, CharSequence title, boolean isShortcut, UserHandle userHandle) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResId, title, isShortcut); String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut, UserHandle userHandle) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName, titleResId, title, isShortcut); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivityAsUser(intent, userHandle); Loading @@ -625,6 +672,7 @@ public final class Utils { * @param context The Context. * @param fragmentName The name of the fragment to display. * @param args Optional arguments to supply to the fragment. * @param titleResPackageName Optional package name for the resource id of the title. * @param titleResId Optional title resource id to show for this item. * @param title Optional title to show for this item. * @param isShortcut tell if this is a Launcher Shortcut or not Loading @@ -632,11 +680,14 @@ public final class Utils { * fragment. */ public static Intent onBuildStartFragmentIntent(Context context, String fragmentName, Bundle args, int titleResId, CharSequence title, boolean isShortcut) { Bundle args, String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClass(context, SubSettings.class); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME, titleResPackageName); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, isShortcut); Loading src/com/android/settings/accounts/AccountSettings.java +25 −6 Original line number Diff line number Diff line Loading @@ -369,6 +369,8 @@ public class AccountSettings extends SettingsPreferenceFragment if (label == null) { continue; } final String titleResPackageName = helper.getPackageForType(accountType); final int titleResId = helper.getLabelIdForType(accountType); final Account[] accounts = AccountManager.get(getActivity()) .getAccountsByTypeAsUser(accountType, userHandle); Loading @@ -382,7 +384,8 @@ public class AccountSettings extends SettingsPreferenceFragment fragmentArguments.putParcelable(EXTRA_USER, userHandle); accountTypePreferences.add(new AccountPreference(getActivity(), label, AccountSyncSettings.class.getName(), fragmentArguments, titleResPackageName, titleResId, AccountSyncSettings.class.getName(), fragmentArguments, helper.getDrawableForType(getActivity(), accountType))); } else { final Bundle fragmentArguments = new Bundle(); Loading @@ -392,7 +395,8 @@ public class AccountSettings extends SettingsPreferenceFragment fragmentArguments.putParcelable(EXTRA_USER, userHandle); accountTypePreferences.add(new AccountPreference(getActivity(), label, ManageAccountsSettings.class.getName(), fragmentArguments, titleResPackageName, titleResId, ManageAccountsSettings.class.getName(), fragmentArguments, helper.getDrawableForType(getActivity(), accountType))); } helper.preloadDrawableForType(getActivity(), accountType); Loading Loading @@ -434,6 +438,17 @@ public class AccountSettings extends SettingsPreferenceFragment */ private final CharSequence mTitle; /** * Packange name used to resolve the resources of the title shown to the user in the new * fragment. */ private final String mTitleResPackageName; /** * Resource id of the title shown to the user in the new fragment. */ private final int mTitleResId; /** * Full class name of the fragment to display when this tile is * selected. Loading @@ -447,10 +462,13 @@ public class AccountSettings extends SettingsPreferenceFragment */ private final Bundle mFragmentArguments; public AccountPreference(Context context, CharSequence title, String fragment, Bundle fragmentArguments, Drawable icon) { public AccountPreference(Context context, CharSequence title, String titleResPackageName, int titleResId, String fragment, Bundle fragmentArguments, Drawable icon) { super(context); mTitle = title; mTitleResPackageName = titleResPackageName; mTitleResId = titleResId; mFragment = fragment; mFragmentArguments = fragmentArguments; setWidgetLayoutResource(R.layout.account_type_preference); Loading @@ -464,8 +482,9 @@ public class AccountSettings extends SettingsPreferenceFragment @Override public boolean onPreferenceClick(Preference preference) { if (mFragment != null) { Utils.startWithFragment( getContext(), mFragment, mFragmentArguments, null, 0, 0, mTitle); Utils.startWithFragment(getContext(), mFragment, mFragmentArguments, null /* resultTo */, 0 /* resultRequestCode */, mTitleResPackageName, mTitleResId, null /* title */); return true; } return false; Loading src/com/android/settings/accounts/AuthenticatorHelper.java +27 −0 Original line number Diff line number Diff line Loading @@ -147,6 +147,33 @@ final public class AuthenticatorHelper extends BroadcastReceiver { return label; } /** * Gets the package associated with a particular account type. If none found, return null. * @param accountType the type of account * @return the package name or null if one cannot be found. */ public String getPackageForType(final String accountType) { if (mTypeToAuthDescription.containsKey(accountType)) { AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType); return desc.packageName; } return null; } /** * Gets the resource id of the label associated with a particular account type. If none found, * return -1. * @param accountType the type of account * @return a resource id for the label or -1 if none found; */ public int getLabelIdForType(final String accountType) { if (mTypeToAuthDescription.containsKey(accountType)) { AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType); return desc.labelId; } return -1; } /** * Updates provider icons. Subclasses should call this in onCreate() * and update any UI that depends on AuthenticatorDescriptions in onAuthDescriptionsUpdated(). Loading Loading
src/com/android/settings/SettingsActivity.java +22 −1 Original line number Diff line number Diff line Loading @@ -184,6 +184,11 @@ public class SettingsActivity extends Activity * that fragment. */ public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; /** * The package name used to resolve the title resource id. */ public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME = ":settings:show_fragment_title_res_package_name"; public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = ":settings:show_fragment_title_resid"; public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = Loading Loading @@ -657,7 +662,23 @@ public class SettingsActivity extends Activity if (initialTitleResId > 0) { mInitialTitle = null; mInitialTitleResId = initialTitleResId; final String initialTitleResPackageName = intent.getStringExtra( EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME); if (initialTitleResPackageName != null) { try { Context authContext = createPackageContextAsUser(initialTitleResPackageName, 0 /* flags */, new UserHandle(UserHandle.myUserId())); mInitialTitle = authContext.getResources().getText(mInitialTitleResId); setTitle(mInitialTitle); mInitialTitleResId = -1; return; } catch (NameNotFoundException e) { Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName); } } else { setTitle(mInitialTitleResId); } } else { mInitialTitleResId = -1; final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); Loading
src/com/android/settings/Utils.java +61 −10 Original line number Diff line number Diff line Loading @@ -590,16 +590,40 @@ public final class Utils { * @param title String to display for the title of this set of preferences. */ public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title) { Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title) { startWithFragment(context, fragmentName, args, resultTo, resultRequestCode, titleResId, title, false /* not a shortcut */); null /* titleResPackageName */, titleResId, title, false /* not a shortcut */); } /** * Start a new instance of the activity, showing only the given fragment. * When launched in this mode, the given preference fragment will be instantiated and fill the * entire activity. * * @param context The context. * @param fragmentName The name of the fragment to display. * @param args Optional arguments to supply to the fragment. * @param resultTo Option fragment that should receive the result of the activity launch. * @param resultRequestCode If resultTo is non-null, this is the request code in which * to report the result. * @param titleResPackageName Optional package name for the resource id of the title. * @param titleResId resource id for the String to display for the title of this set * of preferences. * @param title String to display for the title of this set of preferences. */ public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title, boolean isShortcut) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResId, title, isShortcut); Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId, CharSequence title) { startWithFragment(context, fragmentName, args, resultTo, resultRequestCode, titleResPackageName, titleResId, title, false /* not a shortcut */); } public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title, boolean isShortcut) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, null /* titleResPackageName */, titleResId, title, isShortcut); if (resultTo == null) { context.startActivity(intent); } else { Loading @@ -607,10 +631,33 @@ public final class Utils { } } public static void startWithFragment(Context context, String fragmentName, Bundle args, Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName, titleResId, title, isShortcut); if (resultTo == null) { context.startActivity(intent); } else { resultTo.startActivityForResult(intent, resultRequestCode); } } public static void startWithFragmentAsUser(Context context, String fragmentName, Bundle args, int titleResId, CharSequence title, boolean isShortcut, UserHandle userHandle) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, null /* titleResPackageName */, titleResId, title, isShortcut); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivityAsUser(intent, userHandle); } public static void startWithFragmentAsUser(Context context, String fragmentName, Bundle args, int titleResId, CharSequence title, boolean isShortcut, UserHandle userHandle) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResId, title, isShortcut); String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut, UserHandle userHandle) { Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName, titleResId, title, isShortcut); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivityAsUser(intent, userHandle); Loading @@ -625,6 +672,7 @@ public final class Utils { * @param context The Context. * @param fragmentName The name of the fragment to display. * @param args Optional arguments to supply to the fragment. * @param titleResPackageName Optional package name for the resource id of the title. * @param titleResId Optional title resource id to show for this item. * @param title Optional title to show for this item. * @param isShortcut tell if this is a Launcher Shortcut or not Loading @@ -632,11 +680,14 @@ public final class Utils { * fragment. */ public static Intent onBuildStartFragmentIntent(Context context, String fragmentName, Bundle args, int titleResId, CharSequence title, boolean isShortcut) { Bundle args, String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClass(context, SubSettings.class); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME, titleResPackageName); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, isShortcut); Loading
src/com/android/settings/accounts/AccountSettings.java +25 −6 Original line number Diff line number Diff line Loading @@ -369,6 +369,8 @@ public class AccountSettings extends SettingsPreferenceFragment if (label == null) { continue; } final String titleResPackageName = helper.getPackageForType(accountType); final int titleResId = helper.getLabelIdForType(accountType); final Account[] accounts = AccountManager.get(getActivity()) .getAccountsByTypeAsUser(accountType, userHandle); Loading @@ -382,7 +384,8 @@ public class AccountSettings extends SettingsPreferenceFragment fragmentArguments.putParcelable(EXTRA_USER, userHandle); accountTypePreferences.add(new AccountPreference(getActivity(), label, AccountSyncSettings.class.getName(), fragmentArguments, titleResPackageName, titleResId, AccountSyncSettings.class.getName(), fragmentArguments, helper.getDrawableForType(getActivity(), accountType))); } else { final Bundle fragmentArguments = new Bundle(); Loading @@ -392,7 +395,8 @@ public class AccountSettings extends SettingsPreferenceFragment fragmentArguments.putParcelable(EXTRA_USER, userHandle); accountTypePreferences.add(new AccountPreference(getActivity(), label, ManageAccountsSettings.class.getName(), fragmentArguments, titleResPackageName, titleResId, ManageAccountsSettings.class.getName(), fragmentArguments, helper.getDrawableForType(getActivity(), accountType))); } helper.preloadDrawableForType(getActivity(), accountType); Loading Loading @@ -434,6 +438,17 @@ public class AccountSettings extends SettingsPreferenceFragment */ private final CharSequence mTitle; /** * Packange name used to resolve the resources of the title shown to the user in the new * fragment. */ private final String mTitleResPackageName; /** * Resource id of the title shown to the user in the new fragment. */ private final int mTitleResId; /** * Full class name of the fragment to display when this tile is * selected. Loading @@ -447,10 +462,13 @@ public class AccountSettings extends SettingsPreferenceFragment */ private final Bundle mFragmentArguments; public AccountPreference(Context context, CharSequence title, String fragment, Bundle fragmentArguments, Drawable icon) { public AccountPreference(Context context, CharSequence title, String titleResPackageName, int titleResId, String fragment, Bundle fragmentArguments, Drawable icon) { super(context); mTitle = title; mTitleResPackageName = titleResPackageName; mTitleResId = titleResId; mFragment = fragment; mFragmentArguments = fragmentArguments; setWidgetLayoutResource(R.layout.account_type_preference); Loading @@ -464,8 +482,9 @@ public class AccountSettings extends SettingsPreferenceFragment @Override public boolean onPreferenceClick(Preference preference) { if (mFragment != null) { Utils.startWithFragment( getContext(), mFragment, mFragmentArguments, null, 0, 0, mTitle); Utils.startWithFragment(getContext(), mFragment, mFragmentArguments, null /* resultTo */, 0 /* resultRequestCode */, mTitleResPackageName, mTitleResId, null /* title */); return true; } return false; Loading
src/com/android/settings/accounts/AuthenticatorHelper.java +27 −0 Original line number Diff line number Diff line Loading @@ -147,6 +147,33 @@ final public class AuthenticatorHelper extends BroadcastReceiver { return label; } /** * Gets the package associated with a particular account type. If none found, return null. * @param accountType the type of account * @return the package name or null if one cannot be found. */ public String getPackageForType(final String accountType) { if (mTypeToAuthDescription.containsKey(accountType)) { AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType); return desc.packageName; } return null; } /** * Gets the resource id of the label associated with a particular account type. If none found, * return -1. * @param accountType the type of account * @return a resource id for the label or -1 if none found; */ public int getLabelIdForType(final String accountType) { if (mTypeToAuthDescription.containsKey(accountType)) { AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType); return desc.labelId; } return -1; } /** * Updates provider icons. Subclasses should call this in onCreate() * and update any UI that depends on AuthenticatorDescriptions in onAuthDescriptionsUpdated(). Loading