use of com.android.settings.widget.SettingsMainSwitchPreference in project android_packages_apps_Settings by omnirom.
the class MobileNetworkSwitchControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mSubscriptionManager.setSubscriptionEnabled(eq(mSubId), anyBoolean())).thenReturn(true);
when(mSubscription.isEmbedded()).thenReturn(true);
when(mSubscription.getSubscriptionId()).thenReturn(mSubId);
// Most tests want to have 2 available subscriptions so that the switch bar will show.
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
when(sub2.getSubscriptionId()).thenReturn(456);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription, sub2));
final String key = "prefKey";
mController = new MobileNetworkSwitchController(mContext, key);
mController.init(mLifecycle, mSubscription.getSubscriptionId());
if (Looper.myLooper() == null) {
Looper.prepare();
}
mPreferenceManager = new PreferenceManager(mContext);
mScreen = mPreferenceManager.createPreferenceScreen(mContext);
mSwitchBar = new SettingsMainSwitchPreference(mContext);
mSwitchBar.setKey(key);
mScreen.addPreference(mSwitchBar);
final LayoutInflater inflater = LayoutInflater.from(mContext);
final View view = inflater.inflate(mSwitchBar.getLayoutResource(), new LinearLayout(mContext), false);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(view);
mSwitchBar.onBindViewHolder(holder);
}
use of com.android.settings.widget.SettingsMainSwitchPreference in project android_packages_apps_Settings by omnirom.
the class ToggleFeaturePreferenceFragment method initToggleServiceSwitchPreference.
private void initToggleServiceSwitchPreference() {
mToggleServiceSwitchPreference = new SettingsMainSwitchPreference(getPrefContext());
mToggleServiceSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
if (getArguments().containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
final boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED);
mToggleServiceSwitchPreference.setChecked(enabled);
}
getPreferenceScreen().addPreference(mToggleServiceSwitchPreference);
}
use of com.android.settings.widget.SettingsMainSwitchPreference in project android_packages_apps_Settings by omnirom.
the class BlockPreferenceControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = RuntimeEnvironment.application;
mController = spy(new BlockPreferenceController(mContext, mDependentFieldListener, mBackend));
mPreference = new SettingsMainSwitchPreference(mContext);
final LayoutInflater inflater = LayoutInflater.from(mContext);
final View view = inflater.inflate(mPreference.getLayoutResource(), new LinearLayout(mContext), false);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(view);
mPreference.onBindViewHolder(holder);
}
use of com.android.settings.widget.SettingsMainSwitchPreference in project android_packages_apps_Settings by omnirom.
the class BlockPreferenceController method updateState.
public void updateState(Preference preference) {
SettingsMainSwitchPreference bar = (SettingsMainSwitchPreference) preference;
if (bar != null) {
String switchBarText = getSwitchBarText();
bar.setTitle(switchBarText);
bar.show();
try {
bar.addOnSwitchChangeListener(this);
} catch (IllegalStateException e) {
// an exception is thrown if you try to add the listener twice
}
bar.setDisabledByAdmin(mAdmin);
if (mChannel != null && !isChannelBlockable()) {
bar.setSwitchBarEnabled(false);
}
if (mChannelGroup != null && !isChannelGroupBlockable()) {
bar.setSwitchBarEnabled(false);
}
if (mChannel == null && mAppRow.systemApp && (!mAppRow.banned || mAppRow.lockedImportance)) {
bar.setSwitchBarEnabled(false);
}
if (mChannel != null) {
bar.setChecked(!mAppRow.banned && mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
} else if (mChannelGroup != null) {
bar.setChecked(!mAppRow.banned && !mChannelGroup.isBlocked());
} else {
bar.setChecked(!mAppRow.banned);
}
}
}
use of com.android.settings.widget.SettingsMainSwitchPreference in project android_packages_apps_Settings by omnirom.
the class AutoBrightnessDetailPreferenceController method displayPreference.
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
SettingsMainSwitchPreference pref = (SettingsMainSwitchPreference) screen.findPreference(getPreferenceKey());
pref.addOnSwitchChangeListener(this);
pref.setChecked(isChecked());
}
Aggregations