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