project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TextImageAdapter.java
author Wuzzy <almikes@aol.com>
Sat, 30 Sep 2017 23:52:08 +0200
changeset 12627 07fdda8c13a2
parent 10017 de822cd3df3a
permissions -rw-r--r--
TrophyRace: Fix game never eliminating any hogs after a hog skipped or ran out of time Warning: This commit _might_ invalidate past records, but I'm not sure if this is actually the case. Note that only the eliminiation part of the script is touched, not the actual race logic. Even if records are actually broken by this, I and sheepluva have decided that it's more imporant to fix this very, VERY stupid and old bug than to preserve records.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
     1
/*
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6049
diff changeset
     3
 * Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com>
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
     4
 *
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6700
diff changeset
     5
 * This program is free software; you can redistribute it and/or
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6700
diff changeset
     6
 * modify it under the terms of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6700
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6700
diff changeset
     8
 * of the License, or (at your option) any later version.
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
     9
 *
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    13
 * GNU General Public License for more details.
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    14
 *
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6700
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    18
 */
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    19
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    20
package org.hedgewars.hedgeroid;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    21
import java.util.ArrayList;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    22
import java.util.HashMap;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    23
import java.util.Map;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    24
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    25
import android.content.Context;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    26
import android.graphics.Bitmap;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    27
import android.graphics.BitmapFactory;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    28
import android.view.LayoutInflater;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    29
import android.view.View;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    30
import android.view.ViewGroup;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    31
import android.widget.ImageView;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    32
import android.widget.SimpleAdapter;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    33
import android.widget.TextView;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    34
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    35
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    36
public class TextImageAdapter extends SimpleAdapter {
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    37
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    38
    private Context context;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    39
    private ArrayList<Map<String, ?>> data;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    40
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    41
    public TextImageAdapter(Context _context, ArrayList<Map<String, ?>> _data, int resource, String[] from, int[] to) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    42
        super(_context, _data, resource, from, to);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    43
        context = _context;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    44
        data = _data;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    45
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    46
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    47
    public static TextImageAdapter createAdapter(Context c, String[] txt, String[] img, String[] from, int[] to){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    48
        if(txt.length != img.length) throw new IllegalArgumentException("txt and img parameters not equal");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    49
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    50
        ArrayList<Map<String, ?>> data = new ArrayList<Map<String, ?>>(txt.length);
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    51
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    52
        for(int i = 0; i < txt.length; i++){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    53
            HashMap<String, Object> map = new HashMap<String, Object>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    54
            map.put("txt", txt[i]);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    55
            map.put("img", BitmapFactory.decodeFile(img[i]));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    56
            data.add(map);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    57
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    58
        return new TextImageAdapter(c, data, R.layout.spinner_textimg_entry, from, to);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    59
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    60
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    61
    public View getView(int position, View convertView, ViewGroup parent){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    62
        if(convertView == null){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    63
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    64
            convertView = inflater.inflate(R.layout.spinner_textimg_entry, parent);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    65
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    66
        TextView tv = (TextView) convertView.findViewById(R.id.spinner_txt);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    67
        ImageView img = (ImageView) convertView.findViewById(R.id.spinner_img);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    68
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    69
        tv.setText((String)data.get(position).get("txt"));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    70
        img.setImageBitmap((Bitmap)data.get(position).get("img"));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    71
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    72
        return convertView;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    73
    }
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    74
}