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,12 +21,12 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.SwitchPreference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.widget.MainSwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -42,48 +42,50 @@ public class SmartBatteryPreferenceControllerTest {
private static final int OFF = 0;
private SmartBatteryPreferenceController mController;
private SwitchPreference mPreference;
private ContentResolver mContentResolver;
private FakeFeatureFactory mFeatureFactory;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mFeatureFactory = FakeFeatureFactory.setupForTest();
mContentResolver = RuntimeEnvironment.application.getContentResolver();
mController = new SmartBatteryPreferenceController(RuntimeEnvironment.application);
mPreference = new SwitchPreference(RuntimeEnvironment.application);
}
@Test
public void testUpdateState_smartBatteryOn_preferenceChecked() {
putSmartBatteryValue(ON);
final MainSwitchPreference preference = new MainSwitchPreference(mContext);
mController.updateState(mPreference);
mController.updateState(preference);
assertThat(mPreference.isChecked()).isTrue();
assertThat(preference.isChecked()).isTrue();
}
@Test
public void testUpdateState_smartBatteryOff_preferenceUnchecked() {
putSmartBatteryValue(OFF);
final MainSwitchPreference preference = new MainSwitchPreference(mContext);
mController.updateState(mPreference);
mController.updateState(preference);
assertThat(mPreference.isChecked()).isFalse();
assertThat(preference.isChecked()).isFalse();
}
@Test
public void testUpdateState_checkPreference_smartBatteryOn() {
mController.onPreferenceChange(mPreference, true);
mController.onSwitchChanged(null, true);
assertThat(getSmartBatteryValue()).isEqualTo(ON);
}
@Test
public void testUpdateState_unCheckPreference_smartBatteryOff() {
mController.onPreferenceChange(mPreference, false);
mController.onSwitchChanged(null, false);
assertThat(getSmartBatteryValue()).isEqualTo(OFF);
}