Search in sources :

Example 21 with SwitchPreference

use of androidx.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class UseOpenWifiPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    if (!(preference instanceof SwitchPreference)) {
        return;
    }
    final SwitchPreference useOpenWifiPreference = (SwitchPreference) preference;
    boolean isScorerSet = mNetworkScoreManager.getActiveScorerPackage() != null;
    boolean doesActiveScorerSupportFeature = mEnableUseWifiComponentName != null;
    useOpenWifiPreference.setChecked(isSettingEnabled());
    useOpenWifiPreference.setVisible(isAvailable());
    useOpenWifiPreference.setEnabled(isScorerSet && doesActiveScorerSupportFeature);
    if (!isScorerSet) {
        useOpenWifiPreference.setSummary(R.string.use_open_wifi_automatically_summary_scoring_disabled);
    } else if (!doesActiveScorerSupportFeature) {
        useOpenWifiPreference.setSummary(R.string.use_open_wifi_automatically_summary_scorer_unsupported_disabled);
    } else {
        useOpenWifiPreference.setSummary(R.string.use_open_wifi_automatically_summary);
    }
}
Also used : SwitchPreference(androidx.preference.SwitchPreference)

Example 22 with SwitchPreference

use of androidx.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiWakeupPreferenceController method handlePreferenceTreeClick.

@Override
public boolean handlePreferenceTreeClick(Preference preference) {
    if (!TextUtils.equals(preference.getKey(), KEY_ENABLE_WIFI_WAKEUP)) {
        return false;
    }
    if (!(preference instanceof SwitchPreference)) {
        return false;
    }
    // Toggle wifi-wakeup setting between 1/0 based on its current state, and some other checks.
    if (isWifiWakeupAvailable()) {
        setWifiWakeupEnabled(false);
    } else {
        if (!mLocationManager.isLocationEnabled()) {
            final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            mFragment.startActivityForResult(intent, WIFI_WAKEUP_REQUEST_CODE);
            return true;
        } else if (!getWifiScanningEnabled()) {
            showScanningDialog();
        } else {
            setWifiWakeupEnabled(true);
        }
    }
    updateState(mPreference);
    return true;
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Intent(android.content.Intent)

Example 23 with SwitchPreference

use of androidx.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiWakeupPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    if (!(preference instanceof SwitchPreference)) {
        return;
    }
    final SwitchPreference enableWifiWakeup = (SwitchPreference) preference;
    enableWifiWakeup.setChecked(isWifiWakeupAvailable());
    if (!mLocationManager.isLocationEnabled()) {
        preference.setSummary(getNoLocationSummary());
    } else {
        preference.setSummary(R.string.wifi_wakeup_summary);
    }
}
Also used : SwitchPreference(androidx.preference.SwitchPreference)

Example 24 with SwitchPreference

use of androidx.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InstantAppWebActionPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    mContentResolver = mContext.getContentResolver();
    mController = new InstantAppWebActionPreferenceController(mContext, PREF_KEY);
    mSwitchPreference = new SwitchPreference(mContext);
    mEnableEphemeralFeature = Settings.Global.getInt(mContentResolver, ENABLE_EPHEMERAL_FEATURE, 1);
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Before(org.junit.Before)

Example 25 with SwitchPreference

use of androidx.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BillingCycleSettingsTest method onCreate_emptyArguments_shouldSetDefaultNetworkTemplate.

@Test
public void onCreate_emptyArguments_shouldSetDefaultNetworkTemplate() {
    final BillingCycleSettings billingCycleSettings = spy(new BillingCycleSettings());
    when(billingCycleSettings.getContext()).thenReturn(mContext);
    when(billingCycleSettings.getArguments()).thenReturn(Bundle.EMPTY);
    final FragmentActivity activity = mock(FragmentActivity.class);
    when(billingCycleSettings.getActivity()).thenReturn(activity);
    final Resources.Theme theme = mContext.getTheme();
    when(activity.getTheme()).thenReturn(theme);
    doNothing().when(billingCycleSettings).onCreatePreferences(any(Bundle.class), nullable(String.class));
    when(mContext.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(mNetworkPolicyManager);
    when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mConnectivityManager);
    when(mConnectivityManager.isNetworkSupported(anyInt())).thenReturn(true);
    final SwitchPreference preference = mock(SwitchPreference.class);
    when(billingCycleSettings.findPreference(anyString())).thenReturn(preference);
    final FooterPreferenceMixinCompat footer = mock(FooterPreferenceMixinCompat.class);
    ReflectionHelpers.setField(billingCycleSettings, "mFooterPreferenceMixin", footer);
    when(footer.createFooterPreference()).thenReturn(mock(FooterPreference.class));
    billingCycleSettings.onCreate(Bundle.EMPTY);
    assertThat(billingCycleSettings.mNetworkTemplate).isNotNull();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) SwitchPreference(androidx.preference.SwitchPreference) Bundle(android.os.Bundle) FooterPreferenceMixinCompat(com.android.settingslib.widget.FooterPreferenceMixinCompat) Resources(android.content.res.Resources) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FooterPreference(com.android.settingslib.widget.FooterPreference) Test(org.junit.Test)

Aggregations

SwitchPreference (androidx.preference.SwitchPreference)139 Test (org.junit.Test)61 Before (org.junit.Before)29 Intent (android.content.Intent)9 Preference (androidx.preference.Preference)6 ComponentName (android.content.ComponentName)5 A2dpProfile (com.android.settingslib.bluetooth.A2dpProfile)5 ListPreference (androidx.preference.ListPreference)4 PreferenceScreen (androidx.preference.PreferenceScreen)4 PbapServerProfile (com.android.settingslib.bluetooth.PbapServerProfile)4 BluetoothDevice (android.bluetooth.BluetoothDevice)2 Context (android.content.Context)2 ServiceInfo (android.content.pm.ServiceInfo)2 KeyboardLayout (android.hardware.input.KeyboardLayout)2 Parcel (android.os.Parcel)2 PersistableBundle (android.os.PersistableBundle)2 RemoteException (android.os.RemoteException)2 TelephonyManager (android.telephony.TelephonyManager)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 MultiSelectListPreference (androidx.preference.MultiSelectListPreference)2