--- a/project_files/Android-build/SDL-android-project/AndroidManifest.xml Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/AndroidManifest.xml Sat Jul 21 14:56:52 2012 +0200
@@ -24,7 +24,6 @@
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
-
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@@ -69,7 +68,7 @@
android:windowSoftInputMode="stateUnchanged" >
</activity>
<activity
- android:name=".netplay.TestActivity"
+ android:name=".netplay.LobbyActivity"
android:label="@string/title_activity_lobby" >
</activity>
</application>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/res/layout-large/activity_lobby.xml Sat Jul 21 14:56:52 2012 +0200
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <include layout="@layout/background"/>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:padding="5dp" >
+
+ <FrameLayout
+ android:layout_width="fill_parent"
+ android:layout_height="0dp"
+ android:layout_marginBottom="10dp"
+ android:layout_weight="0.4"
+ android:background="@drawable/box" >
+
+ <fragment
+ android:id="@+id/roomListFragment"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ class="org.hedgewars.hedgeroid.netplay.RoomlistFragment"
+ tools:layout="@layout/lobby_rooms_fragment" />
+ </FrameLayout>
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="0dp"
+ android:layout_weight="0.6"
+ android:baselineAligned="false"
+ android:orientation="horizontal" >
+
+ <FrameLayout
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"
+ android:layout_marginRight="10dp"
+ android:layout_weight="0.7"
+ android:background="@drawable/box" >
+
+ <fragment
+ android:id="@+id/chatFragment"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ class="org.hedgewars.hedgeroid.netplay.LobbyChatFragment"
+ tools:layout="@layout/lobby_chat_fragment" />
+ </FrameLayout>
+
+ <FrameLayout
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"
+ android:layout_weight="0.3"
+ android:background="@drawable/box" >
+
+ <fragment
+ android:id="@+id/playerListFragment"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ class="org.hedgewars.hedgeroid.netplay.PlayerlistFragment"
+ tools:layout="@layout/lobby_players_fragment" />
+ </FrameLayout>
+ </LinearLayout>
+
+ </LinearLayout>
+</FrameLayout>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/res/layout-large/listview_room.xml Sat Jul 21 14:56:52 2012 +0200
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="20dp" >
+
+<TextView
+ android:id="@+id/roomname"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_weight="1.5"
+ android:padding="3dp"
+ android:drawablePadding="5dp"
+ android:gravity="left|center_vertical"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"/>
+
+<include layout="@layout/roomlist_player_team_count" />
+
+<TextView
+ android:id="@+id/owner"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.5"
+ android:padding="3dp"
+ android:gravity="left"
+ android:layout_gravity="center_vertical"
+ android:singleLine="true"/>
+
+<TextView
+ android:id="@+id/map"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.5"
+ android:padding="3dp"
+ android:gravity="left"
+ android:layout_gravity="center_vertical"
+ android:singleLine="true"/>
+
+<TextView
+ android:id="@+id/scheme"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.5"
+ android:padding="3dp"
+ android:gravity="left"
+ android:layout_gravity="center_vertical"
+ android:singleLine="true"/>
+
+<TextView
+ android:id="@+id/weapons"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.5"
+ android:padding="3dp"
+ android:gravity="left"
+ android:layout_gravity="center_vertical"
+ android:singleLine="true"/>
+
+</LinearLayout>
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/res/layout-large/lobby_rooms_fragment.xml Sat Jul 21 14:56:52 2012 +0200
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <FrameLayout
+ android:id="@+id/listHeader"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" >
+ <include layout="@layout/listview_room_header" />
+ </FrameLayout>
+
+ <ListView
+ android:id="@id/android:list"
+ android:layout_width="fill_parent"
+ android:layout_height="0dp"
+ android:layout_alignParentBottom="true"
+ android:layout_below="@+id/listHeader"
+ android:cacheColorHint="@android:color/transparent"
+ android:drawSelectorOnTop="false"
+ tools:listitem="@layout/listview_room" />
+
+ <TextView
+ android:id="@id/android:empty"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_centerVertical="true"
+ android:text="@string/no_rooms_in_list" />
+
+</RelativeLayout>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/res/layout-xlarge/roomlist_player_team_count.xml Sat Jul 21 14:56:52 2012 +0200
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<merge xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools">
+
+ <TextView
+ android:id="@+id/playercount"
+ android:layout_width="20dp"
+ android:layout_height="wrap_content"
+ android:padding="3dp"
+ android:gravity="center"
+ android:layout_gravity="center_vertical"
+ android:singleLine="true"/>
+
+ <TextView
+ android:id="@+id/teamcount"
+ android:layout_width="20dp"
+ android:layout_height="wrap_content"
+ android:padding="3dp"
+ android:gravity="center"
+ android:layout_gravity="center_vertical"
+ android:singleLine="true"/>
+</merge>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/res/layout-xlarge/roomlist_player_team_count_header.xml Sat Jul 21 14:56:52 2012 +0200
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<merge xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools">
+
+ <TextView
+ android:id="@+id/playercount"
+ android:layout_width="20dp"
+ android:layout_height="wrap_content"
+ android:padding="3dp"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/roomlist_header_clients"/>
+
+ <TextView
+ android:id="@+id/teamcount"
+ android:layout_width="20dp"
+ android:layout_height="wrap_content"
+ android:padding="3dp"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/roomlist_header_teams" />
+</merge>
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/res/layout/activity_lobby.xml Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/res/layout/activity_lobby.xml Sat Jul 21 14:56:52 2012 +0200
@@ -4,65 +4,33 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/background"/>
-
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
+ <TabHost
+ android:id="@android:id/tabhost"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:padding="5dp" >
-
- <FrameLayout
- android:layout_width="fill_parent"
- android:layout_height="0dp"
- android:layout_marginBottom="10dp"
- android:layout_weight="0.3"
- android:background="@drawable/box" >
-
- <fragment
- android:id="@+id/roomListFragment"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- class="org.hedgewars.hedgeroid.netplay.RoomlistFragment"
- tools:layout="@layout/lobby_rooms_fragment" />
- </FrameLayout>
-
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="0dp"
- android:layout_weight="0.7"
- android:baselineAligned="false"
- android:orientation="horizontal" >
-
- <FrameLayout
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_marginRight="10dp"
- android:layout_weight="0.7"
- android:background="@drawable/box" >
-
- <fragment
- android:id="@+id/chatFragment"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- class="org.hedgewars.hedgeroid.netplay.LobbyChatFragment"
- tools:layout="@layout/lobby_chat_fragment" />
- </FrameLayout>
-
- <FrameLayout
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="0.3"
- android:background="@drawable/box" >
-
- <fragment
- android:id="@+id/playerListFragment"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- class="org.hedgewars.hedgeroid.netplay.PlayerlistFragment"
- tools:layout="@layout/lobby_players_fragment" />
- </FrameLayout>
- </LinearLayout>
-
- </LinearLayout>
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <TabWidget
+ android:id="@android:id/tabs"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <FrameLayout
+ android:id="@android:id/tabcontent"
+ android:layout_width="0dp"
+ android:layout_height="0dp"/>
+
+ <android.support.v4.view.ViewPager
+ android:id="@+id/pager"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"/>
+
+ </LinearLayout>
+</TabHost>
</FrameLayout>
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/res/layout/activity_lobby_paged.xml Thu Jul 19 22:55:36 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
-
- <android.support.v4.view.ViewPager
- android:id="@+id/pager"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:padding="5dp" />
-</LinearLayout>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/res/layout/listview_room.xml Sat Jul 21 14:56:52 2012 +0200
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:mode="twoLine">
+
+ <TextView
+ android:id="@android:id/text1"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:drawablePadding="5dp"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <TextView
+ android:id="@android:id/text2"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignLeft="@android:id/text1"
+ android:layout_below="@android:id/text1"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+</TwoLineListItem>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/res/layout/listview_room_header.xml Sat Jul 21 14:56:52 2012 +0200
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" >
+
+<TextView
+ android:id="@+id/roomname"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_weight="1.5"
+ android:padding="3dp"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/roomlist_header_roomname" />
+
+<include layout="@layout/roomlist_player_team_count_header" />
+
+<TextView
+ android:id="@+id/owner"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.5"
+ android:padding="3dp"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/roomlist_header_owner" />
+
+<TextView
+ android:id="@+id/map"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.5"
+ android:padding="3dp"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/roomlist_header_map" />
+
+<TextView
+ android:id="@+id/scheme"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.5"
+ android:padding="3dp"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/roomlist_header_scheme" />
+
+<TextView
+ android:id="@+id/weapons"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.5"
+ android:padding="3dp"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/roomlist_header_weapons" />
+
+</LinearLayout>
+
+
--- a/project_files/Android-build/SDL-android-project/res/layout/lobby_chat_fragment.xml Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/res/layout/lobby_chat_fragment.xml Sat Jul 21 14:56:52 2012 +0200
@@ -11,7 +11,11 @@
android:layout_height="0dp"
android:layout_weight="1"
android:clickable="false"
+ android:cacheColorHint="@android:color/transparent"
android:transcriptMode="normal"
+ android:focusableInTouchMode="false"
+ android:focusable="false"
+ android:longClickable="false"
android:stackFromBottom="true"
/>
--- a/project_files/Android-build/SDL-android-project/res/layout/lobby_players_fragment.xml Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/res/layout/lobby_players_fragment.xml Sat Jul 21 14:56:52 2012 +0200
@@ -3,21 +3,21 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical"
- android:paddingLeft="8dp"
- android:paddingRight="8dp" >
+ android:orientation="vertical" >
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
+ android:cacheColorHint="@android:color/transparent"
tools:listitem="@android:layout/simple_list_item_1" />
<TextView
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ android:gravity="center"
android:text="@string/no_players_in_list" />
</LinearLayout>
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/res/layout/lobby_rooms_fragment.xml Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/res/layout/lobby_rooms_fragment.xml Sat Jul 21 14:56:52 2012 +0200
@@ -12,7 +12,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
- tools:listitem="@android:layout/simple_list_item_2" />
+ android:cacheColorHint="@android:color/transparent"
+ tools:listitem="@layout/listview_room" />
<TextView
android:id="@id/android:empty"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/res/layout/roomlist_player_team_count.xml Sat Jul 21 14:56:52 2012 +0200
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<merge xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools">
+</merge>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/Android-build/SDL-android-project/res/layout/roomlist_player_team_count_header.xml Sat Jul 21 14:56:52 2012 +0200
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<merge xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools">
+</merge>
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/res/values/strings.xml Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/res/values/strings.xml Sat Jul 21 14:56:52 2012 +0200
@@ -57,7 +57,7 @@
<string name="bot2">Level 2</string>
<string name="bot1">Level 1</string>
- <string name="title_activity_lobby">LobbyActivity</string>
+ <string name="title_activity_lobby">Hedgewars Server Lobby</string>
<string name="chat_hint">Type here to chat</string>
<!-- Room list -->
@@ -67,10 +67,17 @@
<string name="no_players_in_list">No players</string>
<!-- Roomlist -->
+ <string name="roomlist_header_roomname">Room Name</string>
+ <string name="roomlist_header_clients">C</string>
+ <string name="roomlist_header_teams">T</string>
+ <string name="roomlist_header_owner">Owner</string>
+ <string name="roomlist_header_map">Map</string>
+ <string name="roomlist_header_scheme">Rules</string>
+ <string name="roomlist_header_weapons">Ammo</string>
+
<string name="roomlist_owner">by %1$s</string>
- <string name="roomlist_map">map: %1$s</string>
- <string name="roomlist_scheme">scheme: %1$s</string>
- <string name="roomlist_weapons">weapons: %1$s</string>
+ <string name="roomlist_map">Map: %1$s</string>
+ <string name="roomlist_scheme">Scheme: %1$s</string>
<string name="map_regular">Random map</string>
<string name="map_maze">Random maze</string>
<string name="map_drawn">Drawn map</string>
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java Sat Jul 21 14:56:52 2012 +0200
@@ -25,18 +25,14 @@
import org.hedgewars.hedgeroid.Downloader.DownloadAssets;
import org.hedgewars.hedgeroid.Downloader.DownloadListActivity;
import org.hedgewars.hedgeroid.netplay.LobbyActivity;
-import org.hedgewars.hedgeroid.netplay.TestActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
-import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@@ -58,7 +54,7 @@
startGame.setOnClickListener(startGameClicker);
joinLobby.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
- startActivity(new Intent(getApplicationContext(), TestActivity.class));
+ startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
}
});
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ChatlogAdapter.java Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ChatlogAdapter.java Sat Jul 21 14:56:52 2012 +0200
@@ -8,7 +8,6 @@
import android.content.Context;
import android.text.method.LinkMovementMethod;
-import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
@@ -16,11 +15,15 @@
import android.widget.TextView;
/**
- * A simple TextView that remembers its contents to avoid having to
- * re-layout them.
+ * Optimization: ListView is smart enough to try re-using the same view for an item
+ * with the same ID, but it still calls getView for those items when the list changes.
+ * Since lines with a given ID never change in our chatlog, we can avoid the effort
+ * of TextView.setText in many cases by checking if the view is already set up for the
+ * line with the right ID - but to do that, the view needs to remember the ID it's
+ * holding the text for. That's what the LoglineView does.
*/
class LoglineView extends TextView {
- CharSequence chatlogAdapterText;
+ long chatlogId = -1;
public LoglineView(Context context) {
super(context);
@@ -77,15 +80,15 @@
public View getView(int position, View convertView, ViewGroup parent) {
LoglineView v = (LoglineView)convertView;
- CharSequence line = log.get(position);
if (v == null) {
v = new LoglineView(context);
v.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
v.setMovementMethod(LinkMovementMethod.getInstance());
}
- if(line != v.chatlogAdapterText) {
- v.setText(line);
- v.chatlogAdapterText = line;
+ long id = getItemId(position);
+ if(id != v.chatlogId) {
+ v.setText(log.get(position));
+ v.chatlogId = id;
}
return v;
}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyActivity.java Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyActivity.java Sat Jul 21 14:56:52 2012 +0200
@@ -1,133 +1,185 @@
package org.hedgewars.hedgeroid.netplay;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.Collections;
+import java.util.ArrayList;
import org.hedgewars.hedgeroid.R;
-import org.hedgewars.hedgeroid.Utils;
-import org.hedgewars.hedgeroid.R.layout;
-import com.sun.jna.Library;
-import com.sun.jna.Native;
-import com.sun.jna.Pointer;
-
+import android.content.Context;
import android.os.Bundle;
-import android.os.CountDownTimer;
-import android.app.Activity;
+import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
-import android.text.Html;
-import android.util.Log;
-import android.view.KeyEvent;
+import android.support.v4.app.FragmentPagerAdapter;
+import android.support.v4.view.ViewPager;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.inputmethod.EditorInfo;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.TextView;
-import android.widget.TextView.OnEditorActionListener;
+import android.view.ViewGroup;
+import android.widget.TabHost;
+import android.widget.TabWidget;
public class LobbyActivity extends FragmentActivity {
- static {
- System.loadLibrary("SDL_net");
- }
- static final JnaFrontlib FRONTLIB = (JnaFrontlib)Native.loadLibrary("frontlib", JnaFrontlib.class, Collections.singletonMap(Library.OPTION_TYPE_MAPPER, FrontlibTypeMapper.INSTANCE));
+ TabHost mTabHost;
+ ViewPager mViewPager;
+ TabsAdapter mTabsAdapter;
- TextView textView;
- EditText editText;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.activity_lobby);
+ mTabHost = (TabHost)findViewById(android.R.id.tabhost);
+ if(mTabHost != null) {
+ mTabHost.setup();
+
+ mViewPager = (ViewPager)findViewById(R.id.pager);
+
+ mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);
- boolean disconnected;
- JnaFrontlib.NetconnPtr netconn;
- CountDownTimer timer;
+ mTabsAdapter.addTab(mTabHost.newTabSpec("roomlist").setIndicator("Rooms"),
+ RoomlistFragment.class, null);
+ mTabsAdapter.addTab(mTabHost.newTabSpec("chat").setIndicator("Chat"),
+ LobbyChatFragment.class, null);
+ mTabsAdapter.addTab(mTabHost.newTabSpec("players").setIndicator("Players"),
+ PlayerlistFragment.class, null);
- private void commitText() {
- if(!disconnected && netconn!=null) {
- String text = editText.getText().toString();
- editText.setText("");
- textView.append(Html.fromHtml("<b>AndroidChatter</b>: " + text + "<br/>"));
- FRONTLIB.flib_netconn_send_chat(netconn, text);
+ if (savedInstanceState != null) {
+ mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
+ }
+ }
+ }
+
+ /*@Override
+ protected void onCreate(Bundle arg0) {
+ super.onCreate(arg0);
+ setContentView(R.layout.activity_lobby);
+ ViewPager pager = (ViewPager)findViewById(R.id.pager);
+ if(pager != null) {
+ pager.setAdapter(new Adapter(getSupportFragmentManager()));
}
}
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- disconnected = false;
- setContentView(R.layout.activity_lobby);
- textView = (TextView)findViewById(R.id.lobbyConsole);
- editText = (EditText)findViewById(R.id.lobbyChatInput);
-
- editText.setOnEditorActionListener(new OnEditorActionListener() {
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- boolean handled = false;
- if(actionId == EditorInfo.IME_ACTION_SEND) {
- commitText();
- handled = true;
- }
- return handled;
- }
- });
-
- FRONTLIB.flib_init();
- try {
- JnaFrontlib.MetaschemePtr scheme = FRONTLIB.flib_metascheme_from_ini(new File(Utils.getDataPathFile(this), "metasettings.ini").getAbsolutePath());
- netconn = FRONTLIB.flib_netconn_create("AndroidChatter", scheme, Utils.getDataPathFile(this).getAbsolutePath(), "140.247.62.101", 46631);
- Log.d("Netconn", "netconn is "+netconn);
- FRONTLIB.flib_metascheme_release(scheme);
- } catch (FileNotFoundException e) {
- throw new RuntimeException(e);
+ private static class Adapter extends FragmentPagerAdapter {
+ public Adapter(FragmentManager mgr) {
+ super(mgr);
+ }
+
+ @Override
+ public int getCount() {
+ return 3;
}
-
- FRONTLIB.flib_netconn_onConnected(netconn, handleNetConnected, null);
- FRONTLIB.flib_netconn_onDisconnected(netconn, handleNetDisconnect, null);
- FRONTLIB.flib_netconn_onChat(netconn, handleChat, null);
- FRONTLIB.flib_netconn_onMessage(netconn, handleMessage, null);
- timer = new CountDownTimer(100000000, 100) {
- @Override
- public void onTick(long millisUntilFinished) {
- if(!disconnected) {
- FRONTLIB.flib_netconn_tick(netconn);
- }
+
+ @Override
+ public Fragment getItem(int arg0) {
+ switch(arg0) {
+ case 0: return new RoomlistFragment();
+ case 1: return new LobbyChatFragment();
+ case 2: return new PlayerlistFragment();
+ default: throw new IndexOutOfBoundsException();
}
-
- @Override
- public void onFinish() {
- }
- };
- timer.start();
- }
-
+ }
+ }*/
+
@Override
- protected void onPause() {
- super.onPause();
- FRONTLIB.flib_netconn_send_quit(netconn, "Activity paused");
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ if(mTabHost != null) {
+ outState.putString("tab", mTabHost.getCurrentTabTag());
+ }
}
-
- private JnaFrontlib.VoidCallback handleNetConnected = new JnaFrontlib.VoidCallback() {
- public void callback(Pointer context) {
- textView.append("Connected. You can chat now.\n");
- }
- };
- private JnaFrontlib.IntStrCallback handleNetDisconnect = new JnaFrontlib.IntStrCallback() {
- public void callback(Pointer context, int arg1, String arg2) {
- disconnected = true;
- timer.cancel();
- FRONTLIB.flib_netconn_destroy(netconn);
- netconn.setPointer(Pointer.NULL);
- textView.append("You have been disconnected.");
- }
- };
-
- private JnaFrontlib.StrStrCallback handleChat = new JnaFrontlib.StrStrCallback() {
- public void callback(Pointer context, String arg1, String arg2) {
- textView.append(arg1+": "+arg2+"\n");
- }
- };
-
- private JnaFrontlib.IntStrCallback handleMessage = new JnaFrontlib.IntStrCallback() {
- public void callback(Pointer context, int arg1, String arg2) {
- textView.append(Html.fromHtml(arg2+"<br/>"));
- }
- };
+ /**
+ * This is a helper class that implements the management of tabs and all
+ * details of connecting a ViewPager with associated TabHost. It relies on a
+ * trick. Normally a tab host has a simple API for supplying a View or
+ * Intent that each tab will show. This is not sufficient for switching
+ * between pages. So instead we make the content part of the tab host
+ * 0dp high (it is not shown) and the TabsAdapter supplies its own dummy
+ * view to show as the tab content. It listens to changes in tabs, and takes
+ * care of switch to the correct paged in the ViewPager whenever the selected
+ * tab changes.
+ */
+ public static class TabsAdapter extends FragmentPagerAdapter
+ implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener {
+ private final Context mContext;
+ private final TabHost mTabHost;
+ private final ViewPager mViewPager;
+ private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
+
+ static final class TabInfo {
+ private final Class<?> clss;
+ private final Bundle args;
+
+ TabInfo(Class<?> _class, Bundle _args) {
+ clss = _class;
+ args = _args;
+ }
+ }
+
+ static class DummyTabFactory implements TabHost.TabContentFactory {
+ private final Context mContext;
+
+ public DummyTabFactory(Context context) {
+ mContext = context;
+ }
+
+ public View createTabContent(String tag) {
+ View v = new View(mContext);
+ v.setMinimumWidth(0);
+ v.setMinimumHeight(0);
+ return v;
+ }
+ }
+
+ public TabsAdapter(FragmentActivity activity, TabHost tabHost, ViewPager pager) {
+ super(activity.getSupportFragmentManager());
+ mContext = activity;
+ mTabHost = tabHost;
+ mViewPager = pager;
+ mTabHost.setOnTabChangedListener(this);
+ mViewPager.setAdapter(this);
+ mViewPager.setOnPageChangeListener(this);
+ }
+
+ public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
+ tabSpec.setContent(new DummyTabFactory(mContext));
+
+ TabInfo info = new TabInfo(clss, args);
+ mTabs.add(info);
+ mTabHost.addTab(tabSpec);
+ notifyDataSetChanged();
+ }
+
+ @Override
+ public int getCount() {
+ return mTabs.size();
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ TabInfo info = mTabs.get(position);
+ return Fragment.instantiate(mContext, info.clss.getName(), info.args);
+ }
+
+ public void onTabChanged(String tabId) {
+ int position = mTabHost.getCurrentTab();
+ mViewPager.setCurrentItem(position);
+ }
+
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+ }
+
+ public void onPageSelected(int position) {
+ // Unfortunately when TabHost changes the current tab, it kindly
+ // also takes care of putting focus on it when not in touch mode.
+ // The jerk.
+ // This hack tries to prevent this from pulling focus out of our
+ // ViewPager.
+ TabWidget widget = mTabHost.getTabWidget();
+ int oldFocusability = widget.getDescendantFocusability();
+ widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
+ mTabHost.setCurrentTab(position);
+ widget.setDescendantFocusability(oldFocusability);
+ }
+
+ public void onPageScrollStateChanged(int state) {
+ }
+ }
}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyChatFragment.java Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyChatFragment.java Sat Jul 21 14:56:52 2012 +0200
@@ -17,8 +17,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
-import android.widget.AbsListView;
-import android.widget.AbsListView.OnScrollListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Netconn.java Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Netconn.java Sat Jul 21 14:56:52 2012 +0200
@@ -99,6 +99,13 @@
}
};
+ private IntStrCallback disconnectCb = new IntStrCallback() {
+ public void callback(Pointer context, int arg1, String arg2) {
+ FLIB.flib_netconn_destroy(conn);
+ conn = null;
+ }
+ };
+
/**
* Connect to the official Hedgewars server.
*
@@ -142,6 +149,7 @@
FLIB.flib_netconn_onRoomDelete(conn, roomDeleteCb, null);
FLIB.flib_netconn_onConnected(conn, connectedCb, null);
FLIB.flib_netconn_onRoomlist(conn, roomlistCb, null);
+ FLIB.flib_netconn_onDisconnected(conn, disconnectCb, null);
} finally {
FLIB.flib_metascheme_release(meta);
}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/NetplayService.java Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/NetplayService.java Sat Jul 21 14:56:52 2012 +0200
@@ -7,6 +7,7 @@
import android.os.Binder;
import android.os.CountDownTimer;
import android.os.IBinder;
+import android.util.Log;
public class NetplayService extends Service {
private final NetplayBinder binder = new NetplayBinder();
@@ -20,6 +21,7 @@
@Override
public void onCreate() {
+ Log.d("NetplayService", "Creating");
if(Flib.INSTANCE.flib_init() != 0) {
throw new RuntimeException("Unable to start frontlib");
}
@@ -32,7 +34,7 @@
timer = new CountDownTimer(Long.MAX_VALUE, 50) {
@Override
public void onTick(long millisUntilFinished) {
- if(netconn != null) {
+ if(netconn != null && netconn.isConnected()) {
netconn.tick();
}
}
@@ -46,6 +48,7 @@
@Override
public void onDestroy() {
+ Log.d("NetplayService", "Destroying");
timer.cancel();
netconn.disconnect();
Flib.INSTANCE.flib_quit();
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomListAdapter.java Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomListAdapter.java Sat Jul 21 14:56:52 2012 +0200
@@ -11,10 +11,6 @@
import android.content.Context;
import android.content.res.Resources;
-import android.text.Layout.Alignment;
-import android.text.SpannableStringBuilder;
-import android.text.Spanned;
-import android.text.style.AlignmentSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -51,38 +47,56 @@
notifyDataSetChanged();
}
- private static Spanned formatExtra(Resources res, Room room) {
+ private static CharSequence formatExtra(Resources res, Room room) {
String ownermsg = res.getString(R.string.roomlist_owner, room.owner);
String mapmsg = res.getString(R.string.roomlist_map, Room.formatMapName(res, room.map));
- String schememsg = res.getString(R.string.roomlist_scheme, room.scheme);
- String weaponsmsg = res.getString(R.string.roomlist_weapons, room.weapons);
- SpannableStringBuilder ssb = new SpannableStringBuilder();
- ssb.append(ownermsg).append(" ").append(mapmsg).append("\n").append(schememsg).append(" ").append(weaponsmsg);
-
- int weaponOffset = ownermsg.length()+1+mapmsg.length()+1+schememsg.length()+1;
- ssb.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), ownermsg.length(), ownermsg.length()+mapmsg.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- ssb.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), weaponOffset, weaponOffset+weaponsmsg.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- return ssb;
+ String scheme = room.scheme.equals(room.weapons) ? room.scheme : room.scheme + " / " + room.weapons;
+ String schememsg = res.getString(R.string.roomlist_scheme, scheme);
+ return ownermsg + ". " + mapmsg + ", " + schememsg;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
- TextView tv1;
if (v == null) {
LayoutInflater vi = LayoutInflater.from(context);
- v = vi.inflate(android.R.layout.simple_list_item_2, null);
- tv1 = (TextView)v.findViewById(android.R.id.text1);
- tv1.setCompoundDrawablePadding(5);
- } else {
- tv1 = (TextView)v.findViewById(android.R.id.text1);
+ v = vi.inflate(R.layout.listview_room, null);
}
Room room = rooms.get(position);
int iconRes = room.inProgress ? R.drawable.roomlist_ingame : R.drawable.roomlist_preparing;
- TextView tv2 = (TextView)v.findViewById(android.R.id.text2);
- tv1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
- tv1.setText(room.name);
- tv2.setText(formatExtra(context.getResources(), room));
+
+ if(v.findViewById(android.R.id.text1) == null) {
+ // Tabular room list
+ TextView roomnameView = (TextView)v.findViewById(R.id.roomname);
+ TextView playerCountView = (TextView)v.findViewById(R.id.playercount);
+ TextView teamCountView = (TextView)v.findViewById(R.id.teamcount);
+ TextView ownerView = (TextView)v.findViewById(R.id.owner);
+ TextView mapView = (TextView)v.findViewById(R.id.map);
+ TextView schemeView = (TextView)v.findViewById(R.id.scheme);
+ TextView weaponView = (TextView)v.findViewById(R.id.weapons);
+
+ roomnameView.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
+ roomnameView.setText(room.name);
+ if(playerCountView != null) {
+ playerCountView.setText(String.valueOf(room.playerCount));
+ }
+ if(teamCountView != null) {
+ teamCountView.setText(String.valueOf(room.teamCount));
+ }
+ ownerView.setText(room.owner);
+ mapView.setText(Room.formatMapName(context.getResources(), room.map));
+ schemeView.setText(room.scheme);
+ weaponView.setText(room.weapons);
+ } else {
+ // Small room list
+ TextView v1 = (TextView)v.findViewById(android.R.id.text1);
+ TextView v2 = (TextView)v.findViewById(android.R.id.text2);
+
+ v1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
+ v1.setText(room.name);
+ v2.setText(formatExtra(context.getResources(), room));
+ }
+
return v;
}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomlistFragment.java Thu Jul 19 22:55:36 2012 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomlistFragment.java Sat Jul 21 14:56:52 2012 +0200
@@ -14,6 +14,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ListView;
public class RoomlistFragment extends ListFragment {
private static final int AUTO_REFRESH_INTERVAL_MS = 10000;
@@ -44,7 +45,8 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- return inflater.inflate(R.layout.lobby_rooms_fragment, container, false);
+ View v = inflater.inflate(R.layout.lobby_rooms_fragment, container, false);
+ return v;
}
@Override
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/TestActivity.java Thu Jul 19 22:55:36 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-package org.hedgewars.hedgeroid.netplay;
-
-import org.hedgewars.hedgeroid.R;
-
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentPagerAdapter;
-import android.support.v4.view.ViewPager;
-
-public class TestActivity extends FragmentActivity {
- @Override
- protected void onCreate(Bundle arg0) {
- super.onCreate(arg0);
- setContentView(R.layout.activity_lobby_paged);
- ViewPager pager = (ViewPager)findViewById(R.id.pager);
- pager.setAdapter(new Adapter(getSupportFragmentManager()));
- }
-
- private static class Adapter extends FragmentPagerAdapter {
- public Adapter(FragmentManager mgr) {
- super(mgr);
- }
-
- @Override
- public int getCount() {
- return 3;
- }
-
- @Override
- public Fragment getItem(int arg0) {
- switch(arg0) {
- case 0: return new RoomlistFragment();
- case 1: return new LobbyChatFragment();
- case 2: return new PlayerlistFragment();
- default: throw new IndexOutOfBoundsException();
- }
- }
- }
-}