• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.fuelgauge.batterytip.tips;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.content.res.ColorStateList;
22 import android.os.Parcel;
23 
24 import com.android.settings.R;
25 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
26 
27 /**
28  * Tip to show early warning if battery couldn't make to usual charging time
29  */
30 public class EarlyWarningTip extends BatteryTip {
31     private boolean mPowerSaveModeOn;
32 
EarlyWarningTip(@tateType int state, boolean powerSaveModeOn)33     public EarlyWarningTip(@StateType int state, boolean powerSaveModeOn) {
34         super(TipType.BATTERY_SAVER, state, false /* showDialog */);
35         mPowerSaveModeOn = powerSaveModeOn;
36     }
37 
EarlyWarningTip(Parcel in)38     public EarlyWarningTip(Parcel in) {
39         super(in);
40         mPowerSaveModeOn = in.readBoolean();
41     }
42 
43     @Override
getTitle(Context context)44     public CharSequence getTitle(Context context) {
45         return context.getString(
46                 mState == StateType.HANDLED
47                         ? R.string.battery_tip_early_heads_up_done_title
48                         : R.string.battery_tip_early_heads_up_title);
49     }
50 
51     @Override
getSummary(Context context)52     public CharSequence getSummary(Context context) {
53         return context.getString(
54                 mState == StateType.HANDLED
55                         ? R.string.battery_tip_early_heads_up_done_summary
56                         : R.string.battery_tip_early_heads_up_summary);
57     }
58 
59     @Override
getIconId()60     public int getIconId() {
61         return mState == StateType.HANDLED
62                 ? R.drawable.ic_battery_status_maybe_24dp
63                 : R.drawable.ic_battery_status_bad_24dp;
64     }
65 
66     @Override
getIconTintColorId()67     public int getIconTintColorId() {
68         return mState == StateType.HANDLED
69                 ? R.color.battery_maybe_color_light
70                 : R.color.battery_bad_color_light;
71     }
72 
73     @Override
updateState(BatteryTip tip)74     public void updateState(BatteryTip tip) {
75         final EarlyWarningTip earlyWarningTip = (EarlyWarningTip) tip;
76         if (earlyWarningTip.mState == StateType.NEW) {
77             // Display it if there is early warning
78             mState = StateType.NEW;
79         } else if (mState == StateType.NEW && earlyWarningTip.mState == StateType.INVISIBLE) {
80             // If powerSaveMode is really on, show it as handled, otherwise just dismiss it.
81             mState = earlyWarningTip.mPowerSaveModeOn ? StateType.HANDLED : StateType.INVISIBLE;
82         } else {
83             mState = earlyWarningTip.getState();
84         }
85         mPowerSaveModeOn = earlyWarningTip.mPowerSaveModeOn;
86     }
87 
88     @Override
log(Context context, MetricsFeatureProvider metricsFeatureProvider)89     public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
90         metricsFeatureProvider.action(context, SettingsEnums.ACTION_EARLY_WARNING_TIP,
91                 mState);
92     }
93 
94     @Override
writeToParcel(Parcel dest, int flags)95     public void writeToParcel(Parcel dest, int flags) {
96         super.writeToParcel(dest, flags);
97         dest.writeBoolean(mPowerSaveModeOn);
98     }
99 
isPowerSaveModeOn()100     public boolean isPowerSaveModeOn() {
101         return mPowerSaveModeOn;
102     }
103 
104     public static final Creator CREATOR = new Creator() {
105         public BatteryTip createFromParcel(Parcel in) {
106             return new EarlyWarningTip(in);
107         }
108 
109         public BatteryTip[] newArray(int size) {
110             return new EarlyWarningTip[size];
111         }
112     };
113 }
114