project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/LobbyActivity.java
equal
deleted
inserted
replaced
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.StartGameActivity; |
|
5 import org.hedgewars.hedgeroid.netplay.Netplay.State; |
|
6 import org.hedgewars.hedgeroid.netplay.NetplayStateFragment.NetplayStateListener; |
|
7 import org.hedgewars.hedgeroid.netplay.TextInputDialog.TextInputDialogListener; |
4 |
8 |
5 import android.content.Context; |
9 import android.content.Context; |
|
10 import android.content.Intent; |
6 import android.graphics.drawable.Drawable; |
11 import android.graphics.drawable.Drawable; |
7 import android.os.Bundle; |
12 import android.os.Bundle; |
8 import android.support.v4.app.FragmentActivity; |
13 import android.support.v4.app.FragmentActivity; |
9 import android.support.v4.app.FragmentTransaction; |
14 import android.support.v4.app.FragmentTransaction; |
10 import android.view.LayoutInflater; |
15 import android.view.LayoutInflater; |
13 import android.view.View; |
18 import android.view.View; |
14 import android.widget.ImageView; |
19 import android.widget.ImageView; |
15 import android.widget.LinearLayout; |
20 import android.widget.LinearLayout; |
16 import android.widget.TabHost; |
21 import android.widget.TabHost; |
17 import android.widget.TextView; |
22 import android.widget.TextView; |
18 import android.widget.Toast; |
|
19 |
23 |
20 public class LobbyActivity extends FragmentActivity { |
24 public class LobbyActivity extends FragmentActivity implements TextInputDialogListener, NetplayStateListener { |
|
25 private static final int DIALOG_CREATE_ROOM = 0; |
|
26 |
21 private TabHost tabHost; |
27 private TabHost tabHost; |
22 private Netplay netplay; |
28 private Netplay netplay; |
23 |
29 |
24 @Override |
30 @Override |
25 protected void onCreate(Bundle icicle) { |
31 protected void onCreate(Bundle icicle) { |
77 |
83 |
78 @Override |
84 @Override |
79 public boolean onOptionsItemSelected(MenuItem item) { |
85 public boolean onOptionsItemSelected(MenuItem item) { |
80 switch(item.getItemId()) { |
86 switch(item.getItemId()) { |
81 case R.id.room_create: |
87 case R.id.room_create: |
82 Toast.makeText(this, R.string.not_implemented_yet, Toast.LENGTH_SHORT).show(); |
88 TextInputDialog dialog = new TextInputDialog(DIALOG_CREATE_ROOM, R.string.dialog_create_room_title, 0, R.string.dialog_create_room_hint); |
|
89 dialog.show(getSupportFragmentManager(), "create_room_dialog"); |
83 return true; |
90 return true; |
84 case R.id.disconnect: |
91 case R.id.disconnect: |
85 netplay.disconnect(); |
92 netplay.disconnect(); |
86 return true; |
93 return true; |
87 default: |
94 default: |
100 super.onSaveInstanceState(icicle); |
107 super.onSaveInstanceState(icicle); |
101 if(tabHost != null) { |
108 if(tabHost != null) { |
102 icicle.putString("currentTab", tabHost.getCurrentTabTag()); |
109 icicle.putString("currentTab", tabHost.getCurrentTabTag()); |
103 } |
110 } |
104 } |
111 } |
|
112 |
|
113 public void onTextInputDialogSubmitted(int dialogId, String text) { |
|
114 if(text != null && text.length()>0) { |
|
115 netplay.sendCreateRoom(text); |
|
116 } |
|
117 } |
|
118 |
|
119 public void onTextInputDialogCancelled(int dialogId) { |
|
120 } |
|
121 |
|
122 public void onNetplayStateChanged(State newState) { |
|
123 switch(newState) { |
|
124 case CONNECTING: |
|
125 case NOT_CONNECTED: |
|
126 finish(); |
|
127 break; |
|
128 case ROOM: |
|
129 case INGAME: |
|
130 startActivity(new Intent(getApplicationContext(), RoomActivity.class)); |
|
131 break; |
|
132 case LOBBY: |
|
133 // Do nothing |
|
134 break; |
|
135 default: |
|
136 throw new IllegalStateException("Unknown connection state: "+newState); |
|
137 } |
|
138 } |
105 } |
139 } |