Read both android: and local XML values for prefs

Also add TypedArrayUtils to v4 for easier reading of attributes using
fallback styleables.

Change-Id: I3c132baead6c2cc4ceda68ca12346536a2cd2904
diff --git a/v14/preference/res/values/attrs.xml b/v14/preference/res/values/attrs.xml
index 617e6d4..a57cfe0 100644
--- a/v14/preference/res/values/attrs.xml
+++ b/v14/preference/res/values/attrs.xml
@@ -21,18 +21,23 @@
              SwitchPreference is checked. If separate on/off summaries are not
              needed, the summary attribute can be used instead. -->
         <attr name="summaryOn" />
+        <attr name="android:summaryOn" />
         <!-- The summary for the Preference in a PreferenceActivity screen when the
              SwitchPreference is unchecked. If separate on/off summaries are not
              needed, the summary attribute can be used instead. -->
         <attr name="summaryOff" />
+        <attr name="android:summaryOff" />
         <!-- The text used on the switch itself when in the "on" state.
              This should be a very SHORT string, as it appears in a small space. -->
         <attr name="switchTextOn"/>
+        <attr name="android:switchTextOn"/>
         <!-- The text used on the switch itself when in the "off" state.
              This should be a very SHORT string, as it appears in a small space. -->
         <attr name="switchTextOff" />
+        <attr name="android:switchTextOff" />
         <!-- The state (true for on, or false for off) that causes dependents to be disabled. By default,
              dependents will be disabled when this is unchecked, so the value of this preference is false. -->
         <attr name="disableDependentsState" />
+        <attr name="android:disableDependentsState" />
     </declare-styleable>
 </resources>
diff --git a/v14/preference/src/android/support/v14/preference/SwitchPreference.java b/v14/preference/src/android/support/v14/preference/SwitchPreference.java
index c003caa..330f81b 100644
--- a/v14/preference/src/android/support/v14/preference/SwitchPreference.java
+++ b/v14/preference/src/android/support/v14/preference/SwitchPreference.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.res.TypedArray;
+import android.support.v4.content.res.TypedArrayUtils;
 import android.support.v7.preference.PreferenceViewHolder;
 import android.support.v7.preference.TwoStatePreference;
 import android.util.AttributeSet;
@@ -77,14 +78,25 @@
 
         TypedArray a = context.obtainStyledAttributes(attrs,
                 R.styleable.SwitchPreference, defStyleAttr, defStyleRes);
-        setSummaryOn(a.getString(R.styleable.SwitchPreference_summaryOn));
-        setSummaryOff(a.getString(R.styleable.SwitchPreference_summaryOff));
-        setSwitchTextOn(a.getString(
-                R.styleable.SwitchPreference_switchTextOn));
-        setSwitchTextOff(a.getString(
-                R.styleable.SwitchPreference_switchTextOff));
-        setDisableDependentsState(a.getBoolean(
-                R.styleable.SwitchPreference_disableDependentsState, false));
+
+        setSummaryOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_summaryOn,
+                R.styleable.SwitchPreference_android_summaryOn));
+
+        setSummaryOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_summaryOff,
+                R.styleable.SwitchPreference_android_summaryOff));
+
+        setSwitchTextOn(TypedArrayUtils.getString(a,
+                R.styleable.SwitchPreference_switchTextOn,
+                R.styleable.SwitchPreference_android_switchTextOn));
+
+        setSwitchTextOff(TypedArrayUtils.getString(a,
+                R.styleable.SwitchPreference_switchTextOff,
+                R.styleable.SwitchPreference_android_switchTextOff));
+
+        setDisableDependentsState(TypedArrayUtils.getBoolean(a,
+                R.styleable.SwitchPreference_disableDependentsState,
+                R.styleable.SwitchPreference_android_disableDependentsState, false));
+
         a.recycle();
     }
 
