diff options
6 files changed, 82 insertions, 6 deletions
diff --git a/packages/SettingsLib/res/layout/restricted_icon.xml b/packages/SettingsLib/res/layout/restricted_icon.xml new file mode 100644 index 000000000000..227b6ebfc818 --- /dev/null +++ b/packages/SettingsLib/res/layout/restricted_icon.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> +<ImageView xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/restricted_icon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/ic_settings_lock_outline" + android:gravity="end|center_vertical" />
\ No newline at end of file diff --git a/packages/SettingsLib/res/layout/restricted_switch_widget.xml b/packages/SettingsLib/res/layout/restricted_switch_widget.xml new file mode 100644 index 000000000000..a132e747c7d5 --- /dev/null +++ b/packages/SettingsLib/res/layout/restricted_switch_widget.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> +<merge xmlns:android="http://schemas.android.com/apk/res/android"> + <ImageView xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/restricted_icon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/ic_settings_lock_outline" + 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:layout_width="wrap_content" + android:layout_height="wrap_content" + android:focusable="false" + android:clickable="false" + android:background="@null" /> +</merge>
\ No newline at end of file diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml index 72fa9397e898..ae2c6e71bfc3 100644 --- a/packages/SettingsLib/res/values/strings.xml +++ b/packages/SettingsLib/res/values/strings.xml @@ -773,6 +773,11 @@ <!-- Summary for settings preference disabled by administrator [CHAR LIMIT=50] --> <string name="disabled_by_admin_summary_text">Controlled by admin</string> + <!-- Summary for switch preference to denote it is switched on [CHAR LIMIT=50] --> + <string name="enabled_by_admin">Enabled by administrator</string> + <!-- Summary for switch preference to denote it is switched on [CHAR LIMIT=50] --> + <string name="disabled_by_admin">Disabled by administrator</string> + <!-- Option in navigation drawer that leads to Settings main screen [CHAR LIMIT=30] --> <string name="home">Home</string> diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedPreference.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedPreference.java index 810f6eb28a56..e69497a92034 100644 --- a/packages/SettingsLib/src/com/android/settingslib/RestrictedPreference.java +++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedPreference.java @@ -23,6 +23,7 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceManager; import android.support.v7.preference.PreferenceViewHolder; import android.util.AttributeSet; +import android.view.View; import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; @@ -36,6 +37,7 @@ public class RestrictedPreference extends Preference { public RestrictedPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); + setWidgetLayoutResource(R.layout.restricted_icon); mHelper = new RestrictedPreferenceHelper(context, this, attrs); } @@ -56,6 +58,10 @@ public class RestrictedPreference extends Preference { public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); mHelper.onBindViewHolder(holder); + final View restrictedIcon = holder.findViewById(R.id.restricted_icon); + if (restrictedIcon != null) { + restrictedIcon.setVisibility(isDisabledByAdmin() ? View.VISIBLE : View.GONE); + } } @Override diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedPreferenceHelper.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedPreferenceHelper.java index 227b1e8e1b4d..4280938de39c 100644 --- a/packages/SettingsLib/src/com/android/settingslib/RestrictedPreferenceHelper.java +++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedPreferenceHelper.java @@ -91,12 +91,8 @@ public class RestrictedPreferenceHelper { * Modify PreferenceViewHolder to add padlock if restriction is disabled. */ public void onBindViewHolder(PreferenceViewHolder holder) { - final TextView titleView = (TextView) holder.findViewById(android.R.id.title); - if (titleView != null) { - RestrictedLockUtils.setTextViewPadlock(mContext, titleView, mDisabledByAdmin); - if (mDisabledByAdmin) { - holder.itemView.setEnabled(true); - } + if (mDisabledByAdmin) { + holder.itemView.setEnabled(true); } if (mUseAdminDisabledSummary) { final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary); diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java index 6cae8aa70847..f381286c0697 100644 --- a/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java +++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java @@ -23,6 +23,8 @@ import android.support.v7.preference.PreferenceManager; import android.support.v7.preference.PreferenceViewHolder; import android.support.v14.preference.SwitchPreference; import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; @@ -36,6 +38,7 @@ public class RestrictedSwitchPreference extends SwitchPreference { public RestrictedSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); + setWidgetLayoutResource(R.layout.restricted_switch_widget); mHelper = new RestrictedPreferenceHelper(context, this, attrs); } @@ -56,6 +59,20 @@ public class RestrictedSwitchPreference extends SwitchPreference { public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); mHelper.onBindViewHolder(holder); + final View restrictedIcon = holder.findViewById(R.id.restricted_icon); + final View switchWidget = holder.findViewById(android.R.id.switch_widget); + if (restrictedIcon != null) { + restrictedIcon.setVisibility(isDisabledByAdmin() ? View.VISIBLE : View.GONE); + } + if (switchWidget != null) { + switchWidget.setVisibility(isDisabledByAdmin() ? View.GONE : View.VISIBLE); + } + final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary); + if (summaryView != null && isDisabledByAdmin()) { + summaryView.setText( + isChecked() ? R.string.enabled_by_admin : R.string.disabled_by_admin); + summaryView.setVisibility(View.VISIBLE); + } } @Override |