Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2011 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 android.holo.cts;
     18 
     19 import android.view.LayoutInflater;
     20 import android.view.View;
     21 import android.view.ViewGroup;
     22 import android.widget.BaseAdapter;
     23 import android.widget.TextView;
     24 
     25 import java.util.ArrayList;
     26 import java.util.List;
     27 
     28 /**
     29  * {@link BaseAdapter} containing all the themes.
     30  */
     31 class ThemeAdapter extends BaseAdapter  {
     32 
     33     static class ThemeInfo {
     34         private final String mName;
     35         private final int mTheme;
     36         private final String mFileName;
     37 
     38         private ThemeInfo(String name, int theme, String fileName) {
     39             mName = name;
     40             mTheme = theme;
     41             mFileName = fileName;
     42         }
     43 
     44         public String getName() {
     45             return mName;
     46         }
     47 
     48         public int getTheme() {
     49             return mTheme;
     50         }
     51 
     52         public String getBitmapName() {
     53             return mFileName;
     54         }
     55     }
     56 
     57     private final List<ThemeInfo> mThemeInfos = new ArrayList<ThemeInfo>();
     58 
     59     private final LayoutInflater mInflater;
     60 
     61     ThemeAdapter(LayoutInflater inflater) {
     62         mInflater = inflater;
     63 
     64         addTheme("Holo",
     65                 android.R.style.Theme_Holo,
     66                 "holo");
     67 
     68         addTheme("Holo Dialog",
     69                 android.R.style.Theme_Holo_Dialog,
     70                 "holo_dialog");
     71 
     72         addTheme("Holo Dialog Minimum Width",
     73                 android.R.style.Theme_Holo_Dialog_MinWidth,
     74                 "holo_dialog_minwidth");
     75 
     76         addTheme("Holo Dialog No Action Bar",
     77                 android.R.style.Theme_Holo_Dialog_NoActionBar,
     78                 "holo_dialog_noactionbar");
     79 
     80         addTheme("Holo Dialog No Action Bar Minimum Width",
     81                 android.R.style.Theme_Holo_Dialog_NoActionBar_MinWidth,
     82                 "holo_dialog_noactionbar_minwidth");
     83 
     84         addTheme("Holo Dialog When Large",
     85                 android.R.style.Theme_Holo_DialogWhenLarge,
     86                 "holo_dialogwhenlarge");
     87 
     88         addTheme("Holo Dialog When Large No Action Bar",
     89                 android.R.style.Theme_Holo_DialogWhenLarge_NoActionBar,
     90                 "holo_dialogwhenlarge_noactionbar");
     91 
     92         addTheme("Holo Input Method",
     93                 android.R.style.Theme_Holo_InputMethod,
     94                 "holo_inputmethod");
     95 
     96         addTheme("Holo Light",
     97                 android.R.style.Theme_Holo_Light,
     98                 "holo_light");
     99 
    100         addTheme("Holo Light Dark Action Bar",
    101                 android.R.style.Theme_Holo_Light_DarkActionBar,
    102                 "holo_light_darkactionbar");
    103 
    104         addTheme("Holo Light Dialog",
    105                 android.R.style.Theme_Holo_Light_Dialog,
    106                 "holo_light_dialog");
    107 
    108         addTheme("Holo Light Dialog Minimum Width",
    109                 android.R.style.Theme_Holo_Light_Dialog_MinWidth,
    110                 "holo_light_dialog_minwidth");
    111 
    112         addTheme("Holo Light Dialog No Action Bar",
    113                 android.R.style.Theme_Holo_Light_Dialog_NoActionBar,
    114                 "holo_light_dialog_noactionbar");
    115 
    116         addTheme("Holo Light Dialog No Action Bar Minimum Width",
    117                 android.R.style.Theme_Holo_Light_Dialog_NoActionBar_MinWidth,
    118                 "holo_light_dialog_noactionbar_minwidth");
    119 
    120         addTheme("Holo Light Dialog When Large",
    121                 android.R.style.Theme_Holo_Light_DialogWhenLarge,
    122                 "holo_light_dialogwhenlarge");
    123 
    124         addTheme("Holo Light Dialog When Large No Action Bar",
    125                 android.R.style.Theme_Holo_Light_DialogWhenLarge_NoActionBar,
    126                 "holo_light_dialogwhenlarge_noactionbar");
    127 
    128         addTheme("Holo Light No Action Bar",
    129                 android.R.style.Theme_Holo_Light_NoActionBar,
    130                 "holo_light_noactionbar");
    131 
    132         addTheme("Holo Light No Action Bar Fullscreen",
    133                 android.R.style.Theme_Holo_Light_NoActionBar_Fullscreen,
    134                 "holo_light_noactionbar_fullscreen");
    135 
    136         addTheme("Holo Light Panel",
    137                 android.R.style.Theme_Holo_Light_Panel,
    138                 "holo_light_panel");
    139 
    140         addTheme("Holo No Action Bar",
    141                 android.R.style.Theme_Holo_NoActionBar,
    142                 "holo_noactionbar");
    143 
    144         addTheme("Holo No Action Bar Fullscreen",
    145                 android.R.style.Theme_Holo_NoActionBar_Fullscreen,
    146                 "holo_noactionbar_fullscreen");
    147 
    148         addTheme("Holo Panel",
    149                 android.R.style.Theme_Holo_Panel,
    150                 "holo_panel");
    151 
    152         addTheme("Holo Wallpaper",
    153                 android.R.style.Theme_Holo_Wallpaper,
    154                 "holo_wallpaper");
    155 
    156         addTheme("Holo Wallpaper No Title Bar",
    157                 android.R.style.Theme_Holo_Wallpaper_NoTitleBar,
    158                 "holo_wallpaper_notitlebar");
    159 
    160         // NOTE: Adding a theme doesn't mean it will be tested. You have to add an explicit
    161         //       test in HoloTest for it!
    162     }
    163 
    164     private void addTheme(String name, int theme, String fileNamePrefix) {
    165         mThemeInfos.add(new ThemeInfo(name, theme, fileNamePrefix));
    166     }
    167 
    168     @Override
    169     public int getCount() {
    170         return mThemeInfos.size();
    171     }
    172 
    173     @Override
    174     public ThemeInfo getItem(int position) {
    175         return mThemeInfos.get(position);
    176     }
    177 
    178     @Override
    179     public long getItemId(int position) {
    180         return getItem(position).mTheme;
    181     }
    182 
    183     @Override
    184     public View getView(int position, View convertView, ViewGroup parent) {
    185         TextView textView;
    186         if (convertView != null) {
    187             textView = (TextView) convertView;
    188         } else {
    189             textView = (TextView) mInflater.inflate(android.R.layout.simple_list_item_1,
    190                     parent, false);
    191         }
    192         ThemeInfo themeInfo = getItem(position);
    193         textView.setText(themeInfo.mName);
    194         return textView;
    195     }
    196 }
    197