diff --git a/v4/java/android/support/v4/content/res/TypedArrayUtils.java b/v4/java/android/support/v4/content/res/TypedArrayUtils.java
new file mode 100644
index 0000000..6a34554
--- /dev/null
+++ b/v4/java/android/support/v4/content/res/TypedArrayUtils.java
@@ -0,0 +1,73 @@
+/*
+ * 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 android.support.v4.content.res;
+
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.support.annotation.AnyRes;
+import android.support.annotation.StyleableRes;
+
+/**
+ * Compat methods for accessing TypedArray values.
+ *
+ * @hide
+ */
+public class TypedArrayUtils {
+    public static boolean getBoolean(TypedArray a, @StyleableRes int index,
+            @StyleableRes int fallbackIndex, boolean defaultValue) {
+        boolean val = a.getBoolean(fallbackIndex, defaultValue);
+        return a.getBoolean(index, val);
+    }
+
+    public static Drawable getDrawable(TypedArray a, @StyleableRes int index,
+            @StyleableRes int fallbackIndex) {
+        Drawable val = a.getDrawable(index);
+        if (val == null) {
+            val = a.getDrawable(fallbackIndex);
+        }
+        return val;
+    }
+
+    public static int getInt(TypedArray a, @StyleableRes int index,
+            @StyleableRes int fallbackIndex, int defaultValue) {
+        int val = a.getInt(fallbackIndex, defaultValue);
+        return a.getInt(index, val);
+    }
+
+    public static @AnyRes int getResourceId(TypedArray a, @StyleableRes int index,
+            @StyleableRes int fallbackIndex, @AnyRes int defaultValue) {
+        int val = a.getResourceId(fallbackIndex, defaultValue);
+        return a.getResourceId(index, val);
+    }
+
+    public static String getString(TypedArray a, @StyleableRes int index,
+            @StyleableRes int fallbackIndex) {
+        String val = a.getString(index);
+        if (val == null) {
+            val = a.getString(fallbackIndex);
+        }
+        return val;
+    }
+
+    public static CharSequence[] getTextArray(TypedArray a, @StyleableRes int index,
+            @StyleableRes int fallbackIndex) {
+        CharSequence[] val = a.getTextArray(fallbackIndex);
+        if (val == null) {
+            val = a.getTextArray(fallbackIndex);
+        }
+        return val;
+    }
+}
diff --git a/v7/preference/res/values/attrs.xml b/v7/preference/res/values/attrs.xml
index 5c8219d..50f21aa 100644
--- a/v7/preference/res/values/attrs.xml
+++ b/v7/preference/res/values/attrs.xml
@@ -71,6 +71,7 @@
   <declare-styleable name="PreferenceFragmentCompat">
     <!-- The layout for the PreferenceFragment. This should rarely need to be changed. -->
     <attr name="layout" />
+    <attr name="android:layout" />
   </declare-styleable>
 
   <!-- Base attributes available to PreferenceGroup. -->
@@ -79,48 +80,63 @@
          If this is false, the ordering will follow the Preference order attribute and
          default to alphabetic for those without the order attribute. -->
     <attr name="orderingFromXml" format="boolean" />
+    <attr name="android:orderingFromXml" />
   </declare-styleable>
 
   <!-- Base attributes available to Preference. -->
   <declare-styleable name="Preference">
     <!-- The optional icon for the preference -->
     <attr name="icon" />
+    <attr name="android:icon" />
     <!-- The key to store the Preference value. -->
     <attr name="key" format="string" />
+    <attr name="android:key" />
     <!-- The title for the Preference in a PreferenceActivity screen. -->
     <attr name="title" />
+    <attr name="android:title" />
     <!-- The summary for the Preference in a PreferenceActivity screen. -->
     <attr name="summary" format="string" />
+    <attr name="android:summary" />
     <!-- The order for the Preference (lower values are to be ordered first). If this is not
          specified, the default ordering will be alphabetic. -->
     <attr name="order" format="integer" />
+    <attr name="android:order" />
     <!-- When used inside of a modern PreferenceActivity, this declares
          a new PreferenceFragment to be shown when the user selects this item. -->
     <attr name="fragment" format="string" />
+    <attr name="android:fragment" />
     <!-- The layout for the Preference in a PreferenceActivity screen. This should
          rarely need to be changed, look at widgetLayout instead. -->
     <attr name="layout" />
