PageRenderTime 23ms CodeModel.GetById 11ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Code/src/com/game/ViewData/MapsImageAdapter.java

https://bitbucket.org/DeveloperUX/behaviortree
Java | 88 lines | 55 code | 18 blank | 15 comment | 0 complexity | aecfa9f2afacc8d17b4a5a91eab296ba MD5 | raw file
 1package com.game.ViewData;
 2
 3import com.game.R;
 4import android.content.Context;
 5import android.content.res.TypedArray;
 6import android.view.View;
 7import android.view.ViewGroup;
 8import android.widget.BaseAdapter;
 9import android.widget.Gallery;
10import android.widget.ImageView;
11
12/**
13 * Adapter for the Maps gallery.
14 * 
15 * @author NeoM
16 *
17 */
18
19public class MapsImageAdapter extends BaseAdapter {
20	int galleryItemBackground;
21	private Context context;
22	
23	private static Integer[] imageIDs = {
24        R.drawable.samplemap,
25        R.drawable.map_size800_1
26    };
27	
28	private static Integer[] tilemapIDs = {
29        R.raw.samplemaptilemap,
30        R.raw.map_size800_1tilemap
31	};
32
33	/**
34	 * Initializes the adapter
35	 */
36	public MapsImageAdapter(Context c) {
37		context = c;
38        TypedArray a = c.obtainStyledAttributes(R.styleable.mapsGallery);
39
40        galleryItemBackground = a.getResourceId(
41                R.styleable.mapsGallery_android_galleryItemBackground, 0);
42        a.recycle();
43	}
44	
45	/**
46	 * Returns how many images the gallery has
47	 */
48	@Override
49	public int getCount() {
50		return imageIDs.length;
51	}
52	
53	@Override
54	public Integer getItem(int position) {
55		return imageIDs[position];
56	}
57
58	@Override
59	public long getItemId(int position) {
60		return position;
61	}
62	
63	/**
64	 * Creates, initializes and returns the view of the adapter 
65	 */
66	@Override
67	public View getView(int position, View convertView, ViewGroup parent) {
68		ImageView i = new ImageView(context);
69		
70		i.setImageResource(imageIDs[position]);
71        i.setLayoutParams(new Gallery.LayoutParams(150, 100));
72        i.setScaleType(ImageView.ScaleType.FIT_XY);
73        i.setBackgroundResource(galleryItemBackground);
74
75		
76		return i;
77	}
78	
79	public static int getImageID(int position){
80		return imageIDs[position];
81	}
82	
83	public static int getTilemapID(int position){
84		return tilemapIDs[position];
85	}
86
87}
88