- Implement a tips card UI in Battery Usage. [Screenshot]: - Tips Card with thumbs-up/down feedback in dark mode https://screenshot.googleplex.com/3nRCFYvLTWfiYYT - Tips Card without feedback https://screenshot.googleplex.com/B7QGRJZAHzgWpCP - Tips Card in Force RTL layout https://screenshot.googleplex.com/8crQdj8ao26pKpH - Tips Card in light mode https://screenshot.googleplex.com/885aVvZm8xmhK2S [TODO]: - Add accessibility - Localization Bug: 291689623 Test: Manual Change-Id: I4443cdb21b3ba30900fc2f6fcc21c4c56dc1293f Merged-In: I4443cdb21b3ba30900fc2f6fcc21c4c56dc1293f
78 lines
2.6 KiB
Java
78 lines
2.6 KiB
Java
/*
|
|
* Copyright (C) 2023 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.batteryusage;
|
|
|
|
import android.content.Context;
|
|
|
|
import androidx.preference.PreferenceScreen;
|
|
|
|
import com.android.settings.core.BasePreferenceController;
|
|
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
|
import com.android.settings.overlay.FeatureFactory;
|
|
|
|
/** Controls the update for battery tips card */
|
|
public class BatteryTipsController extends BasePreferenceController {
|
|
|
|
private static final String TAG = "BatteryTipsController";
|
|
private static final String ROOT_PREFERENCE_KEY = "battery_tips_category";
|
|
private static final String CARD_PREFERENCE_KEY = "battery_tips_card";
|
|
|
|
private final PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
|
|
|
private Context mPrefContext;
|
|
private BatteryTipsCardPreference mCardPreference;
|
|
|
|
public BatteryTipsController(Context context) {
|
|
super(context, ROOT_PREFERENCE_KEY);
|
|
mPowerUsageFeatureProvider = FeatureFactory.getFactory(context)
|
|
.getPowerUsageFeatureProvider(context);
|
|
}
|
|
|
|
@Override
|
|
public int getAvailabilityStatus() {
|
|
return AVAILABLE;
|
|
}
|
|
|
|
@Override
|
|
public void displayPreference(PreferenceScreen screen) {
|
|
super.displayPreference(screen);
|
|
mPrefContext = screen.getContext();
|
|
mCardPreference = screen.findPreference(CARD_PREFERENCE_KEY);
|
|
}
|
|
|
|
/**
|
|
* Update the card visibility and contents.
|
|
* @param title a string not extend 2 lines.
|
|
* @param summary a string not extend 10 lines.
|
|
*/
|
|
// TODO: replace parameters with SettingsAnomaly Data Proto
|
|
public void handleBatteryTipsCardUpdated(String title, String summary) {
|
|
if (!mPowerUsageFeatureProvider.isBatteryTipsEnabled()) {
|
|
mCardPreference.setVisible(false);
|
|
return;
|
|
}
|
|
if (title == null || summary == null) {
|
|
mCardPreference.setVisible(false);
|
|
return;
|
|
}
|
|
mCardPreference.setTitle(title);
|
|
mCardPreference.setSummary(summary);
|
|
mCardPreference.setVisible(true);
|
|
}
|
|
|
|
}
|