+    <attr name="android:layout" />
     <!-- The layout for the controllable widget portion of a Preference. This is inflated
          into the layout for a Preference and should be used more frequently than
          the layout attribute. For example, a checkbox preference would specify
          a custom layout (consisting of just the CheckBox) here. -->
     <attr name="widgetLayout" format="reference" />
+    <attr name="android:widgetLayout" />
     <!-- Whether the Preference is enabled. -->
     <attr name="enabled" format="boolean" />
+    <attr name="android:enabled" />
     <!-- Whether the Preference is selectable. -->
     <attr name="selectable" format="boolean" />
+    <attr name="android:selectable" />
     <!-- The key of another Preference that this Preference will depend on.  If the other
          Preference is not set or is off, this Preference will be disabled. -->
     <attr name="dependency" format="string" />
+    <attr name="android:dependency" />
     <!-- Whether the Preference stores its value to the shared preferences. -->
     <attr name="persistent" format="boolean" />
+    <attr name="android:persistent" />
     <!-- The default value for the preference, which will be set either if persistence
          is off or persistence is on and the preference is not found in the persistent
          storage.  -->
     <attr name="defaultValue" format="string|boolean|integer|reference|float" />
+    <attr name="android:defaultValue" />
     <!-- Whether the view of this Preference should be disabled when
          this Preference is disabled. -->
     <attr name="shouldDisableView" format="boolean" />
+    <attr name="android:shouldDisableView" />
   </declare-styleable>
 
   <!-- Base attributes available to CheckBoxPreference. -->
@@ -129,32 +145,41 @@
          CheckBoxPreference is checked. If separate on/off summaries are not
          needed, the summary attribute can be used instead. -->
     <attr name="summaryOn" format="string" />
+    <attr name="android:summaryOn" />
     <!-- The summary for the Preference in a PreferenceActivity screen when the
          CheckBoxPreference is unchecked. If separate on/off summaries are not
          needed, the summary attribute can be used instead. -->
     <attr name="summaryOff" format="string" />
+    <attr name="android:summaryOff" />
     <!-- The state (true for on, or false for off) that causes dependents to be disabled. By default,
          dependents will be disabled when this is unchecked, so the value of this preference is false. -->
     <attr name="disableDependentsState" format="boolean" />
+    <attr name="android:disableDependentsState" />
   </declare-styleable>
 
   <!-- Base attributes available to DialogPreference. -->
   <declare-styleable name="DialogPreference">
     <!-- The title in the dialog. -->
     <attr name="dialogTitle" format="string" />
+    <attr name="android:dialogTitle" />
     <!-- The message in the dialog. If a dialogLayout is provided and contains
          a TextView with ID android:id/message, this message will be placed in there. -->
     <attr name="dialogMessage" format="string" />
+    <attr name="android:dialogMessage" />
     <!-- The icon for the dialog. -->
     <attr name="dialogIcon" format="reference" />
+    <attr name="android:dialogIcon" />
     <!-- The positive button text for the dialog. Set to @null to hide the positive button. -->
     <attr name="positiveButtonText" format="string" />
+    <attr name="android:positiveButtonText" />
     <!-- The negative button text for the dialog. Set to @null to hide the negative button. -->
     <attr name="negativeButtonText" format="string" />
+    <attr name="android:negativeButtonText" />
     <!-- A layout to be used as the content View for the dialog. By default, this shouldn't
          be needed. If a custom DialogPreference is required, this should be set. For example,
          the EditTextPreference uses a layout with an EditText as this attribute. -->
     <attr name="dialogLayout" format="reference" />
+    <attr name="android:dialogLayout" />
   </declare-styleable>
 
   <!-- Base attributes available to ListPreference. -->
@@ -162,20 +187,24 @@
     <!-- The human-readable array to present as a list. Each entry must have a corresponding
          index in entryValues. -->
     <attr name="entries" format="reference" />
+    <attr name="android:entries" />
     <!-- The array to find the value to save for a preference when an entry from
          entries is selected. If a user clicks on the second item in entries, the
          second item in this array will be saved to the preference. -->
     <attr name="entryValues" format="reference" />
