• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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;
18 
19 import android.content.Context;
20 import android.text.TextUtils;
21 import android.text.method.LinkMovementMethod;
22 import android.util.AttributeSet;
23 import android.widget.TextView;
24 
25 import androidx.annotation.Nullable;
26 import androidx.preference.Preference;
27 import androidx.preference.PreferenceViewHolder;
28 
29 import com.android.settings.R;
30 import com.android.settingslib.widget.GroupSectionDividerMixin;
31 
32 /** A preference for battery header text. */
33 public class BatteryHeaderTextPreference extends Preference implements GroupSectionDividerMixin {
34     private static final String TAG = "BatteryHeaderTextPreference";
35 
36     @Nullable private CharSequence mText;
37     @Nullable private CharSequence mContentDescription;
38 
BatteryHeaderTextPreference(Context context, AttributeSet attrs)39     public BatteryHeaderTextPreference(Context context, AttributeSet attrs) {
40         super(context, attrs);
41         setLayoutResource(R.layout.preference_battery_header_text);
42     }
43 
44     @Override
onBindViewHolder(PreferenceViewHolder view)45     public void onBindViewHolder(PreferenceViewHolder view) {
46         final TextView textView = (TextView) view.findViewById(R.id.text);
47         textView.setText(mText);
48         textView.setMovementMethod(LinkMovementMethod.getInstance());
49         if (!TextUtils.isEmpty(mContentDescription)) {
50             textView.setContentDescription(mContentDescription);
51         }
52     }
53 
setText(@ullable CharSequence text)54     void setText(@Nullable CharSequence text) {
55         mText = text;
56         notifyChanged();
57     }
58 
setContentDescription(@ullable CharSequence contentDescription)59     void setContentDescription(@Nullable CharSequence contentDescription) {
60         mContentDescription = contentDescription;
61         notifyChanged();
62     }
63 }
64