Help menus for several screens.

Bug: 5144896
Change-Id: Ib2f5146f6f62f2a33261bb165c3bf1bf13b22f38
diff --git a/res/menu/data_usage.xml b/res/menu/data_usage.xml
index 7847f3b..8a31024 100644
--- a/res/menu/data_usage.xml
+++ b/res/menu/data_usage.xml
@@ -38,4 +38,7 @@
     <item
         android:id="@+id/data_usage_menu_metered"
         android:title="@string/data_usage_menu_metered" />
+    <item
+        android:id="@+id/data_usage_menu_help"
+        android:title="@string/help_label" />
 </menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6337824..7ce4c25 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3941,4 +3941,29 @@
     <string name="app_notifications_switch_on">Enabled</string>
     <!-- Label for disabled state "notifications enabled" switch in app details [CHAR LIMIT=10] -->
     <string name="app_notifications_switch_off">Disabled</string>
+
+
+    <!--  Help URLs for some screens. Not specified here. Specified in product overlays --><skip/>
+    <!-- Help menu label [CHAR LIMIT=20] -->
+    <string name="help_label">Help</string>
+    <!-- Help URL, WiFi [DO NOT TRANSLATE] -->
+    <string name="help_url_wifi" translatable="false"></string>
+    <!-- Help URL, Bluetooth [DO NOT TRANSLATE] -->
+    <string name="help_url_bluetooth" translatable="false"></string>
+    <!-- Help URL, Data usage [DO NOT TRANSLATE] -->
+    <string name="help_url_data_usage" translatable="false"></string>
+    <!-- Help URL, More [DO NOT TRANSLATE] -->
+    <string name="help_url_more_networks" translatable="false"></string>
+    <!-- Help URL, Vpn [DO NOT TRANSLATE] -->
+    <string name="help_url_vpn" translatable="false"></string>
+    <!-- Help URL, Sound [DO NOT TRANSLATE] -->
+    <string name="help_url_sound" translatable="false"></string>
+    <!-- Help URL, Battery [DO NOT TRANSLATE] -->
+    <string name="help_url_battery" translatable="false"></string>
+    <!-- Help URL, Accounts [DO NOT TRANSLATE] -->
+    <string name="help_url_accounts" translatable="false"></string>
+    <!-- Help URL, Choose lockscreen [DO NOT TRANSLATE] -->
+    <string name="help_url_choose_lockscreen" translatable="false"></string>
+    <!-- Help URL, Backup & reset [DO NOT TRANSLATE] -->
+    <string name="help_url_backup_reset" translatable="false"></string>
 </resources>
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java
index 88f7ae6..64f7607 100644
--- a/src/com/android/settings/ChooseLockGeneric.java
+++ b/src/com/android/settings/ChooseLockGeneric.java
@@ -377,5 +377,11 @@
             }
             finish();
         }
+
+        @Override
+        protected int getHelpResource() {
+            return R.string.help_url_choose_lockscreen;
+        }
+
     }
 }
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java
index 0d003b3..62c86d8 100644
--- a/src/com/android/settings/DataUsageSummary.java
+++ b/src/com/android/settings/DataUsageSummary.java
@@ -76,6 +76,7 @@
 import android.net.NetworkStatsHistory;
 import android.net.NetworkTemplate;
 import android.net.TrafficStats;
+import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.INetworkManagementService;
@@ -478,6 +479,18 @@
         } else {
             metered.setVisible(false);
         }
+
+        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))) {
+            Intent helpIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
+            helpIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+            help.setIntent(helpIntent);
+            help.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+        } else {
+            help.setVisible(false);
+        }
     }
 
     @Override
diff --git a/src/com/android/settings/PrivacySettings.java b/src/com/android/settings/PrivacySettings.java
index 3f3b9ad..e2433bd 100644
--- a/src/com/android/settings/PrivacySettings.java
+++ b/src/com/android/settings/PrivacySettings.java
@@ -203,4 +203,9 @@
         mAutoRestore.setEnabled(enable);
         mConfigure.setEnabled(enable);
     }
+
+    @Override
+    protected int getHelpResource() {
+        return R.string.help_url_backup_reset;
+    }
 }
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index f7e3b02..8500f8d 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -21,11 +21,17 @@
 import android.app.Fragment;
 import android.content.ContentResolver;
 import android.content.DialogInterface;
+import android.content.Intent;
 import android.content.pm.PackageManager;
+import android.net.Uri;
 import android.os.Bundle;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceFragment;
