use of com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip 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);
}
use of com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip in project android_packages_apps_Settings by omnirom.
the class BatteryTipDialogFragmentTest method testOnCreateDialog_restrictSixAppsTip_fireRestrictSixAppsDialog.
@Test
public void testOnCreateDialog_restrictSixAppsTip_fireRestrictSixAppsDialog() {
Robolectric.getForegroundThreadScheduler().pause();
final List<AppInfo> appInfos = new ArrayList<>();
for (int i = 0; i < 6; i++) {
appInfos.add(mAppInfo);
}
final RestrictAppTip restrictSixAppsTip = new RestrictAppTip(BatteryTip.StateType.NEW, appInfos);
mDialogFragment = BatteryTipDialogFragment.newInstance(restrictSixAppsTip, METRICS_KEY);
FragmentController.setupFragment(mDialogFragment, FragmentActivity.class, 0, /* containerViewId */
null);
Robolectric.getForegroundThreadScheduler().advanceToLastPostedRunnable();
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
assertThat(shadowDialog.getTitle()).isEqualTo("Restrict 6 apps?");
assertThat(shadowDialog.getMessage()).isEqualTo("To save battery, stop these apps from using battery in the background. " + "Restricted apps may not work properly and notifications may be" + " delayed.\n\nApps:\napp, app, app, app, app, and app.");
}
use of com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip in project android_packages_apps_Settings by omnirom.
the class BatteryTipDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Bundle bundle = getArguments();
final Context context = getContext();
mBatteryTip = bundle.getParcelable(ARG_BATTERY_TIP);
mMetricsKey = bundle.getInt(ARG_METRICS_KEY);
switch(mBatteryTip.getType()) {
case BatteryTip.TipType.SUMMARY:
return new AlertDialog.Builder(context).setMessage(R.string.battery_tip_dialog_summary_message).setPositiveButton(android.R.string.ok, null).create();
case BatteryTip.TipType.HIGH_DEVICE_USAGE:
final HighUsageTip highUsageTip = (HighUsageTip) mBatteryTip;
final RecyclerView view = (RecyclerView) LayoutInflater.from(context).inflate(R.layout.recycler_view, null);
view.setLayoutManager(new LinearLayoutManager(context));
view.setAdapter(new HighUsageAdapter(context, highUsageTip.getHighUsageAppList()));
return new AlertDialog.Builder(context).setMessage(getString(R.string.battery_tip_dialog_message, highUsageTip.getHighUsageAppList().size())).setView(view).setPositiveButton(android.R.string.ok, null).create();
case BatteryTip.TipType.APP_RESTRICTION:
final RestrictAppTip restrictAppTip = (RestrictAppTip) mBatteryTip;
final List<AppInfo> restrictedAppList = restrictAppTip.getRestrictAppList();
final int num = restrictedAppList.size();
final CharSequence appLabel = Utils.getApplicationLabel(context, restrictedAppList.get(0).packageName);
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle(context.getResources().getQuantityString(R.plurals.battery_tip_restrict_app_dialog_title, num, num)).setPositiveButton(R.string.battery_tip_restrict_app_dialog_ok, this).setNegativeButton(android.R.string.cancel, null);
if (num == 1) {
builder.setMessage(getString(R.string.battery_tip_restrict_app_dialog_message, appLabel));
} else if (num <= 5) {
builder.setMessage(getString(R.string.battery_tip_restrict_apps_less_than_5_dialog_message));
final RecyclerView restrictionView = (RecyclerView) LayoutInflater.from(context).inflate(R.layout.recycler_view, null);
restrictionView.setLayoutManager(new LinearLayoutManager(context));
restrictionView.setAdapter(new HighUsageAdapter(context, restrictedAppList));
builder.setView(restrictionView);
} else {
builder.setMessage(context.getString(R.string.battery_tip_restrict_apps_more_than_5_dialog_message, restrictAppTip.getRestrictAppsString(context)));
}
return builder.create();
case BatteryTip.TipType.REMOVE_APP_RESTRICTION:
final UnrestrictAppTip unrestrictAppTip = (UnrestrictAppTip) mBatteryTip;
final CharSequence name = Utils.getApplicationLabel(context, unrestrictAppTip.getPackageName());
return new AlertDialog.Builder(context).setTitle(getString(R.string.battery_tip_unrestrict_app_dialog_title)).setMessage(R.string.battery_tip_unrestrict_app_dialog_message).setPositiveButton(R.string.battery_tip_unrestrict_app_dialog_ok, this).setNegativeButton(R.string.battery_tip_unrestrict_app_dialog_cancel, null).create();
case BatteryTip.TipType.BATTERY_DEFENDER:
mMetricsFeatureProvider.action(context, SettingsEnums.ACTION_TIP_BATTERY_DEFENDER, mMetricsKey);
final String percentage = NumberFormat.getPercentInstance().format(CHARGE_LIMIT_LEVEL);
final String message = context.getString(R.string.battery_tip_limited_temporarily_dialog_msg, percentage);
final boolean isPluggedIn = isPluggedIn();
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context).setTitle(R.string.battery_tip_limited_temporarily_title).setMessage(message);
if (isPluggedIn) {
dialogBuilder.setPositiveButton(R.string.battery_tip_limited_temporarily_dialog_resume_charge, this).setNegativeButton(R.string.okay, null);
} else {
dialogBuilder.setPositiveButton(R.string.okay, null);
}
return dialogBuilder.create();
default:
throw new IllegalArgumentException("unknown type " + mBatteryTip.getType());
}
}
Aggregations