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