+import android.text.TextUtils;
 import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
 import android.widget.Button;
 
 /**
@@ -35,13 +41,51 @@
 
     private static final String TAG = "SettingsPreferenceFragment";
 
+    private static final int MENU_HELP = Menu.FIRST + 100;
+
     private SettingsDialogFragment mDialogFragment;
 
+    private String mHelpUrl;
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+
+        // Prepare help url and enable menu if necessary
+        int helpResource = getHelpResource();
+        if (helpResource != 0) {
+            mHelpUrl = getResources().getString(helpResource);
+            if (!TextUtils.isEmpty(mHelpUrl)) {
+                setHasOptionsMenu(true);
+            }
+        }
+    }
+
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
     }
 
+    /**
+     * Override this if you want to show a help item in the menu, by returning the resource id.
+     * @return the resource id for the help url
+     */
+    protected int getHelpResource() {
+        return 0;
+    }
+
+    @Override
+    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        if (mHelpUrl != null) {
+            Intent helpIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mHelpUrl));
+            helpIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+            MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label);
+            helpItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+            helpItem.setIntent(helpIntent);
+        }
+    }
+
     /*
      * The name is intentionally made different from Activity#finish(), so that
      * users won't misunderstand its meaning.
diff --git a/src/com/android/settings/SoundSettings.java b/src/com/android/settings/SoundSettings.java
index ade45bd..59e40df 100644
--- a/src/com/android/settings/SoundSettings.java
+++ b/src/com/android/settings/SoundSettings.java
@@ -339,4 +339,9 @@
 
         return true;
     }
+
+    @Override
+    protected int getHelpResource() {
+        return R.string.help_url_sound;
+    }
 }
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index ecddd0d..884ff91 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -201,4 +201,9 @@
                     mAirplaneModePreference.isChecked());
         }
     }
+
+    @Override
+    protected int getHelpResource() {
+        return R.string.help_url_more_networks;
+    }
 }
diff --git a/src/com/android/settings/accounts/ManageAccountsSettings.java b/src/com/android/settings/accounts/ManageAccountsSettings.java
index 0177491..f5e143d 100644
--- a/src/com/android/settings/accounts/ManageAccountsSettings.java
+++ b/src/com/android/settings/accounts/ManageAccountsSettings.java
@@ -163,6 +163,7 @@
         MenuItem addAccountItem = menu.add(0, MENU_ADD_ACCOUNT, 0, R.string.add_account_label);
         addAccountItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
                 | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
+        super.onCreateOptionsMenu(menu, inflater);
     }
 
     @Override
@@ -295,4 +296,9 @@
         intent.putExtra(AUTHORITIES_FILTER_KEY, mAuthorities);
         startActivity(intent);
     }
+
+    @Override
+    protected int getHelpResource() {
+        return R.string.help_url_accounts;
+    }
 }
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 7c8cb6e..d30e428 100755
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -182,6 +182,7 @@
                 .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
         menu.add(Menu.NONE, MENU_ID_SHOW_RECEIVED, 0, R.string.bluetooth_show_received_files)
                 .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+        super.onCreateOptionsMenu(menu, inflater);
     }
 
     @Override
@@ -378,4 +379,9 @@
             preference.setOnSettingsClickListener(mDeviceProfilesListener);
         }
     }
+
+    @Override
+    protected int getHelpResource() {
+        return R.string.help_url_bluetooth;
+    }
 }
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index b813ec6..fa2b02d 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -21,6 +21,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.hardware.SensorManager;
+import android.net.Uri;
 import android.os.BatteryStats;
 import android.os.BatteryStats.Uid;
 import android.os.Bundle;
@@ -37,6 +38,7 @@
 import android.preference.PreferenceGroup;
 import android.preference.PreferenceScreen;
 import android.telephony.SignalStrength;
+import android.text.TextUtils;
 import android.util.Log;
 import android.util.SparseArray;
 import android.view.Menu;
@@ -72,6 +74,7 @@
 
     private static final int MENU_STATS_TYPE = Menu.FIRST;
     private static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
+    private static final int MENU_HELP = Menu.FIRST + 2;
 
     private static BatteryStatsImpl sStatsXfer;
 
@@ -318,6 +321,16 @@
                 .setAlphabeticShortcut('r');
         refresh.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
                 MenuItem.SHOW_AS_ACTION_WITH_TEXT);
+
+        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);
+            Intent helpIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
+            helpIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+            help.setIntent(helpIntent);
+            help.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+        }
     }
 
     @Override
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index 5db434c..a26623b 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -464,6 +464,11 @@
         }
     }
 
+    @Override
+    protected int getHelpResource() {
+        return R.string.help_url_vpn;
+    }
+
     private class VpnPreference extends Preference {
         private VpnProfile mProfile;
         private int mState = -1;
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 8f64edf..04d0220 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -879,4 +879,9 @@
             mScanner.resume();
         }
     }
+
+    @Override
+    protected int getHelpResource() {
+        return R.string.help_url_wifi;
+    }
 }