Loading packages/SettingsLib/res/layout/restricted_switch_preference.xml 0 → 100644 +86 −0 Original line number Diff line number Diff line <?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. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeightSmall" android:gravity="center_vertical" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:background="?android:attr/activatedBackgroundIndicator" android:clipToPadding="false"> <LinearLayout android:id="@+id/icon_frame" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="60dp" android:gravity="start|center_vertical" android:orientation="horizontal" android:paddingEnd="12dp" android:paddingTop="4dp" android:paddingBottom="4dp"> <com.android.internal.widget.PreferenceImageView android:id="@android:id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxWidth="48dp" android:maxHeight="48dp" /> </LinearLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:paddingTop="16dp" android:paddingBottom="16dp"> <TextView android:id="@android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppearance="?android:attr/textAppearanceListItem" android:ellipsize="marquee" /> <TextView android:id="@android:id/summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignStart="@android:id/title" android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textColor="?android:attr/textColorSecondary" android:maxLines="10" /> <TextView android:id="@+id/additional_summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/summary" android:layout_alignStart="@android:id/summary" android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textColor="?android:attr/textColorSecondary" android:maxLines="10" android:visibility="gone" /> </RelativeLayout> <!-- Preference should place its actual preference widget here. --> <LinearLayout android:id="@android:id/widget_frame" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="end|center_vertical" android:paddingStart="16dp" android:orientation="vertical" /> </LinearLayout> No newline at end of file packages/SettingsLib/res/values/attrs.xml +8 −0 Original line number Diff line number Diff line Loading @@ -15,10 +15,18 @@ --> <resources> <declare-styleable name="RestrictedPreference"> <!-- The user restriction on which the preference disabled by admin state will be based on. --> <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" /> <!-- 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" /> </declare-styleable> <declare-styleable name="WifiEncryptionState"> <attr name="state_encrypted" format="boolean" /> </declare-styleable> Loading packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java +41 −5 Original line number Diff line number Diff line Loading @@ -17,12 +17,14 @@ package com.android.settingslib; import android.content.Context; import android.content.res.TypedArray; import android.os.UserHandle; import android.support.v4.content.res.TypedArrayUtils; import android.support.v7.preference.PreferenceManager; import android.support.v7.preference.PreferenceViewHolder; import android.support.v14.preference.SwitchPreference; import android.util.AttributeSet; import android.util.TypedValue; import android.view.View; import android.widget.TextView; Loading @@ -34,12 +36,28 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; */ public class RestrictedSwitchPreference extends SwitchPreference { RestrictedPreferenceHelper mHelper; boolean mUseAdditionalSummary = false; 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); if (attrs != null) { final TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.RestrictedPreference); final TypedValue useAdditionalSummary = attributes.peekValue(R.styleable.RestrictedPreference_useAdditionalSummary); if (useAdditionalSummary != null) { mUseAdditionalSummary = (useAdditionalSummary.type == TypedValue.TYPE_INT_BOOLEAN && useAdditionalSummary.data != 0); } } if (mUseAdditionalSummary) { setLayoutResource(R.layout.restricted_switch_preference); useAdminDisabledSummary(false); } } public RestrictedSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) { Loading Loading @@ -67,13 +85,31 @@ public class RestrictedSwitchPreference extends SwitchPreference { if (switchWidget != null) { switchWidget.setVisibility(isDisabledByAdmin() ? View.GONE : View.VISIBLE); } if (mUseAdditionalSummary) { final TextView additionalSummaryView = (TextView) holder.findViewById( R.id.additional_summary); if (additionalSummaryView != null) { if (isDisabledByAdmin()) { additionalSummaryView.setText( isChecked() ? R.string.enabled_by_admin : R.string.disabled_by_admin); additionalSummaryView.setVisibility(View.VISIBLE); } } else { additionalSummaryView.setVisibility(View.GONE); } } else { final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary); if (summaryView != null && isDisabledByAdmin()) { if (summaryView != null) { if (isDisabledByAdmin()) { summaryView.setText( isChecked() ? R.string.enabled_by_admin : R.string.disabled_by_admin); summaryView.setVisibility(View.VISIBLE); } } // No need to change the visibility to GONE in the else case here since Preference class // would have already changed it if there is no summary to display. } } @Override public void performClick() { Loading Loading
packages/SettingsLib/res/layout/restricted_switch_preference.xml 0 → 100644 +86 −0 Original line number Diff line number Diff line <?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. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeightSmall" android:gravity="center_vertical" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:background="?android:attr/activatedBackgroundIndicator" android:clipToPadding="false"> <LinearLayout android:id="@+id/icon_frame" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="60dp" android:gravity="start|center_vertical" android:orientation="horizontal" android:paddingEnd="12dp" android:paddingTop="4dp" android:paddingBottom="4dp"> <com.android.internal.widget.PreferenceImageView android:id="@android:id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxWidth="48dp" android:maxHeight="48dp" /> </LinearLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:paddingTop="16dp" android:paddingBottom="16dp"> <TextView android:id="@android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppearance="?android:attr/textAppearanceListItem" android:ellipsize="marquee" /> <TextView android:id="@android:id/summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignStart="@android:id/title" android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textColor="?android:attr/textColorSecondary" android:maxLines="10" /> <TextView android:id="@+id/additional_summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/summary" android:layout_alignStart="@android:id/summary" android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textColor="?android:attr/textColorSecondary" android:maxLines="10" android:visibility="gone" /> </RelativeLayout> <!-- Preference should place its actual preference widget here. --> <LinearLayout android:id="@android:id/widget_frame" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="end|center_vertical" android:paddingStart="16dp" android:orientation="vertical" /> </LinearLayout> No newline at end of file
packages/SettingsLib/res/values/attrs.xml +8 −0 Original line number Diff line number Diff line Loading @@ -15,10 +15,18 @@ --> <resources> <declare-styleable name="RestrictedPreference"> <!-- The user restriction on which the preference disabled by admin state will be based on. --> <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" /> <!-- 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" /> </declare-styleable> <declare-styleable name="WifiEncryptionState"> <attr name="state_encrypted" format="boolean" /> </declare-styleable> Loading
packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java +41 −5 Original line number Diff line number Diff line Loading @@ -17,12 +17,14 @@ package com.android.settingslib; import android.content.Context; import android.content.res.TypedArray; import android.os.UserHandle; import android.support.v4.content.res.TypedArrayUtils; import android.support.v7.preference.PreferenceManager; import android.support.v7.preference.PreferenceViewHolder; import android.support.v14.preference.SwitchPreference; import android.util.AttributeSet; import android.util.TypedValue; import android.view.View; import android.widget.TextView; Loading @@ -34,12 +36,28 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; */ public class RestrictedSwitchPreference extends SwitchPreference { RestrictedPreferenceHelper mHelper; boolean mUseAdditionalSummary = false; 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); if (attrs != null) { final TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.RestrictedPreference); final TypedValue useAdditionalSummary = attributes.peekValue(R.styleable.RestrictedPreference_useAdditionalSummary); if (useAdditionalSummary != null) { mUseAdditionalSummary = (useAdditionalSummary.type == TypedValue.TYPE_INT_BOOLEAN && useAdditionalSummary.data != 0); } } if (mUseAdditionalSummary) { setLayoutResource(R.layout.restricted_switch_preference); useAdminDisabledSummary(false); } } public RestrictedSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) { Loading Loading @@ -67,13 +85,31 @@ public class RestrictedSwitchPreference extends SwitchPreference { if (switchWidget != null) { switchWidget.setVisibility(isDisabledByAdmin() ? View.GONE : View.VISIBLE); } if (mUseAdditionalSummary) { final TextView additionalSummaryView = (TextView) holder.findViewById( R.id.additional_summary); if (additionalSummaryView != null) { if (isDisabledByAdmin()) { additionalSummaryView.setText( isChecked() ? R.string.enabled_by_admin : R.string.disabled_by_admin); additionalSummaryView.setVisibility(View.VISIBLE); } } else { additionalSummaryView.setVisibility(View.GONE); } } else { final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary); if (summaryView != null && isDisabledByAdmin()) { if (summaryView != null) { if (isDisabledByAdmin()) { summaryView.setText( isChecked() ? R.string.enabled_by_admin : R.string.disabled_by_admin); summaryView.setVisibility(View.VISIBLE); } } // No need to change the visibility to GONE in the else case here since Preference class // would have already changed it if there is no summary to display. } } @Override public void performClick() { Loading