Loading src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java +15 −10 Original line number Diff line number Diff line Loading @@ -52,7 +52,8 @@ import com.android.settingslib.widget.LayoutPreference; * Controller that update the battery header view */ public class BatteryHeaderPreferenceController extends BasePreferenceController implements PreferenceControllerMixin, LifecycleObserver, OnStart { implements PreferenceControllerMixin, LifecycleObserver, OnStart, BatteryPreferenceController { @VisibleForTesting static final String KEY_BATTERY_HEADER = "battery_header"; private static final String ANNOTATION_URL = "url"; Loading Loading @@ -121,16 +122,20 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController .styleActionBar(mActivity); } public void updateHeaderPreference(BatteryInfo info) { mBatteryPercentText.setText(formatBatteryPercentageText(info.batteryLevel)); if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) { private CharSequence generateLabel(BatteryInfo info) { if (BatteryUtils.isBatteryDefenderOn(info)) { mSummary1.setText(null); return null; } else if (info.remainingLabel == null) { mSummary1.setText(info.statusLabel); return info.statusLabel; } else { mSummary1.setText(info.remainingLabel); return info.remainingLabel; } } public void updateHeaderPreference(BatteryInfo info) { mBatteryPercentText.setText(formatBatteryPercentageText(info.batteryLevel)); if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) { mSummary1.setText(generateLabel(info)); } mBatteryMeterView.setBatteryLevel(info.batteryLevel); Loading @@ -141,8 +146,8 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController /** * Callback which receives text for the summary line. */ public void updateBatteryStatus(String statusLabel) { mSummary1.setText(statusLabel); public void updateBatteryStatus(String label, BatteryInfo info) { mSummary1.setText(label != null ? label : generateLabel(info)); } public void quickUpdateHeaderPreference() { Loading src/com/android/settings/fuelgauge/BatteryPreferenceController.java 0 → 100644 +30 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 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; /** * Common interface for a preference controller that updates battery status */ public interface BatteryPreferenceController { /** * Updates the label for the preference controller. If the label is null, the * implementation should revert back to the original label based on the * battery info. */ void updateBatteryStatus(String label, BatteryInfo info); } src/com/android/settings/fuelgauge/BatteryStatusFeatureProvider.java +1 −1 Original line number Diff line number Diff line Loading @@ -25,5 +25,5 @@ public interface BatteryStatusFeatureProvider { * Trigger a battery status update; return false if built-in status should be used. */ boolean triggerBatteryStatusUpdate( BatteryHeaderPreferenceController batteryHeaderPreferenceController, BatteryInfo info); BatteryPreferenceController controller, BatteryInfo info); } src/com/android/settings/fuelgauge/BatteryStatusFeatureProviderImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ public class BatteryStatusFeatureProviderImpl implements BatteryStatusFeaturePro @Override public boolean triggerBatteryStatusUpdate( BatteryHeaderPreferenceController batteryHeaderPreferenceController, BatteryInfo info) { BatteryPreferenceController controller, BatteryInfo info) { return false; } } src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java +35 −7 Original line number Diff line number Diff line Loading @@ -26,18 +26,21 @@ import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; import com.android.settings.core.FeatureFlags; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; public class TopLevelBatteryPreferenceController extends BasePreferenceController implements LifecycleObserver, OnStart, OnStop { LifecycleObserver, OnStart, OnStop, BatteryPreferenceController { @VisibleForTesting boolean mIsBatteryPresent = true; protected boolean mIsBatteryPresent = true; private final BatteryBroadcastReceiver mBatteryBroadcastReceiver; private Preference mPreference; private BatteryInfo mBatteryInfo; private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider; private String mBatteryStatusLabel; public TopLevelBatteryPreferenceController(Context context, String preferenceKey) { super(context, preferenceKey); Loading @@ -51,6 +54,9 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle updateState(mPreference); }, true /* shortString */); }); mBatteryStatusFeatureProvider = FeatureFactory.getFactory(context) .getBatteryStatusFeatureProvider(context); } @Override Loading Loading @@ -88,20 +94,42 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle return getDashboardLabel(mContext, mBatteryInfo); } static CharSequence getDashboardLabel(Context context, BatteryInfo info) { protected CharSequence getDashboardLabel(Context context, BatteryInfo info) { if (info == null || context == null) { return null; } CharSequence label; if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info) || mBatteryStatusLabel == null) { label = generateLabel(info); } else { label = mBatteryStatusLabel; } return label; } private CharSequence generateLabel(BatteryInfo info) { if (!info.discharging && info.chargeLabel != null) { label = info.chargeLabel; return info.chargeLabel; } else if (info.remainingLabel == null) { label = info.batteryPercentString; return info.batteryPercentString; } else { label = context.getString(R.string.power_remaining_settings_home_page, return mContext.getString(R.string.power_remaining_settings_home_page, info.batteryPercentString, info.remainingLabel); } return label; } /** * Callback which receives text for the label. */ public void updateBatteryStatus(String label, BatteryInfo info) { mBatteryStatusLabel = (label != null) ? label : generateLabel(info).toString(); if (mPreference != null) { updateState(mPreference); } } } Loading
src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java +15 −10 Original line number Diff line number Diff line Loading @@ -52,7 +52,8 @@ import com.android.settingslib.widget.LayoutPreference; * Controller that update the battery header view */ public class BatteryHeaderPreferenceController extends BasePreferenceController implements PreferenceControllerMixin, LifecycleObserver, OnStart { implements PreferenceControllerMixin, LifecycleObserver, OnStart, BatteryPreferenceController { @VisibleForTesting static final String KEY_BATTERY_HEADER = "battery_header"; private static final String ANNOTATION_URL = "url"; Loading Loading @@ -121,16 +122,20 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController .styleActionBar(mActivity); } public void updateHeaderPreference(BatteryInfo info) { mBatteryPercentText.setText(formatBatteryPercentageText(info.batteryLevel)); if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) { private CharSequence generateLabel(BatteryInfo info) { if (BatteryUtils.isBatteryDefenderOn(info)) { mSummary1.setText(null); return null; } else if (info.remainingLabel == null) { mSummary1.setText(info.statusLabel); return info.statusLabel; } else { mSummary1.setText(info.remainingLabel); return info.remainingLabel; } } public void updateHeaderPreference(BatteryInfo info) { mBatteryPercentText.setText(formatBatteryPercentageText(info.batteryLevel)); if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) { mSummary1.setText(generateLabel(info)); } mBatteryMeterView.setBatteryLevel(info.batteryLevel); Loading @@ -141,8 +146,8 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController /** * Callback which receives text for the summary line. */ public void updateBatteryStatus(String statusLabel) { mSummary1.setText(statusLabel); public void updateBatteryStatus(String label, BatteryInfo info) { mSummary1.setText(label != null ? label : generateLabel(info)); } public void quickUpdateHeaderPreference() { Loading
src/com/android/settings/fuelgauge/BatteryPreferenceController.java 0 → 100644 +30 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 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; /** * Common interface for a preference controller that updates battery status */ public interface BatteryPreferenceController { /** * Updates the label for the preference controller. If the label is null, the * implementation should revert back to the original label based on the * battery info. */ void updateBatteryStatus(String label, BatteryInfo info); }
src/com/android/settings/fuelgauge/BatteryStatusFeatureProvider.java +1 −1 Original line number Diff line number Diff line Loading @@ -25,5 +25,5 @@ public interface BatteryStatusFeatureProvider { * Trigger a battery status update; return false if built-in status should be used. */ boolean triggerBatteryStatusUpdate( BatteryHeaderPreferenceController batteryHeaderPreferenceController, BatteryInfo info); BatteryPreferenceController controller, BatteryInfo info); }
src/com/android/settings/fuelgauge/BatteryStatusFeatureProviderImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ public class BatteryStatusFeatureProviderImpl implements BatteryStatusFeaturePro @Override public boolean triggerBatteryStatusUpdate( BatteryHeaderPreferenceController batteryHeaderPreferenceController, BatteryInfo info) { BatteryPreferenceController controller, BatteryInfo info) { return false; } }
src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java +35 −7 Original line number Diff line number Diff line Loading @@ -26,18 +26,21 @@ import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; import com.android.settings.core.FeatureFlags; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; public class TopLevelBatteryPreferenceController extends BasePreferenceController implements LifecycleObserver, OnStart, OnStop { LifecycleObserver, OnStart, OnStop, BatteryPreferenceController { @VisibleForTesting boolean mIsBatteryPresent = true; protected boolean mIsBatteryPresent = true; private final BatteryBroadcastReceiver mBatteryBroadcastReceiver; private Preference mPreference; private BatteryInfo mBatteryInfo; private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider; private String mBatteryStatusLabel; public TopLevelBatteryPreferenceController(Context context, String preferenceKey) { super(context, preferenceKey); Loading @@ -51,6 +54,9 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle updateState(mPreference); }, true /* shortString */); }); mBatteryStatusFeatureProvider = FeatureFactory.getFactory(context) .getBatteryStatusFeatureProvider(context); } @Override Loading Loading @@ -88,20 +94,42 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle return getDashboardLabel(mContext, mBatteryInfo); } static CharSequence getDashboardLabel(Context context, BatteryInfo info) { protected CharSequence getDashboardLabel(Context context, BatteryInfo info) { if (info == null || context == null) { return null; } CharSequence label; if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info) || mBatteryStatusLabel == null) { label = generateLabel(info); } else { label = mBatteryStatusLabel; } return label; } private CharSequence generateLabel(BatteryInfo info) { if (!info.discharging && info.chargeLabel != null) { label = info.chargeLabel; return info.chargeLabel; } else if (info.remainingLabel == null) { label = info.batteryPercentString; return info.batteryPercentString; } else { label = context.getString(R.string.power_remaining_settings_home_page, return mContext.getString(R.string.power_remaining_settings_home_page, info.batteryPercentString, info.remainingLabel); } return label; } /** * Callback which receives text for the label. */ public void updateBatteryStatus(String label, BatteryInfo info) { mBatteryStatusLabel = (label != null) ? label : generateLabel(info).toString(); if (mPreference != null) { updateState(mPreference); } } }