diff --git a/res/layout/switch_bar.xml b/res/layout/switch_bar.xml
deleted file mode 100644
index 3bdfbd49cbc..00000000000
--- a/res/layout/switch_bar.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/values-night/colors.xml b/res/values-night/colors.xml
index 78881911fbc..b83b2fa869e 100644
--- a/res/values-night/colors.xml
+++ b/res/values-night/colors.xml
@@ -16,8 +16,6 @@
- #82000000
- @android:color/black
#783BE5
#3F5FBD
@*android:color/material_grey_900
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
index b13447fe1ad..391a30426c9 100755
--- a/res/values-sw600dp/dimens.xml
+++ b/res/values-sw600dp/dimens.xml
@@ -24,9 +24,6 @@
24dp
80dp
-
- 80dp
-
560dp
diff --git a/res/values-sw720dp-land/dimens.xml b/res/values-sw720dp-land/dimens.xml
index 82c3fef30b8..363817c0b27 100644
--- a/res/values-sw720dp-land/dimens.xml
+++ b/res/values-sw720dp-land/dimens.xml
@@ -20,8 +20,4 @@
128dp
128dp
-
- 128dp
- 128dp
-
diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml
index 6480d482aa3..d09d2fd41be 100644
--- a/res/values-sw720dp/dimens.xml
+++ b/res/values-sw720dp/dimens.xml
@@ -19,10 +19,6 @@
80dp
80dp
-
- 80dp
- 80dp
-
348dp
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 6f024a32be3..40a7c581159 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -112,12 +112,8 @@
+
-
-
-
-
-
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 657ba110545..ae979458acc 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -72,10 +72,6 @@
@*android:color/background_device_default_light
- @*android:color/material_grey_600
- #BFFFFFFF
- @android:color/white
-
#43a047
#f44336
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 205e2a3d310..1c19833e240 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -75,10 +75,6 @@
12dp
-
- 72dp
- 16dp
-
16dp
52dp
@@ -239,11 +235,6 @@
20dp
27dp
-
- 16dp
-
- @*android:dimen/config_restrictedIconSize
-
36dp
diff --git a/res/values/styles.xml b/res/values/styles.xml
index ee78a45d066..1f5c743817e 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -215,10 +215,6 @@
-
-
-
@@ -109,23 +106,9 @@
- ?android:attr/textColorSecondary
-
-
-
-
-
+
+
-
-
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
index cc1087e7f4c..4b827826f7d 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
@@ -39,8 +39,6 @@ import android.view.View;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
-import com.android.settings.widget.SwitchBar;
-import com.android.settings.widget.SwitchBarController;
import com.android.settings.widget.SwitchWidgetController;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -80,6 +78,7 @@ public class BluetoothEnablerTest {
private SwitchWidgetController.OnSwitchChangeListener mCallback;
private Context mContext;
+ @Mock
private SwitchWidgetController mSwitchController;
private BluetoothEnabler mBluetoothEnabler;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
@@ -90,7 +89,6 @@ public class BluetoothEnablerTest {
mContext = spy(RuntimeEnvironment.application);
mRestrictedSwitchPreference = new RestrictedSwitchPreference(mContext);
- mSwitchController = spy(new SwitchBarController(new SwitchBar(mContext)));
mBluetoothEnabler = new BluetoothEnabler(
mContext,
mSwitchController,
@@ -215,7 +213,7 @@ public class BluetoothEnablerTest {
verify(mSwitchController, never()).setChecked(anyBoolean());
mBluetoothEnabler.resume(mContext);
verify(mSwitchController, never()).setChecked(false);
- verify(mSwitchController).setChecked(true);
+ when(mSwitchController.isChecked()).thenReturn(true);
// Now simulate bluetooth being turned off via an event.
BroadcastReceiver receiver = captor.getValue();
diff --git a/tests/robotests/src/com/android/settings/development/WirelessDebuggingEnablerTest.java b/tests/robotests/src/com/android/settings/development/WirelessDebuggingEnablerTest.java
index 1baf4836a79..14c0bc72ff1 100644
--- a/tests/robotests/src/com/android/settings/development/WirelessDebuggingEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/development/WirelessDebuggingEnablerTest.java
@@ -29,8 +29,7 @@ import androidx.lifecycle.LifecycleOwner;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settings.testutils.shadow.ShadowWirelessDebuggingPreferenceController;
-import com.android.settings.widget.SwitchBar;
-import com.android.settings.widget.SwitchBarController;
+import com.android.settings.widget.SwitchWidgetController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.After;
@@ -49,23 +48,22 @@ import org.robolectric.util.ReflectionHelpers;
public class WirelessDebuggingEnablerTest {
@Mock
- private SwitchBar mSwitchBar;
+ private SwitchWidgetController mSwitchWidgetController;
@Mock
private WirelessDebuggingEnabler.OnEnabledListener mListener;
private WirelessDebuggingEnabler mWirelessDebuggingEnabler;
private Context mContext;
- private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycleOwner = () -> mLifecycle;
+ LifecycleOwner mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
mWirelessDebuggingEnabler = spy(new WirelessDebuggingEnabler(
- mContext, new SwitchBarController(mSwitchBar), mListener, mLifecycle));
+ mContext, mSwitchWidgetController, mListener, mLifecycle));
}
@After
@@ -75,14 +73,14 @@ public class WirelessDebuggingEnablerTest {
@Test
public void onCreation_shouldShowSwitchBar() {
- verify(mSwitchBar).show();
+ verify(mSwitchWidgetController).setupView();
}
@Test
public void teardownSwitchController_shouldHideSwitchBar() {
mWirelessDebuggingEnabler.teardownSwitchController();
- verify(mSwitchBar).hide();
+ verify(mSwitchWidgetController).teardownView();
}
@Test
@@ -92,7 +90,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 0 /* setting disabled */);
mWirelessDebuggingEnabler.onResume();
- verify(mSwitchBar).setChecked(false);
+ verify(mSwitchWidgetController).setChecked(false);
verify(mListener).onEnabled(false);
Global.putInt(mContext.getContentResolver(),
@@ -101,7 +99,7 @@ public class WirelessDebuggingEnablerTest {
ReflectionHelpers.getField(mWirelessDebuggingEnabler, "mSettingsObserver");
observer.onChange(true, Global.getUriFor(Global.ADB_WIFI_ENABLED));
- verify(mSwitchBar).setChecked(true);
+ verify(mSwitchWidgetController).setChecked(true);
// Should also get a callback
verify(mListener).onEnabled(true);
}
@@ -112,7 +110,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 1 /* setting enabled */);
mWirelessDebuggingEnabler.onResume();
- verify(mSwitchBar).setChecked(true);
+ verify(mSwitchWidgetController).setChecked(true);
verify(mListener).onEnabled(true);
Global.putInt(mContext.getContentResolver(),
@@ -121,7 +119,7 @@ public class WirelessDebuggingEnablerTest {
ReflectionHelpers.getField(mWirelessDebuggingEnabler, "mSettingsObserver");
observer.onChange(true, Global.getUriFor(Global.ADB_WIFI_ENABLED));
- verify(mSwitchBar).setChecked(false);
+ verify(mSwitchWidgetController).setChecked(false);
// Should also get a callback
verify(mListener).onEnabled(false);
}
@@ -133,7 +131,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 0 /* setting disabled */);
mWirelessDebuggingEnabler.onResume();
- verify(mSwitchBar).setChecked(false);
+ verify(mSwitchWidgetController).setChecked(false);
verify(mListener).onEnabled(false);
mWirelessDebuggingEnabler.onSwitchToggled(true);
@@ -149,7 +147,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 0 /* setting disabled */);
mWirelessDebuggingEnabler.onResume();
- verify(mSwitchBar).setChecked(false);
+ verify(mSwitchWidgetController).setChecked(false);
verify(mListener).onEnabled(false);
mWirelessDebuggingEnabler.onSwitchToggled(true);
@@ -165,7 +163,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 1 /* setting disabled */);
mWirelessDebuggingEnabler.onResume();
- verify(mSwitchBar).setChecked(true);
+ verify(mSwitchWidgetController).setChecked(true);
verify(mListener).onEnabled(true);
mWirelessDebuggingEnabler.onSwitchToggled(false);
@@ -181,7 +179,7 @@ public class WirelessDebuggingEnablerTest {
Global.ADB_WIFI_ENABLED, 1 /* setting disabled */);
mWirelessDebuggingEnabler.onResume();
- verify(mSwitchBar).setChecked(true);
+ verify(mSwitchWidgetController).setChecked(true);
verify(mListener).onEnabled(true);
mWirelessDebuggingEnabler.onSwitchToggled(false);
diff --git a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverGlobalSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverGlobalSwitchBarControllerTest.java
index 838703d3381..cedc060a938 100644
--- a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverGlobalSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverGlobalSwitchBarControllerTest.java
@@ -27,8 +27,6 @@ import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
-import com.android.settings.widget.SwitchBar;
-import com.android.settings.widget.SwitchBarController;
import com.android.settings.widget.SwitchWidgetController;
import org.junit.Before;
@@ -42,8 +40,6 @@ import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class GraphicsDriverGlobalSwitchBarControllerTest {
- @Mock
- private SwitchBar mSwitchBar;
@Mock
private SwitchWidgetController mSwitchWidgetController;
@Mock
@@ -65,9 +61,9 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
Settings.Global.putInt(
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController = new GraphicsDriverGlobalSwitchBarController(
- mContext, new SwitchBarController(mSwitchBar));
+ mContext, mSwitchWidgetController);
- verify(mSwitchBar).setChecked(true);
+ verify(mSwitchWidgetController).setChecked(true);
}
@Test
@@ -75,34 +71,33 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
mController = new GraphicsDriverGlobalSwitchBarController(
- mContext, new SwitchBarController(mSwitchBar));
+ mContext, mSwitchWidgetController);
- verify(mSwitchBar).setChecked(false);
+ verify(mSwitchWidgetController).setChecked(false);
}
@Test
public void constructor_developmentSettingsEnabled_shouldEnableSwitchBar() {
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mController = new GraphicsDriverGlobalSwitchBarController(
- mContext, new SwitchBarController(mSwitchBar));
+ mContext, mSwitchWidgetController);
- verify(mSwitchBar).setEnabled(true);
+ verify(mSwitchWidgetController).setEnabled(true);
}
@Test
public void constructor_developmentSettingsDisabled_shouldDisableSwitchBar() {
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
mController = new GraphicsDriverGlobalSwitchBarController(
- mContext, new SwitchBarController(mSwitchBar));
+ mContext, mSwitchWidgetController);
- verify(mSwitchBar).setEnabled(false);
+ verify(mSwitchWidgetController).setEnabled(false);
}
@Test
public void onStart_shouldStartListeningAndRegister() {
mController = new GraphicsDriverGlobalSwitchBarController(
- mContext, new SwitchBarController(mSwitchBar));
- mController.mSwitchWidgetController = mSwitchWidgetController;
+ mContext, mSwitchWidgetController);
mController.mGraphicsDriverContentObserver = mGraphicsDriverContentObserver;
mController.onStart();
@@ -113,8 +108,7 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
@Test
public void onStop_shouldStopListeningAndUnregister() {
mController = new GraphicsDriverGlobalSwitchBarController(
- mContext, new SwitchBarController(mSwitchBar));
- mController.mSwitchWidgetController = mSwitchWidgetController;
+ mContext, mSwitchWidgetController);
mController.mGraphicsDriverContentObserver = mGraphicsDriverContentObserver;
mController.onStop();
@@ -127,7 +121,7 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
Settings.Global.putInt(mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS,
UPDATABLE_DRIVER_OFF);
mController = new GraphicsDriverGlobalSwitchBarController(
- mContext, new SwitchBarController(mSwitchBar));
+ mContext, mSwitchWidgetController);
mController.onSwitchToggled(true);
assertThat(Settings.Global.getInt(
@@ -141,7 +135,7 @@ public class GraphicsDriverGlobalSwitchBarControllerTest {
Settings.Global.putInt(
mResolver, Settings.Global.UPDATABLE_DRIVER_ALL_APPS, UPDATABLE_DRIVER_DEFAULT);
mController = new GraphicsDriverGlobalSwitchBarController(
- mContext, new SwitchBarController(mSwitchBar));
+ mContext, mSwitchWidgetController);
mController.onSwitchToggled(false);
assertThat(Settings.Global.getInt(
diff --git a/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java b/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
index bb4b0c41492..e7a31ce0de0 100644
--- a/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
@@ -33,6 +33,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -51,8 +52,6 @@ import android.net.wifi.WifiManager;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.network.TetherEnabler.OnTetherStateUpdateListener;
-import com.android.settings.widget.SwitchBar;
-import com.android.settings.widget.SwitchBarController;
import com.android.settings.widget.SwitchWidgetController;
import org.junit.Before;
@@ -82,8 +81,8 @@ public class TetherEnablerTest {
@Mock
private BluetoothAdapter mBluetoothAdapter;
- private SwitchBar mSwitchBar;
private TetherEnabler mEnabler;
+ @Mock
private SwitchWidgetController mSwitchWidgetController;
private static final String[] USB_TETHERED = {"usb"};
@@ -93,8 +92,6 @@ public class TetherEnablerTest {
Context context = spy(ApplicationProvider.getApplicationContext());
AtomicReference panReference = spy(AtomicReference.class);
- mSwitchBar = spy(new SwitchBar(context));
- mSwitchWidgetController = spy(new SwitchBarController(mSwitchBar));
when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
mConnectivityManager);
@@ -115,7 +112,8 @@ public class TetherEnablerTest {
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
mEnabler.onStart();
- assertThat(mSwitchBar.isChecked()).isTrue();
+
+ verify(mSwitchWidgetController).setChecked(true);
}
@Test
@@ -150,26 +148,29 @@ public class TetherEnablerTest {
mEnabler.onStart();
mEnabler.startTethering(TetheringManager.TETHERING_WIFI);
+ clearInvocations(mSwitchWidgetController);
when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[0]);
mEnabler.mOnStartTetheringCallback.onTetheringFailed();
- assertThat(mSwitchBar.isChecked()).isFalse();
- assertThat(mSwitchBar.isEnabled()).isTrue();
+ verify(mSwitchWidgetController).setEnabled(true);
+ verify(mSwitchWidgetController).setChecked(false);
}
@Test
public void onDataSaverChanged_setsEnabledCorrectly() {
- mSwitchBar.setEnabled(true);
+ mSwitchWidgetController.setEnabled(true);
// try to turn data saver on
+ clearInvocations(mSwitchWidgetController);
when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(true);
mEnabler.onDataSaverChanged(true);
- assertThat(mSwitchBar.isEnabled()).isFalse();
+ verify(mSwitchWidgetController).setEnabled(false);
// lets turn data saver off again
+ clearInvocations(mSwitchWidgetController);
when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(false);
mEnabler.onDataSaverChanged(false);
- assertThat(mSwitchBar.isEnabled()).isTrue();
+ verify(mSwitchWidgetController).setEnabled(true);
}
@Test
@@ -250,7 +251,7 @@ public class TetherEnablerTest {
ReflectionHelpers.setField(mEnabler, "mDataSaverEnabled", false);
mEnabler.updateState(null/*tethered*/);
- verify(mSwitchBar).setEnabled(true);
+ verify(mSwitchWidgetController).setEnabled(true);
}
@Test
@@ -263,7 +264,7 @@ public class TetherEnablerTest {
ReflectionHelpers.setField(mEnabler, "mDataSaverEnabled", false);
mEnabler.updateState(null/*tethered*/);
- verify(mSwitchBar).setEnabled(true);
+ verify(mSwitchWidgetController).setEnabled(true);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java
index 718e01bebe0..1cfb3f614b9 100644
--- a/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java
@@ -17,8 +17,8 @@
package com.android.settings.users;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
@@ -26,8 +26,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import com.android.settings.testutils.shadow.ShadowUserManager;
-import com.android.settings.widget.SwitchBar;
-import com.android.settings.widget.SwitchBarController;
+import com.android.settings.widget.SwitchWidgetController;
import org.junit.After;
import org.junit.Before;
@@ -43,14 +42,14 @@ public class MultiUserSwitchBarControllerTest {
private Context mContext;
private ShadowUserManager mUserManager;
- private SwitchBarController mSwitchBarController;
+ private SwitchWidgetController mSwitchWidgetController;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mUserManager = ShadowUserManager.getShadow();
- mSwitchBarController = spy(new SwitchBarController(new SwitchBar(mContext)));
+ mSwitchWidgetController = mock(SwitchWidgetController.class);
mUserManager.setSupportsMultipleUsers(true);
}
@@ -65,9 +64,9 @@ public class MultiUserSwitchBarControllerTest {
UserManager.DISALLOW_USER_SWITCH, true);
final MultiUserSwitchBarController controller = new MultiUserSwitchBarController(mContext,
- mSwitchBarController, null);
+ mSwitchWidgetController, null);
- verify(mSwitchBarController).setDisabledByAdmin(any());
+ verify(mSwitchWidgetController).setDisabledByAdmin(any());
}
@Test
@@ -76,8 +75,8 @@ public class MultiUserSwitchBarControllerTest {
UserManager.DISALLOW_USER_SWITCH, false);
final MultiUserSwitchBarController controller = new MultiUserSwitchBarController(mContext,
- mSwitchBarController, null);
+ mSwitchWidgetController, null);
- verify(mSwitchBarController, never()).setDisabledByAdmin(any());
+ verify(mSwitchWidgetController, never()).setDisabledByAdmin(any());
}
}
diff --git a/tests/robotests/src/com/android/settings/widget/SwitchBarTest.java b/tests/robotests/src/com/android/settings/widget/SwitchBarTest.java
deleted file mode 100644
index 0c297f45408..00000000000
--- a/tests/robotests/src/com/android/settings/widget/SwitchBarTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.widget;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.robolectric.RuntimeEnvironment.application;
-
-import android.content.Context;
-import android.graphics.drawable.ColorDrawable;
-import android.widget.TextView;
-
-import com.android.settings.R;
-import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.Robolectric;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-@RunWith(RobolectricTestRunner.class)
-public class SwitchBarTest {
-
- private static final int COLOR_BACKGROUND = 1;
- private static final int COLOR_BACKGROUND_ACTIVATED = 2;
-
- private Context mContext;
- private SwitchBar mBar;
-
- @Before
- public void setUp() {
- mContext = RuntimeEnvironment.application;
- mBar = new SwitchBar(application, Robolectric.buildAttributeSet()
- .addAttribute(R.attr.switchBarBackgroundColor, String.valueOf(COLOR_BACKGROUND))
- .addAttribute(R.attr.switchBarBackgroundActivatedColor,
- String.valueOf(COLOR_BACKGROUND_ACTIVATED))
- .build());
- }
-
- @Test
- public void cycleChecked_defaultLabel_shouldUpdateTextAndBackground() {
- final int defaultOnText = R.string.switch_on_text;
- final int defaultOffText = R.string.switch_off_text;
-
- assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
- .isEqualTo(mContext.getString(defaultOffText));
-
- mBar.setChecked(true);
-
- assertThat(mBar.getBackground()).isInstanceOf(ColorDrawable.class);
- assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
- .isEqualTo(mContext.getString(defaultOnText));
- }
-
- @Test
- public void cycleChecked_customLabel_shouldUpdateTextAndBackground() {
- final int onText = R.string.main_clear_progress_text;
- final int offText = R.string.clear_user_data_text;
-
- mBar.setSwitchBarText(onText, offText);
- assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
- .isEqualTo(mContext.getString(offText));
-
- mBar.setChecked(true);
- assertThat(mBar.getBackground()).isInstanceOf(ColorDrawable.class);
-
- assertThat(((TextView) mBar.findViewById(R.id.switch_text)).getText())
- .isEqualTo(mContext.getString(onText));
- }
-
- @Test
- public void setCheck_customLabelWithStringType_shouldUpdateTextAndBackground() {
- final String onText = mContext.getString(
- R.string.accessibility_service_primary_switch_title);
- final String offText = mContext.getString(
- R.string.accessibility_service_primary_switch_title);
- final TextView switchBarTextView = ((TextView) mBar.findViewById(R.id.switch_text));
-
- mBar.setSwitchBarText(onText, offText);
-
- assertThat(switchBarTextView.getText()).isEqualTo(offText);
-
- mBar.setChecked(true);
-
- assertThat(mBar.getBackground()).isInstanceOf(ColorDrawable.class);
- assertThat(switchBarTextView.getText()).isEqualTo(onText);
- }
-
- @Test
- public void disabledByAdmin_shouldDelegateToRestrictedIcon() {
- mBar.setDisabledByAdmin(new EnforcedAdmin());
- assertThat(mBar.getDelegatingView().getId()).isEqualTo(R.id.restricted_icon);
- }
-
- @Test
- public void notDisabledByAdmin_shouldDelegateToSwitch() {
- mBar.setDisabledByAdmin(null);
- assertThat(mBar.getDelegatingView().getId()).isEqualTo(R.id.switch_widget);
- }
-
- @Test
- public void performClick_shouldIsCheckedValueChange() {
- boolean isChecked = mBar.isChecked();
- mBar.performClick();
- assertThat(mBar.isChecked()).isEqualTo(!isChecked);
- }
-}