project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomPlayerlistAdapter.java
author Wuzzy <Wuzzy2@mail.ru>
Fri, 12 Oct 2018 03:40:21 +0200
changeset 13881 99b265e0d1d0
parent 10017 de822cd3df3a
permissions -rw-r--r--
Drop internal PhysFS, bump PhysFS requirement to 3.0.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     1
/*
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     3
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     4
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
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: 7508
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: 7508
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: 7508
diff changeset
     8
 * of the License, or (at your option) any later version.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     9
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    13
 * GNU General Public License for more details.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    14
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    15
 * You should have received a copy 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: 7508
diff changeset
    16
 * along with this program; if not, write to the Free Software
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    18
 */
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    19
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    20
package org.hedgewars.hedgeroid;
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
import java.util.Comparator;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
import org.hedgewars.hedgeroid.R;
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    25
import org.hedgewars.hedgeroid.Datastructures.PlayerInRoom;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    26
import org.hedgewars.hedgeroid.util.ObservableTreeMapAdapter;
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
import android.view.LayoutInflater;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
import android.view.View;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
import android.view.ViewGroup;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
import android.widget.TextView;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
public class RoomPlayerlistAdapter extends ObservableTreeMapAdapter<String, PlayerInRoom> {
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    34
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    35
    protected Comparator<PlayerInRoom> getEntryOrder() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    36
        return AlphabeticalOrderComparator.INSTANCE;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    37
    }
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    39
    public View getView(int position, View convertView, ViewGroup parent) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    40
        View v = convertView;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    41
        if (v == null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    42
            LayoutInflater vi = LayoutInflater.from(parent.getContext());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    43
            v = vi.inflate(R.layout.listview_player, null);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    44
        }
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    46
        PlayerInRoom player = getItem(position);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    47
        TextView username = (TextView) v.findViewById(android.R.id.text1);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    48
        username.setText(player.player.name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    49
        int readyDrawable = player.ready ? R.drawable.lightbulb_on : R.drawable.lightbulb_off;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    50
        username.setCompoundDrawablesWithIntrinsicBounds(readyDrawable, 0, 0, 0);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    51
        return v;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    52
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    53
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    54
    private static final class AlphabeticalOrderComparator implements Comparator<PlayerInRoom> {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    55
        public static final AlphabeticalOrderComparator INSTANCE = new AlphabeticalOrderComparator();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    56
        public int compare(PlayerInRoom lhs, PlayerInRoom rhs) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    57
            return lhs.player.name.compareToIgnoreCase(rhs.player.name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    58
        };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    59
    }
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
}