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