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