+    <attr name="android:entryValues" />
   </declare-styleable>
 
   <declare-styleable name="MultiSelectListPreference">
     <!-- The human-readable array to present as a list. Each entry must have a corresponding
          index in entryValues. -->
     <attr name="entries" />
+    <attr name="android:entries" />
     <!-- The array to find the value to save for a preference when an entry from
          entries is selected. If a user clicks the second item in entries, the
          second item in this array will be saved to the preference. -->
     <attr name="entryValues" />
+    <attr name="android:entryValues" />
   </declare-styleable>
 
   <declare-styleable name="SwitchPreferenceCompat">
@@ -183,24 +212,31 @@
          SwitchPreference is checked. If separate on/off summaries are not
          needed, the summary attribute can be used instead. -->
     <attr name="summaryOn" />
+    <attr name="android:summaryOn" />
     <!-- The summary for the Preference in a PreferenceActivity screen when the
          SwitchPreference is unchecked. If separate on/off summaries are not
          needed, the summary attribute can be used instead. -->
     <attr name="summaryOff" />
+    <attr name="android:summaryOff" />
     <!-- The text used on the switch itself when in the "on" state.
          This should be a very SHORT string, as it appears in a small space. -->
     <attr name="switchTextOn" format="string" />
+    <attr name="android:switchTextOn" />
     <!-- The text used on the switch itself when in the "off" state.
          This should be a very SHORT string, as it appears in a small space. -->
     <attr name="switchTextOff" format="string" />
+    <attr name="android:switchTextOff" />
     <!-- The state (true for on, or false for off) that causes dependents to be disabled. By default,
          dependents will be disabled when this is unchecked, so the value of this preference is false. -->
     <attr name="disableDependentsState" />
+    <attr name="android:disableDependentsState" />
   </declare-styleable>
 
   <declare-styleable name="PreferenceImageView">
     <attr name="maxWidth" format="dimension" />
+    <attr name="android:maxWidth" />
     <attr name="maxHeight" format="dimension" />
+    <attr name="android:maxHeight" />
   </declare-styleable>
 
 </resources>
diff --git a/v7/preference/src/android/support/v7/preference/CheckBoxPreference.java b/v7/preference/src/android/support/v7/preference/CheckBoxPreference.java
index 755006e..0e2219e 100644
--- a/v7/preference/src/android/support/v7/preference/CheckBoxPreference.java
+++ b/v7/preference/src/android/support/v7/preference/CheckBoxPreference.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.res.TypedArray;
+import android.support.v4.content.res.TypedArrayUtils;
 import android.util.AttributeSet;
 import android.view.View;
 import android.widget.Checkable;
@@ -44,10 +45,17 @@
 
         final TypedArray a = context.obtainStyledAttributes(attrs,
                 R.styleable.CheckBoxPreference, defStyleAttr, defStyleRes);
-        setSummaryOn(a.getString(R.styleable.CheckBoxPreference_summaryOn));
-        setSummaryOff(a.getString(R.styleable.CheckBoxPreference_summaryOff));
-        setDisableDependentsState(a.getBoolean(
-                R.styleable.CheckBoxPreference_disableDependentsState, false));
+
+        setSummaryOn(TypedArrayUtils.getString(a, R.styleable.CheckBoxPreference_summaryOn,
+                R.styleable.CheckBoxPreference_android_summaryOn));
+
+        setSummaryOff(TypedArrayUtils.getString(a, R.styleable.CheckBoxPreference_summaryOff,
+                R.styleable.CheckBoxPreference_android_summaryOff));
+
+        setDisableDependentsState(TypedArrayUtils.getBoolean(a,
+                R.styleable.CheckBoxPreference_disableDependentsState,
+                R.styleable.CheckBoxPreference_android_disableDependentsState, false));
+
         a.recycle();
     }
 
diff --git a/v7/preference/src/android/support/v7/preference/DialogPreference.java b/v7/preference/src/android/support/v7/preference/DialogPreference.java
index 82c1fa7..bf0f4ef 100644
--- a/v7/preference/src/android/support/v7/preference/DialogPreference.java
+++ b/v7/preference/src/android/support/v7/preference/DialogPreference.java
@@ -20,6 +20,7 @@
 import android.content.res.TypedArray;
 import android.graphics.drawable.Drawable;
 import android.support.v4.content.ContextCompat;
