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