1 /* 2 * Copyright (C) 2013 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.settings.accessibility; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.View; 22 import android.view.accessibility.CaptioningManager.CaptionStyle; 23 import android.widget.TextView; 24 25 import com.android.internal.widget.SubtitleView; 26 import com.android.settings.R; 27 28 /** Grid preference that allows the user to pick a captioning preset type. */ 29 public class PresetPreference extends ListDialogPreference { 30 31 private static final float DEFAULT_FONT_SIZE = 32f; 32 private final CaptionHelper mCaptionHelper; 33 PresetPreference(Context context, AttributeSet attrs)34 public PresetPreference(Context context, AttributeSet attrs) { 35 super(context, attrs); 36 mCaptionHelper = new CaptionHelper(context); 37 38 setDialogLayoutResource(R.layout.grid_picker_dialog); 39 setListItemLayoutResource(R.layout.preset_picker_item); 40 } 41 42 @Override shouldDisableDependents()43 public boolean shouldDisableDependents() { 44 return getValue() != CaptionStyle.PRESET_CUSTOM 45 || super.shouldDisableDependents(); 46 } 47 48 @Override onBindListItem(View view, int index)49 protected void onBindListItem(View view, int index) { 50 final View previewViewport = view.findViewById(R.id.preview_viewport); 51 final SubtitleView previewText = view.findViewById(R.id.preview); 52 final int value = getValueAt(index); 53 mCaptionHelper.applyCaptionProperties(previewText, previewViewport, value); 54 55 final float density = getContext().getResources().getDisplayMetrics().density; 56 previewText.setTextSize(DEFAULT_FONT_SIZE * density); 57 58 final CharSequence title = getTitleAt(index); 59 if (title != null) { 60 final TextView summary = view.findViewById(R.id.summary); 61 summary.setText(title); 62 } 63 } 64 } 65