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

@@ -21,16 +21,17 @@ import android.nfc.NfcAdapter;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.SwitchPreference;
import com.android.settingslib.widget.MainSwitchPreference;
/**
* NfcEnabler is a helper to manage the Nfc on/off checkbox preference. It turns on/off Nfc
* and ensures the summary of the preference reflects the current state.
*/
public class NfcEnabler extends BaseNfcEnabler {
private final SwitchPreference mPreference;
private final MainSwitchPreference mPreference;
public NfcEnabler(Context context, SwitchPreference preference) {
public NfcEnabler(Context context, MainSwitchPreference preference) {
super(context);
mPreference = preference;
}
@@ -39,19 +40,19 @@ public class NfcEnabler extends BaseNfcEnabler {
protected void handleNfcStateChanged(int newState) {
switch (newState) {
case NfcAdapter.STATE_OFF:
mPreference.setChecked(false);
mPreference.updateStatus(false);
mPreference.setEnabled(isToggleable());
break;
case NfcAdapter.STATE_ON:
mPreference.setChecked(true);
mPreference.updateStatus(true);
mPreference.setEnabled(true);
break;
case NfcAdapter.STATE_TURNING_ON:
mPreference.setChecked(true);
mPreference.updateStatus(true);
mPreference.setEnabled(false);
break;
case NfcAdapter.STATE_TURNING_OFF:
mPreference.setChecked(false);
mPreference.updateStatus(false);
mPreference.setEnabled(false);
break;
}