diff options
author | Jason Monk <jmonk@google.com> | 2015-04-14 19:54:18 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-04-14 19:54:19 +0000 |
commit | c1235be6f00520ee18b76d5619a40ea1a99087bb (patch) | |
tree | c56efc40029ca600910ebcec36b14849bcc21dfe /src/com | |
parent | bc90ee8736f2f547fbb7013a9cf77db0bfa417ad (diff) | |
parent | 23acc2bb8af7da000d72a8c1d8c28a2792200348 (diff) | |
download | packages_apps_Settings-c1235be6f00520ee18b76d5619a40ea1a99087bb.tar.gz packages_apps_Settings-c1235be6f00520ee18b76d5619a40ea1a99087bb.tar.bz2 packages_apps_Settings-c1235be6f00520ee18b76d5619a40ea1a99087bb.zip |
Merge "Allow help to be defined to intent uri"
Diffstat (limited to 'src/com')
13 files changed, 111 insertions, 22 deletions
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 @@ -90,6 +90,11 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In } @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 130e29d6f..9e645ab08 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); } } @@ -278,14 +277,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 @@ -40,6 +40,11 @@ public class WallpaperTypeSettings extends SettingsPreferenceFragment implements } @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 @@ -204,6 +204,11 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements } @Override + protected int getHelpResource() { + return R.string.help_uri_accessibility; + } + + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); addPreferencesFromResource(R.xml.accessibility_settings); diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java index 825a215de..b6b2b8289 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; @@ -449,6 +450,8 @@ public class ManageApplications extends InstrumentedFragment if (mListType != LIST_TYPE_MAIN) { return; } + HelpUtils.prepareHelpMenuItem(getActivity(), menu, mListType == LIST_TYPE_MAIN + ? R.string.help_uri_apps : R.string.help_uri_notifications); 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 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; @@ -75,6 +76,19 @@ public class DashboardSummary extends InstrumentedFragment { } @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 @@ -97,6 +97,11 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index } @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 @@ -172,6 +172,11 @@ public class OtherSoundSettings extends SettingsPreferenceFragment implements In } @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 @@ -129,6 +129,11 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment } @Override + protected int getHelpResource() { + return R.string.help_uri_printing; + } + + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); addPreferencesFromResource(R.xml.print_settings); |