Refine Anomaly detail page
1. Fix the layout issue(title not vertical horizontal) 2. Add subtitle for anomaly Bug: 36924669 Test: RunSettingsRoboTests Change-Id: I9b3627f09bbe37b104644d203ff8924f0faaea47
This commit is contained in:
@@ -21,6 +21,7 @@ import android.os.BatteryStats;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
@@ -29,6 +30,8 @@ import android.util.SparseLongArray;
|
||||
import com.android.internal.os.BatterySipper;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -291,6 +294,20 @@ public class BatteryUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getSummaryResIdFromAnomalyType(@Anomaly.AnomalyType int type) {
|
||||
switch (type) {
|
||||
case Anomaly.AnomalyType.WAKE_LOCK:
|
||||
return R.string.battery_abnormal_wakelock_summary;
|
||||
case Anomaly.AnomalyType.WAKEUP_ALARM:
|
||||
return R.string.battery_abnormal_wakeup_alarm_summary;
|
||||
case Anomaly.AnomalyType.BLUETOOTH_SCAN:
|
||||
return R.string.battery_abnormal_location_summary;
|
||||
default:
|
||||
throw new IllegalArgumentException("Incorrect anomaly type: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
public long convertUsToMs(long timeUs) {
|
||||
return timeUs / 1000;
|
||||
}
|
||||
|
@@ -57,6 +57,8 @@ public class PowerUsageAnomalyDetails extends DashboardFragment implements
|
||||
PreferenceGroup mAbnormalListGroup;
|
||||
@VisibleForTesting
|
||||
PackageManager mPackageManager;
|
||||
@VisibleForTesting
|
||||
BatteryUtils mBatteryUtils;
|
||||
IconDrawableFactory mIconDrawableFactory;
|
||||
|
||||
public static void startBatteryAbnormalPage(SettingsActivity caller,
|
||||
@@ -78,6 +80,7 @@ public class PowerUsageAnomalyDetails extends DashboardFragment implements
|
||||
mAbnormalListGroup = (PreferenceGroup) findPreference(KEY_PREF_ANOMALY_LIST);
|
||||
mPackageManager = context.getPackageManager();
|
||||
mIconDrawableFactory = IconDrawableFactory.newInstance(context, false /* EmbedShadow */);
|
||||
mBatteryUtils = BatteryUtils.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,16 +129,16 @@ public class PowerUsageAnomalyDetails extends DashboardFragment implements
|
||||
}
|
||||
|
||||
void refreshUi() {
|
||||
//TODO(b/37681665): cache the preference so we don't need to create new one every time.
|
||||
mAbnormalListGroup.removeAll();
|
||||
for (int i = 0, size = mAnomalies.size(); i < size; i++) {
|
||||
final Anomaly anomaly = mAnomalies.get(i);
|
||||
Preference pref = new AnomalyPreference(getPrefContext(), anomaly);
|
||||
|
||||
pref.setSummary(mBatteryUtils.getSummaryResIdFromAnomalyType(anomaly.type));
|
||||
Drawable icon = getIconFromPackageName(anomaly.packageName);
|
||||
if (icon != null) {
|
||||
pref.setIcon(icon);
|
||||
}
|
||||
|
||||
mAbnormalListGroup.addPreference(pref);
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,6 @@ public class AnomalyPreference extends Preference {
|
||||
public AnomalyPreference(Context context, Anomaly anomaly) {
|
||||
super(context);
|
||||
mAnomaly = anomaly;
|
||||
setLayoutResource(R.layout.preference_app);
|
||||
|
||||
if (anomaly != null) {
|
||||
setTitle(anomaly.displayName);
|
||||
|
Reference in New Issue
Block a user