Merge "Clean up useless defender dialog code" into tm-qpr-dev
This commit is contained in:
@@ -43,7 +43,6 @@ import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
|
|||||||
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
||||||
import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;
|
import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,29 +141,6 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
|
|||||||
.setPositiveButton(R.string.battery_tip_unrestrict_app_dialog_ok, this)
|
.setPositiveButton(R.string.battery_tip_unrestrict_app_dialog_ok, this)
|
||||||
.setNegativeButton(R.string.battery_tip_unrestrict_app_dialog_cancel, null)
|
.setNegativeButton(R.string.battery_tip_unrestrict_app_dialog_cancel, null)
|
||||||
.create();
|
.create();
|
||||||
case BatteryTip.TipType.BATTERY_DEFENDER:
|
|
||||||
mMetricsFeatureProvider.action(context,
|
|
||||||
SettingsEnums.ACTION_TIP_BATTERY_DEFENDER, mMetricsKey);
|
|
||||||
final double chargeLimitLevel = 0.8f;
|
|
||||||
final String percentage =
|
|
||||||
NumberFormat.getPercentInstance().format(chargeLimitLevel);
|
|
||||||
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:
|
default:
|
||||||
throw new IllegalArgumentException("unknown type " + mBatteryTip.getType());
|
throw new IllegalArgumentException("unknown type " + mBatteryTip.getType());
|
||||||
}
|
}
|
||||||
|
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.fuelgauge.batterytip.actions;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import com.android.settings.SettingsActivity;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Action to open the Support Center article
|
|
||||||
*/
|
|
||||||
public class BatteryDefenderAction extends BatteryTipAction {
|
|
||||||
private SettingsActivity mSettingsActivity;
|
|
||||||
|
|
||||||
public BatteryDefenderAction(SettingsActivity settingsActivity) {
|
|
||||||
super(settingsActivity.getApplicationContext());
|
|
||||||
mSettingsActivity = settingsActivity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handlePositiveAction(int metricsKey) {
|
|
||||||
final Intent intent = FeatureFactory.getFactory(mContext)
|
|
||||||
.getPowerUsageFeatureProvider(mContext).getResumeChargeIntent();
|
|
||||||
if (intent != null) {
|
|
||||||
mContext.sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -244,20 +244,4 @@ public class BatteryTipDialogFragmentTest {
|
|||||||
assertThat(shadowDialog.getMessage()).isEqualTo(
|
assertThat(shadowDialog.getMessage()).isEqualTo(
|
||||||
mContext.getText(R.string.battery_tip_dialog_summary_message));
|
mContext.getText(R.string.battery_tip_dialog_summary_message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnCreateDialog_defenderTip_fireDialog() {
|
|
||||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mDefenderTip, METRICS_KEY);
|
|
||||||
|
|
||||||
FragmentController.setupFragment(mDialogFragment, FragmentActivity.class,
|
|
||||||
0 /* containerViewId */, null /* bundle */);
|
|
||||||
|
|
||||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
|
||||||
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
|
||||||
|
|
||||||
assertThat(shadowDialog.getTitle()).isEqualTo(
|
|
||||||
mContext.getString(R.string.battery_tip_limited_temporarily_title));
|
|
||||||
assertThat(shadowDialog.getMessage()).isEqualTo(
|
|
||||||
mContext.getString(R.string.battery_tip_limited_temporarily_dialog_msg, "80%"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user