Merge "Fix UI to mocks" into lmp-dev
diff --git a/res/xml/language_settings.xml b/res/xml/language_settings.xml
index 9d12857..b60dc5e 100644
--- a/res/xml/language_settings.xml
+++ b/res/xml/language_settings.xml
@@ -65,34 +65,6 @@
             android:persistent="false">
         <!-- Additional preference screens are inserted here programmatically
              with low order values to set the key map of each attached keyboard. -->
-
-        <CheckBoxPreference
-                android:key="auto_replace"
-                android:title="@string/auto_replace"
-                android:summaryOn="@string/auto_replace_summary"
-                android:summaryOff="@string/auto_replace_summary"
-                android:order="1000"
-                android:persistent="false"
-                />
-
-        <CheckBoxPreference
-                android:key="auto_caps"
-                android:title="@string/auto_caps"
-                android:summaryOn="@string/auto_caps_summary"
-                android:summaryOff="@string/auto_caps_summary"
-                android:order="1001"
-                android:persistent="false"
-                />
-
-        <CheckBoxPreference
-                android:key="auto_punctuate"
-                android:title="@string/auto_punctuate"
-                android:summaryOn="@string/auto_punctuate_summary"
-                android:summaryOff="@string/auto_punctuate_summary"
-                android:order="1002"
-                android:persistent="false"
-                />
-
     </PreferenceCategory>
 
     <PreferenceCategory
diff --git a/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java b/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
index b80e42a..4466aea 100644
--- a/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
@@ -92,7 +92,6 @@
             mDeviceNameEdited = savedInstanceState.getBoolean(KEY_NAME_EDITED, false);
         }
         mAlertDialog = new AlertDialog.Builder(getActivity())
-                .setIcon(android.R.drawable.ic_dialog_info)
                 .setTitle(R.string.bluetooth_rename_device)
                 .setView(createDialogView(deviceName))
                 .setPositiveButton(R.string.bluetooth_rename_button,
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
index d88c516..9d3edd5 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
@@ -86,7 +86,7 @@
 
         void addTick(int x, int bin) {
             if (bin != mLastBin && mNumTicks < mTicks.length) {
-                mTicks[mNumTicks] = x | bin << CHART_DATA_BIN_SHIFT;
+                mTicks[mNumTicks] = (x&CHART_DATA_X_MASK) | (bin<<CHART_DATA_BIN_SHIFT);
                 mNumTicks++;
                 mLastBin = bin;
             }
@@ -540,6 +540,7 @@
         }
         mDrainString = "";
         mChargeDurationString = "";
+        setContentDescription(mChargeLabelString);
 
         int pos = 0;
         int lastInteresting = 0;
@@ -804,6 +805,9 @@
                 }
                 if (curWalltime != 0 && rec.isDeltaData()) {
                     x = mLevelLeft + (int)(((curWalltime-walltimeStart)*levelWidth)/walltimeChange);
+                    if (x < 0) {
+                        x = 0;
+                    }
                     if (false) {
                         StringBuilder sb = new StringBuilder(128);
                         sb.append("walloff=");
@@ -984,6 +988,9 @@
         } else {
             // Figure out where the actual data ends on the screen.
             x = mLevelLeft + (int)(((mEndDataWallTime-walltimeStart)*levelWidth)/walltimeChange);
+            if (x < 0) {
+                x = 0;
+            }
         }
 
         finishPaths(x, h, levelh, startX, lastY, curLevelPath, lastX,
diff --git a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
index 1601cd0..b8ae493 100644
--- a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
+++ b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java
@@ -88,14 +88,6 @@
     // false: on ICS or later
     private static final boolean SHOW_INPUT_METHOD_SWITCHER_SETTINGS = false;
 
-    private static final String[] sSystemSettingNames = {
-        System.TEXT_AUTO_REPLACE, System.TEXT_AUTO_CAPS, System.TEXT_AUTO_PUNCTUATE,
-    };
-
-    private static final String[] sHardKeyboardKeys = {
-        "auto_replace", "auto_caps", "auto_punctuate",
-    };
-
     private int mDefaultInputMethodSelectorVisibility = 0;
     private ListPreference mShowInputMethodSelectorPref;
     private PreferenceCategory mKeyboardSettingsCategory;
@@ -274,16 +266,6 @@
             }
         }
 
