/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

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