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

Commit 14501730 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Add support for adding preference summary when disabled by admin.

Change-Id: I455c3180266734fa4ba6b5bf7cb5fc2f34177759
parent 9ef46c26
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -17,5 +17,6 @@
<resources>
    <declare-styleable name="RestrictedPreference">
        <attr name="userRestriction" format="string" />
        <attr name="useAdminDisabledSummary" format="boolean" />
    </declare-styleable>
</resources>
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -765,4 +765,7 @@
    <!-- Battery Info screen. Value for a status item.  Used for diagnostic info screens, precise translation isn't needed -->
    <string name="battery_info_status_full">Full</string>

    <!-- Summary for settings preference disabled by administrator [CHAR LIMIT=50] -->
    <string name="disabled_by_admin_summary_text">Disabled by administrator</string>

</resources>
+4 −0
Original line number Diff line number Diff line
@@ -65,6 +65,10 @@ public class RestrictedPreference extends Preference {
        }
    }

    public void useAdminDisabledSummary(boolean useSummary) {
        mHelper.useAdminDisabledSummary(useSummary);
    }

    @Override
    protected void onAttachedToHierarchy(PreferenceManager preferenceManager) {
        mHelper.onAttachedToHierarchy();
+25 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.text.SpannableStringBuilder;
import android.text.style.ImageSpan;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -44,6 +45,7 @@ public class RestrictedPreferenceHelper {
    private boolean mDisabledByAdmin;
    private EnforcedAdmin mEnforcedAdmin;
    private String mAttrUserRestriction = null;
    private boolean mUseAdminDisabledSummary = false;

    public RestrictedPreferenceHelper(Context context, Preference preference,
            AttributeSet attrs) {
@@ -68,6 +70,14 @@ public class RestrictedPreferenceHelper {
                }
            }
            mAttrUserRestriction = data == null ? null : data.toString();

            final TypedValue useAdminDisabledSummary =
                    attributes.peekValue(R.styleable.RestrictedPreference_useAdminDisabledSummary);
            if (useAdminDisabledSummary != null) {
                mUseAdminDisabledSummary =
                        (useAdminDisabledSummary.type == TypedValue.TYPE_INT_BOOLEAN
                                && useAdminDisabledSummary.data != 0);
            }
        }
    }

@@ -82,6 +92,21 @@ public class RestrictedPreferenceHelper {
                holder.itemView.setEnabled(true);
            }
        }
        if (mUseAdminDisabledSummary) {
            final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
            if (summaryView != null) {
                if (mDisabledByAdmin) {
                    summaryView.setText(R.string.disabled_by_admin_summary_text);
                    summaryView.setVisibility(View.VISIBLE);
                } else {
                    summaryView.setVisibility(View.GONE);
                }
            }
        }
    }

    public void useAdminDisabledSummary(boolean useSummary) {
        mUseAdminDisabledSummary = useSummary;
    }

    /**
+4 −0
Original line number Diff line number Diff line
@@ -65,6 +65,10 @@ public class RestrictedSwitchPreference extends SwitchPreference {
        }
    }

    public void useAdminDisabledSummary(boolean useSummary) {
        mHelper.useAdminDisabledSummary(useSummary);
    }

    @Override
    protected void onAttachedToHierarchy(PreferenceManager preferenceManager) {
        mHelper.onAttachedToHierarchy();