project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LobbyPlayerlistAdapter.java
author koda
Tue, 21 Jan 2014 22:43:06 +0100
changeset 10017 de822cd3df3a
parent 7691 55c0a856ecd0
permissions -rw-r--r--
fixwhitespace and dos2unix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     1
/*
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     3
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     4
 *
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     5
 * This program is free software; you can redistribute it and/or
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     6
 * modify it under the terms of the GNU General Public License
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     8
 * of the License, or (at your option) any later version.
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     9
 *
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    13
 * GNU General Public License for more details.
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    14
 *
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    15
 * You should have received a copy of the GNU General Public License
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    16
 * along with this program; if not, write to the Free Software
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    18
 */
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    19
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
package org.hedgewars.hedgeroid;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
import java.util.Comparator;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
import org.hedgewars.hedgeroid.R;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
import org.hedgewars.hedgeroid.Datastructures.Player;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
import org.hedgewars.hedgeroid.util.ObservableTreeMapAdapter;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
7691
55c0a856ecd0 frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents: 7584
diff changeset
    28
import android.graphics.Color;
55c0a856ecd0 frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents: 7584
diff changeset
    29
import android.graphics.Typeface;
55c0a856ecd0 frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents: 7584
diff changeset
    30
import android.text.Spannable;
55c0a856ecd0 frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents: 7584
diff changeset
    31
import android.text.SpannableString;
55c0a856ecd0 frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents: 7584
diff changeset
    32
import android.text.Spanned;
55c0a856ecd0 frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents: 7584
diff changeset
    33
import android.text.style.ForegroundColorSpan;
55c0a856ecd0 frontlib+Hedgeroid: Added support for the new client flags (chief, admin, reg)
Medo <smaxein@googlemail.com>
parents: 7584
diff changeset
    34
import android.text.style.StyleSpan;
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
import android.view.LayoutInflater;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
import android.view.View;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
import android.view.ViewGroup;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
import android.widget.TextView;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    40
/**
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    41
 * Simple adapter for displaying the list of players in the lobby.
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    42
 */
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
public class LobbyPlayerlistAdapter extends ObservableTreeMapAdapter<String, Player> {
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    44
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    45
    protected Comparator<Player> getEntryOrder() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    46
        return Player.ADMIN_NAME_ORDER;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    47
    }
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    49
    public View getView(int position, View convertView, ViewGroup parent) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    50
        View v = convertView;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    51
        if (v == null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    52
            LayoutInflater vi = LayoutInflater.from(parent.getContext());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    53
            v = vi.inflate(R.layout.listview_player, null);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    54
        }
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    56
        Player player = getItem(position);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    57
        TextView username = (TextView) v.findViewById(android.R.id.text1);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    58
        Spannable spannable = new SpannableString(player.name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    59
        if(player.registered) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    60
            spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    61
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    62
        if(player.admin) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    63
            spannable.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    64
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    65
        username.setText(spannable);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    66
        return v;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7691
diff changeset
    67
    }
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
}