Home | History | Annotate | Download | only in accessibility
      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 = 96f;
     31 
     32     private final CaptioningManager mCaptioningManager;
     33 
     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
     45     public boolean shouldDisableDependents() {
     46         return getValue() != CaptionStyle.PRESET_CUSTOM
     47                 || super.shouldDisableDependents();
     48     }
     49 
     50     @Override
     51     protected void onBindListItem(View view, int index) {
     52         final SubtitleView previewText = (SubtitleView) view.findViewById(R.id.preview);
     53         final int value = getValueAt(index);
     54         CaptionPropertiesFragment.applyCaptionProperties(
     55                 mCaptioningManager, previewText, value);
     56 
     57         previewText.setTextSize(DEFAULT_FONT_SIZE);
     58 
     59         final CharSequence title = getTitleAt(index);
     60         if (title != null) {
     61             final TextView summary = (TextView) view.findViewById(R.id.summary);
     62             summary.setText(title);
     63         }
     64     }
     65 }
     66