Search in sources :

Example 21 with CheckBoxPreference

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

the class RestrictedAppDetailsTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    mRestrictedAppDetails = spy(new RestrictedAppDetails());
    mAppInfo = new AppInfo.Builder().setPackageName(PACKAGE_NAME).setUid(UID).build();
    mPreferenceManager = new PreferenceManager(mContext);
    doReturn(mPreferenceManager).when(mRestrictedAppDetails).getPreferenceManager();
    doReturn(mContext).when(mFragment).getContext();
    doReturn(mContext).when(mRestrictedAppDetails).getContext();
    mRestrictedAppDetails.mPackageManager = mPackageManager;
    mRestrictedAppDetails.mIconDrawableFactory = mIconDrawableFactory;
    mRestrictedAppDetails.mAppInfos = new ArrayList<>();
    mRestrictedAppDetails.mAppInfos.add(mAppInfo);
    mRestrictedAppDetails.mRestrictedAppListGroup = spy(new PreferenceCategory(mContext));
    mRestrictedAppDetails.mBatteryUtils = spy(new BatteryUtils(mContext));
    mRestrictedAppDetails.mBatteryDatabaseManager = mBatteryDatabaseManager;
    doReturn(mPreferenceManager).when(mRestrictedAppDetails.mRestrictedAppListGroup).getPreferenceManager();
    mCheckBoxPreference = new CheckBoxPreference(mContext);
    mCheckBoxPreference.setKey(mRestrictedAppDetails.getKeyFromAppInfo(mAppInfo));
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) CheckBoxPreference(androidx.preference.CheckBoxPreference) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 22 with CheckBoxPreference

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

the class RestrictedAppDetails method refreshUi.

@VisibleForTesting
void refreshUi() {
    mRestrictedAppListGroup.removeAll();
    final Context context = getPrefContext();
    final SparseLongArray timestampArray = mBatteryDatabaseManager.queryActionTime(AnomalyDatabaseHelper.ActionType.RESTRICTION);
    final long now = System.currentTimeMillis();
    for (int i = 0, size = mAppInfos.size(); i < size; i++) {
        final CheckBoxPreference checkBoxPreference = new AppCheckBoxPreference(context);
        final AppInfo appInfo = mAppInfos.get(i);
        try {
            final ApplicationInfo applicationInfo = mPackageManager.getApplicationInfoAsUser(appInfo.packageName, 0, /* flags */
            UserHandle.getUserId(appInfo.uid));
            checkBoxPreference.setChecked(mBatteryUtils.isForceAppStandbyEnabled(appInfo.uid, appInfo.packageName));
            checkBoxPreference.setTitle(mPackageManager.getApplicationLabel(applicationInfo));
            checkBoxPreference.setIcon(Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, appInfo.packageName, UserHandle.getUserId(appInfo.uid)));
            checkBoxPreference.setKey(getKeyFromAppInfo(appInfo));
            checkBoxPreference.setOnPreferenceChangeListener((pref, value) -> {
                final BatteryTipDialogFragment fragment = createDialogFragment(appInfo, (Boolean) value);
                fragment.setTargetFragment(this, 0);
                fragment.show(getFragmentManager(), TAG);
                return false;
            });
            final long timestamp = timestampArray.get(appInfo.uid, TIME_NULL);
            if (timestamp != TIME_NULL) {
                checkBoxPreference.setSummary(getString(R.string.restricted_app_time_summary, StringUtil.formatRelativeTime(context, now - timestamp, false)));
            }
            final CharSequence test = checkBoxPreference.getSummaryOn();
            mRestrictedAppListGroup.addPreference(checkBoxPreference);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "Can't find package: " + appInfo.packageName);
        }
    }
}
Also used : Context(android.content.Context) BatteryTipDialogFragment(com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment) PackageManager(android.content.pm.PackageManager) CheckBoxPreference(androidx.preference.CheckBoxPreference) AppCheckBoxPreference(com.android.settings.widget.AppCheckBoxPreference) AppCheckBoxPreference(com.android.settings.widget.AppCheckBoxPreference) ApplicationInfo(android.content.pm.ApplicationInfo) SparseLongArray(android.util.SparseLongArray) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 23 with CheckBoxPreference

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

