Merge "Add restrictedSwitchSummary attribute to restricted switch preferences." into nyc-dev
diff --git a/packages/SettingsLib/res/layout/restricted_switch_widget.xml b/packages/SettingsLib/res/layout/restricted_switch_widget.xml
index 6183812..b286df0 100644
--- a/packages/SettingsLib/res/layout/restricted_switch_widget.xml
+++ b/packages/SettingsLib/res/layout/restricted_switch_widget.xml
@@ -22,7 +22,7 @@
         android:gravity="end|center_vertical" />
     <!-- Based off frameworks/base/core/res/res/layout/preference_widget_switch.xml -->
     <Switch xmlns:android="http://schemas.android.com/apk/res/android"
-        android:id="@+android:id/switch_widget"
+        android:id="@android:id/switch_widget"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:focusable="false"
diff --git a/packages/SettingsLib/res/values/attrs.xml b/packages/SettingsLib/res/values/attrs.xml
index 4cdc177..f064e4e 100644
--- a/packages/SettingsLib/res/values/attrs.xml
+++ b/packages/SettingsLib/res/values/attrs.xml
@@ -21,10 +21,16 @@
         <attr name="userRestriction" format="string" />
         <!-- If true then we can use enabled/disabled by admin strings for summary (android.R.id.summary). -->
         <attr name="useAdminDisabledSummary" format="boolean" />
+    </declare-styleable>
+
+    <declare-styleable name="RestrictedSwitchPreference">
         <!-- If true, an additional summary will be added in addition to the existing summary and
         this will be used for enabled/disabled by admin strings leaving android.R.id.summary untouched.
         As such when this is true, useAdminDisabledSummary will be overwritten to false. -->
         <attr name="useAdditionalSummary" format="boolean" />
+        <!-- This is used as summary for restricted switch preferences, default value is
+        @string/disabled_by_admin (Disabled by administrator). -->
+        <attr name="restrictedSwitchSummary" format="reference" />
     </declare-styleable>
 
     <declare-styleable name="WifiEncryptionState">
diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java
index b178e48..1ad710a 100644
--- a/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java
+++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java
@@ -37,6 +37,7 @@
 public class RestrictedSwitchPreference extends SwitchPreference {
     RestrictedPreferenceHelper mHelper;
     boolean mUseAdditionalSummary = false;
+    String mRestrictedSwitchSummary = null;
 
     public RestrictedSwitchPreference(Context context, AttributeSet attrs,
             int defStyleAttr, int defStyleRes) {
@@ -45,14 +46,30 @@
         mHelper = new RestrictedPreferenceHelper(context, this, attrs);
         if (attrs != null) {
             final TypedArray attributes = context.obtainStyledAttributes(attrs,
-                    R.styleable.RestrictedPreference);
-            final TypedValue useAdditionalSummary =
-                    attributes.peekValue(R.styleable.RestrictedPreference_useAdditionalSummary);
+                    R.styleable.RestrictedSwitchPreference);
+            final TypedValue useAdditionalSummary = attributes.peekValue(
+                    R.styleable.RestrictedSwitchPreference_useAdditionalSummary);
             if (useAdditionalSummary != null) {
                 mUseAdditionalSummary =
                         (useAdditionalSummary.type == TypedValue.TYPE_INT_BOOLEAN
                                 && useAdditionalSummary.data != 0);
             }
+
+            final TypedValue restrictedSwitchSummary = attributes.peekValue(
+                    R.styleable.RestrictedSwitchPreference_restrictedSwitchSummary);
+            CharSequence data = null;
+            if (restrictedSwitchSummary != null
+                    && restrictedSwitchSummary.type == TypedValue.TYPE_STRING) {
+                if (restrictedSwitchSummary.resourceId != 0) {
+                    data = context.getString(restrictedSwitchSummary.resourceId);
+                } else {
+                    data = restrictedSwitchSummary.string;
+                }
+            }
+            mRestrictedSwitchSummary = data == null ? null : data.toString();
+        }
+        if (mRestrictedSwitchSummary == null) {
+            mRestrictedSwitchSummary = context.getString(R.string.disabled_by_admin);
         }
         if (mUseAdditionalSummary) {
             setLayoutResource(R.layout.restricted_switch_preference);
@@ -91,8 +108,7 @@
                     R.id.additional_summary);
             if (additionalSummaryView != null) {
                 if (isDisabledByAdmin()) {
-                    additionalSummaryView.setText(
-                            isChecked() ? R.string.enabled_by_admin : R.string.disabled_by_admin);
+                    additionalSummaryView.setText(mRestrictedSwitchSummary);
                     additionalSummaryView.setVisibility(View.VISIBLE);
                 } else {
                     additionalSummaryView.setVisibility(View.GONE);
@@ -102,8 +118,7 @@
             final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
             if (summaryView != null) {
                 if (isDisabledByAdmin()) {
-                    summaryView.setText(
-                            isChecked() ? R.string.enabled_by_admin : R.string.disabled_by_admin);
+                    summaryView.setText(mRestrictedSwitchSummary);
                     summaryView.setVisibility(View.VISIBLE);
                 }
                 // No need to change the visibility to GONE in the else case here since Preference