1 /* 2 * Copyright (C) 2017 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.os.Parcel; 22 import android.os.Parcelable; 23 24 import com.android.settings.R; 25 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; 26 27 /** 28 * Tip to show current battery level is low or remaining time is less than a certain period 29 */ 30 public class LowBatteryTip extends EarlyWarningTip { 31 private CharSequence mSummary; 32 LowBatteryTip(@tateType int state, boolean powerSaveModeOn, CharSequence summary)33 public LowBatteryTip(@StateType int state, boolean powerSaveModeOn, CharSequence summary) { 34 super(state, powerSaveModeOn); 35 mType = TipType.LOW_BATTERY; 36 mSummary = summary; 37 } 38 LowBatteryTip(Parcel in)39 public LowBatteryTip(Parcel in) { 40 super(in); 41 mSummary = in.readCharSequence(); 42 } 43 44 @Override getSummary(Context context)45 public CharSequence getSummary(Context context) { 46 return mState == StateType.HANDLED ? context.getString( 47 R.string.battery_tip_early_heads_up_done_summary) : mSummary; 48 } 49 50 @Override writeToParcel(Parcel dest, int flags)51 public void writeToParcel(Parcel dest, int flags) { 52 super.writeToParcel(dest, flags); 53 dest.writeCharSequence(mSummary); 54 } 55 56 @Override log(Context context, MetricsFeatureProvider metricsFeatureProvider)57 public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) { 58 metricsFeatureProvider.action(context, SettingsEnums.ACTION_LOW_BATTERY_TIP, 59 mState); 60 } 61 62 public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 63 public BatteryTip createFromParcel(Parcel in) { 64 return new LowBatteryTip(in); 65 } 66 67 public BatteryTip[] newArray(int size) { 68 return new LowBatteryTip[size]; 69 } 70 }; 71 72 } 73