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 com.android.test.hwui; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.content.res.Resources; 22 import android.os.Bundle; 23 import android.util.DisplayMetrics; 24 import android.view.View; 25 import android.view.ViewGroup; 26 import android.widget.ArrayAdapter; 27 import android.widget.ListView; 28 import android.widget.TextView; 29 30 @SuppressWarnings({"UnusedDeclaration"}) 31 public class ViewLayersActivity4 extends Activity { 32 @Override onCreate(Bundle savedInstanceState)33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 36 setContentView(R.layout.view_layers_4); 37 38 setupList(R.id.list1); 39 } 40 setListTranslucent(View v)41 public void setListTranslucent(View v) { 42 findViewById(R.id.list1).setAlpha(0.5f); 43 } 44 setListOpaque(View v)45 public void setListOpaque(View v) { 46 findViewById(R.id.list1).setAlpha(1.0f); 47 } 48 setupList(int listId)49 private void setupList(int listId) { 50 final ListView list = (ListView) findViewById(listId); 51 list.setAdapter(new SimpleListAdapter(this)); 52 list.setLayerType(View.LAYER_TYPE_HARDWARE, null); 53 } 54 55 private static class SimpleListAdapter extends ArrayAdapter<String> { SimpleListAdapter(Context context)56 public SimpleListAdapter(Context context) { 57 super(context, android.R.layout.simple_list_item_1, DATA_LIST); 58 } 59 60 @Override getView(int position, View convertView, ViewGroup parent)61 public View getView(int position, View convertView, ViewGroup parent) { 62 TextView v = (TextView) super.getView(position, convertView, parent); 63 final Resources r = getContext().getResources(); 64 final DisplayMetrics metrics = r.getDisplayMetrics(); 65 v.setCompoundDrawablePadding((int) (6 * metrics.density + 0.5f)); 66 v.setCompoundDrawablesWithIntrinsicBounds(r.getDrawable(R.drawable.icon), 67 null, null, null); 68 return v; 69 } 70 } 71 72 private static final String[] DATA_LIST = { 73 "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", 74 "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", 75 "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", 76 "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", 77 "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", 78 "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", 79 "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria", 80 "Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde", 81 "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", 82 "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", 83 "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic", 84 "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic", 85 "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", 86 "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland", 87 "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia", 88 "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar", 89 "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", 90 "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary", 91 "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", 92 "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos", 93 "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", 94 "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", 95 "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova", 96 "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", 97 "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", 98 "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas", 99 "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", 100 "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar", 101 "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena", 102 "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon", 103 "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal", 104 "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", 105 "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea", 106 "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", 107 "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas", 108 "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", 109 "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda", 110 "Ukraine", "United Arab Emirates", "United Kingdom", 111 "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", 112 "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara", 113 "Yemen", "Yugoslavia", "Zambia", "Zimbabwe" 114 }; 115 } 116