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;
23 import android.view.accessibility.CaptioningManager.CaptionStyle;
24 import android.widget.TextView;
25 
26 import com.android.internal.widget.SubtitleView;
27 import com.android.settings.R;
28 
29 public class PresetPreference extends ListDialogPreference {
30     private static final float DEFAULT_FONT_SIZE = 32f;
31 
32     private final CaptioningManager mCaptioningManager;
33 
PresetPreference(Context context, AttributeSet attrs)34     public PresetPreference(Context context, AttributeSet attrs) {
35         super(context, attrs);
36 
37         setDialogLayoutResource(R.layout.grid_picker_dialog);
38         setListItemLayoutResource(R.layout.preset_picker_item);
39 
40         mCaptioningManager = (CaptioningManager) context.getSystemService(
41                 Context.CAPTIONING_SERVICE);
42     }
43 
44     @Override
shouldDisableDependents()45     public boolean shouldDisableDependents() {
46         return getValue() != CaptionStyle.PRESET_CUSTOM
47                 || super.shouldDisableDependents();
48     }
49 
50     @Override
onBindListItem(View view, int index)51     protected void onBindListItem(View view, int index) {
52         final View previewViewport = view.findViewById(R.id.preview_viewport);
53         final SubtitleView previewText = (SubtitleView) view.findViewById(R.id.preview);
54         final int value = getValueAt(index);
55         CaptionAppearanceFragment.applyCaptionProperties(
56                 mCaptioningManager, previewText, previewViewport, value);
57 
58         final float density = getContext().getResources().getDisplayMetrics().density;
59         previewText.setTextSize(DEFAULT_FONT_SIZE * density);
60 
61         final CharSequence title = getTitleAt(index);
62         if (title != null) {
63             final TextView summary = (TextView) view.findViewById(R.id.summary);
64             summary.setText(title);
65         }
66     }
67 }
68