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