# HG changeset patch # User Medo # Date 1342875412 -7200 # Node ID 12fdfd2038d4613a7bcd7372d8c391ac05325038 # Parent b0f67c5b4215646804920350f7132ae9a99fc4ca Hedgeroid: More work on the lobby activity diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/AndroidManifest.xml --- 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" > - @@ -69,7 +68,7 @@ android:windowSoftInputMode="stateUnchanged" > diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout-large/activity_lobby.xml --- /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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout-large/listview_room.xml --- /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 @@ + + + + + + + + + + + + + + + + + + diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout-large/lobby_rooms_fragment.xml --- /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 @@ + + + + + + + + + + + + \ No newline at end of file diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout-xlarge/roomlist_player_team_count.xml --- /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 @@ + + + + + + + \ No newline at end of file diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout-xlarge/roomlist_player_team_count_header.xml --- /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 @@ + + + + + + + \ No newline at end of file diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout/activity_lobby.xml --- 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"> - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="match_parent"> + + + + + + + + + + + \ No newline at end of file diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout/activity_lobby_paged.xml --- 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 @@ - - - - - \ No newline at end of file diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout/listview_room.xml --- /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 @@ + + + + + + + + \ No newline at end of file diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout/listview_room_header.xml --- /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 @@ + + + + + + + + + + + + + + + + + + diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout/lobby_chat_fragment.xml --- 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" /> diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout/lobby_players_fragment.xml --- 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" > \ No newline at end of file diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout/lobby_rooms_fragment.xml --- 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" /> + + \ No newline at end of file diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/layout/roomlist_player_team_count_header.xml --- /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 @@ + + + \ No newline at end of file diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/res/values/strings.xml --- 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 @@ Level 2 Level 1 - LobbyActivity + Hedgewars Server Lobby Type here to chat @@ -67,10 +67,17 @@ No players + Room Name + C + T + Owner + Map + Rules + Ammo + by %1$s - map: %1$s - scheme: %1$s - weapons: %1$s + Map: %1$s + Scheme: %1$s Random map Random maze Drawn map diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java --- 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)); } }); diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ChatlogAdapter.java --- 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; } diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyActivity.java --- 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("AndroidChatter: " + text + "
")); - 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+"
")); - } - }; + /** + * 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 mTabs = new ArrayList(); + + 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) { + } + } } diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyChatFragment.java --- 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; diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Netconn.java --- 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); } diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/NetplayService.java --- 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(); diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomListAdapter.java --- 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; } diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomlistFragment.java --- 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 diff -r b0f67c5b4215 -r 12fdfd2038d4 project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/TestActivity.java --- 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(); - } - } - } -}