Search in sources :

Example 11 with MasterSwitchPreference

use of com.android.settings.widget.MasterSwitchPreference in project android_packages_apps_Settings by SudaMod.

the class BluetoothEnablerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    when(mBluetoothManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter);
    mSwitch = new Switch(mContext);
    mMasterSwitchPreference = new MasterSwitchPreference(mContext);
    mMasterSwitchController = spy(new MasterSwitchController(mMasterSwitchPreference));
    mBluetoothEnabler = new BluetoothEnabler(mContext, mMasterSwitchController, mMetricsFeatureProvider, mBluetoothManager, 123, mRestrictionUtils);
    PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(mock(View.class));
    when(holder.findViewById(R.id.switchWidget)).thenReturn(mSwitch);
    mMasterSwitchPreference.onBindViewHolder(holder);
}
Also used : MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) Switch(android.widget.Switch) MasterSwitchController(com.android.settings.widget.MasterSwitchController) PreferenceViewHolder(android.support.v7.preference.PreferenceViewHolder) View(android.view.View) Before(org.junit.Before)

Example 12 with MasterSwitchPreference

use of com.android.settings.widget.MasterSwitchPreference in project android_packages_apps_Settings by DirtyUnicorns.

the class BluetoothEnablerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    when(mBluetoothManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter);
    mSwitch = new Switch(mContext);
    mMasterSwitchPreference = new MasterSwitchPreference(mContext);
    mMasterSwitchController = spy(new MasterSwitchController(mMasterSwitchPreference));
    mBluetoothEnabler = new BluetoothEnabler(mContext, mMasterSwitchController, mMetricsFeatureProvider, mBluetoothManager, 123, mRestrictionUtils);
    PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(mock(View.class));
    when(holder.findViewById(R.id.switchWidget)).thenReturn(mSwitch);
    mMasterSwitchPreference.onBindViewHolder(holder);
}
Also used : MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) Switch(android.widget.Switch) MasterSwitchController(com.android.settings.widget.MasterSwitchController) PreferenceViewHolder(android.support.v7.preference.PreferenceViewHolder) View(android.view.View) Before(org.junit.Before)

Example 13 with MasterSwitchPreference

use of com.android.settings.widget.MasterSwitchPreference in project android_packages_apps_Settings by DirtyUnicorns.

the class WifiTetherPreferenceControllerTest method start_wifiApOn_shouldSetInitialStateToOn.

@Test
public void start_wifiApOn_shouldSetInitialStateToOn() {
    when(mWifiManager.getWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED);
    final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
    final MasterSwitchPreference pref = mock(MasterSwitchPreference.class);
    when(mScreen.findPreference(anyString())).thenReturn(pref);
    mController.displayPreference(mScreen);
    mLifecycle.onStart();
    assertThat(ShadowWifiTetherSwitchBarController.onStartCalled).isTrue();
    verify(mContext).registerReceiver(eq(receiver), any(IntentFilter.class));
    verify(pref).setChecked(true);
}
Also used : IntentFilter(android.content.IntentFilter) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) BroadcastReceiver(android.content.BroadcastReceiver) Test(org.junit.Test)

Example 14 with MasterSwitchPreference

use of com.android.settings.widget.MasterSwitchPreference in project android_packages_apps_Settings by DirtyUnicorns.

the class WifiTetherPreferenceControllerTest method start_wifiApOff_shouldSetInitialStateToOff.

@Test
public void start_wifiApOff_shouldSetInitialStateToOff() {
    when(mWifiManager.getWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_DISABLED);
    final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
    final MasterSwitchPreference pref = mock(MasterSwitchPreference.class);
    when(mScreen.findPreference(anyString())).thenReturn(pref);
    mController.displayPreference(mScreen);
    mLifecycle.onStart();
    assertThat(ShadowWifiTetherSwitchBarController.onStartCalled).isTrue();
    verify(mContext).registerReceiver(eq(receiver), any(IntentFilter.class));
    verify(pref).setChecked(false);
}
Also used : IntentFilter(android.content.IntentFilter) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) BroadcastReceiver(android.content.BroadcastReceiver) Test(org.junit.Test)

Example 15 with MasterSwitchPreference

use of com.android.settings.widget.MasterSwitchPreference in project platform_packages_apps_Settings by BlissRoms.

the class WifiTetherPreferenceControllerTest method start_wifiApOn_shouldSetInitialStateToOn.

@Test
public void start_wifiApOn_shouldSetInitialStateToOn() {
    when(mWifiManager.getWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED);
    final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
    final MasterSwitchPreference pref = mock(MasterSwitchPreference.class);
    when(mScreen.findPreference(anyString())).thenReturn(pref);
    mController.displayPreference(mScreen);
    mLifecycle.onStart();
    assertThat(ShadowWifiTetherSwitchBarController.onStartCalled).isTrue();
    verify(mContext).registerReceiver(eq(receiver), any(IntentFilter.class));
    verify(pref).setChecked(true);
}
Also used : IntentFilter(android.content.IntentFilter) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) BroadcastReceiver(android.content.BroadcastReceiver) Test(org.junit.Test)

Aggregations

MasterSwitchPreference (com.android.settings.widget.MasterSwitchPreference)31 BroadcastReceiver (android.content.BroadcastReceiver)12 IntentFilter (android.content.IntentFilter)12 Test (org.junit.Test)12 Before (org.junit.Before)11 Bundle (android.os.Bundle)7 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)7 Intent (android.content.Intent)6 Preference (android.support.v7.preference.Preference)6 LayoutPreference (com.android.settings.applications.LayoutPreference)6 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)6 FooterPreference (com.android.settingslib.widget.FooterPreference)6 PreferenceViewHolder (android.support.v7.preference.PreferenceViewHolder)5 View (android.view.View)5 Switch (android.widget.Switch)5 MasterSwitchController (com.android.settings.widget.MasterSwitchController)5 NotificationChannel (android.app.NotificationChannel)1 SwitchPreference (android.support.v14.preference.SwitchPreference)1 Preference (androidx.preference.Preference)1 PreferenceGroup (androidx.preference.PreferenceGroup)1