-        // Hard keyboard
-        if (!mHardKeyboardPreferenceList.isEmpty()) {
-            for (int i = 0; i < sHardKeyboardKeys.length; ++i) {
-                CheckBoxPreference chkPref = (CheckBoxPreference)
-                        mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i]);
-                chkPref.setChecked(
-                        System.getInt(getContentResolver(), sSystemSettingNames[i], 1) > 0);
-            }
-        }
-
         updateInputDevices();
 
         // Refresh internal states in mInputMethodSettingValues to keep the latest
@@ -339,15 +321,6 @@
             }
         } else if (preference instanceof CheckBoxPreference) {
             final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
-            if (!mHardKeyboardPreferenceList.isEmpty()) {
-                for (int i = 0; i < sHardKeyboardKeys.length; ++i) {
-                    if (chkPref == mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i])) {
-                        System.putInt(getContentResolver(), sSystemSettingNames[i],
-                                chkPref.isChecked() ? 1 : 0);
-                        return true;
-                    }
-                }
-            }
             if (chkPref == mGameControllerCategory.findPreference("vibrate_input_devices")) {
                 System.putInt(getContentResolver(), Settings.System.VIBRATE_INPUT_DEVICES,
                         chkPref.isChecked() ? 1 : 0);
@@ -564,35 +537,33 @@
 
     private void updateHardKeyboards() {
         mHardKeyboardPreferenceList.clear();
-        if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY) {
-            final int[] devices = InputDevice.getDeviceIds();
-            for (int i = 0; i < devices.length; i++) {
-                InputDevice device = InputDevice.getDevice(devices[i]);
-                if (device != null
-                        && !device.isVirtual()
-                        && device.isFullKeyboard()) {
-                    final InputDeviceIdentifier identifier = device.getIdentifier();
-                    final String keyboardLayoutDescriptor =
-                            mIm.getCurrentKeyboardLayoutForInputDevice(identifier);
-                    final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ?
-                            mIm.getKeyboardLayout(keyboardLayoutDescriptor) : null;
+        final int[] devices = InputDevice.getDeviceIds();
+        for (int i = 0; i < devices.length; i++) {
+            InputDevice device = InputDevice.getDevice(devices[i]);
+            if (device != null
+                    && !device.isVirtual()
+                    && device.isFullKeyboard()) {
+                final InputDeviceIdentifier identifier = device.getIdentifier();
+                final String keyboardLayoutDescriptor =
+                    mIm.getCurrentKeyboardLayoutForInputDevice(identifier);
+                final KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ?
+                    mIm.getKeyboardLayout(keyboardLayoutDescriptor) : null;
 
-                    final PreferenceScreen pref = new PreferenceScreen(getActivity(), null);
-                    pref.setTitle(device.getName());
-                    if (keyboardLayout != null) {
-                        pref.setSummary(keyboardLayout.toString());
-                    } else {
-                        pref.setSummary(R.string.keyboard_layout_default_label);
-                    }
-                    pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
-                        @Override
-                        public boolean onPreferenceClick(Preference preference) {
-                            showKeyboardLayoutDialog(identifier);
-                            return true;
-                        }
-                    });
-                    mHardKeyboardPreferenceList.add(pref);
+                final PreferenceScreen pref = new PreferenceScreen(getActivity(), null);
+                pref.setTitle(device.getName());
+                if (keyboardLayout != null) {
+                    pref.setSummary(keyboardLayout.toString());
+                } else {
+                    pref.setSummary(R.string.keyboard_layout_default_label);
                 }
+                pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+                    @Override
+                    public boolean onPreferenceClick(Preference preference) {
+                        showKeyboardLayoutDialog(identifier);
+                        return true;
+                    }
+                });
+                mHardKeyboardPreferenceList.add(pref);
             }
         }
 
