Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2008 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.example.android.apis.view;
     18 
     19 import android.app.ListActivity;
     20 import android.content.Context;
     21 import android.os.Bundle;
     22 import android.view.LayoutInflater;
     23 import android.view.View;
     24 import android.view.ViewGroup;
     25 import android.widget.AbsListView;
     26 import android.widget.BaseAdapter;
     27 import android.widget.ListView;
     28 import android.widget.TextView;
     29 import android.widget.AbsListView.OnScrollListener;
     30 
     31 import com.example.android.apis.R;
     32 
     33 
     34 /**
     35  * Demonstrates how a list can avoid expensive operations during scrolls or flings. In this
     36  * case, we pretend that binding a view to its data is slow (even though it really isn't). When
     37  * a scroll/fling is happening, the adapter binds the view to temporary data. After the scroll/fling
     38  * has finished, the temporary data is replace with the actual data.
     39  *
     40  */
     41 public class List13 extends ListActivity implements ListView.OnScrollListener {
     42 
     43     private TextView mStatus;
     44 
     45     private boolean mBusy = false;
     46 
     47     /**
     48      * Will not bind views while the list is scrolling
     49      *
     50      */
     51     private class SlowAdapter extends BaseAdapter {
     52         private LayoutInflater mInflater;
     53 
     54         public SlowAdapter(Context context) {
     55             mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     56         }
     57 
     58         /**
     59          * The number of items in the list is determined by the number of speeches
     60          * in our array.
     61          *
     62          * @see android.widget.ListAdapter#getCount()
     63          */
     64         public int getCount() {
     65             return mStrings.length;
     66         }
     67 
     68         /**
     69          * Since the data comes from an array, just returning the index is
     70          * sufficent to get at the data. If we were using a more complex data
     71          * structure, we would return whatever object represents one row in the
     72          * list.
     73          *
     74          * @see android.widget.ListAdapter#getItem(int)
     75          */
     76         public Object getItem(int position) {
     77             return position;
     78         }
     79 
     80         /**
     81          * Use the array index as a unique id.
     82          *
     83          * @see android.widget.ListAdapter#getItemId(int)
     84          */
     85         public long getItemId(int position) {
     86             return position;
     87         }
     88 
     89         /**
     90          * Make a view to hold each row.
     91          *
     92          * @see android.widget.ListAdapter#getView(int, android.view.View,
     93          *      android.view.ViewGroup)
     94          */
     95         public View getView(int position, View convertView, ViewGroup parent) {
     96             TextView text;
     97 
     98             if (convertView == null) {
     99                 text = (TextView)mInflater.inflate(android.R.layout.simple_list_item_1, parent, false);
    100             } else {
    101                 text = (TextView)convertView;
    102             }
    103 
    104             if (!mBusy) {
    105                 text.setText(mStrings[position]);
    106                 // Null tag means the view has the correct data
    107                 text.setTag(null);
    108             } else {
    109                 text.setText("Loading...");
    110                 // Non-null tag means the view still needs to load it's data
    111                 text.setTag(this);
    112             }
    113 
    114             return text;
    115         }
    116     }
    117 
    118     @Override
    119     public void onCreate(Bundle savedInstanceState) {
    120         super.onCreate(savedInstanceState);
    121         setContentView(R.layout.list_13);
    122         mStatus = (TextView) findViewById(R.id.status);
    123         mStatus.setText("Idle");
    124 
    125         // Use an existing ListAdapter that will map an array
    126         // of strings to TextViews
    127         setListAdapter(new SlowAdapter(this));
    128 
    129         getListView().setOnScrollListener(this);
    130     }
    131 
    132 
    133     public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
    134             int totalItemCount) {
    135     }
    136 
    137 
    138     public void onScrollStateChanged(AbsListView view, int scrollState) {
    139         switch (scrollState) {
    140         case OnScrollListener.SCROLL_STATE_IDLE:
    141             mBusy = false;
    142 
    143             int first = view.getFirstVisiblePosition();
    144             int count = view.getChildCount();
    145             for (int i=0; i<count; i++) {
    146                 TextView t = (TextView)view.getChildAt(i);
    147                 if (t.getTag() != null) {
    148                     t.setText(mStrings[first + i]);
    149                     t.setTag(null);
    150                 }
    151             }
    152 
    153             mStatus.setText("Idle");
    154             break;
    155         case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
    156             mBusy = true;
    157             mStatus.setText("Touch scroll");
    158             break;
    159         case OnScrollListener.SCROLL_STATE_FLING:
    160             mBusy = true;
    161             mStatus.setText("Fling");
    162             break;
    163         }
    164     }
    165 
    166     private String[] mStrings = {
    167             "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam",
    168             "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis",
    169             "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
    170             "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese",
    171             "Ami du Chambertin", "Anejo Enchilado", "Anneau du Vic-Bilh",
    172             "Anthoriro", "Appenzell", "Aragon", "Ardi Gasna", "Ardrahan",
    173             "Armenian String", "Aromes au Gene de Marc", "Asadero", "Asiago",
    174             "Aubisque Pyrenees", "Autun", "Avaxtskyr", "Baby Swiss", "Babybel",
    175             "Baguette Laonnaise", "Bakers", "Baladi", "Balaton", "Bandal",
    176             "Banon", "Barry's Bay Cheddar", "Basing", "Basket Cheese",
    177             "Bath Cheese", "Bavarian Bergkase", "Baylough", "Beaufort",
    178             "Beauvoorde", "Beenleigh Blue", "Beer Cheese", "Bel Paese",
    179             "Bergader", "Bergere Bleue", "Berkswell", "Beyaz Peynir",
    180             "Bierkase", "Bishop Kennedy", "Blarney", "Bleu d'Auvergne",
    181             "Bleu de Gex", "Bleu de Laqueuille", "Bleu de Septmoncel",
    182             "Bleu Des Causses", "Blue", "Blue Castello", "Blue Rathgore",
    183             "Blue Vein (Australian)", "Blue Vein Cheeses", "Bocconcini",
    184             "Bocconcini (Australian)", "Boeren Leidenkaas", "Bonchester",
    185             "Bosworth", "Bougon", "Boule Du Roves", "Boulette d'Avesnes",
    186             "Boursault", "Boursin", "Bouyssou", "Bra", "Braudostur",
    187             "Breakfast Cheese", "Brebis du Lavort", "Brebis du Lochois",
    188             "Brebis du Puyfaucon", "Bresse Bleu", "Brick", "Brie",
    189             "Brie de Meaux", "Brie de Melun", "Brillat-Savarin", "Brin",
    190             "Brin d' Amour", "Brin d'Amour", "Brinza (Burduf Brinza)",
    191             "Briquette de Brebis", "Briquette du Forez", "Broccio",
    192             "Broccio Demi-Affine", "Brousse du Rove", "Bruder Basil",
    193             "Brusselae Kaas (Fromage de Bruxelles)", "Bryndza",
    194             "Buchette d'Anjou", "Buffalo", "Burgos", "Butte", "Butterkase",
    195             "Button (Innes)", "Buxton Blue", "Cabecou", "Caboc", "Cabrales",
    196             "Cachaille", "Caciocavallo", "Caciotta", "Caerphilly",
    197             "Cairnsmore", "Calenzana", "Cambazola", "Camembert de Normandie",
    198             "Canadian Cheddar", "Canestrato", "Cantal", "Caprice des Dieux",
    199             "Capricorn Goat", "Capriole Banon", "Carre de l'Est",
    200             "Casciotta di Urbino", "Cashel Blue", "Castellano", "Castelleno",
    201             "Castelmagno", "Castelo Branco", "Castigliano", "Cathelain",
    202             "Celtic Promise", "Cendre d'Olivet", "Cerney", "Chabichou",
    203             "Chabichou du Poitou", "Chabis de Gatine", "Chaource", "Charolais",
    204             "Chaumes", "Cheddar", "Cheddar Clothbound", "Cheshire", "Chevres",
    205             "Chevrotin des Aravis", "Chontaleno", "Civray",
    206             "Coeur de Camembert au Calvados", "Coeur de Chevre", "Colby",
    207             "Cold Pack", "Comte", "Coolea", "Cooleney", "Coquetdale",
    208             "Corleggy", "Cornish Pepper", "Cotherstone", "Cotija",
    209             "Cottage Cheese", "Cottage Cheese (Australian)", "Cougar Gold",
    210             "Coulommiers", "Coverdale", "Crayeux de Roncq", "Cream Cheese",
    211             "Cream Havarti", "Crema Agria", "Crema Mexicana", "Creme Fraiche",
    212             "Crescenza", "Croghan", "Crottin de Chavignol",
    213             "Crottin du Chavignol", "Crowdie", "Crowley", "Cuajada", "Curd",
    214             "Cure Nantais", "Curworthy", "Cwmtawe Pecorino",
    215             "Cypress Grove Chevre", "Danablu (Danish Blue)", "Danbo",
    216             "Danish Fontina", "Daralagjazsky", "Dauphin", "Delice des Fiouves",
    217             "Denhany Dorset Drum", "Derby", "Dessertnyj Belyj", "Devon Blue",
    218             "Devon Garland", "Dolcelatte", "Doolin", "Doppelrhamstufel",
    219             "Dorset Blue Vinney", "Double Gloucester", "Double Worcester",
    220             "Dreux a la Feuille", "Dry Jack", "Duddleswell", "Dunbarra",
    221             "Dunlop", "Dunsyre Blue", "Duroblando", "Durrus",
    222             "Dutch Mimolette (Commissiekaas)", "Edam", "Edelpilz",
    223             "Emental Grand Cru", "Emlett", "Emmental", "Epoisses de Bourgogne",
    224             "Esbareich", "Esrom", "Etorki", "Evansdale Farmhouse Brie",
    225             "Evora De L'Alentejo", "Exmoor Blue", "Explorateur", "Feta",
    226             "Feta (Australian)", "Figue", "Filetta", "Fin-de-Siecle",
    227             "Finlandia Swiss", "Finn", "Fiore Sardo", "Fleur du Maquis",
    228             "Flor de Guia", "Flower Marie", "Folded",
    229             "Folded cheese with mint", "Fondant de Brebis", "Fontainebleau",
    230             "Fontal", "Fontina Val d'Aosta", "Formaggio di capra", "Fougerus",
    231             "Four Herb Gouda", "Fourme d' Ambert", "Fourme de Haute Loire",
    232             "Fourme de Montbrison", "Fresh Jack", "Fresh Mozzarella",
    233             "Fresh Ricotta", "Fresh Truffles", "Fribourgeois", "Friesekaas",
    234             "Friesian", "Friesla", "Frinault", "Fromage a Raclette",
    235             "Fromage Corse", "Fromage de Montagne de Savoie", "Fromage Frais",
    236             "Fruit Cream Cheese", "Frying Cheese", "Fynbo", "Gabriel",
    237             "Galette du Paludier", "Galette Lyonnaise",
    238             "Galloway Goat's Milk Gems", "Gammelost", "Gaperon a l'Ail",
    239             "Garrotxa", "Gastanberra", "Geitost", "Gippsland Blue", "Gjetost",
    240             "Gloucester", "Golden Cross", "Gorgonzola", "Gornyaltajski",
    241             "Gospel Green", "Gouda", "Goutu", "Gowrie", "Grabetto", "Graddost",
    242             "Grafton Village Cheddar", "Grana", "Grana Padano", "Grand Vatel",
    243             "Grataron d' Areches", "Gratte-Paille", "Graviera", "Greuilh",
    244             "Greve", "Gris de Lille", "Gruyere", "Gubbeen", "Guerbigny",
    245             "Halloumi", "Halloumy (Australian)", "Haloumi-Style Cheese",
    246             "Harbourne Blue", "Havarti", "Heidi Gruyere", "Hereford Hop",
    247             "Herrgardsost", "Herriot Farmhouse", "Herve", "Hipi Iti",
    248             "Hubbardston Blue Cow", "Hushallsost", "Iberico", "Idaho Goatster",
    249             "Idiazabal", "Il Boschetto al Tartufo", "Ile d'Yeu",
    250             "Isle of Mull", "Jarlsberg", "Jermi Tortes", "Jibneh Arabieh",
    251             "Jindi Brie", "Jubilee Blue", "Juustoleipa", "Kadchgall", "Kaseri",
    252             "Kashta", "Kefalotyri", "Kenafa", "Kernhem", "Kervella Affine",
    253             "Kikorangi", "King Island Cape Wickham Brie", "King River Gold",
    254             "Klosterkaese", "Knockalara", "Kugelkase", "L'Aveyronnais",
    255             "L'Ecir de l'Aubrac", "La Taupiniere", "La Vache Qui Rit",
    256             "Laguiole", "Lairobell", "Lajta", "Lanark Blue", "Lancashire",
    257             "Langres", "Lappi", "Laruns", "Lavistown", "Le Brin",
    258             "Le Fium Orbo", "Le Lacandou", "Le Roule", "Leafield", "Lebbene",
    259             "Leerdammer", "Leicester", "Leyden", "Limburger",
    260             "Lincolnshire Poacher", "Lingot Saint Bousquet d'Orb", "Liptauer",
    261             "Little Rydings", "Livarot", "Llanboidy", "Llanglofan Farmhouse",
    262             "Loch Arthur Farmhouse", "Loddiswell Avondale", "Longhorn",
    263             "Lou Palou", "Lou Pevre", "Lyonnais", "Maasdam", "Macconais",
    264             "Mahoe Aged Gouda", "Mahon", "Malvern", "Mamirolle", "Manchego",
    265             "Manouri", "Manur", "Marble Cheddar", "Marbled Cheeses",
    266             "Maredsous", "Margotin", "Maribo", "Maroilles", "Mascares",
    267             "Mascarpone", "Mascarpone (Australian)", "Mascarpone Torta",
    268             "Matocq", "Maytag Blue", "Meira", "Menallack Farmhouse",
    269             "Menonita", "Meredith Blue", "Mesost", "Metton (Cancoillotte)",
    270             "Meyer Vintage Gouda", "Mihalic Peynir", "Milleens", "Mimolette",
    271             "Mine-Gabhar", "Mini Baby Bells", "Mixte", "Molbo",
    272             "Monastery Cheeses", "Mondseer", "Mont D'or Lyonnais", "Montasio",
    273             "Monterey Jack", "Monterey Jack Dry", "Morbier",
    274             "Morbier Cru de Montagne", "Mothais a la Feuille", "Mozzarella",
    275             "Mozzarella (Australian)", "Mozzarella di Bufala",
    276             "Mozzarella Fresh, in water", "Mozzarella Rolls", "Munster",
    277             "Murol", "Mycella", "Myzithra", "Naboulsi", "Nantais",
    278             "Neufchatel", "Neufchatel (Australian)", "Niolo", "Nokkelost",
    279             "Northumberland", "Oaxaca", "Olde York", "Olivet au Foin",
    280             "Olivet Bleu", "Olivet Cendre", "Orkney Extra Mature Cheddar",
    281             "Orla", "Oschtjepka", "Ossau Fermier", "Ossau-Iraty", "Oszczypek",
    282             "Oxford Blue", "P'tit Berrichon", "Palet de Babligny", "Paneer",
    283             "Panela", "Pannerone", "Pant ys Gawn", "Parmesan (Parmigiano)",
    284             "Parmigiano Reggiano", "Pas de l'Escalette", "Passendale",
    285             "Pasteurized Processed", "Pate de Fromage", "Patefine Fort",
    286             "Pave d'Affinois", "Pave d'Auge", "Pave de Chirac",
    287             "Pave du Berry", "Pecorino", "Pecorino in Walnut Leaves",
    288             "Pecorino Romano", "Peekskill Pyramid", "Pelardon des Cevennes",
    289             "Pelardon des Corbieres", "Penamellera", "Penbryn", "Pencarreg",
    290             "Perail de Brebis", "Petit Morin", "Petit Pardou", "Petit-Suisse",
    291             "Picodon de Chevre", "Picos de Europa", "Piora",
    292             "Pithtviers au Foin", "Plateau de Herve", "Plymouth Cheese",
    293             "Podhalanski", "Poivre d'Ane", "Polkolbin", "Pont l'Eveque",
    294             "Port Nicholson", "Port-Salut", "Postel", "Pouligny-Saint-Pierre",
    295             "Pourly", "Prastost", "Pressato", "Prince-Jean",
    296             "Processed Cheddar", "Provolone", "Provolone (Australian)",
    297             "Pyengana Cheddar", "Pyramide", "Quark", "Quark (Australian)",
    298             "Quartirolo Lombardo", "Quatre-Vents", "Quercy Petit",
    299             "Queso Blanco", "Queso Blanco con Frutas --Pina y Mango",
    300             "Queso de Murcia", "Queso del Montsec", "Queso del Tietar",
    301             "Queso Fresco", "Queso Fresco (Adobera)", "Queso Iberico",
    302             "Queso Jalapeno", "Queso Majorero", "Queso Media Luna",
    303             "Queso Para Frier", "Queso Quesadilla", "Rabacal", "Raclette",
    304             "Ragusano", "Raschera", "Reblochon", "Red Leicester",
    305             "Regal de la Dombes", "Reggianito", "Remedou", "Requeson",
    306             "Richelieu", "Ricotta", "Ricotta (Australian)", "Ricotta Salata",
    307             "Ridder", "Rigotte", "Rocamadour", "Rollot", "Romano",
    308             "Romans Part Dieu", "Roncal", "Roquefort", "Roule",
    309             "Rouleau De Beaulieu", "Royalp Tilsit", "Rubens", "Rustinu",
    310             "Saaland Pfarr", "Saanenkaese", "Saga", "Sage Derby",
    311             "Sainte Maure", "Saint-Marcellin", "Saint-Nectaire",
    312             "Saint-Paulin", "Salers", "Samso", "San Simon", "Sancerre",
    313             "Sap Sago", "Sardo", "Sardo Egyptian", "Sbrinz", "Scamorza",
    314             "Schabzieger", "Schloss", "Selles sur Cher", "Selva", "Serat",
    315             "Seriously Strong Cheddar", "Serra da Estrela", "Sharpam",
    316             "Shelburne Cheddar", "Shropshire Blue", "Siraz", "Sirene",
    317             "Smoked Gouda", "Somerset Brie", "Sonoma Jack",
    318             "Sottocenare al Tartufo", "Soumaintrain", "Sourire Lozerien",
    319             "Spenwood", "Sraffordshire Organic", "St. Agur Blue Cheese",
    320             "Stilton", "Stinking Bishop", "String", "Sussex Slipcote",
    321             "Sveciaost", "Swaledale", "Sweet Style Swiss", "Swiss",
    322             "Syrian (Armenian String)", "Tala", "Taleggio", "Tamie",
    323             "Tasmania Highland Chevre Log", "Taupiniere", "Teifi", "Telemea",
    324             "Testouri", "Tete de Moine", "Tetilla", "Texas Goat Cheese",
    325             "Tibet", "Tillamook Cheddar", "Tilsit", "Timboon Brie", "Toma",
    326             "Tomme Brulee", "Tomme d'Abondance", "Tomme de Chevre",
    327             "Tomme de Romans", "Tomme de Savoie", "Tomme des Chouans",
    328             "Tommes", "Torta del Casar", "Toscanello", "Touree de L'Aubier",
    329             "Tourmalet", "Trappe (Veritable)", "Trois Cornes De Vendee",
    330             "Tronchon", "Trou du Cru", "Truffe", "Tupi", "Turunmaa",
    331             "Tymsboro", "Tyn Grug", "Tyning", "Ubriaco", "Ulloa",
    332             "Vacherin-Fribourgeois", "Valencay", "Vasterbottenost", "Venaco",
    333             "Vendomois", "Vieux Corse", "Vignotte", "Vulscombe",
    334             "Waimata Farmhouse Blue", "Washed Rind Cheese (Australian)",
    335             "Waterloo", "Weichkaese", "Wellington", "Wensleydale",
    336             "White Stilton", "Whitestone Farmhouse", "Wigmore",
    337             "Woodside Cabecou", "Xanadu", "Xynotyro", "Yarg Cornish",
    338             "Yarra Valley Pyramid", "Yorkshire Blue", "Zamorano",
    339             "Zanetti Grana Padano", "Zanetti Parmigiano Reggiano"};
    340 
    341 }
    342