• 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.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 in a pill shape.
33  * Alternative to the {@link BasicSlicePreference}.
34  */
35 public class BasicCenteredSlicePreference extends SlicePreference implements TooltipPreference {
36     private ControlWidget.TooltipConfig mTooltipConfig = new ControlWidget.TooltipConfig();
37 
BasicCenteredSlicePreference(Context context)38     public BasicCenteredSlicePreference(Context context) {
39         this(context, null);
40     }
41 
BasicCenteredSlicePreference(Context context, @Nullable AttributeSet attrs)42     public BasicCenteredSlicePreference(Context context, @Nullable AttributeSet attrs) {
43         super(context, attrs);
44         setLayoutResource(R.layout.basic_centered_slice_pref);
45     }
46 
47     @Override
onBindViewHolder(@onNull PreferenceViewHolder holder)48     public void onBindViewHolder(@NonNull PreferenceViewHolder holder) {
49         super.onBindViewHolder(holder);
50         BasicCenteredControlWidget widget = (BasicCenteredControlWidget) 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 BasicCenteredControlWidget extends ControlWidget {
65 
BasicCenteredControlWidget(Context context)66         public BasicCenteredControlWidget(Context context) {
67             this(context, /* attrs= */ null);
68         }
69 
BasicCenteredControlWidget(Context context, @Nullable AttributeSet attrs)70         public BasicCenteredControlWidget(Context context, @Nullable AttributeSet attrs) {
71             this(context, attrs, /* defStyleAttr= */ 0);
72         }
73 
BasicCenteredControlWidget(Context context, @Nullable AttributeSet attrs, int defStyleAttr)74         public BasicCenteredControlWidget(Context context, @Nullable AttributeSet attrs,
75                 int defStyleAttr) {
76             super(context, attrs, defStyleAttr);
77             View.inflate(context, R.layout.basic_centered_control_widget, /* root= */ this);
78         }
79     }
80 
81 }
82