Add incompatible charging battery tip UI and card skeleton
Bug: 263193978 Bug: 246960554 Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.fuelgauge.batterytip" Change-Id: I8180022bd39f66c88463a2552c6050669bb0357c
This commit is contained in:
@@ -106,10 +106,6 @@ public class BatteryDefenderTip extends BatteryTip {
|
||||
R.string.battery_tip_limited_temporarily_sec_button_content_description));
|
||||
}
|
||||
|
||||
private CardPreference castToCardPreferenceSafely(Preference preference) {
|
||||
return preference instanceof CardPreference ? (CardPreference) preference : null;
|
||||
}
|
||||
|
||||
private void resumeCharging(Context context) {
|
||||
final Intent intent =
|
||||
FeatureFactory.getFactory(context)
|
||||
|
@@ -27,6 +27,7 @@ import androidx.annotation.IntDef;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -59,7 +60,8 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
TipType.LOW_BATTERY,
|
||||
TipType.REMOVE_APP_RESTRICTION,
|
||||
TipType.BATTERY_DEFENDER,
|
||||
TipType.DOCK_DEFENDER})
|
||||
TipType.DOCK_DEFENDER,
|
||||
TipType.INCOMPATIBLE_CHARGER})
|
||||
public @interface TipType {
|
||||
int SMART_BATTERY_MANAGER = 0;
|
||||
int APP_RESTRICTION = 1;
|
||||
@@ -71,6 +73,7 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
int REMOVE_APP_RESTRICTION = 7;
|
||||
int BATTERY_DEFENDER = 8;
|
||||
int DOCK_DEFENDER = 9;
|
||||
int INCOMPATIBLE_CHARGER = 10;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -81,12 +84,13 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
TIP_ORDER.append(TipType.LOW_BATTERY, 1);
|
||||
TIP_ORDER.append(TipType.BATTERY_DEFENDER, 2);
|
||||
TIP_ORDER.append(TipType.DOCK_DEFENDER, 3);
|
||||
TIP_ORDER.append(TipType.APP_RESTRICTION, 4);
|
||||
TIP_ORDER.append(TipType.HIGH_DEVICE_USAGE, 5);
|
||||
TIP_ORDER.append(TipType.SUMMARY, 6);
|
||||
TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 7);
|
||||
TIP_ORDER.append(TipType.REDUCED_BATTERY, 8);
|
||||
TIP_ORDER.append(TipType.REMOVE_APP_RESTRICTION, 9);
|
||||
TIP_ORDER.append(TipType.INCOMPATIBLE_CHARGER, 4);
|
||||
TIP_ORDER.append(TipType.APP_RESTRICTION, 5);
|
||||
TIP_ORDER.append(TipType.HIGH_DEVICE_USAGE, 6);
|
||||
TIP_ORDER.append(TipType.SUMMARY, 7);
|
||||
TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 8);
|
||||
TIP_ORDER.append(TipType.REDUCED_BATTERY, 9);
|
||||
TIP_ORDER.append(TipType.REMOVE_APP_RESTRICTION, 10);
|
||||
}
|
||||
|
||||
private static final String KEY_PREFIX = "key_battery_tip";
|
||||
@@ -203,4 +207,8 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
public String toString() {
|
||||
return "type=" + mType + " state=" + mState;
|
||||
}
|
||||
|
||||
CardPreference castToCardPreferenceSafely(Preference preference) {
|
||||
return preference instanceof CardPreference ? (CardPreference) preference : null;
|
||||
}
|
||||
}
|
||||
|
@@ -151,10 +151,6 @@ public class DockDefenderTip extends BatteryTip {
|
||||
|
||||
}
|
||||
|
||||
private CardPreference castToCardPreferenceSafely(Preference preference) {
|
||||
return preference instanceof CardPreference ? (CardPreference) preference : null;
|
||||
}
|
||||
|
||||
private void resumeCharging(Context context) {
|
||||
final Intent intent =
|
||||
FeatureFactory.getFactory(context)
|
||||
|
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.tips;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
/** Tip to show incompatible charger state */
|
||||
public final class IncompatibleChargerTip extends BatteryTip {
|
||||
private static final String TAG = "IncompatibleChargerTip";
|
||||
|
||||
public IncompatibleChargerTip(@StateType int state) {
|
||||
super(TipType.INCOMPATIBLE_CHARGER, state, /* showDialog */ false);
|
||||
}
|
||||
|
||||
private IncompatibleChargerTip(Parcel in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle(Context context) {
|
||||
return context.getString(R.string.battery_tip_incompatible_charging_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary(Context context) {
|
||||
return context.getString(R.string.battery_tip_incompatible_charging_message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconId() {
|
||||
return R.drawable.ic_battery_charging;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(BatteryTip tip) {
|
||||
mState = tip.mState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
|
||||
metricsFeatureProvider.action(context, SettingsEnums.ACTION_INCOMPATIBLE_CHARGING_TIP,
|
||||
mState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreference(Preference preference) {
|
||||
super.updatePreference(preference);
|
||||
final Context context = preference.getContext();
|
||||
final CardPreference cardPreference = castToCardPreferenceSafely(preference);
|
||||
if (cardPreference == null) {
|
||||
Log.e(TAG, "cast Preference to CardPreference failed");
|
||||
return;
|
||||
}
|
||||
|
||||
cardPreference.setSelectable(false);
|
||||
cardPreference.setSecondaryButtonText(context.getString(R.string.learn_more));
|
||||
cardPreference.setSecondaryButtonClickListener(
|
||||
button -> button.startActivityForResult(
|
||||
HelpUtils.getHelpIntent(
|
||||
context,
|
||||
context.getString(R.string.help_url_incompatible_charging),
|
||||
/* backupContext */ ""), /* requestCode */ 0));
|
||||
cardPreference.setSecondaryButtonVisible(true);
|
||||
cardPreference.setSecondaryButtonContentDescription(context.getString(
|
||||
R.string.battery_tip_incompatible_charging_content_description));
|
||||
}
|
||||
|
||||
public static final Creator CREATOR = new Creator() {
|
||||
public BatteryTip createFromParcel(Parcel in) {
|
||||
return new IncompatibleChargerTip(in);
|
||||
}
|
||||
|
||||
public BatteryTip[] newArray(int size) {
|
||||
return new IncompatibleChargerTip[size];
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user