Search in sources :

Example 1 with SettingsMainSwitchPreference

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);
}
Also used : SettingsMainSwitchPreference(com.android.settings.widget.SettingsMainSwitchPreference) LayoutInflater(android.view.LayoutInflater) SubscriptionInfo(android.telephony.SubscriptionInfo) PreferenceManager(androidx.preference.PreferenceManager) View(android.view.View) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) LinearLayout(android.widget.LinearLayout) Before(org.junit.Before)

Example 2 with SettingsMainSwitchPreference

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);
}
Also used : SettingsMainSwitchPreference(com.android.settings.widget.SettingsMainSwitchPreference)

Example 3 with SettingsMainSwitchPreference

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);
}
Also used : SettingsMainSwitchPreference(com.android.settings.widget.SettingsMainSwitchPreference) LayoutInflater(android.view.LayoutInflater) ShadowApplication(org.robolectric.shadows.ShadowApplication) View(android.view.View) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) LinearLayout(android.widget.LinearLayout) Before(org.junit.Before)

Example 4 with SettingsMainSwitchPreference

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);
        }
    }
}
Also used : SettingsMainSwitchPreference(com.android.settings.widget.SettingsMainSwitchPreference)

Example 5 with SettingsMainSwitchPreference

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());
}
Also used : SettingsMainSwitchPreference(com.android.settings.widget.SettingsMainSwitchPreference)

Aggregations

SettingsMainSwitchPreference (com.android.settings.widget.SettingsMainSwitchPreference)5 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 LinearLayout (android.widget.LinearLayout)2 PreferenceViewHolder (androidx.preference.PreferenceViewHolder)2 Before (org.junit.Before)2 SubscriptionInfo (android.telephony.SubscriptionInfo)1 PreferenceManager (androidx.preference.PreferenceManager)1 ShadowApplication (org.robolectric.shadows.ShadowApplication)1