Impl highlight effect on BatteryChartView slots.
Screenshot: https://screenshot.googleplex.com/F5VrGjj5kdNHMV6 Bug: 284893240 Bug: 291689623 Test: manual Change-Id: I846d95d31e8bb839481b86a94d5191ff205f8328
This commit is contained in:
@@ -16,9 +16,7 @@
|
||||
|
||||
package com.android.settings.fuelgauge.batteryusage;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
@@ -31,8 +29,6 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -45,10 +41,17 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
|
||||
|
||||
private static final String TAG = "BatteryTipsCardPreference";
|
||||
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
interface OnConfirmListener {
|
||||
void onConfirm();
|
||||
}
|
||||
|
||||
private String mAnomalyEventId;
|
||||
private PowerAnomalyKey mPowerAnomalyKey;
|
||||
interface OnRejectListener {
|
||||
void onReject();
|
||||
}
|
||||
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private OnConfirmListener mOnConfirmListener;
|
||||
private OnRejectListener mOnRejectListener;
|
||||
private int mIconResourceId = 0;
|
||||
private int mMainButtonStrokeColorResourceId = 0;
|
||||
|
||||
@@ -56,12 +59,6 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
|
||||
CharSequence mMainButtonLabel;
|
||||
@VisibleForTesting
|
||||
CharSequence mDismissButtonLabel;
|
||||
@VisibleForTesting
|
||||
String mDestinationComponentName;
|
||||
@VisibleForTesting
|
||||
String mPreferenceHighlightKey;
|
||||
@VisibleForTesting
|
||||
Integer mSourceMetricsCategory;
|
||||
|
||||
public BatteryTipsCardPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
@@ -69,7 +66,14 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
|
||||
setSelectable(false);
|
||||
final FeatureFactory featureFactory = FeatureFactory.getFactory(context);
|
||||
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
|
||||
mPowerAnomalyKey = null;
|
||||
}
|
||||
|
||||
public void setOnConfirmListener(OnConfirmListener listener) {
|
||||
mOnConfirmListener = listener;
|
||||
}
|
||||
|
||||
public void setOnRejectListener(OnRejectListener listener) {
|
||||
mOnRejectListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,13 +96,6 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the anomaly event id which is used in metrics.
|
||||
*/
|
||||
public void setAnomalyEventId(final String anomalyEventId) {
|
||||
mAnomalyEventId = anomalyEventId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the label of main button in tips card.
|
||||
*/
|
||||
@@ -119,50 +116,18 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the power anomaly key of battery tips card.
|
||||
*/
|
||||
public void setPowerAnomalyKey(final PowerAnomalyKey powerAnomalyKey) {
|
||||
mPowerAnomalyKey = powerAnomalyKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the info of target fragment launched by main button.
|
||||
*/
|
||||
public void setMainButtonLauncherInfo(final String destinationClassName,
|
||||
final Integer sourceMetricsCategory, final String highlightKey) {
|
||||
mDestinationComponentName = destinationClassName;
|
||||
mSourceMetricsCategory = sourceMetricsCategory;
|
||||
mPreferenceHighlightKey = highlightKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final int viewId = view.getId();
|
||||
if (viewId == R.id.main_button || viewId == R.id.tips_card) {
|
||||
if (TextUtils.isEmpty(mDestinationComponentName)) {
|
||||
return;
|
||||
}
|
||||
Bundle arguments = Bundle.EMPTY;
|
||||
if (!TextUtils.isEmpty(mPreferenceHighlightKey)) {
|
||||
arguments = new Bundle(1);
|
||||
arguments.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
|
||||
mPreferenceHighlightKey);
|
||||
}
|
||||
new SubSettingLauncher(getContext())
|
||||
.setDestination(mDestinationComponentName)
|
||||
.setSourceMetricsCategory(mSourceMetricsCategory)
|
||||
.setArguments(arguments)
|
||||
.launch();
|
||||
setVisible(false);
|
||||
mMetricsFeatureProvider.action(
|
||||
getContext(), SettingsEnums.ACTION_BATTERY_TIPS_CARD_ACCEPT, mAnomalyEventId);
|
||||
if (mOnConfirmListener != null) {
|
||||
mOnConfirmListener.onConfirm();
|
||||
}
|
||||
} else if (viewId == R.id.dismiss_button) {
|
||||
setVisible(false);
|
||||
mMetricsFeatureProvider.action(
|
||||
getContext(), SettingsEnums.ACTION_BATTERY_TIPS_CARD_DISMISS, mAnomalyEventId);
|
||||
if (mPowerAnomalyKey != null) {
|
||||
DatabaseUtils.setDismissedPowerAnomalyKeys(getContext(), mPowerAnomalyKey.name());
|
||||
if (mOnRejectListener != null) {
|
||||
mOnRejectListener.onReject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user