1 /*
2  * Copyright (C) 2007 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.example.android.apis.view;
18 
19 import com.example.android.apis.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.GridView;
28 import android.widget.ImageView;
29 
30 /**
31  * A grid that displays a set of framed photos.
32  *
33  */
34 public class Grid2 extends Activity {
35 
36     @Override
onCreate(Bundle savedInstanceState)37     public void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39 
40         setContentView(R.layout.grid_2);
41 
42         GridView g = (GridView) findViewById(R.id.myGrid);
43         g.setAdapter(new ImageAdapter(this));
44     }
45 
46     public class ImageAdapter extends BaseAdapter {
ImageAdapter(Context c)47         public ImageAdapter(Context c) {
48             mContext = c;
49         }
50 
getCount()51         public int getCount() {
52             return mThumbIds.length;
53         }
54 
getItem(int position)55         public Object getItem(int position) {
56             return position;
57         }
58 
getItemId(int position)59         public long getItemId(int position) {
60             return position;
61         }
62 
getView(int position, View convertView, ViewGroup parent)63         public View getView(int position, View convertView, ViewGroup parent) {
64             ImageView imageView;
65             if (convertView == null) {
66                 imageView = new ImageView(mContext);
67                 imageView.setLayoutParams(new GridView.LayoutParams(45, 45));
68                 imageView.setAdjustViewBounds(false);
69                 imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
70                 imageView.setPadding(8, 8, 8, 8);
71             } else {
72                 imageView = (ImageView) convertView;
73             }
74 
75             imageView.setImageResource(mThumbIds[position]);
76 
77             return imageView;
78         }
79 
80         private Context mContext;
81 
82         private Integer[] mThumbIds = {
83                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
84                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
85                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
86                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
87                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
88                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
89                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
90                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
91                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
92                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
93                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
94                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
95                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
96                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
97                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
98                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
99                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
100                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
101                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
102                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
103                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
104                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
105                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
106                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
107                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
108                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
109                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
110                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
111                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
112                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
113                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
114                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
115                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
116                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
117                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
118                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
119                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
120                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
121                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
122                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
123                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
124                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
125                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
126                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
127                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
128                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
129                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
130                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
131                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
132                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
133                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
134                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
135                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
136                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
137                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
138                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
139                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
140                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
141                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
142                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
143                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
144                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
145                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
146                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
147                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
148                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
149                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
150                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
151                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
152                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
153                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
154                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
155                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
156                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
157                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
158                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
159                 R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
160                 R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
161                 R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
162                 R.drawable.sample_thumb_6, R.drawable.sample_thumb_7,
163         };
164     }
165 
166 }
167