Split battery header text to a separated preference

This is a no-op refactor. This change makes the Catalyst migration of battery level bar easy.

Bug: 372774754
Test: manual
Flag: EXEMPT bug fix
Change-Id: I6e64e6d9b34aeca584f4d4e951c58c3e1b361f9d
This commit is contained in:
Zaiyue Xue
2024-11-20 17:06:49 +08:00
parent 0a06641369
commit 178eb0bd15
8 changed files with 183 additions and 647 deletions

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2024 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;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
/** A preference for battery header text. */
public class BatteryHeaderTextPreference extends Preference {
private static final String TAG = "BatteryHeaderTextPreference";
@Nullable private CharSequence mText;
@Nullable private CharSequence mContentDescription;
public BatteryHeaderTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutResource(R.layout.preference_battery_header_text);
}
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
final TextView textView = (TextView) view.findViewById(R.id.text);
textView.setText(mText);
if (!TextUtils.isEmpty(mContentDescription)) {
textView.setContentDescription(mContentDescription);
}
}
void setText(@Nullable CharSequence text) {
mText = text;
notifyChanged();
}
void setContentDescription(@Nullable CharSequence contentDescription) {
mContentDescription = contentDescription;
notifyChanged();
}
}