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