1 /* 2 * Copyright (C) 2010 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.graphics.drawable.Drawable; 21 import android.os.Bundle; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 import android.widget.ArrayAdapter; 26 import android.widget.ImageView; 27 import android.widget.StackView; 28 import android.widget.TextView; 29 30 @SuppressWarnings({"UnusedDeclaration"}) 31 public class StackActivity extends Activity { 32 @Override onCreate(Bundle savedInstanceState)33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 36 setContentView(R.layout.stack); 37 38 StackView stack = findViewById(R.id.stack_view); 39 stack.setAdapter(new ArrayAdapter<Drawable>(this, android.R.layout.simple_list_item_1, 40 android.R.id.text1, new Drawable[] { 41 getResources().getDrawable(R.drawable.sunset1), 42 getResources().getDrawable(R.drawable.sunset2), 43 }) { 44 @Override 45 public View getView(int position, View convertView, ViewGroup parent) { 46 View item = convertView; 47 if (item == null) { 48 item = LayoutInflater.from(getContext()).inflate( 49 R.layout.stack_item, null, false); 50 } 51 ((ImageView) item.findViewById(R.id.textview_icon)).setImageDrawable( 52 getItem(position % getCount())); 53 ((TextView) item.findViewById(R.id.mini_text)).setText("" + position); 54 return item; 55 } 56 }); 57 stack.setDisplayedChild(0); 58 } 59 } 60