Use MainSwitchPreference to replace the button style switches.

Fix: 177967926
Fix: 177968295
Fix: 177967925
Fix: 177968078

Test: Run robotest and apply the widget in Settings and see the ui
Change-Id: Ie854de96e5495fa564fb8a097ed4547bbd2b10c5
This commit is contained in:
Stanley Wang
2021-01-29 01:17:43 +08:00
parent 70864998c4
commit 10b7a7d483
25 changed files with 307 additions and 513 deletions

View File

@@ -17,8 +17,11 @@
package com.android.settings.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.PreferenceViewHolder;
import androidx.preference.TwoStatePreference;
@@ -47,23 +50,23 @@ public class SettingsMainSwitchPreference extends TwoStatePreference {
public SettingsMainSwitchPreference(Context context) {
super(context);
init();
init(context, null);
}
public SettingsMainSwitchPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init();
init(context, attrs);
}
public SettingsMainSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
init(context, attrs);
}
public SettingsMainSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
init(context, attrs);
}
@Override
@@ -79,8 +82,21 @@ public class SettingsMainSwitchPreference extends TwoStatePreference {
registerListenerToSwitchBar();
}
private void init() {
private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.preference_widget_main_switch);
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs,
androidx.preference.R.styleable.Preference, 0/*defStyleAttr*/,
0/*defStyleRes*/);
final CharSequence title = TypedArrayUtils.getText(a,
androidx.preference.R.styleable.Preference_title,
androidx.preference.R.styleable.Preference_android_title);
if (!TextUtils.isEmpty(title)) {
setTitle(title.toString());
}
a.recycle();
}
}
/**
@@ -153,7 +169,7 @@ public class SettingsMainSwitchPreference extends TwoStatePreference {
/**
* Enable or disable the text and switch.
*/
public void setEnabled(boolean enabled) {
public void setSwitchBarEnabled(boolean enabled) {
if (mMainSwitchBar != null) {
mMainSwitchBar.setEnabled(enabled);
}