Help dialog for useragent switcher lab

Change-Id: I1126f2dae652a36a133aa85a3a8aa823ab875b7b
diff --git a/res/drawable-mdpi/help_useragent_laptop.png b/res/drawable-mdpi/help_useragent_laptop.png
new file mode 100644
index 0000000..59aa721
--- /dev/null
+++ b/res/drawable-mdpi/help_useragent_laptop.png
Binary files differ
diff --git a/res/drawable-mdpi/help_useragent_tablet.png b/res/drawable-mdpi/help_useragent_tablet.png
new file mode 100644
index 0000000..7b579cd
--- /dev/null
+++ b/res/drawable-mdpi/help_useragent_tablet.png
Binary files differ
diff --git a/res/layout/help_dialog_useragent_switcher.xml b/res/layout/help_dialog_useragent_switcher.xml
new file mode 100644
index 0000000..cc29a2d
--- /dev/null
+++ b/res/layout/help_dialog_useragent_switcher.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:orientation="vertical">
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/help_useragent_switcher" />
+
+    <ImageView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:src="@drawable/help_useragent_tablet" />
+
+    <ImageView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:src="@drawable/help_useragent_laptop" />
+
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ad8f64d..ae28023 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -665,7 +665,9 @@
     <!-- Title for the useragent switcher lab feature [CHAR LIMIT=40] -->
     <string name="pref_enable_useragent_switcher">Useragent Switcher</string>
     <!-- Summary for the useragent switcher lab feature [CHAR LIMIT=120] -->
-    <string name="pref_enable_useragent_switcher_summary">Toggle between tablet and desktop versions of a site (per tab)</string>
+    <string name="pref_enable_useragent_switcher_summary">Toggle between the tablet and desktop versions of a site</string>
+    <!-- Text explaining how to use the useragent switcher lab feature [CHAR LIMIT=none] -->
+    <string name="help_useragent_switcher">Tap on the Android or laptop icon to toggle between the tablet and desktop versions of a site.</string>
 
     <!-- Title for a dialog displayed when the browser has a data connectivity
             problem -->
diff --git a/src/com/android/browser/preferences/LabPreferencesFragment.java b/src/com/android/browser/preferences/LabPreferencesFragment.java
index f99b96d..d9ef3df 100644
--- a/src/com/android/browser/preferences/LabPreferencesFragment.java
+++ b/src/com/android/browser/preferences/LabPreferencesFragment.java
@@ -22,11 +22,14 @@
 import com.android.browser.R;
 import com.android.browser.search.SearchEngine;
 
+import android.app.AlertDialog;
 import android.content.Intent;
 import android.os.Bundle;
 import android.preference.Preference;
 import android.preference.Preference.OnPreferenceChangeListener;
 import android.preference.PreferenceFragment;
+import android.view.LayoutInflater;
+import android.view.View;
 
 public class LabPreferencesFragment extends PreferenceFragment
         implements OnPreferenceChangeListener {
@@ -41,12 +44,16 @@
 
         // Load the XML preferences file
         addPreferencesFromResource(R.xml.lab_preferences);
+        registerChangeListener(PreferenceKeys.PREF_ENABLE_QUICK_CONTROLS);
+        registerChangeListener(PreferenceKeys.PREF_ENABLE_USERAGENT_SWITCHER);
+        useInstantPref = findPreference(PreferenceKeys.PREF_USE_INSTANT_SEARCH);
+    }
 
-        Preference e = findPreference(PreferenceKeys.PREF_ENABLE_QUICK_CONTROLS);
+    private void registerChangeListener(String key) {
+        Preference e = findPreference(key);
         if (e != null) {
             e.setOnPreferenceChangeListener(this);
         }
-        useInstantPref = findPreference(PreferenceKeys.PREF_USE_INSTANT_SEARCH);
     }
 
     @Override
@@ -68,9 +75,23 @@
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
-        // Attempt to restart
-        startActivity(new Intent(BrowserActivity.ACTION_RESTART, null,
-                getActivity(), BrowserActivity.class));
+        String key = preference.getKey();
+        if (PreferenceKeys.PREF_ENABLE_QUICK_CONTROLS.equals(key)) {
+            // Attempt to restart
+            startActivity(new Intent(BrowserActivity.ACTION_RESTART, null,
+                    getActivity(), BrowserActivity.class));
+        }
+        if (PreferenceKeys.PREF_ENABLE_USERAGENT_SWITCHER.equals(key)) {
+            if ((Boolean)newValue) {
+                // Show the help
+                LayoutInflater inflater = LayoutInflater.from(getActivity());
+                View content = inflater.inflate(R.layout.help_dialog_useragent_switcher, null);
+                new AlertDialog.Builder(getActivity())
+                        .setView(content)
+                        .setNeutralButton(android.R.string.ok, null)
+                        .show();
+            }
+        }
         return true;
     }
 }