Search in sources :

Example 1 with CheckBoxPreference

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

the class RestrictedAppDetails method onBatteryTipHandled.

@Override
public void onBatteryTipHandled(BatteryTip batteryTip) {
    final AppInfo appInfo;
    final boolean isRestricted = batteryTip instanceof RestrictAppTip;
    if (isRestricted) {
        appInfo = ((RestrictAppTip) batteryTip).getRestrictAppList().get(0);
    } else {
        appInfo = ((UnrestrictAppTip) batteryTip).getUnrestrictAppInfo();
    }
    CheckBoxPreference preference = (CheckBoxPreference) mRestrictedAppListGroup.findPreference(getKeyFromAppInfo(appInfo));
    if (preference != null) {
        preference.setChecked(isRestricted);
    }
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) AppCheckBoxPreference(com.android.settings.widget.AppCheckBoxPreference) RestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo)

Example 2 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project fdroidclient by f-droid.

the class PreferencesFragment method updateSummary.

private void updateSummary(String key, boolean changing) {
    switch(key) {
        case Preferences.PREF_UPDATE_INTERVAL:
            updateIntervalSeekBar.setMax(Preferences.UPDATE_INTERVAL_VALUES.length - 1);
            int seekBarPosition = updateIntervalSeekBar.getValue();
            updateIntervalSeekBar.setSummary(UPDATE_INTERVAL_NAMES[seekBarPosition]);
            break;
        case Preferences.PREF_OVER_WIFI:
            overWifiSeekBar.setMax(Preferences.OVER_NETWORK_ALWAYS);
            setNetworkSeekBarSummary(overWifiSeekBar);
            enableUpdateInverval();
            break;
        case Preferences.PREF_OVER_DATA:
            overDataSeekBar.setMax(Preferences.OVER_NETWORK_ALWAYS);
            setNetworkSeekBarSummary(overDataSeekBar);
            enableUpdateInverval();
            break;
        case Preferences.PREF_UPDATE_NOTIFICATION_ENABLED:
            checkSummary(key, R.string.notify_on);
            break;
        case Preferences.PREF_THEME:
            entrySummary(key);
            if (changing) {
                AppCompatActivity activity = (AppCompatActivity) getActivity();
                FDroidApp fdroidApp = (FDroidApp) activity.getApplication();
                fdroidApp.applyTheme();
            }
            break;
        case Preferences.PREF_USE_PURE_BLACK_DARK_THEME:
            if (changing) {
                AppCompatActivity activity = (AppCompatActivity) getActivity();
                // Theme will be applied upon activity creation
                if (activity != null) {
                    ActivityCompat.recreate(activity);
                }
            }
            break;
        case Preferences.PREF_SHOW_INCOMPAT_VERSIONS:
            checkSummary(key, R.string.show_incompat_versions_on);
            break;
        case Preferences.PREF_SHOW_ANTI_FEATURES:
            checkSummary(key, R.string.show_anti_feature_apps_on);
            break;
        case Preferences.PREF_FORCE_TOUCH_APPS:
            checkSummary(key, R.string.force_touch_apps_on);
            break;
        case Preferences.PREF_LOCAL_REPO_NAME:
            textSummary(key, R.string.local_repo_name_summary);
            break;
        case Preferences.PREF_LOCAL_REPO_HTTPS:
            checkSummary(key, R.string.local_repo_https_on);
            break;
        case Preferences.PREF_LANGUAGE:
            entrySummary(key);
            if (changing) {
                AppCompatActivity activity = (AppCompatActivity) getActivity();
                Languages.setLanguage(activity);
                RepoProvider.Helper.clearEtags(getActivity());
                UpdateService.updateNow(getActivity());
                Languages.forceChangeLanguage(activity);
            }
            break;
        case Preferences.PREF_KEEP_CACHE_TIME:
            entrySummary(key);
            if (changing && currentKeepCacheTime != Preferences.get().getKeepCacheTime()) {
                CleanCacheWorker.schedule(requireContext());
            }
            break;
        case Preferences.PREF_EXPERT:
            checkSummary(key, R.string.expert_on);
            int expertPreferencesCount = 0;
            boolean isExpertMode = Preferences.get().expertMode();
            for (int i = 0; i < otherPrefGroup.getPreferenceCount(); i++) {
                Preference pref = otherPrefGroup.getPreference(i);
                if (TextUtils.equals(Preferences.PREF_EXPERT, pref.getDependency())) {
                    pref.setVisible(isExpertMode);
                    expertPreferencesCount++;
                }
            }
            if (changing) {
                RecyclerView recyclerView = getListView();
                int preferencesCount = recyclerView.getAdapter().getItemCount();
                if (!isExpertMode) {
                    expertPreferencesCount = 0;
                }
                topScroller.setTargetPosition(preferencesCount - expertPreferencesCount - 1);
                recyclerView.getLayoutManager().startSmoothScroll(topScroller);
            }
            break;
        case Preferences.PREF_PRIVILEGED_INSTALLER:
            // We may have removed this preference if it is not suitable to show the user.
            // So lets check it is here first.
            final CheckBoxPreference pref = (CheckBoxPreference) findPreference(Preferences.PREF_PRIVILEGED_INSTALLER);
            if (pref != null) {
                checkSummary(key, R.string.system_installer_on);
            }
            break;
        case Preferences.PREF_ENABLE_PROXY:
            SwitchPreferenceCompat checkPref = (SwitchPreferenceCompat) findPreference(key);
            checkPref.setSummary(R.string.enable_proxy_summary);
            break;
        case Preferences.PREF_PROXY_HOST:
            EditTextPreference textPref = (EditTextPreference) findPreference(key);
            String text = Preferences.get().getProxyHost();
            if (TextUtils.isEmpty(text) || text.equals(Preferences.DEFAULT_PROXY_HOST)) {
                textPref.setSummary(R.string.proxy_host_summary);
            } else {
                textPref.setSummary(text);
            }
            break;
        case Preferences.PREF_PROXY_PORT:
            EditTextPreference textPref2 = (EditTextPreference) findPreference(key);
            int port = Preferences.get().getProxyPort();
            if (port == Preferences.DEFAULT_PROXY_PORT) {
                textPref2.setSummary(R.string.proxy_port_summary);
            } else {
                textPref2.setSummary(String.valueOf(port));
            }
            break;
        case Preferences.PREF_KEEP_INSTALL_HISTORY:
            if (keepInstallHistoryPref.isChecked()) {
                InstallHistoryService.register(getActivity());
                installHistoryPref.setVisible(true);
                sendToFDroidMetricsPref.setEnabled(true);
            } else {
                InstallHistoryService.unregister(getActivity());
                installHistoryPref.setVisible(false);
                sendToFDroidMetricsPref.setEnabled(false);
            }
            setFDroidMetricsWorker();
            break;
        case Preferences.PREF_SEND_TO_FDROID_METRICS:
            setFDroidMetricsWorker();
            break;
    }
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) SeekBarPreference(androidx.preference.SeekBarPreference) EditTextPreference(androidx.preference.EditTextPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) CheckBoxPreference(androidx.preference.CheckBoxPreference) SwitchPreferenceCompat(androidx.preference.SwitchPreferenceCompat) FDroidApp(org.fdroid.fdroid.FDroidApp) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) RecyclerView(androidx.recyclerview.widget.RecyclerView) EditTextPreference(androidx.preference.EditTextPreference)

