author | Medo <smaxein@googlemail.com> |
Wed, 01 Aug 2012 21:13:39 +0200 | |
changeset 7455 | 8e86d8d2927d |
parent 7449 | 2e63537b44f3 |
child 7461 | 38acbfdb484f |
permissions | -rw-r--r-- |
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
1 |
package org.hedgewars.hedgeroid.netplay; |
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
2 |
|
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
3 |
import org.hedgewars.hedgeroid.R; |
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
4 |
|
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
5 |
import android.content.Context; |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
6 |
import android.graphics.drawable.Drawable; |
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
7 |
import android.os.Bundle; |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
7328
diff
changeset
|
8 |
import android.support.v4.app.FragmentActivity; |
7449 | 9 |
import android.support.v4.app.FragmentTransaction; |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
10 |
import android.view.LayoutInflater; |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
11 |
import android.view.Menu; |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
12 |
import android.view.MenuItem; |
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
13 |
import android.view.View; |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
14 |
import android.widget.ImageView; |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
15 |
import android.widget.LinearLayout; |
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
16 |
import android.widget.TabHost; |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
17 |
import android.widget.TextView; |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
18 |
import android.widget.Toast; |
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
19 |
|
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
7328
diff
changeset
|
20 |
public class LobbyActivity extends FragmentActivity { |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
21 |
private TabHost tabHost; |
7449 | 22 |
private Netplay netplay; |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
23 |
|
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
24 |
@Override |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
25 |
protected void onCreate(Bundle icicle) { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
26 |
super.onCreate(icicle); |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
27 |
|
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
28 |
setContentView(R.layout.activity_lobby); |
7455
8e86d8d2927d
Hedgeroid: Fix argument passing to ChatFragment, small layout fixes
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
29 |
ChatFragment chatFragment = (ChatFragment)getSupportFragmentManager().findFragmentById(R.id.chatFragment); |
8e86d8d2927d
Hedgeroid: Fix argument passing to ChatFragment, small layout fixes
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
30 |
chatFragment.setInRoom(false); |
7449 | 31 |
|
32 |
FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); |
|
33 |
trans.add(new NetplayStateFragment(), "netplayFragment"); |
|
34 |
trans.commit(); |
|
35 |
||
36 |
netplay = Netplay.getAppInstance(getApplicationContext()); |
|
37 |
||
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
38 |
tabHost = (TabHost)findViewById(android.R.id.tabhost); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
39 |
if(tabHost != null) { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
40 |
tabHost.setup(); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
41 |
tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
42 |
|
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
43 |
tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_rooms, getResources().getDrawable(R.drawable.roomlist_ingame))).setContent(R.id.roomListFragment)); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
44 |
tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_chat, getResources().getDrawable(R.drawable.edit))).setContent(R.id.chatFragment)); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
45 |
tabHost.addTab(tabHost.newTabSpec("players").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_players, getResources().getDrawable(R.drawable.human))).setContent(R.id.playerListFragment)); |
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
|
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
47 |
if (icicle != null) { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
48 |
tabHost.setCurrentTabByTag(icicle.getString("currentTab")); |
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
49 |
} |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
50 |
} |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
51 |
} |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
52 |
|
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
53 |
private View createIndicatorView(TabHost tabHost, int label, Drawable icon) { |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
54 |
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
55 |
|
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
56 |
View tabIndicator = inflater.inflate(R.layout.tab_indicator, |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
57 |
tabHost.getTabWidget(), // tab widget is the parent |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
58 |
false); // no inflate params |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
59 |
|
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
60 |
final TextView tv = (TextView) tabIndicator.findViewById(R.id.title); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
61 |
tv.setText(label); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
62 |
|
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
63 |
if(icon != null) { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
64 |
final ImageView iconView = (ImageView) tabIndicator.findViewById(R.id.icon); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
65 |
iconView.setImageDrawable(icon); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
66 |
} |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
67 |
|
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
68 |
return tabIndicator; |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
69 |
} |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
70 |
|
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
71 |
@Override |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
72 |
public boolean onCreateOptionsMenu(Menu menu) { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
73 |
super.onCreateOptionsMenu(menu); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
74 |
getMenuInflater().inflate(R.menu.lobby_options, menu); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
75 |
return true; |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
76 |
} |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
77 |
|
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
78 |
@Override |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
79 |
public boolean onOptionsItemSelected(MenuItem item) { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
80 |
switch(item.getItemId()) { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
81 |
case R.id.room_create: |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
82 |
Toast.makeText(this, R.string.not_implemented_yet, Toast.LENGTH_SHORT).show(); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
83 |
return true; |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
84 |
case R.id.disconnect: |
7449 | 85 |
netplay.disconnect(); |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
86 |
return true; |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
87 |
default: |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
88 |
return super.onOptionsItemSelected(item); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
89 |
} |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
90 |
} |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
91 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
92 |
@Override |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
93 |
public void onBackPressed() { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
94 |
super.onBackPressed(); |
7449 | 95 |
netplay.disconnect(); |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
96 |
} |
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
97 |
|
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
98 |
@Override |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
99 |
protected void onSaveInstanceState(Bundle icicle) { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
100 |
super.onSaveInstanceState(icicle); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
101 |
if(tabHost != null) { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
102 |
icicle.putString("currentTab", tabHost.getCurrentTabTag()); |
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
103 |
} |
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
104 |
} |
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
105 |
} |