+import android.support.v4.content.res.TypedArrayUtils;
 import android.util.AttributeSet;
 import android.view.View;
 
@@ -54,18 +55,33 @@
 
         final TypedArray a = context.obtainStyledAttributes(attrs,
                 R.styleable.DialogPreference, defStyleAttr, defStyleRes);
-        mDialogTitle = a.getString(R.styleable.DialogPreference_dialogTitle);
+
+        mDialogTitle = TypedArrayUtils.getString(a, R.styleable.DialogPreference_dialogTitle,
+                R.styleable.DialogPreference_android_dialogTitle);
         if (mDialogTitle == null) {
-            // Fallback on the regular title of the preference
+            // Fall back on the regular title of the preference
             // (the one that is seen in the list)
             mDialogTitle = getTitle();
         }
-        mDialogMessage = a.getString(R.styleable.DialogPreference_dialogMessage);
-        mDialogIcon = a.getDrawable(R.styleable.DialogPreference_dialogIcon);
-        mPositiveButtonText = a.getString(R.styleable.DialogPreference_positiveButtonText);
-        mNegativeButtonText = a.getString(R.styleable.DialogPreference_negativeButtonText);
-        mDialogLayoutResId = a.getResourceId(R.styleable.DialogPreference_dialogLayout,
-                mDialogLayoutResId);
+
+        mDialogMessage = TypedArrayUtils.getString(a, R.styleable.DialogPreference_dialogMessage,
+                R.styleable.DialogPreference_android_dialogMessage);
+
+        mDialogIcon = TypedArrayUtils.getDrawable(a, R.styleable.DialogPreference_dialogIcon,
+                R.styleable.DialogPreference_android_dialogIcon);
+
+        mPositiveButtonText = TypedArrayUtils.getString(a,
+                R.styleable.DialogPreference_positiveButtonText,
+                R.styleable.DialogPreference_android_positiveButtonText);
+
+        mNegativeButtonText = TypedArrayUtils.getString(a,
+                R.styleable.DialogPreference_negativeButtonText,
+                R.styleable.DialogPreference_android_negativeButtonText);
+
+        mDialogLayoutResId = TypedArrayUtils.getResourceId(a,
+                R.styleable.DialogPreference_dialogLayout,
+                R.styleable.DialogPreference_android_dialogLayout, 0);
+
         a.recycle();
     }
 
diff --git a/v7/preference/src/android/support/v7/preference/ListPreference.java b/v7/preference/src/android/support/v7/preference/ListPreference.java
index ba17c03..ba6bc51 100644
--- a/v7/preference/src/android/support/v7/preference/ListPreference.java
+++ b/v7/preference/src/android/support/v7/preference/ListPreference.java
@@ -21,6 +21,7 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.support.annotation.NonNull;
+import android.support.v4.content.res.TypedArrayUtils;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 
@@ -46,8 +47,13 @@
 
         TypedArray a = context.obtainStyledAttributes(
                 attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes);
-        mEntries = a.getTextArray(R.styleable.ListPreference_entries);
-        mEntryValues = a.getTextArray(R.styleable.ListPreference_entryValues);
+
+        mEntries = TypedArrayUtils.getTextArray(a, R.styleable.ListPreference_entries,
+                R.styleable.ListPreference_android_entries);
+
+        mEntryValues = TypedArrayUtils.getTextArray(a, R.styleable.ListPreference_entryValues,
+                R.styleable.ListPreference_android_entryValues);
+
         a.recycle();
 
         /* Retrieve the Preference summary attribute since it's private
@@ -55,7 +61,10 @@
          */
         a = context.obtainStyledAttributes(attrs,
                 R.styleable.Preference, defStyleAttr, defStyleRes);
-        mSummary = a.getString(R.styleable.Preference_summary);
+
+        mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
+                R.styleable.Preference_android_summary);
+
         a.recycle();
     }
 