@@ -795,76 +766,74 @@
             // Hard keyboards
             InputManager inputManager = (InputManager) context.getSystemService(
                     Context.INPUT_SERVICE);
-            if (resources.getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY) {
-                boolean hasHardKeyboards = false;
+            boolean hasHardKeyboards = false;
 
-                final int[] devices = InputDevice.getDeviceIds();
-                for (int i = 0; i < devices.length; i++) {
-                    InputDevice device = InputDevice.getDevice(devices[i]);
-                    if (device == null || device.isVirtual() || !device.isFullKeyboard()) {
-                        continue;
-                    }
-
-                    hasHardKeyboards = true;
-
-                    InputDeviceIdentifier identifier = device.getIdentifier();
-                    String keyboardLayoutDescriptor =
-                            inputManager.getCurrentKeyboardLayoutForInputDevice(identifier);
-                    KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ?
-                            inputManager.getKeyboardLayout(keyboardLayoutDescriptor) : null;
-
-                    String summary;
-                    if (keyboardLayout != null) {
-                        summary = keyboardLayout.toString();
-                    } else {
-                        summary = context.getString(R.string.keyboard_layout_default_label);
-                    }
-
-                    indexable = new SearchIndexableRaw(context);
-                    indexable.key = device.getName();
-                    indexable.title = device.getName();
-                    indexable.summaryOn = summary;
-                    indexable.summaryOff = summary;
-                    indexable.screenTitle = screenTitle;
-                    indexables.add(indexable);
+            final int[] devices = InputDevice.getDeviceIds();
+            for (int i = 0; i < devices.length; i++) {
+                InputDevice device = InputDevice.getDevice(devices[i]);
+                if (device == null || device.isVirtual() || !device.isFullKeyboard()) {
+                    continue;
                 }
 
-                if (hasHardKeyboards) {
-                    // Hard keyboard category.
-                    indexable = new SearchIndexableRaw(context);
-                    indexable.key = "builtin_keyboard_settings";
-                    indexable.title = context.getString(
-                            R.string.builtin_keyboard_settings_title);
-                    indexable.screenTitle = screenTitle;
-                    indexables.add(indexable);
+                hasHardKeyboards = true;
 
-                    // Auto replace.
-                    indexable = new SearchIndexableRaw(context);
-                    indexable.key = "auto_replace";
-                    indexable.title = context.getString(R.string.auto_replace);
-                    indexable.summaryOn = context.getString(R.string.auto_replace_summary);
-                    indexable.summaryOff = context.getString(R.string.auto_replace_summary);
-                    indexable.screenTitle = screenTitle;
-                    indexables.add(indexable);
+                InputDeviceIdentifier identifier = device.getIdentifier();
+                String keyboardLayoutDescriptor =
+                        inputManager.getCurrentKeyboardLayoutForInputDevice(identifier);
+                KeyboardLayout keyboardLayout = keyboardLayoutDescriptor != null ?
+                        inputManager.getKeyboardLayout(keyboardLayoutDescriptor) : null;
 
-                    // Auto caps.
-                    indexable = new SearchIndexableRaw(context);
-                    indexable.key = "auto_caps";
-                    indexable.title = context.getString(R.string.auto_caps);
-                    indexable.summaryOn = context.getString(R.string.auto_caps_summary);
-                    indexable.summaryOff = context.getString(R.string.auto_caps_summary);
-                    indexable.screenTitle = screenTitle;
-                    indexables.add(indexable);
-
-                    // Auto punctuate.
-                    indexable = new SearchIndexableRaw(context);
-                    indexable.key = "auto_punctuate";
-                    indexable.title = context.getString(R.string.auto_punctuate);
-                    indexable.summaryOn = context.getString(R.string.auto_punctuate_summary);
-                    indexable.summaryOff = context.getString(R.string.auto_punctuate_summary);
-                    indexable.screenTitle = screenTitle;
-                    indexables.add(indexable);
+                String summary;
+                if (keyboardLayout != null) {
+                    summary = keyboardLayout.toString();
+                } else {
+                    summary = context.getString(R.string.keyboard_layout_default_label);
                 }
+
+                indexable = new SearchIndexableRaw(context);
+                indexable.key = device.getName();
+                indexable.title = device.getName();
+                indexable.summaryOn = summary;
+                indexable.summaryOff = summary;
+                indexable.screenTitle = screenTitle;
+                indexables.add(indexable);
+            }
+
+            if (hasHardKeyboards) {
+                // Hard keyboard category.
+                indexable = new SearchIndexableRaw(context);
+                indexable.key = "builtin_keyboard_settings";
+                indexable.title = context.getString(
+                        R.string.builtin_keyboard_settings_title);
+                indexable.screenTitle = screenTitle;
+                indexables.add(indexable);
+
+                // Auto replace.
+                indexable = new SearchIndexableRaw(context);
+                indexable.key = "auto_replace";
+                indexable.title = context.getString(R.string.auto_replace);
+                indexable.summaryOn = context.getString(R.string.auto_replace_summary);
+                indexable.summaryOff = context.getString(R.string.auto_replace_summary);
+                indexable.screenTitle = screenTitle;
+                indexables.add(indexable);
+
+                // Auto caps.
+                indexable = new SearchIndexableRaw(context);
+                indexable.key = "auto_caps";
+                indexable.title = context.getString(R.string.auto_caps);
+                indexable.summaryOn = context.getString(R.string.auto_caps_summary);
+                indexable.summaryOff = context.getString(R.string.auto_caps_summary);
+                indexable.screenTitle = screenTitle;
+                indexables.add(indexable);
+
+                // Auto punctuate.
+                indexable = new SearchIndexableRaw(context);
+                indexable.key = "auto_punctuate";
+                indexable.title = context.getString(R.string.auto_punctuate);
+                indexable.summaryOn = context.getString(R.string.auto_punctuate_summary);
+                indexable.summaryOff = context.getString(R.string.auto_punctuate_summary);
+                indexable.screenTitle = screenTitle;
+                indexables.add(indexable);
             }
 
             // Voice recognizers.
diff --git a/src/com/android/settings/tts/TtsEngineSettingsFragment.java b/src/com/android/settings/tts/TtsEngineSettingsFragment.java
index c8531fa..2449353 100644
--- a/src/com/android/settings/tts/TtsEngineSettingsFragment.java
+++ b/src/com/android/settings/tts/TtsEngineSettingsFragment.java
@@ -140,7 +140,7 @@
 
             mLocalePreference.setEntries(entries);
             mLocalePreference.setEntryValues(entryValues);
-            mLocalePreference.setValue(value.toString());
+            mLocalePreference.setValue(value != null ? value.toString() : null);
             mLocalePreference.setEnabled(entries.length > 0);
         }
 
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index ba93931..93f9b0f 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -803,7 +803,19 @@
             mUserListCategory.addPreference(pref);
         }
 
-        if (!mIsGuest) {
+        boolean showGuestPreference = !mIsGuest;
+        // If user has DISALLOW_ADD_USER don't allow creating a guest either.
+        if (showGuestPreference && mUserManager.hasUserRestriction(UserManager.DISALLOW_ADD_USER)) {
+            showGuestPreference = false;
+            // If guest already exists, no user creation needed.
+            for (UserInfo user : users) {
+                if (user.isGuest()) {
+                    showGuestPreference = true;
+                    break;
+                }
+            }
+        }
+        if (showGuestPreference) {
             // Add a virtual Guest user for guest defaults
             Preference pref = new UserPreference(getActivity(), null,
                     UserPreference.USERID_GUEST_DEFAULTS,
@@ -930,6 +942,10 @@
             }
         }
         // No guest user. Create one.
+        if (mUserManager.hasUserRestriction(UserManager.DISALLOW_ADD_USER)) {
+            Log.i(TAG, "Blocking guest creation because it is restricted");
+            return;
+        }
         UserInfo guestUser = mUserManager.createGuest(getActivity(),
                     getResources().getString(R.string.user_guest));
         if (guestUser != null) {
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index e83cb06..5f22146 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -27,7 +27,6 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.location.LocationManager;
@@ -50,6 +49,7 @@
 import android.util.Log;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
+import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -129,7 +129,6 @@
     private WifiManager.ActionListener mConnectListener;
     private WifiManager.ActionListener mSaveListener;
     private WifiManager.ActionListener mForgetListener;
-    private boolean mP2pSupported;
 
     private WifiEnabler mWifiEnabler;
     // An access point being editted is stored here.
@@ -156,7 +155,7 @@
     private boolean mDlgEdit;
     private AccessPoint mDlgAccessPoint;
     private Bundle mAccessPointSavedState;
-    private Preference mWifiAssistantPreference;
+    private View mWifiAssistantCard;
     private NetworkScorerAppData mWifiAssistantApp;
 
     /** verbose logging flag. this flag is set thru developer debugging options
@@ -165,52 +164,6 @@
 
     /* End of "used in Wifi Setup context" */
 
-    /** Holds the Wifi Assistant Card. */
-    private class WifiAssistantPreference extends Preference {
-        public WifiAssistantPreference() {
-            super(getActivity());
-            setLayoutResource(R.layout.wifi_assistant_card);
-        }
-
-        @Override
-        public void onBindView(View view) {
-            super.onBindView(view);
-            Button setup = (Button)view.findViewById(R.id.setup);
-            Button noThanks = (Button)view.findViewById(R.id.no_thanks_button);
-
-            if (setup != null && noThanks != null) {
-                setup.setOnClickListener(new OnClickListener() {
-                    @Override
-                    public void onClick(View v) {
-                        Intent intent = new Intent();
-                        if (mWifiAssistantApp.mConfigurationActivityClassName != null) {
-                            // App has a custom configuration activity; launch that.
-                            // This custom activity will be responsible for launching the system
-                            // dialog.
-                            intent.setClassName(mWifiAssistantApp.mPackageName,
-                                    mWifiAssistantApp.mConfigurationActivityClassName);
-                        } else {
-                            // Fall back on the system dialog.
-                            intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE);
-                            intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME,
-                                    mWifiAssistantApp.mPackageName);
-                        }
-                        startActivityForResult(intent, REQUEST_ENABLE_WIFI_ASSISTANT);
-                    }
-                });
-
-                noThanks.setOnClickListener(new OnClickListener() {
-                    @Override
-                    public void onClick(View v) {
-                        setWifiAssistantTimeout();
-                        getPreferenceScreen().removePreference(WifiAssistantPreference.this);
-                        mWifiAssistantApp = null;
-                    }
-                });
-            }
-        }
-    }
-
     /** A restricted multimap for use in constructAccessPoints */
     private static class Multimap<K,V> {
         private final HashMap<K,List<V>> store = new HashMap<K,List<V>>();
@@ -285,7 +238,7 @@
         mReceiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
-                handleEvent(context, intent);
+                handleEvent(intent);
             }
         };
 