the class PreferencesFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String s) {
    Preferences preferences = Preferences.get();
    preferences.migrateOldPreferences();
    addPreferencesFromResource(R.xml.preferences);
    otherPrefGroup = (PreferenceGroup) findPreference("pref_category_other");
    Preference aboutPreference = findPreference("pref_about");
    if (aboutPreference != null) {
        aboutPreference.setOnPreferenceClickListener(aboutPrefClickedListener);
    }
    keepInstallHistoryPref = (CheckBoxPreference) findPreference(Preferences.PREF_KEEP_INSTALL_HISTORY);
    sendToFDroidMetricsPref = findPreference(Preferences.PREF_SEND_TO_FDROID_METRICS);
    sendToFDroidMetricsPref.setEnabled(keepInstallHistoryPref.isChecked());
    installHistoryPref = findPreference("installHistory");
    installHistoryPref.setVisible(keepInstallHistoryPref.isChecked());
    if (preferences.isSendingToFDroidMetrics()) {
        installHistoryPref.setTitle(R.string.install_history_and_metrics);
    } else {
        installHistoryPref.setTitle(R.string.install_history);
    }
    useTorCheckPref = (SwitchPreferenceCompat) findPreference(Preferences.PREF_USE_TOR);
    useTorCheckPref.setOnPreferenceChangeListener(useTorChangedListener);
    enableProxyCheckPref = (SwitchPreferenceCompat) findPreference(Preferences.PREF_ENABLE_PROXY);
    enableProxyCheckPref.setOnPreferenceChangeListener(proxyEnabledChangedListener);
    updateAutoDownloadPref = findPreference(Preferences.PREF_AUTO_DOWNLOAD_INSTALL_UPDATES);
    overWifiSeekBar = (LiveSeekBarPreference) findPreference(Preferences.PREF_OVER_WIFI);
    overWifiPrevious = overWifiSeekBar.getValue();
    overWifiSeekBar.setSeekBarLiveUpdater(new LiveSeekBarPreference.SeekBarLiveUpdater() {

        @Override
        public String seekBarUpdated(int position) {
            return getNetworkSeekBarSummary(position);
        }
    });
    overDataSeekBar = (LiveSeekBarPreference) findPreference(Preferences.PREF_OVER_DATA);
    overDataPrevious = overDataSeekBar.getValue();
    overDataSeekBar.setSeekBarLiveUpdater(new LiveSeekBarPreference.SeekBarLiveUpdater() {

        @Override
        public String seekBarUpdated(int position) {
            return getNetworkSeekBarSummary(position);
        }
    });
    updateIntervalSeekBar = (LiveSeekBarPreference) findPreference(Preferences.PREF_UPDATE_INTERVAL);
    updateIntervalPrevious = updateIntervalSeekBar.getValue();
    updateIntervalSeekBar.setSeekBarLiveUpdater(new LiveSeekBarPreference.SeekBarLiveUpdater() {

        @Override
        public String seekBarUpdated(int position) {
            return getString(UPDATE_INTERVAL_NAMES[position]);
        }
    });
    ListPreference languagePref = (ListPreference) findPreference(Preferences.PREF_LANGUAGE);
    if (Build.VERSION.SDK_INT >= 24) {
        PreferenceCategory category = (PreferenceCategory) findPreference("pref_category_display");
        category.removePreference(languagePref);
    } else {
        Languages languages = Languages.get((AppCompatActivity) getActivity());
        languagePref.setDefaultValue(Languages.USE_SYSTEM_DEFAULT);
        languagePref.setEntries(languages.getAllNames());
        languagePref.setEntryValues(languages.getSupportedLocales());
    }
    if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
        PreferenceCategory category = (PreferenceCategory) findPreference("pref_category_appcompatibility");
        category.removePreference(findPreference(Preferences.PREF_FORCE_TOUCH_APPS));
    }
    topScroller = new LinearSmoothScroller(getActivity()) {

        @Override
        protected int getVerticalSnapPreference() {
            return SNAP_TO_START;
        }
    };
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) SeekBarPreference(androidx.preference.SeekBarPreference) EditTextPreference(androidx.preference.EditTextPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) PreferenceCategory(androidx.preference.PreferenceCategory) LinearSmoothScroller(androidx.recyclerview.widget.LinearSmoothScroller) Languages(org.fdroid.fdroid.Languages) ListPreference(androidx.preference.ListPreference) Preferences(org.fdroid.fdroid.Preferences) SharedPreferences(android.content.SharedPreferences)

