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

am: df9ecfc

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

Change-Id: Ie74b078ccf945cba8d702080d5195e77a2be987d
This commit is contained in:
Sudheer Shanka
2016-04-20 18:13:17 +00:00
committed by android-build-merger
3 changed files with 29 additions and 8 deletions

View File

@@ -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"

View File

@@ -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">

View File

@@ -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