From 23acc2bb8af7da000d72a8c1d8c28a2792200348 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Tue, 14 Apr 2015 15:06:39 -0400 Subject: Allow help to be defined to intent uri Allow help uris to be either an intent uri or as uri (as they were before). Also add a default help uri, and specific helps for several screens. Bug: 15475009 Change-Id: Iff982892973f01d32ff61ea88d4844e9a7153500 --- src/com/android/settings/DeviceInfoSettings.java | 5 +++ src/com/android/settings/DisplaySettings.java | 5 +++ src/com/android/settings/HelpUtils.java | 47 +++++++++++++++++----- .../settings/SettingsPreferenceFragment.java | 14 +++---- .../android/settings/WallpaperTypeSettings.java | 5 +++ .../accessibility/AccessibilitySettings.java | 5 +++ .../settings/applications/ManageApplications.java | 3 ++ .../settings/dashboard/DashboardSummary.java | 18 ++++++++- .../settings/deviceinfo/StorageSettings.java | 5 +++ src/com/android/settings/nfc/AndroidBeam.java | 11 ++++- .../settings/notification/OtherSoundSettings.java | 5 +++ .../settings/notification/ZenModeSettings.java | 5 +++ .../settings/print/PrintSettingsFragment.java | 5 +++ 13 files changed, 111 insertions(+), 22 deletions(-) (limited to 'src/com') diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java index 061b1337f..37d9c9cf0 100644 --- a/src/com/android/settings/DeviceInfoSettings.java +++ b/src/com/android/settings/DeviceInfoSettings.java @@ -89,6 +89,11 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In return MetricsLogger.DEVICEINFO; } + @Override + protected int getHelpResource() { + return R.string.help_uri_about; + } + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java index 47cbcdebc..7ad383236 100644 --- a/src/com/android/settings/DisplaySettings.java +++ b/src/com/android/settings/DisplaySettings.java @@ -422,6 +422,11 @@ public class DisplaySettings extends SettingsPreferenceFragment implements return false; } + @Override + protected int getHelpResource() { + return R.string.help_uri_display; + } + public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() { @Override diff --git a/src/com/android/settings/HelpUtils.java b/src/com/android/settings/HelpUtils.java index 22e2f7620..36fb19445 100644 --- a/src/com/android/settings/HelpUtils.java +++ b/src/com/android/settings/HelpUtils.java @@ -24,8 +24,10 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; import android.text.TextUtils; import android.util.Log; +import android.view.Menu; import android.view.MenuItem; +import java.net.URISyntaxException; import java.util.Locale; /** @@ -33,7 +35,9 @@ import java.util.Locale; * browser to a particular URL, while taking into account the preferred language and app version. */ public class HelpUtils { - private final static String TAG = HelpUtils.class.getName(); + private final static String TAG = HelpUtils.class.getSimpleName(); + + private static final int MENU_HELP = Menu.FIRST + 100; /** * Help URL query parameter key for the preferred language. @@ -53,6 +57,16 @@ public class HelpUtils { /** Static helper that is not instantiable*/ private HelpUtils() { } + public static boolean prepareHelpMenuItem(Context context, Menu menu, String helpUri) { + MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label); + return prepareHelpMenuItem(context, helpItem, helpUri); + } + + public static boolean prepareHelpMenuItem(Context context, Menu menu, int helpUriResource) { + 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 @@ -77,22 +91,15 @@ public class HelpUtils { * @return returns whether the help menu item has been made visible. */ public static boolean prepareHelpMenuItem(Context context, MenuItem helpMenuItem, - String helpUrlString) { - if (TextUtils.isEmpty(helpUrlString)) { + String helpUriString) { + if (TextUtils.isEmpty(helpUriString)) { // The help url string is empty or null, so set the help menu item to be invisible. helpMenuItem.setVisible(false); // return that the help menu item is not visible (i.e. false) return false; } else { - // The help url string exists, so first add in some extra query parameters. - final Uri fullUri = uriWithAddedParameters(context, Uri.parse(helpUrlString)); - - // Then, create an intent that will be fired when the user - // selects this help menu item. - Intent intent = new Intent(Intent.ACTION_VIEW, fullUri); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + Intent intent = getHelpIntent(context, helpUriString); // Set the intent to the help menu item, show the help menu item in the overflow // menu, and make it visible. @@ -111,6 +118,24 @@ public class HelpUtils { } } + private static Intent getHelpIntent(Context context, String helpUriString) { + // Try to handle as Intent Uri, otherwise just treat as Uri. + try { + return Intent.parseUri(helpUriString, + Intent.URI_ANDROID_APP_SCHEME | Intent.URI_INTENT_SCHEME); + } catch (URISyntaxException e) { + } + // The help url string exists, so first add in some extra query parameters. + final Uri fullUri = uriWithAddedParameters(context, Uri.parse(helpUriString)); + + // Then, create an intent that will be fired when the user + // selects this help menu item. + Intent intent = new Intent(Intent.ACTION_VIEW, fullUri); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + return intent; + } + /** * 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 bf41c8038..74cb0fe3f 100644 --- a/src/com/android/settings/SettingsPreferenceFragment.java +++ b/src/com/android/settings/SettingsPreferenceFragment.java @@ -50,14 +50,13 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF private static final String TAG = "SettingsPreferenceFragment"; - private static final int MENU_HELP = Menu.FIRST + 100; private static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 600; private static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted"; private SettingsDialogFragment mDialogFragment; - private String mHelpUrl; + private String mHelpUri; // Cache the content resolver for async callbacks private ContentResolver mContentResolver; @@ -93,7 +92,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF // Prepare help url and enable menu if necessary int helpResource = getHelpResource(); if (helpResource != 0) { - mHelpUrl = getResources().getString(helpResource); + mHelpUri = getResources().getString(helpResource); } } @@ -125,7 +124,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - if (!TextUtils.isEmpty(mHelpUrl)) { + if (!TextUtils.isEmpty(mHelpUri)) { setHasOptionsMenu(true); } } @@ -273,14 +272,13 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF * @return the resource id for the help url */ protected int getHelpResource() { - return 0; + return R.string.help_uri_default; } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (mHelpUrl != null && getActivity() != null) { - MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label); - HelpUtils.prepareHelpMenuItem(getActivity(), helpItem, mHelpUrl); + if (mHelpUri != null && getActivity() != null) { + HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri); } } diff --git a/src/com/android/settings/WallpaperTypeSettings.java b/src/com/android/settings/WallpaperTypeSettings.java index 8c8da3130..9046bfbeb 100644 --- a/src/com/android/settings/WallpaperTypeSettings.java +++ b/src/com/android/settings/WallpaperTypeSettings.java @@ -39,6 +39,11 @@ public class WallpaperTypeSettings extends SettingsPreferenceFragment implements return MetricsLogger.WALLPAPER_TYPE; } + @Override + protected int getHelpResource() { + return R.string.help_uri_wallpaper; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java index c4b3a9660..96577a09d 100644 --- a/src/com/android/settings/accessibility/AccessibilitySettings.java +++ b/src/com/android/settings/accessibility/AccessibilitySettings.java @@ -203,6 +203,11 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements return MetricsLogger.ACCESSIBILITY; } + @Override + protected int getHelpResource() { + return R.string.help_uri_accessibility; + } + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java index b0b35ab94..2b3eb419b 100644 --- a/src/com/android/settings/applications/ManageApplications.java +++ b/src/com/android/settings/applications/ManageApplications.java @@ -55,6 +55,7 @@ import android.widget.Spinner; import com.android.internal.content.PackageHelper; import com.android.internal.logging.MetricsLogger; +import com.android.settings.HelpUtils; import com.android.settings.InstrumentedFragment; import com.android.settings.R; import com.android.settings.Settings.AllApplicationsActivity; @@ -431,6 +432,8 @@ public class ManageApplications extends InstrumentedFragment // No option menu return; } + HelpUtils.prepareHelpMenuItem(getActivity(), menu, mListType == LIST_TYPE_MAIN + ? R.string.help_uri_apps : R.string.help_uri_notifications); mOptionsMenu = menu; if (mListType == LIST_TYPE_MAIN) { // Only show advanced options when in the main app list (from dashboard). diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java index ae1b6d025..b1d2cbaf0 100644 --- a/src/com/android/settings/dashboard/DashboardSummary.java +++ b/src/com/android/settings/dashboard/DashboardSummary.java @@ -16,7 +16,6 @@ package com.android.settings.dashboard; -import android.app.Fragment; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -29,13 +28,15 @@ import android.os.Message; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; - import com.android.internal.logging.MetricsLogger; +import com.android.settings.HelpUtils; import com.android.settings.InstrumentedFragment; import com.android.settings.R; import com.android.settings.SettingsActivity; @@ -74,6 +75,19 @@ public class DashboardSummary extends InstrumentedFragment { return MetricsLogger.DASHBOARD_SUMMARY; } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setHasOptionsMenu(true); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + HelpUtils.prepareHelpMenuItem(getActivity(), menu, R.string.help_uri_dashboard); + } + @Override public void onResume() { super.onResume(); diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java index 001f00d89..0502d3fd2 100644 --- a/src/com/android/settings/deviceinfo/StorageSettings.java +++ b/src/com/android/settings/deviceinfo/StorageSettings.java @@ -96,6 +96,11 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index return MetricsLogger.DEVICEINFO_STORAGE; } + @Override + protected int getHelpResource() { + return R.string.help_uri_storage; + } + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); diff --git a/src/com/android/settings/nfc/AndroidBeam.java b/src/com/android/settings/nfc/AndroidBeam.java index 62675703e..a907ea191 100644 --- a/src/com/android/settings/nfc/AndroidBeam.java +++ b/src/com/android/settings/nfc/AndroidBeam.java @@ -17,17 +17,19 @@ package com.android.settings.nfc; import android.app.ActionBar; -import android.app.Fragment; import android.content.Context; import android.nfc.NfcAdapter; import android.os.Bundle; import android.os.UserManager; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Switch; import com.android.internal.logging.MetricsLogger; +import com.android.settings.HelpUtils; import com.android.settings.InstrumentedFragment; import com.android.settings.R; import com.android.settings.SettingsActivity; @@ -53,6 +55,13 @@ public class AndroidBeam extends InstrumentedFragment mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity()); mBeamDisallowed = ((UserManager) getActivity().getSystemService(Context.USER_SERVICE)) .hasUserRestriction(UserManager.DISALLOW_OUTGOING_BEAM); + setHasOptionsMenu(true); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + HelpUtils.prepareHelpMenuItem(getActivity(), menu, R.string.help_uri_beam); } @Override diff --git a/src/com/android/settings/notification/OtherSoundSettings.java b/src/com/android/settings/notification/OtherSoundSettings.java index b765b3519..c2269061a 100644 --- a/src/com/android/settings/notification/OtherSoundSettings.java +++ b/src/com/android/settings/notification/OtherSoundSettings.java @@ -171,6 +171,11 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In return MetricsLogger.NOTIFICATION_OTHER_SOUND; } + @Override + protected int getHelpResource() { + return R.string.help_uri_other_sounds; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java index 24774cb69..34abf5930 100644 --- a/src/com/android/settings/notification/ZenModeSettings.java +++ b/src/com/android/settings/notification/ZenModeSettings.java @@ -229,6 +229,11 @@ public class ZenModeSettings extends ZenModeSettingsBase return rt; } + @Override + protected int getHelpResource() { + return R.string.help_uri_interruptions; + } + // Enable indexing of searchable data public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() { diff --git a/src/com/android/settings/print/PrintSettingsFragment.java b/src/com/android/settings/print/PrintSettingsFragment.java index 27ccc592c..cea65d737 100644 --- a/src/com/android/settings/print/PrintSettingsFragment.java +++ b/src/com/android/settings/print/PrintSettingsFragment.java @@ -128,6 +128,11 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment return MetricsLogger.PRINT_SETTINGS; } + @Override + protected int getHelpResource() { + return R.string.help_uri_printing; + } + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); -- cgit v1.2.3