[Settings] Support master switch of inline toggle of Settings Injection v2
Allow developers to inject MasterSwitchPreference, a switch preference with two tap targets, to Settings page. Developers should declare keyhint and switch_uri for the activity in AndroidManifest,and then implement a SwitchesProvider. Bug: 132808482 Test: robotest Change-Id: I64cdf18268be0cfcd38aab2c059144536dd79b32
This commit is contained in:
@@ -36,6 +36,7 @@ public class MasterSwitchPreference extends TwoTargetPreference {
|
||||
|
||||
private Switch mSwitch;
|
||||
private boolean mChecked;
|
||||
private boolean mCheckedSet;
|
||||
private boolean mEnableSwitch = true;
|
||||
|
||||
public MasterSwitchPreference(Context context, AttributeSet attrs,
|
||||
@@ -94,9 +95,14 @@ public class MasterSwitchPreference extends TwoTargetPreference {
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
mChecked = checked;
|
||||
if (mSwitch != null) {
|
||||
mSwitch.setChecked(checked);
|
||||
// Always set checked the first time; don't assume the field's default of false.
|
||||
final boolean changed = mChecked != checked;
|
||||
if (changed || !mCheckedSet) {
|
||||
mChecked = checked;
|
||||
mCheckedSet = true;
|
||||
if (mSwitch != null) {
|
||||
mSwitch.setChecked(checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user