@@ -296,7 +249,6 @@
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
-        mP2pSupported = getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT);
         mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
 
         mConnectListener = new WifiManager.ActionListener() {
@@ -347,7 +299,7 @@
         if (savedInstanceState != null) {
             mDlgEdit = savedInstanceState.getBoolean(SAVE_DIALOG_EDIT_MODE);
             if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {
-                mAccessPointSavedState = 
+                mAccessPointSavedState =
                     savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
             }
         }
@@ -384,7 +336,7 @@
         if (requestCode == REQUEST_ENABLE_WIFI_ASSISTANT) {
             if (resultCode == Activity.RESULT_OK) {
                 setWifiAssistantTimeout();
-                getPreferenceScreen().removePreference(mWifiAssistantPreference);
+                getListView().removeHeaderView(mWifiAssistantCard);
                 mWifiAssistantApp = null;
             }
         } else {
@@ -706,8 +658,9 @@
                     addMessagePreference(R.string.wifi_empty_list_wifi_on);
                 }
 
+                getListView().removeHeaderView(mWifiAssistantCard);
                 if (mWifiAssistantApp != null) {
-                    getPreferenceScreen().addPreference(mWifiAssistantPreference);
+                    getListView().addHeaderView(mWifiAssistantCard);
                 }
 
                 for (AccessPoint accessPoint : accessPoints) {
@@ -732,38 +685,72 @@
         }
     }
 
