Merge "Fix preferences v14 issues in lock screeen setup"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index acdc3ca..9ad93db 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -672,7 +672,6 @@
                   android:excludeFromRecents="true">
             <intent-filter android:priority="1">
                 <action android:name="com.android.settings.USER_DICTIONARY_INSERT" />
-                <action android:name="com.android.settings.USER_DICTIONARY_EDIT" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -1737,27 +1736,6 @@
         <activity android:name=".AppPicker" android:label="@string/select_application"
                 android:theme="@android:style/Theme.Material.Light.Dialog" />
 
-        <activity android:name="Settings$UsbSettingsActivity"
-                android:label="@string/storage_title_usb"
-                android:taskAffinity="com.android.settings"
-                android:parentActivityName="Settings$StorageSettingsActivity">
-            <intent-filter android:priority="1">
-                <action android:name="android.settings.STORAGE_USB_SETTINGS" />
-                <action android:name="com.android.settings.STORAGE_USB_SETTINGS" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
-            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                android:value="com.android.settings.deviceinfo.UsbSettings" />
-            <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
-                android:resource="@id/storage_settings" />
-            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
-                android:value="true" />
-        </activity>
-
         <!-- Keep compatibility with old shortcuts. -->
         <activity-alias android:name="UsbSettings"
                   android:exported="true"
