• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.tv.twopanelsettings.slices;
18 
19 import android.content.Context;
20 import android.text.TextUtils;
21 import android.view.View;
22 
23 import androidx.preference.PreferenceViewHolder;
24 import androidx.slice.core.SliceActionImpl;
25 
26 /**
27  * Slice version of RadioPreference.
28  */
29 public class SliceRadioPreference extends RadioPreference implements HasSliceAction, HasSliceUri,
30         HasCustomContentDescription {
31     private int mActionId;
32     private SliceActionImpl mSliceAction;
33     private String mUri;
34     private SliceActionImpl mFollowupSliceAction;
35     private String mContentDescription;
36 
SliceRadioPreference(Context context, SliceActionImpl action)37     public SliceRadioPreference(Context context, SliceActionImpl action) {
38         super(context);
39         mSliceAction = action;
40         update();
41     }
42 
43     @Override
onBindViewHolder(PreferenceViewHolder holder)44     public void onBindViewHolder(PreferenceViewHolder holder) {
45         super.onBindViewHolder(holder);
46         if (!TextUtils.isEmpty(mContentDescription)) {
47             holder.itemView.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
48             holder.itemView.setContentDescription(mContentDescription);
49         }
50     }
51 
52     @Override
getActionId()53     public int getActionId() {
54         return mActionId;
55     }
56 
57     @Override
setActionId(int actionId)58     public void setActionId(int actionId) {
59         mActionId = actionId;
60     }
61 
62     @Override
getSliceAction()63     public SliceActionImpl getSliceAction() {
64         return mSliceAction;
65     }
66 
67     @Override
setSliceAction(SliceActionImpl sliceAction)68     public void setSliceAction(SliceActionImpl sliceAction) {
69         mSliceAction = sliceAction;
70     }
71 
72     @Override
getFollowupSliceAction()73     public SliceActionImpl getFollowupSliceAction() {
74         return mFollowupSliceAction;
75     }
76 
77     @Override
setFollowupSliceAction(SliceActionImpl sliceAction)78     public void setFollowupSliceAction(SliceActionImpl sliceAction) {
79         mFollowupSliceAction = sliceAction;
80     }
81 
update()82     private void update() {
83         this.setChecked(mSliceAction.isChecked());
84     }
85 
86     @Override
setUri(String uri)87     public void setUri(String uri) {
88         this.mUri = uri;
89     }
90 
91     @Override
getUri()92     public String getUri() {
93         return mUri;
94     }
95 
96     /**
97      * Sets the accessibility content description that will be read to the TalkBack users when they
98      * select this preference.
99      */
100     @Override
setContentDescription(String contentDescription)101     public void setContentDescription(String contentDescription) {
102         this.mContentDescription = contentDescription;
103     }
104 
105     @Override
getContentDescription()106     public String getContentDescription() {
107         return mContentDescription;
108     }
109 }
110