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.systemui.tv.media.settings; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.View; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 import androidx.preference.PreferenceViewHolder; 26 27 import com.android.systemui.tv.res.R; 28 import com.android.tv.twopanelsettings.slices.SlicePreference; 29 30 31 /** 32 * Basic slice preference for one panel settings that only shows the title, subtitle and icon. 33 * If there's only a title, the {@link BasicCenteredSlicePreference} might be used. 34 */ 35 public class BasicSlicePreference extends SlicePreference implements TooltipPreference { 36 private ControlWidget.TooltipConfig mTooltipConfig = new ControlWidget.TooltipConfig(); 37 BasicSlicePreference(Context context)38 public BasicSlicePreference(Context context) { 39 this(context, null); 40 } 41 BasicSlicePreference(Context context, @Nullable AttributeSet attrs)42 public BasicSlicePreference(Context context, @Nullable AttributeSet attrs) { 43 super(context, attrs); 44 setLayoutResource(R.layout.basic_slice_pref); 45 } 46 47 @Override onBindViewHolder(@onNull PreferenceViewHolder holder)48 public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { 49 super.onBindViewHolder(holder); 50 BasicControlWidget widget = (BasicControlWidget) holder.itemView; 51 widget.setEnabled(this.isEnabled()); 52 widget.setTooltipConfig(mTooltipConfig); 53 } 54 55 /** Set tool tip related attributes. */ 56 @Override setTooltipConfig(ControlWidget.TooltipConfig tooltipConfig)57 public void setTooltipConfig(ControlWidget.TooltipConfig tooltipConfig) { 58 if (!this.mTooltipConfig.equals(tooltipConfig)) { 59 this.mTooltipConfig = tooltipConfig; 60 notifyChanged(); 61 } 62 } 63 64 static class BasicControlWidget extends ControlWidget { BasicControlWidget(Context context)65 public BasicControlWidget(Context context) { 66 this(context, /* attrs= */ null); 67 } 68 BasicControlWidget(Context context, @Nullable AttributeSet attrs)69 public BasicControlWidget(Context context, @Nullable AttributeSet attrs) { 70 this(context, attrs, /* defStyleAttr= */ 0); 71 } 72 BasicControlWidget(Context context, @Nullable AttributeSet attrs, int defStyleAttr)73 public BasicControlWidget(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 74 super(context, attrs, defStyleAttr); 75 View.inflate(context, R.layout.basic_control_widget, /* root= */ this); 76 } 77 } 78 } 79