diff --git a/v7/preference/src/android/support/v7/preference/Preference.java b/v7/preference/src/android/support/v7/preference/Preference.java
index c294887..90c495a 100644
--- a/v7/preference/src/android/support/v7/preference/Preference.java
+++ b/v7/preference/src/android/support/v7/preference/Preference.java
@@ -27,6 +27,7 @@
 import android.support.annotation.NonNull;
 import android.support.v4.content.ContextCompat;
 import android.support.v4.content.SharedPreferencesCompat;
+import android.support.v4.content.res.TypedArrayUtils;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.AbsSavedState;
@@ -219,38 +220,53 @@
 
         final TypedArray a = context.obtainStyledAttributes(
                 attrs, R.styleable.Preference, defStyleAttr, defStyleRes);
-        for (int i = a.getIndexCount() - 1; i >= 0; i--) {
-            int attr = a.getIndex(i);
-            if (attr == R.styleable.Preference_icon) {
-                mIconResId = a.getResourceId(attr, 0);
-            } else if (attr == R.styleable.Preference_key) {
-                mKey = a.getString(attr);
-            } else if (attr == R.styleable.Preference_title) {
-                mTitle = a.getString(attr);
-            } else if (attr == R.styleable.Preference_summary) {
-                mSummary = a.getString(attr);
-            } else if (attr == R.styleable.Preference_order) {
-                mOrder = a.getInt(attr, mOrder);
-            } else if (attr == R.styleable.Preference_fragment) {
-                mFragment = a.getString(attr);
-            } else if (attr == R.styleable.Preference_layout) {
-                mLayoutResId = a.getResourceId(attr, mLayoutResId);
-            } else if (attr == R.styleable.Preference_widgetLayout) {
-                mWidgetLayoutResId = a.getResourceId(attr, mWidgetLayoutResId);
-            } else if (attr == R.styleable.Preference_enabled) {
-                mEnabled = a.getBoolean(attr, true);
-            } else if (attr == R.styleable.Preference_selectable) {
-                mSelectable = a.getBoolean(attr, true);
-            } else if (attr == R.styleable.Preference_persistent) {
-                mPersistent = a.getBoolean(attr, mPersistent);
-            } else if (attr == R.styleable.Preference_dependency) {
-                mDependencyKey = a.getString(attr);
-            } else if (attr == R.styleable.Preference_defaultValue) {
-                mDefaultValue = onGetDefaultValue(a, attr);
-            } else if (attr == R.styleable.Preference_shouldDisableView) {
-                mShouldDisableView = a.getBoolean(attr, mShouldDisableView);
-            }
+
+        mIconResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_icon,
+                R.styleable.Preference_android_icon, 0);
+
+        mKey = TypedArrayUtils.getString(a, R.styleable.Preference_key,
+                R.styleable.Preference_key);
+
+        mTitle = TypedArrayUtils.getString(a, R.styleable.Preference_title,
+                R.styleable.Preference_android_title);
+
+        mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
+                R.styleable.Preference_android_summary);
+
+        mOrder = TypedArrayUtils.getInt(a, R.styleable.Preference_order,
+                R.styleable.Preference_android_order, DEFAULT_ORDER);
+
+        mFragment = TypedArrayUtils.getString(a, R.styleable.Preference_fragment,
+                R.styleable.Preference_android_fragment);
+
+        mLayoutResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_layout,
+                R.styleable.Preference_android_layout, R.layout.preference);
+
+        mWidgetLayoutResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_widgetLayout,
+                R.styleable.Preference_android_widgetLayout, 0);
+
+        mEnabled = TypedArrayUtils.getBoolean(a, R.styleable.Preference_enabled,
+                R.styleable.Preference_android_enabled, true);
+
+        mSelectable = TypedArrayUtils.getBoolean(a, R.styleable.Preference_selectable,
+                R.styleable.Preference_android_selectable, true);
+
+        mPersistent = TypedArrayUtils.getBoolean(a, R.styleable.Preference_persistent,
+                R.styleable.Preference_android_persistent, true);
+
+        mDependencyKey = TypedArrayUtils.getString(a, R.styleable.Preference_dependency,
+                R.styleable.Preference_android_dependency);
+
+        if (a.hasValue(R.styleable.Preference_defaultValue)) {
+            mDefaultValue = onGetDefaultValue(a, R.styleable.Preference_defaultValue);
+        } else if (a.hasValue(R.styleable.Preference_android_defaultValue)) {
+            mDefaultValue = onGetDefaultValue(a, R.styleable.Preference_android_defaultValue);
         }
