1 /*
2  * Copyright (C) 2023 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.batteryusage;
18 
19 import android.content.Context;
20 import android.text.TextUtils;
21 import android.view.View;
22 import android.widget.LinearLayout;
23 import android.widget.TextView;
24 
25 import androidx.preference.PreferenceViewHolder;
26 
27 import com.android.settings.R;
28 
29 class AnomalyAppItemPreference extends PowerGaugePreference {
30 
31     private static final String TAG = "AnomalyAppItemPreference";
32 
33     private CharSequence mAnomalyHintText;
34 
AnomalyAppItemPreference(Context context)35     AnomalyAppItemPreference(Context context) {
36         super(context, /* attrs */ null);
37         setLayoutResource(R.layout.anomaly_app_item_preference);
38     }
39 
setAnomalyHint(CharSequence anomalyHintText)40     void setAnomalyHint(CharSequence anomalyHintText) {
41         if (!TextUtils.equals(mAnomalyHintText, anomalyHintText)) {
42             mAnomalyHintText = anomalyHintText;
43             notifyChanged();
44         }
45     }
46 
47     @Override
onBindViewHolder(PreferenceViewHolder viewHolder)48     public void onBindViewHolder(PreferenceViewHolder viewHolder) {
49         super.onBindViewHolder(viewHolder);
50         final LinearLayout warningChipView =
51                 (LinearLayout) viewHolder.findViewById(R.id.warning_chip);
52 
53         if (!TextUtils.isEmpty(mAnomalyHintText)) {
54             ((TextView) warningChipView.findViewById(R.id.warning_info)).setText(mAnomalyHintText);
55             warningChipView.setVisibility(View.VISIBLE);
56         } else {
57             warningChipView.setVisibility(View.GONE);
58         }
59     }
60 }
61