Use SettingsLib's MainSwitchBar to replace SwitchBar in Settings.

To log Settings metrics, the MainSwitch extends MainSwitchBar and
replace the SwitchBar in SettingsActivity.

Bug: 175181773
Test: Run robotest and apply the widget in Settings and see the ui

Change-Id: I3add3702e9058ad9192b5172c7cf0e2ccfb55a70
This commit is contained in:
Stanley Wang
2020-12-25 16:27:32 +08:00
parent c61c2fb1d7
commit b87ddba6cd
51 changed files with 783 additions and 271 deletions

View File

@@ -24,11 +24,11 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import android.widget.Switch;
import androidx.lifecycle.LifecycleOwner;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch;
import com.android.settings.widget.SettingsMainSwitchBar;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -45,9 +45,9 @@ import org.robolectric.util.ReflectionHelpers;
public class LocationSwitchBarControllerTest {
@Mock
private SwitchBar mSwitchBar;
private SettingsMainSwitchBar mSwitchBar;
@Mock
private ToggleSwitch mSwitch;
private Switch mSwitch;
@Mock
private LocationEnabler mEnabler;
@@ -132,22 +132,22 @@ public class LocationSwitchBarControllerTest {
public void onLocationModeChanged_locationOn_shouldCheckSwitch() {
doReturn(null).when(mEnabler).getShareLocationEnforcedAdmin(anyInt());
doReturn(false).when(mEnabler).hasShareLocationRestriction(anyInt());
when(mSwitch.isChecked()).thenReturn(false);
when(mSwitchBar.isChecked()).thenReturn(false);
doReturn(true).when(mEnabler).isEnabled(anyInt());
mController.onLocationModeChanged(Settings.Secure.LOCATION_MODE_BATTERY_SAVING, false);
verify(mSwitch).setChecked(true);
verify(mSwitchBar).setChecked(true);
}
@Test
public void onLocationModeChanged_locationOff_shouldUncheckSwitch() {
doReturn(null).when(mEnabler).getShareLocationEnforcedAdmin(anyInt());
doReturn(false).when(mEnabler).hasShareLocationRestriction(anyInt());
when(mSwitch.isChecked()).thenReturn(true);
when(mSwitchBar.isChecked()).thenReturn(true);
mController.onLocationModeChanged(Settings.Secure.LOCATION_MODE_OFF, false);
verify(mSwitch).setChecked(false);
verify(mSwitchBar).setChecked(false);
}
}