Example 3 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project fdroidclient by f-droid.

the class PreferencesFragment method initPrivilegedInstallerPreference.

/**
 * Initializes SystemInstaller preference, which can only be enabled when F-Droid is installed as a system-app
 */
private void initPrivilegedInstallerPreference() {
    final CheckBoxPreference pref = (CheckBoxPreference) findPreference(Preferences.PREF_PRIVILEGED_INSTALLER);
    // this preference.
    if (pref == null) {
        return;
    }
    Preferences p = Preferences.get();
    boolean enabled = p.isPrivilegedInstallerEnabled();
    boolean installed = PrivilegedInstaller.isExtensionInstalledCorrectly(getActivity()) == PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES;
    // way to easily install from here.
    if (Build.VERSION.SDK_INT > 19 && !installed) {
        if (pref != null) {
            otherPrefGroup.removePreference(pref);
        }
    } else {
        pref.setEnabled(installed);
        pref.setDefaultValue(installed);
        pref.setChecked(enabled && installed);
        pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
                if (pref.isChecked()) {
                    editor.remove(Preferences.PREF_PRIVILEGED_INSTALLER);
                } else {
                    editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false);
                }
                editor.apply();
                return true;
            }
        });
    }
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) CheckBoxPreference(androidx.preference.CheckBoxPreference) SeekBarPreference(androidx.preference.SeekBarPreference) EditTextPreference(androidx.preference.EditTextPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) Preferences(org.fdroid.fdroid.Preferences) SharedPreferences(android.content.SharedPreferences)

Example 4 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.

the class TypeFilterPreferenceControllerTest method updateState_enabled_metaData_disableFilter_notThisField.

@Test
public void updateState_enabled_metaData_disableFilter_notThisField() {
    mSi.metaData = new Bundle();
    mSi.metaData.putCharSequence(NotificationListenerService.META_DATA_DISABLED_FILTER_TYPES, "1|alerting");
    when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
    when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
    CheckBoxPreference pref = new CheckBoxPreference(mContext);
    mController.updateState(pref);
    assertThat(pref.isEnabled()).isTrue();
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) Bundle(android.os.Bundle) NotificationListenerFilter(android.service.notification.NotificationListenerFilter) Test(org.junit.Test)

Example 5 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.

the class TypeFilterPreferenceControllerTest method updateState_checked.

@Test
public void updateState_checked() {
    NotificationListenerFilter nlf = new NotificationListenerFilter(mController.getType(), new ArraySet<>());
    when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
    when(mNm.getListenerFilter(mCn, 0)).thenReturn(nlf);
    CheckBoxPreference pref = new CheckBoxPreference(mContext);
    mController.updateState(pref);
    assertThat(pref.isChecked()).isTrue();
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) NotificationListenerFilter(android.service.notification.NotificationListenerFilter) Test(org.junit.Test)

Aggregations

CheckBoxPreference (androidx.preference.CheckBoxPreference)31 Test (org.junit.Test)16 NotificationListenerFilter (android.service.notification.NotificationListenerFilter)14 Bundle (android.os.Bundle)5 ListPreference (androidx.preference.ListPreference)5 Preference (androidx.preference.Preference)5 VersionedPackage (android.content.pm.VersionedPackage)4 SparseLongArray (android.util.SparseLongArray)4 AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)4 AppCheckBoxPreference (com.android.settings.widget.AppCheckBoxPreference)4 Context (android.content.Context)3 ArraySet (android.util.ArraySet)3 EditTextPreference (androidx.preference.EditTextPreference)3 PreferenceCategory (androidx.preference.PreferenceCategory)3 SeekBarPreference (androidx.preference.SeekBarPreference)3 ArrayList (java.util.ArrayList)3 SharedPreferences (android.content.SharedPreferences)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageManager (android.content.pm.PackageManager)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2