• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.util.AttributeSet;
21 
22 /**
23  * An embedded slice preference which would be embedded in common TvSettings preference
24  * items, but will automatically update its status and communicates with external apps through
25  * slice api.
26  */
27 public class EmbeddedSlicePreference extends SlicePreference
28         implements HasCustomContentDescription {
29     private static final String TAG = "EmbeddedSlicePreference";
30     private final EmbeddedSlicePreferenceHelper mHelper;
31     private String mContentDescription;
32 
EmbeddedSlicePreference(Context context, String uri)33     public EmbeddedSlicePreference(Context context, String uri) {
34         super(context);
35         setUri(uri);
36         mHelper = new EmbeddedSlicePreferenceHelper(this, getUri());
37     }
38 
EmbeddedSlicePreference(Context context, AttributeSet attrs)39     public EmbeddedSlicePreference(Context context, AttributeSet attrs) {
40         super(context, attrs);
41         mHelper = new EmbeddedSlicePreferenceHelper(this, getUri());
42     }
43 
44     @Override
onAttached()45     public void onAttached() {
46         super.onAttached();
47         mHelper.onAttached();
48     }
49 
50     @Override
onDetached()51     public void onDetached() {
52         super.onDetached();
53         mHelper.onDetached();
54     }
55 
addListener(EmbeddedSlicePreferenceHelper.SlicePreferenceListener listener)56     public void addListener(EmbeddedSlicePreferenceHelper.SlicePreferenceListener listener) {
57         mHelper.mListener = listener;
58     }
59 
removeListener(EmbeddedSlicePreferenceHelper.SlicePreferenceListener listener)60     public void removeListener(EmbeddedSlicePreferenceHelper.SlicePreferenceListener listener) {
61         mHelper.mListener = null;
62     }
63 
update()64     void update() {
65         setEnabled(mHelper.mNewPref.isEnabled());
66         setTitle(mHelper.mNewPref.getTitle());
67         setSummary(mHelper.mNewPref.getSummary());
68         setIcon(mHelper.mNewPref.getIcon());
69         if (mHelper.mNewPref instanceof HasSliceAction
70                 && ((HasSliceAction) mHelper.mNewPref).getSliceAction() != null) {
71             setIntent(((HasSliceAction) mHelper.mNewPref).getSliceAction().getAction().getIntent());
72         }
73     }
74 
75 
76     /**
77      * Sets the accessibility content description that will be read to the TalkBack users when they
78      * focus on this preference.
79      */
setContentDescription(String contentDescription)80     public void setContentDescription(String contentDescription) {
81         this.mContentDescription = contentDescription;
82     }
83 
getContentDescription()84     public String getContentDescription() {
85         return mContentDescription;
86     }
87 }
88