Search in sources :

Example 6 with BatteryTipDialogFragment

use of com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment 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 7 with BatteryTipDialogFragment

use of com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment in project android_packages_apps_Settings by omnirom.

the class BackgroundActivityPreferenceController method showDialog.

@VisibleForTesting
void showDialog(boolean restricted) {
    final AppInfo appInfo = new AppInfo.Builder().setUid(mUid).setPackageName(mTargetPackage).build();
    BatteryTip tip = restricted ? new UnrestrictAppTip(BatteryTip.StateType.NEW, appInfo) : new RestrictAppTip(BatteryTip.StateType.NEW, appInfo);
    final BatteryTipDialogFragment dialogFragment = BatteryTipDialogFragment.newInstance(tip, mFragment.getMetricsCategory());
    dialogFragment.setTargetFragment(mFragment, 0);
    dialogFragment.show(mFragment.getFragmentManager(), TAG);
}
Also used : BatteryTipDialogFragment(com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment) RestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) UnrestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 8 with BatteryTipDialogFragment

use of com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment in project android_packages_apps_Settings by omnirom.

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);
                mMetricsFeatureProvider.action(getContext(), SettingsEnums.ACTION_APP_RESTRICTED_LIST_UNCHECKED, appInfo.packageName);
                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)

Aggregations

BatteryTipDialogFragment (com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment)8 VisibleForTesting (androidx.annotation.VisibleForTesting)4 AlertDialog (androidx.appcompat.app.AlertDialog)4 AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)4 ShadowAlertDialogCompat (com.android.settings.testutils.shadow.ShadowAlertDialogCompat)4 Test (org.junit.Test)4 Context (android.content.Context)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageManager (android.content.pm.PackageManager)2 SparseLongArray (android.util.SparseLongArray)2 CheckBoxPreference (androidx.preference.CheckBoxPreference)2 BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)2 RestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip)2 UnrestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip)2 AppCheckBoxPreference (com.android.settings.widget.AppCheckBoxPreference)2