1 /* 2 * Copyright (C) 2008 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 android.widget.cts; 18 19 import com.android.cts.stub.R; 20 21 import android.app.Activity; 22 import android.content.Context; 23 import android.os.Bundle; 24 import android.view.View; 25 import android.view.ViewGroup; 26 import android.widget.BaseAdapter; 27 import android.widget.Gallery; 28 import android.widget.ImageView; 29 30 /** 31 * A minimal application for {@link Gallery} test. 32 */ 33 public class GalleryStubActivity extends Activity { 34 @Override onCreate(Bundle savedInstanceState)35 public void onCreate(Bundle savedInstanceState) { 36 super.onCreate(savedInstanceState); 37 setContentView(R.layout.gallery_test); 38 39 Gallery gallery = (Gallery) findViewById(R.id.gallery_test); 40 ImageAdapter adapter = new ImageAdapter(this); 41 gallery.setAdapter(adapter); 42 } 43 44 private static class ImageAdapter extends BaseAdapter { ImageAdapter(Context c)45 public ImageAdapter(Context c) { 46 mContext = c; 47 } 48 getCount()49 public int getCount() { 50 return mImageIds.length; 51 } 52 getItem(int position)53 public Object getItem(int position) { 54 return position; 55 } 56 getItemId(int position)57 public long getItemId(int position) { 58 return position; 59 } 60 getView(int position, View convertView, ViewGroup parent)61 public View getView(int position, View convertView, ViewGroup parent) { 62 ImageView i = new ImageView(mContext); 63 64 i.setImageResource(mImageIds[position]); 65 i.setScaleType(ImageView.ScaleType.FIT_XY); 66 // let the item's width be 136, height be 88 67 i.setLayoutParams(new Gallery.LayoutParams(136, 88)); 68 69 return i; 70 } 71 72 private Context mContext; 73 74 private Integer[] mImageIds = { 75 R.drawable.faces, 76 R.drawable.scenery, 77 R.drawable.testimage, 78 R.drawable.faces, 79 R.drawable.scenery, 80 R.drawable.testimage, 81 R.drawable.faces, 82 R.drawable.scenery, 83 R.drawable.testimage, 84 }; 85 } 86 } 87