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.util.Pair; 21 import android.view.LayoutInflater; 22 import android.view.View; 23 import android.view.ViewGroup; 24 import android.widget.TextView; 25 26 import androidx.preference.Preference; 27 import androidx.preference.PreferenceViewHolder; 28 29 import com.android.tv.twopanelsettings.R; 30 31 import java.util.List; 32 33 /** 34 * InfoPreference which could be used to display a list of information. 35 */ 36 public class InfoPreference extends Preference implements HasCustomContentDescription { 37 private String mContentDescription; 38 private List<Pair<CharSequence, CharSequence>> mInfoList; 39 InfoPreference(Context context, List<Pair<CharSequence, CharSequence>> infoList)40 public InfoPreference(Context context, List<Pair<CharSequence, CharSequence>> infoList) { 41 super(context); 42 mInfoList = infoList; 43 setLayoutResource(R.layout.info_preference); 44 setEnabled(false); 45 } 46 47 @Override onBindViewHolder(final PreferenceViewHolder holder)48 public void onBindViewHolder(final PreferenceViewHolder holder) { 49 super.onBindViewHolder(holder); 50 ViewGroup container = (ViewGroup) holder.findViewById(R.id.item_container); 51 container.removeAllViews(); 52 for (Pair<CharSequence, CharSequence> info : mInfoList) { 53 View view = LayoutInflater.from(getContext()).inflate(R.layout.info_preference_item, 54 container, false); 55 ((TextView) view.findViewById(R.id.info_item_title)).setText(info.first); 56 ((TextView) view.findViewById(R.id.info_item_summary)).setText(info.second); 57 container.addView(view); 58 } 59 } 60 61 /** 62 * Sets the accessibility content description that will be read to the TalkBack users when they 63 * focus on this preference. 64 */ setContentDescription(String contentDescription)65 public void setContentDescription(String contentDescription) { 66 this.mContentDescription = contentDescription; 67 } 68 getContentDescription()69 public String getContentDescription() { 70 return mContentDescription; 71 } 72 } 73