• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
onCreate(Bundle savedInstanceState)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                 middleList.setVerticalFadingEdgeEnabled(true);
85                 rightList.setLayerType(View.LAYER_TYPE_SOFTWARE, p2);
86 
87                 moveRight.start();
88                 moveLeft.start();
89                 rotate.start();
90 
91                 ((View) leftList.getParent()).setAlpha(0.5f);
92             }
93         }, 2000);
94     }
95 
setupList(int listId)96     private void setupList(int listId) {
97         final ListView list = (ListView) findViewById(listId);
98         list.setAdapter(new SimpleListAdapter(this));
99     }
100 
101     private static class SimpleListAdapter extends ArrayAdapter<String> {
SimpleListAdapter(Context context)102         public SimpleListAdapter(Context context) {
103             super(context, android.R.layout.simple_list_item_1, DATA_LIST);
104         }
105 
106         @Override
getView(int position, View convertView, ViewGroup parent)107         public View getView(int position, View convertView, ViewGroup parent) {
108             TextView v = (TextView) super.getView(position, convertView, parent);
109             final Resources r = getContext().getResources();
110             final DisplayMetrics metrics = r.getDisplayMetrics();
111             v.setCompoundDrawablePadding((int) (6 * metrics.density + 0.5f));
112             v.setCompoundDrawablesWithIntrinsicBounds(r.getDrawable(R.drawable.icon),
113                     null, null, null);
114             return v;
115         }
116     }
117 
118     private static final String[] DATA_LIST = {
119             "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
120             "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
121             "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
122             "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
123             "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
124             "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
125             "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria",
126             "Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
127             "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
128             "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
129             "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
130             "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
131             "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
132             "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
133             "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia",
134             "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar",
135             "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau",
136             "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary",
137             "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica",
138             "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
139             "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
140             "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
141             "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
142             "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia",
143             "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand",
144             "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas",
145             "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru",
146             "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar",
147             "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
148             "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon",
149             "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
150             "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
151             "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea",
152             "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden",
153             "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas",
154             "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey",
155             "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda",
156             "Ukraine", "United Arab Emirates", "United Kingdom",
157             "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
158             "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara",
159             "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
160     };
161 }
162