Merge changes I3ee2313c,Ibbf9eb2a
* changes: Remove divider line for battery card preference Add CardPreference in battery settings page
This commit is contained in:
@@ -21,7 +21,6 @@ import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
@@ -32,6 +31,7 @@ import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -56,7 +56,7 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private boolean mNeedUpdate;
|
||||
@VisibleForTesting
|
||||
PreferenceGroup mPreferenceGroup;
|
||||
CardPreference mCardPreference;
|
||||
@VisibleForTesting
|
||||
Context mPrefContext;
|
||||
InstrumentedPreferenceFragment mFragment;
|
||||
@@ -89,12 +89,12 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPrefContext = screen.getContext();
|
||||
mPreferenceGroup = (PreferenceGroup) screen.findPreference(getPreferenceKey());
|
||||
mCardPreference = screen.findPreference(getPreferenceKey());
|
||||
|
||||
// Add summary tip in advance to avoid UI flakiness
|
||||
final SummaryTip summaryTip = new SummaryTip(BatteryTip.StateType.NEW,
|
||||
Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
|
||||
mPreferenceGroup.addPreference(summaryTip.buildPreference(mPrefContext));
|
||||
summaryTip.updatePreference(mCardPreference);
|
||||
}
|
||||
|
||||
public void updateBatteryTips(List<BatteryTip> batteryTips) {
|
||||
@@ -110,14 +110,12 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
}
|
||||
}
|
||||
|
||||
mPreferenceGroup.removeAll();
|
||||
for (int i = 0, size = batteryTips.size(); i < size; i++) {
|
||||
final BatteryTip batteryTip = mBatteryTips.get(i);
|
||||
batteryTip.sanityCheck(mContext);
|
||||
if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
|
||||
final Preference preference = batteryTip.buildPreference(mPrefContext);
|
||||
mBatteryTipMap.put(preference.getKey(), batteryTip);
|
||||
mPreferenceGroup.addPreference(preference);
|
||||
batteryTip.updatePreference(mCardPreference);
|
||||
mBatteryTipMap.put(mCardPreference.getKey(), batteryTip);
|
||||
batteryTip.log(mContext, mMetricsFeatureProvider);
|
||||
mNeedUpdate = batteryTip.needUpdate();
|
||||
break;
|
||||
|
||||
@@ -26,6 +26,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;
|
||||
@@ -146,14 +147,11 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
*/
|
||||
public abstract void log(Context context, MetricsFeatureProvider metricsFeatureProvider);
|
||||
|
||||
public Preference buildPreference(Context context) {
|
||||
Preference preference = new Preference(context);
|
||||
|
||||
preference.setKey(getKey());
|
||||
public void updatePreference(Preference preference) {
|
||||
final Context context = preference.getContext();
|
||||
preference.setTitle(getTitle(context));
|
||||
preference.setSummary(getSummary(context));
|
||||
preference.setIcon(getIconId());
|
||||
return preference;
|
||||
}
|
||||
|
||||
public boolean shouldShowDialog() {
|
||||
|
||||
39
src/com/android/settings/widget/CardPreference.java
Normal file
39
src/com/android/settings/widget/CardPreference.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
|
||||
/**
|
||||
* Preference that wrapped by {@link MaterialCardView}, only support to set icon, title and summary
|
||||
*/
|
||||
public class CardPreference extends Preference {
|
||||
public CardPreference(Context context) {
|
||||
this(context, null /* attrs */);
|
||||
}
|
||||
|
||||
public CardPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs, R.attr.cardPreferenceStyle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user