Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit df9ecfc5 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Add restrictedSwitchSummary attribute to restricted switch preferences." into nyc-dev

parents 801d4161 a1790c3b
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@
        android:gravity="end|center_vertical" />
        android:gravity="end|center_vertical" />
    <!-- Based off frameworks/base/core/res/res/layout/preference_widget_switch.xml -->
    <!-- Based off frameworks/base/core/res/res/layout/preference_widget_switch.xml -->
    <Switch xmlns:android="http://schemas.android.com/apk/res/android"
    <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_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusable="false"
+6 −0
Original line number Original line Diff line number Diff line
@@ -21,10 +21,16 @@
        <attr name="userRestriction" format="string" />
        <attr name="userRestriction" format="string" />
        <!-- If true then we can use enabled/disabled by admin strings for summary (android.R.id.summary). -->
        <!-- If true then we can use enabled/disabled by admin strings for summary (android.R.id.summary). -->
        <attr name="useAdminDisabledSummary" format="boolean" />
        <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
        <!-- 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.
        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. -->
        As such when this is true, useAdminDisabledSummary will be overwritten to false. -->
        <attr name="useAdditionalSummary" format="boolean" />
        <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>


    <declare-styleable name="WifiEncryptionState">
    <declare-styleable name="WifiEncryptionState">
+22 −7
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
public class RestrictedSwitchPreference extends SwitchPreference {
public class RestrictedSwitchPreference extends SwitchPreference {
    RestrictedPreferenceHelper mHelper;
    RestrictedPreferenceHelper mHelper;
    boolean mUseAdditionalSummary = false;
    boolean mUseAdditionalSummary = false;
    String mRestrictedSwitchSummary = null;


    public RestrictedSwitchPreference(Context context, AttributeSet attrs,
    public RestrictedSwitchPreference(Context context, AttributeSet attrs,
            int defStyleAttr, int defStyleRes) {
            int defStyleAttr, int defStyleRes) {
@@ -45,14 +46,30 @@ public class RestrictedSwitchPreference extends SwitchPreference {
        mHelper = new RestrictedPreferenceHelper(context, this, attrs);
        mHelper = new RestrictedPreferenceHelper(context, this, attrs);
        if (attrs != null) {
        if (attrs != null) {
            final TypedArray attributes = context.obtainStyledAttributes(attrs,
            final TypedArray attributes = context.obtainStyledAttributes(attrs,
                    R.styleable.RestrictedPreference);
                    R.styleable.RestrictedSwitchPreference);
            final TypedValue useAdditionalSummary =
            final TypedValue useAdditionalSummary = attributes.peekValue(
                    attributes.peekValue(R.styleable.RestrictedPreference_useAdditionalSummary);
                    R.styleable.RestrictedSwitchPreference_useAdditionalSummary);
            if (useAdditionalSummary != null) {
            if (useAdditionalSummary != null) {
                mUseAdditionalSummary =
                mUseAdditionalSummary =
                        (useAdditionalSummary.type == TypedValue.TYPE_INT_BOOLEAN
                        (useAdditionalSummary.type == TypedValue.TYPE_INT_BOOLEAN
                                && useAdditionalSummary.data != 0);
                                && 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) {
        if (mUseAdditionalSummary) {
            setLayoutResource(R.layout.restricted_switch_preference);
            setLayoutResource(R.layout.restricted_switch_preference);
@@ -91,8 +108,7 @@ public class RestrictedSwitchPreference extends SwitchPreference {
                    R.id.additional_summary);
                    R.id.additional_summary);
            if (additionalSummaryView != null) {
            if (additionalSummaryView != null) {
                if (isDisabledByAdmin()) {
                if (isDisabledByAdmin()) {
                    additionalSummaryView.setText(
                    additionalSummaryView.setText(mRestrictedSwitchSummary);
                            isChecked() ? R.string.enabled_by_admin : R.string.disabled_by_admin);
                    additionalSummaryView.setVisibility(View.VISIBLE);
                    additionalSummaryView.setVisibility(View.VISIBLE);
                } else {
                } else {
                    additionalSummaryView.setVisibility(View.GONE);
                    additionalSummaryView.setVisibility(View.GONE);
@@ -102,8 +118,7 @@ public class RestrictedSwitchPreference extends SwitchPreference {
            final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
            final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
            if (summaryView != null) {
            if (summaryView != null) {
                if (isDisabledByAdmin()) {
                if (isDisabledByAdmin()) {
                    summaryView.setText(
                    summaryView.setText(mRestrictedSwitchSummary);
                            isChecked() ? R.string.enabled_by_admin : R.string.disabled_by_admin);
                    summaryView.setVisibility(View.VISIBLE);
                    summaryView.setVisibility(View.VISIBLE);
                }
                }
                // No need to change the visibility to GONE in the else case here since Preference
                // No need to change the visibility to GONE in the else case here since Preference