1cc0e782871eb6b946ded880e391866f27953654bAlan Viverette/*
2cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * Copyright (C) 2013 The Android Open Source Project
3cc0e782871eb6b946ded880e391866f27953654bAlan Viverette *
4cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * Licensed under the Apache License, Version 2.0 (the "License");
5cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * you may not use this file except in compliance with the License.
6cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * You may obtain a copy of the License at
7cc0e782871eb6b946ded880e391866f27953654bAlan Viverette *
8cc0e782871eb6b946ded880e391866f27953654bAlan Viverette *      http://www.apache.org/licenses/LICENSE-2.0
9cc0e782871eb6b946ded880e391866f27953654bAlan Viverette *
10cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * Unless required by applicable law or agreed to in writing, software
11cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * distributed under the License is distributed on an "AS IS" BASIS,
12cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * See the License for the specific language governing permissions and
14cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * limitations under the License.
15cc0e782871eb6b946ded880e391866f27953654bAlan Viverette */
16cc0e782871eb6b946ded880e391866f27953654bAlan Viverette
17cc0e782871eb6b946ded880e391866f27953654bAlan Viverettepackage com.android.settings.accessibility;
18cc0e782871eb6b946ded880e391866f27953654bAlan Viverette
19cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.content.Context;
20cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.util.AttributeSet;
21cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.view.View;
225ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viveretteimport android.view.accessibility.CaptioningManager;
23cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.view.accessibility.CaptioningManager.CaptionStyle;
24cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.widget.TextView;
25cc0e782871eb6b946ded880e391866f27953654bAlan Viverette
26e873aeb3a659ac970609cebb5ec2f460afd1206aAlan Viveretteimport com.android.internal.widget.SubtitleView;
27cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport com.android.settings.R;
28cc0e782871eb6b946ded880e391866f27953654bAlan Viverette
29cc0e782871eb6b946ded880e391866f27953654bAlan Viverettepublic class PresetPreference extends ListDialogPreference {
30bc02ced9fb1f65cfd80961c11d8cbe999e57b793Alan Viverette    private static final float DEFAULT_FONT_SIZE = 32f;
315ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette
325ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette    private final CaptioningManager mCaptioningManager;
335ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette
34cc0e782871eb6b946ded880e391866f27953654bAlan Viverette    public PresetPreference(Context context, AttributeSet attrs) {
35cc0e782871eb6b946ded880e391866f27953654bAlan Viverette        super(context, attrs);
36cc0e782871eb6b946ded880e391866f27953654bAlan Viverette
37cc0e782871eb6b946ded880e391866f27953654bAlan Viverette        setDialogLayoutResource(R.layout.grid_picker_dialog);
38cc0e782871eb6b946ded880e391866f27953654bAlan Viverette        setListItemLayoutResource(R.layout.preset_picker_item);
395ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette
405ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette        mCaptioningManager = (CaptioningManager) context.getSystemService(
415ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette                Context.CAPTIONING_SERVICE);
42cc0e782871eb6b946ded880e391866f27953654bAlan Viverette    }
43cc0e782871eb6b946ded880e391866f27953654bAlan Viverette
44cc0e782871eb6b946ded880e391866f27953654bAlan Viverette    @Override
45cc0e782871eb6b946ded880e391866f27953654bAlan Viverette    public boolean shouldDisableDependents() {
46cc0e782871eb6b946ded880e391866f27953654bAlan Viverette        return getValue() != CaptionStyle.PRESET_CUSTOM
47cc0e782871eb6b946ded880e391866f27953654bAlan Viverette                || super.shouldDisableDependents();
48cc0e782871eb6b946ded880e391866f27953654bAlan Viverette    }
49cc0e782871eb6b946ded880e391866f27953654bAlan Viverette
50cc0e782871eb6b946ded880e391866f27953654bAlan Viverette    @Override
51cc0e782871eb6b946ded880e391866f27953654bAlan Viverette    protected void onBindListItem(View view, int index) {
52a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette        final View previewViewport = view.findViewById(R.id.preview_viewport);
53e873aeb3a659ac970609cebb5ec2f460afd1206aAlan Viverette        final SubtitleView previewText = (SubtitleView) view.findViewById(R.id.preview);
54cc0e782871eb6b946ded880e391866f27953654bAlan Viverette        final int value = getValueAt(index);
554098dba2535453a89ba74022de47578f2556bd41Alan Viverette        CaptionPropertiesFragment.applyCaptionProperties(
56a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette                mCaptioningManager, previewText, previewViewport, value);
575ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette
58bc02ced9fb1f65cfd80961c11d8cbe999e57b793Alan Viverette        final float density = getContext().getResources().getDisplayMetrics().density;
59bc02ced9fb1f65cfd80961c11d8cbe999e57b793Alan Viverette        previewText.setTextSize(DEFAULT_FONT_SIZE * density);
60cc0e782871eb6b946ded880e391866f27953654bAlan Viverette
61cc0e782871eb6b946ded880e391866f27953654bAlan Viverette        final CharSequence title = getTitleAt(index);
62cc0e782871eb6b946ded880e391866f27953654bAlan Viverette        if (title != null) {
63cc0e782871eb6b946ded880e391866f27953654bAlan Viverette            final TextView summary = (TextView) view.findViewById(R.id.summary);
64cc0e782871eb6b946ded880e391866f27953654bAlan Viverette            summary.setText(title);
65cc0e782871eb6b946ded880e391866f27953654bAlan Viverette        }
66cc0e782871eb6b946ded880e391866f27953654bAlan Viverette    }
67cc0e782871eb6b946ded880e391866f27953654bAlan Viverette}
68