1 package org.hedgewars.hedgeroid.netplay; |
1 package org.hedgewars.hedgeroid.netplay; |
2 |
2 |
3 import org.hedgewars.hedgeroid.R; |
3 import org.hedgewars.hedgeroid.R; |
4 import org.hedgewars.hedgeroid.netplay.JnaFrontlib.NetconnPtr; |
4 import org.hedgewars.hedgeroid.netplay.JnaFrontlib.NetconnPtr; |
|
5 import org.hedgewars.hedgeroid.netplay.Netplay.State; |
|
6 import org.hedgewars.hedgeroid.netplay.NetplayStateFragment.NetplayStateListener; |
5 |
7 |
|
8 import android.content.Intent; |
6 import android.content.IntentFilter; |
9 import android.content.IntentFilter; |
7 import android.os.Bundle; |
10 import android.os.Bundle; |
8 import android.support.v4.app.Fragment; |
11 import android.support.v4.app.Fragment; |
9 import android.support.v4.app.FragmentActivity; |
12 import android.support.v4.app.FragmentActivity; |
|
13 import android.support.v4.app.FragmentTransaction; |
10 import android.support.v4.content.LocalBroadcastManager; |
14 import android.support.v4.content.LocalBroadcastManager; |
11 import android.widget.LinearLayout; |
15 import android.widget.LinearLayout; |
12 import android.widget.TabHost; |
16 import android.widget.TabHost; |
|
17 import android.widget.Toast; |
13 |
18 |
14 public class RoomActivity extends FragmentActivity { |
19 public class RoomActivity extends FragmentActivity implements NetplayStateListener { |
15 private TabHost tabHost; |
20 private TabHost tabHost; |
16 private Netplay netconn; |
21 private Netplay netplay; |
17 |
22 |
18 @Override |
23 @Override |
19 protected void onCreate(Bundle icicle) { |
24 protected void onCreate(Bundle icicle) { |
20 super.onCreate(icicle); |
25 super.onCreate(icicle); |
21 netconn = Netplay.getAppInstance(getApplicationContext()); |
26 netplay = Netplay.getAppInstance(getApplicationContext()); |
22 |
27 |
23 setContentView(R.layout.activity_lobby); |
28 setContentView(R.layout.activity_netroom); |
24 Fragment chatFragment = getSupportFragmentManager().findFragmentById(R.id.chatFragment); |
29 ChatFragment chatFragment = (ChatFragment)getSupportFragmentManager().findFragmentById(R.id.chatFragment); |
25 chatFragment.getArguments().putBoolean(ChatFragment.ARGUMENT_INROOM, true); |
30 chatFragment.setInRoom(true); |
26 |
31 |
27 tabHost = (TabHost)findViewById(android.R.id.tabhost); |
32 FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); |
|
33 trans.add(new NetplayStateFragment(), "netplayFragment"); |
|
34 trans.commit(); |
|
35 |
|
36 /*tabHost = (TabHost)findViewById(android.R.id.tabhost); |
28 if(tabHost != null) { |
37 if(tabHost != null) { |
29 tabHost.setup(); |
38 tabHost.setup(); |
30 tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL); |
39 tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL); |
31 |
40 |
32 //tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_chat, getResources().getDrawable(R.drawable.edit))).setContent(R.id.chatFragment)); |
41 //tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_chat, getResources().getDrawable(R.drawable.edit))).setContent(R.id.chatFragment)); |
33 //tabHost.addTab(tabHost.newTabSpec("players").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_players, getResources().getDrawable(R.drawable.human))).setContent(R.id.playerListFragment)); |
42 //tabHost.addTab(tabHost.newTabSpec("players").setIndicator(createIndicatorView(tabHost, R.string.lobby_tab_players, getResources().getDrawable(R.drawable.human))).setContent(R.id.playerListFragment)); |
34 |
43 |
35 if (icicle != null) { |
44 if (icicle != null) { |
36 tabHost.setCurrentTabByTag(icicle.getString("currentTab")); |
45 tabHost.setCurrentTabByTag(icicle.getString("currentTab")); |
37 } |
46 } |
38 } |
47 }*/ |
39 } |
48 } |
40 |
49 |
|
50 @Override |
|
51 public void onBackPressed() { |
|
52 netplay.sendLeaveRoom(null); |
|
53 } |
|
54 |
41 @Override |
55 @Override |
42 protected void onSaveInstanceState(Bundle icicle) { |
56 protected void onSaveInstanceState(Bundle icicle) { |
43 super.onSaveInstanceState(icicle); |
57 super.onSaveInstanceState(icicle); |
44 if(tabHost != null) { |
58 if(tabHost != null) { |
45 icicle.putString("currentTab", tabHost.getCurrentTabTag()); |
59 icicle.putString("currentTab", tabHost.getCurrentTabTag()); |
46 } |
60 } |
47 } |
61 } |
|
62 |
|
63 public void onNetplayStateChanged(State newState) { |
|
64 switch(newState) { |
|
65 case NOT_CONNECTED: |
|
66 case CONNECTING: |
|
67 case LOBBY: |
|
68 finish(); |
|
69 break; |
|
70 case ROOM: |
|
71 // Do nothing |
|
72 break; |
|
73 case INGAME: |
|
74 //startActivity(new Intent(getApplicationContext(), RoomActivity.class)); |
|
75 Toast.makeText(getApplicationContext(), R.string.not_implemented_yet, Toast.LENGTH_SHORT).show(); |
|
76 break; |
|
77 default: |
|
78 throw new IllegalStateException("Unknown connection state: "+newState); |
|
79 } |
|
80 } |
48 } |
81 } |