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.SliceRadioPreference; 29 import com.android.tv.twopanelsettings.slices.compat.core.SliceActionImpl; 30 31 /** 32 * Slice preference for one panel settings which shows a radio button in addition to the 33 * capabilities of the {@link BasicSlicePreference}. 34 */ 35 public class RadioSlicePreference extends SliceRadioPreference implements TooltipPreference { 36 private ControlWidget.TooltipConfig mTooltipConfig = new ControlWidget.TooltipConfig(); 37 RadioSlicePreference(Context context, SliceActionImpl action)38 public RadioSlicePreference(Context context, SliceActionImpl action) { 39 super(context, action); 40 setLayoutResource(R.layout.radio_slice_pref); 41 } 42 43 @Override onBindViewHolder(@onNull PreferenceViewHolder holder)44 public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { 45 super.onBindViewHolder(holder); 46 47 RadioControlWidget widget = (RadioControlWidget) holder.itemView; 48 widget.setEnabled(this.isEnabled()); 49 widget.setTooltipConfig(mTooltipConfig); 50 } 51 52 /** Set tool tip related attributes. */ 53 @Override setTooltipConfig(ControlWidget.TooltipConfig tooltipConfig)54 public void setTooltipConfig(ControlWidget.TooltipConfig tooltipConfig) { 55 if (!this.mTooltipConfig.equals(tooltipConfig)) { 56 this.mTooltipConfig = tooltipConfig; 57 notifyChanged(); 58 } 59 } 60 61 static class RadioControlWidget extends ControlWidget { 62 RadioControlWidget(Context context)63 public RadioControlWidget(Context context) { 64 this(context, /* attrs= */ null); 65 } 66 RadioControlWidget(Context context, @Nullable AttributeSet attrs)67 public RadioControlWidget(Context context, @Nullable AttributeSet attrs) { 68 this(context, attrs, /* defStyleAttr= */ 0); 69 } 70 RadioControlWidget(Context context, @Nullable AttributeSet attrs, int defStyleAttr)71 public RadioControlWidget(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 72 super(context, attrs, defStyleAttr); 73 View.inflate(context, R.layout.radio_control_widget, /* root= */ this); 74 } 75 } 76 77 } 78