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.content.res.Resources; 21 import android.graphics.Color; 22 import android.util.AttributeSet; 23 import android.view.View; 24 import android.view.accessibility.CaptioningManager.CaptionStyle; 25 import android.widget.TextView; 26 27 import com.android.internal.widget.SubtitleView; 28 import com.android.settings.R; 29 30 /** 31 * Grid preference that allows the user to pick a captioning edge type. 32 */ 33 public class EdgeTypePreference extends ListDialogPreference { 34 private static final int DEFAULT_FOREGROUND_COLOR = Color.WHITE; 35 private static final int DEFAULT_BACKGROUND_COLOR = Color.TRANSPARENT; 36 private static final int DEFAULT_EDGE_COLOR = Color.BLACK; 37 private static final float DEFAULT_FONT_SIZE = 96f; 38 39 public EdgeTypePreference(Context context, AttributeSet attrs) { 40 super(context, attrs); 41 42 final Resources res = context.getResources(); 43 setValues(res.getIntArray(R.array.captioning_edge_type_selector_values)); 44 setTitles(res.getStringArray(R.array.captioning_edge_type_selector_titles)); 45 setDialogLayoutResource(R.layout.grid_picker_dialog); 46 setListItemLayoutResource(R.layout.preset_picker_item); 47 } 48 49 @Override 50 public boolean shouldDisableDependents() { 51 return getValue() == CaptionStyle.EDGE_TYPE_NONE || super.shouldDisableDependents(); 52 } 53 54 @Override 55 protected void onBindListItem(View view, int index) { 56 final SubtitleView preview = (SubtitleView) view.findViewById(R.id.preview); 57 58 preview.setForegroundColor(DEFAULT_FOREGROUND_COLOR); 59 preview.setBackgroundColor(DEFAULT_BACKGROUND_COLOR); 60 preview.setTextSize(DEFAULT_FONT_SIZE); 61 62 final int value = getValueAt(index); 63 preview.setEdgeType(value); 64 preview.setEdgeColor(DEFAULT_EDGE_COLOR); 65 66 final CharSequence title = getTitleAt(index); 67 if (title != null) { 68 final TextView summary = (TextView) view.findViewById(R.id.summary); 69 summary.setText(title); 70 } 71 } 72 } 73