|
1 /* |
|
2 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation; version 2 of the License |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 */ |
|
18 |
|
19 |
|
20 package org.hedgewars.hedgeroid; |
|
21 import java.util.ArrayList; |
|
22 import java.util.HashMap; |
|
23 import java.util.Map; |
|
24 |
|
25 import org.hedgewars.mobile.R; |
|
26 |
|
27 import android.content.Context; |
|
28 import android.graphics.Bitmap; |
|
29 import android.graphics.BitmapFactory; |
|
30 import android.view.LayoutInflater; |
|
31 import android.view.View; |
|
32 import android.view.ViewGroup; |
|
33 import android.widget.ImageView; |
|
34 import android.widget.SimpleAdapter; |
|
35 import android.widget.TextView; |
|
36 |
|
37 |
|
38 public class TextImageAdapter extends SimpleAdapter { |
|
39 |
|
40 private Context context; |
|
41 private ArrayList<Map<String, ?>> data; |
|
42 |
|
43 public TextImageAdapter(Context _context, ArrayList<Map<String, ?>> _data, int resource, String[] from, int[] to) { |
|
44 super(_context, _data, resource, from, to); |
|
45 context = _context; |
|
46 data = _data; |
|
47 } |
|
48 |
|
49 public static TextImageAdapter createAdapter(Context c, String[] txt, String[] img, String[] from, int[] to){ |
|
50 if(txt.length != img.length) throw new IllegalArgumentException("txt and img parameters not equal"); |
|
51 |
|
52 ArrayList<Map<String, ?>> data = new ArrayList<Map<String, ?>>(txt.length); |
|
53 |
|
54 for(int i = 0; i < txt.length; i++){ |
|
55 HashMap<String, Object> map = new HashMap<String, Object>(); |
|
56 map.put("txt", txt[i]); |
|
57 map.put("img", BitmapFactory.decodeFile(img[i])); |
|
58 data.add(map); |
|
59 } |
|
60 return new TextImageAdapter(c, data, R.layout.spinner_textimg_entry, from, to); |
|
61 } |
|
62 |
|
63 public View getView(int position, View convertView, ViewGroup parent){ |
|
64 if(convertView == null){ |
|
65 LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
66 convertView = inflater.inflate(R.layout.spinner_textimg_entry, parent); |
|
67 } |
|
68 TextView tv = (TextView) convertView.findViewById(R.id.spinner_txt); |
|
69 ImageView img = (ImageView) convertView.findViewById(R.id.spinner_img); |
|
70 |
|
71 tv.setText((String)data.get(position).get("txt")); |
|
72 img.setImageBitmap((Bitmap)data.get(position).get("img")); |
|
73 |
|
74 return convertView; |
|
75 } |
|
76 } |