diff options
author | Jason Monk <jmonk@google.com> | 2015-05-27 16:02:08 -0400 |
---|---|---|
committer | Jason Monk <jmonk@google.com> | 2015-05-28 09:50:45 -0400 |
commit | 15dcebe1e79ad396a08873f940e2f33d432cf387 (patch) | |
tree | df04a6a1c9073e88cefeb8ef31b07c6faffc6963 | |
parent | ecf4339bc74f8d4fb504e8f32b1d4828e9975e37 (diff) | |
download | packages_apps_Settings-15dcebe1e79ad396a08873f940e2f33d432cf387.tar.gz packages_apps_Settings-15dcebe1e79ad396a08873f940e2f33d432cf387.tar.bz2 packages_apps_Settings-15dcebe1e79ad396a08873f940e2f33d432cf387.zip |
Help fallbacks and intent work
- Handle a backup URI, so that if the specified URI is not available,
another can be used.
- Add some data to help intents when they are intent URIs
- Fill in the context with a classname when it isn't present
Bug: 15475009
Change-Id: I7050fa61121901929e650b20bd7a0ae21e8ba207
8 files changed, 53 insertions, 32 deletions
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java index ed5de25d8..744ed3f17 100644 --- a/src/com/android/settings/DataUsageSummary.java +++ b/src/com/android/settings/DataUsageSummary.java @@ -588,7 +588,7 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable final MenuItem help = menu.findItem(R.id.data_usage_menu_help); String helpUrl; if (!TextUtils.isEmpty(helpUrl = getResources().getString(R.string.help_url_data_usage))) { - HelpUtils.prepareHelpMenuItem(context, help, helpUrl); + HelpUtils.prepareHelpMenuItem(context, help, helpUrl, getClass().getName()); } else { help.setVisible(false); } diff --git a/src/com/android/settings/HelpUtils.java b/src/com/android/settings/HelpUtils.java index 67e7b537f..0e79c6df6 100644 --- a/src/com/android/settings/HelpUtils.java +++ b/src/com/android/settings/HelpUtils.java @@ -21,9 +21,11 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.Resources.Theme; import android.net.Uri; import android.text.TextUtils; import android.util.Log; +import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; @@ -49,6 +51,12 @@ public class HelpUtils { */ private final static String PARAM_VERSION = "version"; + // Constants for help intents. + private static final String EXTRA_CONTEXT = "EXTRA_CONTEXT"; + private static final String EXTRA_THEME = "EXTRA_THEME"; + private static final String EXTRA_PRIMARY_COLOR = "EXTRA_PRIMARY_COLOR"; + private static final String EXTRA_BACKUP_URI = "EXTRA_BACKUP_URI"; + /** * Cached version code to prevent repeated calls to the package manager. */ @@ -57,29 +65,17 @@ public class HelpUtils { /** Static helper that is not instantiable*/ private HelpUtils() { } - public static boolean prepareHelpMenuItem(Context context, Menu menu, String helpUri) { + public static boolean prepareHelpMenuItem(Context context, Menu menu, String helpUri, + String backupContext) { MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label); - return prepareHelpMenuItem(context, helpItem, helpUri); + return prepareHelpMenuItem(context, helpItem, helpUri, backupContext); } - public static boolean prepareHelpMenuItem(Context context, Menu menu, int helpUriResource) { + public static boolean prepareHelpMenuItem(Context context, Menu menu, int helpUriResource, + String backupContext) { MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label); - return prepareHelpMenuItem(context, helpItem, context.getString(helpUriResource)); - } - - /** - * Prepares the help menu item by doing the following. - * - If the string corresponding to the helpUrlResourceId is empty or null, then the help menu - * item is made invisible. - * - Otherwise, this makes the help menu item visible and sets the intent for the help menu - * item to view the URL. - * - * @return returns whether the help menu item has been made visible. - */ - public static boolean prepareHelpMenuItem(Context context, MenuItem helpMenuItem, - int helpUrlResourceId) { - String helpUrlString = context.getResources().getString(helpUrlResourceId); - return prepareHelpMenuItem(context, helpMenuItem, helpUrlString); + return prepareHelpMenuItem(context, helpItem, context.getString(helpUriResource), + backupContext); } /** @@ -91,7 +87,7 @@ public class HelpUtils { * @return returns whether the help menu item has been made visible. */ public static boolean prepareHelpMenuItem(Context context, MenuItem helpMenuItem, - String helpUriString) { + String helpUriString, String backupContext) { if (TextUtils.isEmpty(helpUriString)) { // The help url string is empty or null, so set the help menu item to be invisible. helpMenuItem.setVisible(false); @@ -99,12 +95,11 @@ public class HelpUtils { // return that the help menu item is not visible (i.e. false) return false; } else { - Intent intent = getHelpIntent(context, helpUriString); + Intent intent = getHelpIntent(context, helpUriString, backupContext); // Set the intent to the help menu item, show the help menu item in the overflow // menu, and make it visible. - ComponentName component = intent.resolveActivity(context.getPackageManager()); - if (component != null) { + if (intent != null) { helpMenuItem.setIntent(intent); helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); helpMenuItem.setVisible(true); @@ -118,11 +113,23 @@ public class HelpUtils { } } - public static Intent getHelpIntent(Context context, String helpUriString) { + public static Intent getHelpIntent(Context context, String helpUriString, + String backupContext) { // Try to handle as Intent Uri, otherwise just treat as Uri. try { - return Intent.parseUri(helpUriString, + Intent intent = Intent.parseUri(helpUriString, Intent.URI_ANDROID_APP_SCHEME | Intent.URI_INTENT_SCHEME); + addIntentParameters(context, intent, backupContext); + ComponentName component = intent.resolveActivity(context.getPackageManager()); + if (component != null) { + return intent; + } else if (intent.hasExtra(EXTRA_BACKUP_URI)) { + // This extra contains a backup URI for when the intent isn't available. + return getHelpIntent(context, intent.getStringExtra(EXTRA_BACKUP_URI), + backupContext); + } else { + return null; + } } catch (URISyntaxException e) { } // The help url string exists, so first add in some extra query parameters. @@ -136,6 +143,18 @@ public class HelpUtils { return intent; } + private static void addIntentParameters(Context context, Intent intent, String backupContext) { + if (!intent.hasExtra(EXTRA_CONTEXT)) { + // Insert some context if none exists. + intent.putExtra(EXTRA_CONTEXT, backupContext); + } + intent.putExtra(EXTRA_THEME, 1 /* Light, dark action bar */); + Theme theme = context.getTheme(); + TypedValue typedValue = new TypedValue(); + theme.resolveAttribute(android.R.attr.colorPrimary, typedValue, true); + intent.putExtra(EXTRA_PRIMARY_COLOR, context.getColor(typedValue.resourceId)); + } + /** * Adds two query parameters into the Uri, namely the language code and the version code * of the app's package as gotten via the context. diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java index 095785bbe..baf04d4f1 100644 --- a/src/com/android/settings/SettingsPreferenceFragment.java +++ b/src/com/android/settings/SettingsPreferenceFragment.java @@ -294,7 +294,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (mHelpUri != null && getActivity() != null) { - HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri); + HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri, getClass().getName()); } } diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java index fa95427db..18a3f1146 100644 --- a/src/com/android/settings/applications/ManageApplications.java +++ b/src/com/android/settings/applications/ManageApplications.java @@ -461,7 +461,7 @@ public class ManageApplications extends InstrumentedFragment return; } HelpUtils.prepareHelpMenuItem(getActivity(), menu, mListType == LIST_TYPE_MAIN - ? R.string.help_uri_apps : R.string.help_uri_notifications); + ? R.string.help_uri_apps : R.string.help_uri_notifications, getClass().getName()); mOptionsMenu = menu; inflater.inflate(R.menu.manage_apps, menu); updateOptionsMenu(); diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java index 31aa0df2c..6408636f0 100644 --- a/src/com/android/settings/dashboard/DashboardSummary.java +++ b/src/com/android/settings/dashboard/DashboardSummary.java @@ -87,7 +87,8 @@ public class DashboardSummary extends InstrumentedFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); - HelpUtils.prepareHelpMenuItem(getActivity(), menu, R.string.help_uri_dashboard); + HelpUtils.prepareHelpMenuItem(getActivity(), menu, R.string.help_uri_dashboard, + getClass().getName()); } @Override diff --git a/src/com/android/settings/fingerprint/FingerprintSettings.java b/src/com/android/settings/fingerprint/FingerprintSettings.java index 0c45cd93d..a0ccb24d0 100644 --- a/src/com/android/settings/fingerprint/FingerprintSettings.java +++ b/src/com/android/settings/fingerprint/FingerprintSettings.java @@ -542,7 +542,7 @@ public class FingerprintSettings extends SubSettings { @Override public void onClick(View widget) { Context ctx = widget.getContext(); - Intent intent = HelpUtils.getHelpIntent(ctx, getURL()); + Intent intent = HelpUtils.getHelpIntent(ctx, getURL(), ctx.getClass().getName()); try { ctx.startActivity(intent); } catch (ActivityNotFoundException e) { diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java index 89a3325bb..3576ee247 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java +++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java @@ -135,7 +135,7 @@ public class PowerUsageSummary extends PowerUsageBase { String helpUrl; if (!TextUtils.isEmpty(helpUrl = getResources().getString(R.string.help_url_battery))) { final MenuItem help = menu.add(0, MENU_HELP, 0, R.string.help_label); - HelpUtils.prepareHelpMenuItem(getActivity(), help, helpUrl); + HelpUtils.prepareHelpMenuItem(getActivity(), help, helpUrl, getClass().getName()); } } diff --git a/src/com/android/settings/nfc/AndroidBeam.java b/src/com/android/settings/nfc/AndroidBeam.java index a907ea191..f1c8863e1 100644 --- a/src/com/android/settings/nfc/AndroidBeam.java +++ b/src/com/android/settings/nfc/AndroidBeam.java @@ -61,7 +61,8 @@ public class AndroidBeam extends InstrumentedFragment @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); - HelpUtils.prepareHelpMenuItem(getActivity(), menu, R.string.help_uri_beam); + HelpUtils.prepareHelpMenuItem(getActivity(), menu, R.string.help_uri_beam, + getClass().getName()); } @Override |