-    private boolean prepareWifiAssistantCard() {
-        if (mWifiAssistantPreference == null) {
-            mWifiAssistantPreference = new WifiAssistantPreference();
-        }
-
+    private void prepareWifiAssistantCard() {
         if (getActivity() instanceof WifiPickerActivity) {
-            return false;
+            return;
         }
 
         if (NetworkScorerAppManager.getActiveScorer(getActivity()) != null) {
             // A scorer is already enabled; don't show the card.
-            return false;
+            return;
         }
 
         Collection<NetworkScorerAppData> scorers =
                 NetworkScorerAppManager.getAllValidScorers(getActivity());
         if (scorers.isEmpty()) {
             // No scorers are available to enable; don't show the card.
-            return false;
+            return;
         }
 
         SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
         long lastTimeoutEndTime = sharedPreferences.getLong(KEY_ASSISTANT_START_TIME, 0);
         long dismissTime = sharedPreferences.getLong(KEY_ASSISTANT_DISMISS_TIME, 0);
 
-        boolean shouldShow = ((System.currentTimeMillis() - lastTimeoutEndTime) > dismissTime);
-        if (shouldShow) {
-            // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first
-            // scorer on the system, we should allow the user to select one.
-            mWifiAssistantApp = scorers.iterator().next();
+        if ((System.currentTimeMillis() - lastTimeoutEndTime) <= dismissTime) {
+            return;
         }
-        return shouldShow;
+
+        // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first
+        // scorer on the system, we should allow the user to select one.
+        mWifiAssistantApp = scorers.iterator().next();
+
+        if (mWifiAssistantCard == null) {
+            mWifiAssistantCard = LayoutInflater.from(getActivity())
+                    .inflate(R.layout.wifi_assistant_card, getListView(), false);
+            Button setup = (Button) mWifiAssistantCard.findViewById(R.id.setup);
+            Button noThanks = (Button) mWifiAssistantCard.findViewById(R.id.no_thanks_button);
+
+            if (setup != null && noThanks != null) {
+                setup.setOnClickListener(new OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        Intent intent = new Intent();
+                        if (mWifiAssistantApp.mConfigurationActivityClassName != null) {
+                            // App has a custom configuration activity; launch that.
+                            // This custom activity will be responsible for launching the system
+                            // dialog.
+                            intent.setClassName(mWifiAssistantApp.mPackageName,
+                                    mWifiAssistantApp.mConfigurationActivityClassName);
+                        } else {
+                            // Fall back on the system dialog.
+                            intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE);
+                            intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME,
+                                    mWifiAssistantApp.mPackageName);
+                        }
+                        startActivityForResult(intent, REQUEST_ENABLE_WIFI_ASSISTANT);
+                    }
+                });
+
+                noThanks.setOnClickListener(new OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        setWifiAssistantTimeout();
+                        getListView().removeHeaderView(mWifiAssistantCard);
+                        mWifiAssistantApp = null;
+                    }
+                });
+            }
+        }
     }
 
     private void setWifiAssistantTimeout() {
@@ -861,7 +848,7 @@
         return accessPoints;
     }
 
-    private void handleEvent(Context context, Intent intent) {
+    private void handleEvent(Intent intent) {
         String action = intent.getAction();
         if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
             updateWifiState(intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,