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

Commit ecbf20f3 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by android-build-merger
Browse files

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

am: df9ecfc5

* commit 'df9ecfc5':
  Add restrictedSwitchSummary attribute to restricted switch preferences.

Change-Id: Ie74b078ccf945cba8d702080d5195e77a2be987d
parents ee1134a8 df9ecfc5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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"
+6 −0
Original line number Diff line number Diff line
@@ -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">
+22 −7
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
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 @@ public class RestrictedSwitchPreference extends SwitchPreference {
        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 @@ public class RestrictedSwitchPreference extends SwitchPreference {
                    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 @@ public class RestrictedSwitchPreference extends SwitchPreference {
            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