[Expressive Battery] Refactor pref with anomaly hint.
- WarningFramePreference & warning_frame_preference.xml is a battery customized layout which looks like a standard Preference layout with an optional app icon & warning chip. - PowerGaugePreference extends the WarningFramePreference to display the app Preference with optional warning chip in Battery > Battery Usage. - PowerUsageTimePreference extends the WarningFramePreference to display the usage time with optional warning chip in Battery > Battery Usage > App battery usage. Bug: 349652542 Test: atest BatteryUsageBreakdownControllerTest PowerGaugePreferenceTest PowerUsageTimeControllerTest Flag: com.android.settingslib.widget.theme.flags.is_expressive_design_enabled Change-Id: I5d22703ccc487c54a2bbbc1d9737b92a2de54ba5
This commit is contained in:
@@ -17,74 +17,17 @@
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.GroupSectionDividerMixin;
|
||||
|
||||
/** Custom preference for displaying the app power usage time. */
|
||||
public class PowerUsageTimePreference extends Preference {
|
||||
public class PowerUsageTimePreference extends WarningFramePreference implements
|
||||
GroupSectionDividerMixin {
|
||||
private static final String TAG = "PowerUsageTimePreference";
|
||||
|
||||
@VisibleForTesting CharSequence mTimeTitle;
|
||||
@VisibleForTesting CharSequence mTimeSummary;
|
||||
@VisibleForTesting CharSequence mAnomalyHintText;
|
||||
|
||||
public PowerUsageTimePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayoutResource(R.layout.power_usage_time);
|
||||
}
|
||||
|
||||
void setTimeTitle(CharSequence timeTitle) {
|
||||
if (!TextUtils.equals(mTimeTitle, timeTitle)) {
|
||||
mTimeTitle = timeTitle;
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void setTimeSummary(CharSequence timeSummary) {
|
||||
if (!TextUtils.equals(mTimeSummary, timeSummary)) {
|
||||
mTimeSummary = timeSummary;
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void setAnomalyHint(CharSequence anomalyHintText) {
|
||||
if (!TextUtils.equals(mAnomalyHintText, anomalyHintText)) {
|
||||
mAnomalyHintText = anomalyHintText;
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void showAnomalyHint(PreferenceViewHolder view) {
|
||||
if (TextUtils.isEmpty(mAnomalyHintText)) {
|
||||
return;
|
||||
}
|
||||
final View anomalyHintView = view.findViewById(R.id.anomaly_hints);
|
||||
if (anomalyHintView == null) {
|
||||
return;
|
||||
}
|
||||
final TextView warningInfo = anomalyHintView.findViewById(R.id.warning_info);
|
||||
if (warningInfo == null) {
|
||||
return;
|
||||
}
|
||||
warningInfo.setText(mAnomalyHintText);
|
||||
anomalyHintView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
|
||||
((TextView) view.findViewById(R.id.time_title)).setText(mTimeTitle);
|
||||
((TextView) view.findViewById(R.id.time_summary)).setText(mTimeSummary);
|
||||
|
||||
showAnomalyHint(view);
|
||||
setSelectable(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user