Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1235be6 authored by Jason Monk's avatar Jason Monk Committed by Android (Google) Code Review
Browse files

Merge "Allow help to be defined to intent uri"

parents bc90ee87 23acc2bb
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -5507,6 +5507,34 @@
    <!--  Help URLs for some screens. Not specified here. Specified in product overlays --><skip/>
    <!-- Help menu label [CHAR LIMIT=20] -->
    <string name="help_label">Help &amp; feedback</string>

    <!-- Help URI, Default [DO NOT TRANSLATE] -->
    <string name="help_uri_default" translatable="false"></string>
    <!-- Help URI, Dashboard [DO NOT TRANSLATE] -->
    <string name="help_uri_dashboard" translatable="false"></string>
    <!-- Help URI, Android beam [DO NOT TRANSLATE] -->
    <string name="help_uri_beam" translatable="false"></string>
    <!-- Help URI, Display [DO NOT TRANSLATE] -->
    <string name="help_uri_display" translatable="false"></string>
    <!-- Help URI, Wallpaper [DO NOT TRANSLATE] -->
    <string name="help_uri_wallpaper" translatable="false"></string>
    <!-- Help URI, Interruptions [DO NOT TRANSLATE] -->
    <string name="help_uri_interruptions" translatable="false"></string>
    <!-- Help URI, Other sounds [DO NOT TRANSLATE] -->
    <string name="help_uri_other_sounds" translatable="false"></string>
    <!-- Help URI, Notifications [DO NOT TRANSLATE] -->
    <string name="help_uri_notifications" translatable="false"></string>
    <!-- Help URI, Apps [DO NOT TRANSLATE] -->
    <string name="help_uri_apps" translatable="false"></string>
    <!-- Help URI, Storage [DO NOT TRANSLATE] -->
    <string name="help_uri_storage" translatable="false"></string>
    <!-- Help URI, Accessibility [DO NOT TRANSLATE] -->
    <string name="help_uri_accessibility" translatable="false"></string>
    <!-- Help URI, Printing [DO NOT TRANSLATE] -->
    <string name="help_uri_printing" translatable="false"></string>
    <!-- Help URI, About phone [DO NOT TRANSLATE] -->
    <string name="help_uri_about" translatable="false"></string>

    <!-- Help URL, WiFi [DO NOT TRANSLATE] -->
    <string name="help_url_wifi" translatable="false"></string>
    <!-- Help URL, Bluetooth [DO NOT TRANSLATE] -->
+5 −0
Original line number Diff line number Diff line
@@ -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);
+5 −0
Original line number Diff line number Diff line
@@ -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
+36 −11
Original line number Diff line number Diff line
@@ -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.
+6 −8
Original line number Diff line number Diff line
@@ -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);
        }
    }

Loading