Example 24 with CheckBoxPreference

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

the class RestrictedAppDetailsTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    mRestrictedAppDetails = spy(new RestrictedAppDetails());
    mAppInfo = new AppInfo.Builder().setPackageName(PACKAGE_NAME).setUid(UID).build();
    mPreferenceManager = new PreferenceManager(mContext);
    doReturn(mPreferenceManager).when(mRestrictedAppDetails).getPreferenceManager();
    doReturn(mContext).when(mFragment).getContext();
    doReturn(mContext).when(mRestrictedAppDetails).getContext();
    mRestrictedAppDetails.mPackageManager = mPackageManager;
    mRestrictedAppDetails.mIconDrawableFactory = mIconDrawableFactory;
    mRestrictedAppDetails.mAppInfos = new ArrayList<>();
    mRestrictedAppDetails.mAppInfos.add(mAppInfo);
    mRestrictedAppDetails.mRestrictedAppListGroup = spy(new PreferenceCategory(mContext));
    mRestrictedAppDetails.mBatteryUtils = spy(new BatteryUtils(mContext));
    mRestrictedAppDetails.mBatteryDatabaseManager = mBatteryDatabaseManager;
    doReturn(mPreferenceManager).when(mRestrictedAppDetails.mRestrictedAppListGroup).getPreferenceManager();
    mCheckBoxPreference = new CheckBoxPreference(mContext);
    mCheckBoxPreference.setKey(mRestrictedAppDetails.getKeyFromAppInfo(mAppInfo));
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) CheckBoxPreference(androidx.preference.CheckBoxPreference) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 25 with CheckBoxPreference

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

the class RestrictedAppDetailsTest method refreshUi_displayPreference.

@Test
public void refreshUi_displayPreference() throws Exception {
    doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfoAsUser(PACKAGE_NAME, 0, USER_ID);
    doReturn(APP_NAME).when(mPackageManager).getApplicationLabel(mApplicationInfo);
    doReturn(true).when(mRestrictedAppDetails.mBatteryUtils).isForceAppStandbyEnabled(UID, PACKAGE_NAME);
    final SparseLongArray timestampArray = new SparseLongArray();
    timestampArray.put(UID, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(5));
    doReturn(timestampArray).when(mBatteryDatabaseManager).queryActionTime(AnomalyDatabaseHelper.ActionType.RESTRICTION);
    mRestrictedAppDetails.refreshUi();
    assertThat(mRestrictedAppDetails.mRestrictedAppListGroup.getPreferenceCount()).isEqualTo(1);
    final CheckBoxPreference preference = (CheckBoxPreference) mRestrictedAppDetails.mRestrictedAppListGroup.getPreference(0);
    assertThat(preference.getTitle()).isEqualTo(APP_NAME);
    assertThat(preference.isChecked()).isTrue();
    assertThat(preference.getSummary()).isEqualTo("Restricted 5 hours ago");
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) SparseLongArray(android.util.SparseLongArray) Test(org.junit.Test)

Aggregations

CheckBoxPreference (androidx.preference.CheckBoxPreference)36 Test (org.junit.Test)16 NotificationListenerFilter (android.service.notification.NotificationListenerFilter)14 Preference (androidx.preference.Preference)8 ListPreference (androidx.preference.ListPreference)7 Bundle (android.os.Bundle)6 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 SharedPreferences (android.content.SharedPreferences)3 PackageManager (android.content.pm.PackageManager)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 ApplicationInfo (android.content.pm.ApplicationInfo)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2