diff --git a/res/layout/add_account_screen.xml b/res/layout/add_account_screen.xml
deleted file mode 100644
index 7e1564c..0000000
--- a/res/layout/add_account_screen.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/* //device/apps/common/assets/res/layout/list_content.xml
-**
-** Copyright 2006, 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="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical"
-    android:paddingStart="16dip"
-    android:paddingEnd="16dip">
-
-    <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list"
-        android:layout_width="match_parent"
-        android:layout_height="0dip"
-        android:layout_weight="1"
-        android:drawSelectorOnTop="false"
-        android:scrollbarAlwaysDrawVerticalTrack="true"
-    />
-
-</LinearLayout>
diff --git a/res/layout/managed_service_settings.xml b/res/layout/managed_service_settings.xml
deleted file mode 100644
index b2fc0b2..0000000
--- a/res/layout/managed_service_settings.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2013 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="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical">
-
-    <FrameLayout
-            android:layout_width="match_parent"
-            android:layout_height="0px"
-            android:layout_weight="1">
-
-        <ListView android:id="@android:id/list"
-                android:layout_width="match_parent" 
-                android:layout_height="match_parent"
-                android:paddingStart="@dimen/settings_side_margin"
-                android:paddingEnd="@dimen/settings_side_margin"
-                android:drawSelectorOnTop="false"
-                android:fastScrollEnabled="true"
-                android:scrollbarStyle="outsideInset" />
-
-        <TextView android:id="@android:id/empty"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:gravity="center"
-                android:textAppearance="?android:attr/textAppearanceMedium" />
-
-    </FrameLayout>
-
-</LinearLayout>
diff --git a/src/com/android/settings/accounts/ChooseAccountActivity.java b/src/com/android/settings/accounts/ChooseAccountActivity.java
index d1e29f3..f2f1f86 100644
--- a/src/com/android/settings/accounts/ChooseAccountActivity.java
+++ b/src/com/android/settings/accounts/ChooseAccountActivity.java
@@ -96,7 +96,6 @@
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
-        setContentView(R.layout.add_account_screen);
         addPreferencesFromResource(R.xml.add_account_settings);
         mAuthorities = getIntent().getStringArrayExtra(
                 AccountPreferenceBase.AUTHORITIES_FILTER_KEY);
diff --git a/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java b/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java
index b3e30af..b44bc33 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java
@@ -138,6 +138,10 @@
         @Override
         protected void onPostExecute(Exception e) {
             final StorageWizardFormatProgress activity = mActivity;
+            if (activity.isDestroyed()) {
+                return;
+            }
+
             if (e != null) {
                 Log.e(TAG, "Failed to partition", e);
                 Toast.makeText(activity, e.getMessage(), Toast.LENGTH_LONG).show();
diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java
index ab5c2d6..d457939 100644
--- a/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java
+++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java
@@ -56,7 +56,10 @@
         // The following will get the EXTRA_WORD and EXTRA_LOCALE fields that are in the intent.
         // We do need to add the action by hand, because UserDictionaryAddWordContents expects
         // it to be in the bundle, in the EXTRA_MODE key.
-        final Bundle args = intent.getExtras();
+        Bundle args = intent.getExtras();
+        if (args == null) {
+            args = new Bundle();
+        }
         args.putInt(UserDictionaryAddWordContents.EXTRA_MODE, mode);
 
         if (null != savedInstanceState) {
@@ -74,6 +77,7 @@
 
     private void reportBackToCaller(final int resultCode, final Bundle result) {
         final Intent senderIntent = getIntent();
+        if (senderIntent.getExtras() == null) return;
         final Object listener = senderIntent.getExtras().get("listener");
         if (!(listener instanceof Messenger)) return; // This will work if listener is null too.
         final Messenger messenger = (Messenger)listener;
diff --git a/src/com/android/settings/notification/EmptyTextSettings.java b/src/com/android/settings/notification/EmptyTextSettings.java
new file mode 100644
index 0000000..dd7a321
--- /dev/null
+++ b/src/com/android/settings/notification/EmptyTextSettings.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+package com.android.settings.notification;
+
+import android.annotation.Nullable;
+import android.os.Bundle;
+import android.util.TypedValue;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
+import android.widget.TextView;
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+public abstract class EmptyTextSettings extends SettingsPreferenceFragment {
+
+    private TextView mEmpty;
+
+    @Override
+    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+        super.onViewCreated(view, savedInstanceState);
+        mEmpty = new TextView(getContext());
+        mEmpty.setGravity(Gravity.CENTER);
+        TypedValue value = new TypedValue();
+        getContext().getTheme().resolveAttribute(android.R.attr.textAppearanceMedium, value, true);
+        mEmpty.setTextAppearance(value.resourceId);
+        ((ViewGroup) view.findViewById(R.id.list_container)).addView(mEmpty,
+                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
+        setEmptyView(mEmpty);
+    }
+
+    protected void setEmptyText(int text) {
+        mEmpty.setText(text);
+    }
+}
diff --git a/src/com/android/settings/notification/ManagedServiceSettings.java b/src/com/android/settings/notification/ManagedServiceSettings.java
index 8775933..401e650 100644
--- a/src/com/android/settings/notification/ManagedServiceSettings.java
+++ b/src/com/android/settings/notification/ManagedServiceSettings.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.notification;
 
+import android.annotation.Nullable;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.DialogFragment;
@@ -30,19 +31,14 @@
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.Preference.OnPreferenceChangeListener;
 import android.support.v7.preference.PreferenceScreen;
-import android.view.LayoutInflater;
 import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ListView;
 import android.widget.TextView;
-
 import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
 
 import java.util.Collections;
 import java.util.List;
 
-public abstract class ManagedServiceSettings extends SettingsPreferenceFragment {
+public abstract class ManagedServiceSettings extends EmptyTextSettings {
     private final Config mConfig;
 
     private Context mContext;
@@ -73,13 +69,9 @@
     }
 
     @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
-            Bundle savedInstanceState) {
-        final View v =  inflater.inflate(R.layout.managed_service_settings, container, false);
-        mEmpty = (TextView) v.findViewById(android.R.id.empty);
-        mEmpty.setText(mConfig.emptyText);
-        ((ListView) v.findViewById(android.R.id.list)).setEmptyView(mEmpty);
-        return v;
+    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+        super.onViewCreated(view, savedInstanceState);
+        setEmptyText(mConfig.emptyText);
     }
 
     @Override
diff --git a/src/com/android/settings/notification/ZenAccessSettings.java b/src/com/android/settings/notification/ZenAccessSettings.java
index d125d21..1c85f4d 100644
--- a/src/com/android/settings/notification/ZenAccessSettings.java
+++ b/src/com/android/settings/notification/ZenAccessSettings.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.notification;
 
+import android.annotation.Nullable;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.DialogFragment;
@@ -38,27 +39,21 @@
 import android.support.v7.preference.PreferenceScreen;
 import android.text.TextUtils;
 import android.util.ArraySet;
-import android.view.LayoutInflater;
 import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
 import com.android.internal.logging.MetricsLogger;
 import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-public class ZenAccessSettings extends SettingsPreferenceFragment {
+public class ZenAccessSettings extends EmptyTextSettings {
 
     private final SettingObserver mObserver = new SettingObserver();
 
     private Context mContext;
     private PackageManager mPkgMan;
     private NotificationManager mNoMan;
-    private TextView mEmpty;
 
     @Override
     protected int getMetricsCategory() {
@@ -76,12 +71,9 @@
     }
 
     @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
-            Bundle savedInstanceState) {
-        final View v =  inflater.inflate(R.layout.managed_service_settings, container, false);
-        mEmpty = (TextView) v.findViewById(android.R.id.empty);
-        mEmpty.setText(R.string.zen_access_empty_text);
-        return v;
+    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+        super.onViewCreated(view, savedInstanceState);
+        setEmptyText(R.string.zen_access_empty_text);
     }
 
     @Override
@@ -141,7 +133,6 @@
             });
             screen.addPreference(pref);
         }
-        mEmpty.setVisibility(apps.isEmpty() ? View.VISIBLE : View.GONE);
     }
 
     private boolean hasAccess(String pkg) {