+
+        mShouldDisableView =
+                TypedArrayUtils.getBoolean(a, R.styleable.Preference_shouldDisableView,
+                        R.styleable.Preference_shouldDisableView, true);
+
         a.recycle();
     }
 
diff --git a/v7/preference/src/android/support/v7/preference/PreferenceGroup.java b/v7/preference/src/android/support/v7/preference/PreferenceGroup.java
index dd603d7..f1c79dd 100644
--- a/v7/preference/src/android/support/v7/preference/PreferenceGroup.java
+++ b/v7/preference/src/android/support/v7/preference/PreferenceGroup.java
@@ -19,6 +19,7 @@
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.os.Bundle;
+import android.support.v4.content.res.TypedArrayUtils;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 
@@ -61,8 +62,11 @@
 
         final TypedArray a = context.obtainStyledAttributes(
                 attrs, R.styleable.PreferenceGroup, defStyleAttr, defStyleRes);
-        mOrderingAsAdded = a.getBoolean(R.styleable.PreferenceGroup_orderingFromXml,
-                mOrderingAsAdded);
+
+        mOrderingAsAdded =
+                TypedArrayUtils.getBoolean(a, R.styleable.PreferenceGroup_orderingFromXml,
+                        R.styleable.PreferenceGroup_orderingFromXml, true);
+
         a.recycle();
     }
 
diff --git a/v7/preference/src/android/support/v7/preference/SwitchPreferenceCompat.java b/v7/preference/src/android/support/v7/preference/SwitchPreferenceCompat.java
index 6da45ce..4b8f99f 100644
--- a/v7/preference/src/android/support/v7/preference/SwitchPreferenceCompat.java
+++ b/v7/preference/src/android/support/v7/preference/SwitchPreferenceCompat.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.res.TypedArray;
+import android.support.v4.content.res.TypedArrayUtils;
 import android.support.v7.widget.SwitchCompat;
 import android.util.AttributeSet;
 import android.view.View;
@@ -75,14 +76,25 @@
 
         TypedArray a = context.obtainStyledAttributes(attrs,
                 R.styleable.SwitchPreferenceCompat, defStyleAttr, defStyleRes);
-        setSummaryOn(a.getString(R.styleable.SwitchPreferenceCompat_summaryOn));
-        setSummaryOff(a.getString(R.styleable.SwitchPreferenceCompat_summaryOff));
-        setSwitchTextOn(a.getString(
-                R.styleable.SwitchPreferenceCompat_switchTextOn));
-        setSwitchTextOff(a.getString(
-                R.styleable.SwitchPreferenceCompat_switchTextOff));
-        setDisableDependentsState(a.getBoolean(
-                R.styleable.SwitchPreferenceCompat_disableDependentsState, false));
+
+        setSummaryOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_summaryOn,
+                R.styleable.SwitchPreferenceCompat_android_summaryOn));
+
+        setSummaryOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_summaryOff,
+                R.styleable.SwitchPreferenceCompat_android_summaryOff));
+
+        setSwitchTextOn(TypedArrayUtils.getString(a,
+                R.styleable.SwitchPreferenceCompat_switchTextOn,
+                R.styleable.SwitchPreferenceCompat_android_switchTextOn));
+
+        setSwitchTextOff(TypedArrayUtils.getString(a,
+                R.styleable.SwitchPreferenceCompat_switchTextOff,
+                R.styleable.SwitchPreferenceCompat_android_switchTextOff));
+
+        setDisableDependentsState(TypedArrayUtils.getBoolean(a,
+                R.styleable.SwitchPreferenceCompat_disableDependentsState,
+                R.styleable.SwitchPreferenceCompat_android_disableDependentsState, false));
+
         a.recycle();
     }