23 import java.io.IOException; |
23 import java.io.IOException; |
24 |
24 |
25 import org.hedgewars.hedgeroid.Downloader.DownloadAssets; |
25 import org.hedgewars.hedgeroid.Downloader.DownloadAssets; |
26 import org.hedgewars.hedgeroid.Downloader.DownloadListActivity; |
26 import org.hedgewars.hedgeroid.Downloader.DownloadListActivity; |
27 import org.hedgewars.hedgeroid.netplay.LobbyActivity; |
27 import org.hedgewars.hedgeroid.netplay.LobbyActivity; |
|
28 import org.hedgewars.hedgeroid.netplay.NetplayService; |
28 |
29 |
29 import android.app.AlertDialog; |
30 import android.app.AlertDialog; |
30 import android.app.Dialog; |
31 import android.app.Dialog; |
31 import android.app.ProgressDialog; |
32 import android.app.ProgressDialog; |
|
33 import android.content.BroadcastReceiver; |
|
34 import android.content.Context; |
32 import android.content.DialogInterface; |
35 import android.content.DialogInterface; |
33 import android.content.Intent; |
36 import android.content.Intent; |
|
37 import android.content.IntentFilter; |
34 import android.content.SharedPreferences; |
38 import android.content.SharedPreferences; |
35 import android.content.SharedPreferences.Editor; |
39 import android.content.SharedPreferences.Editor; |
36 import android.os.Bundle; |
40 import android.os.Bundle; |
37 import android.support.v4.app.FragmentActivity; |
41 import android.support.v4.app.FragmentActivity; |
|
42 import android.support.v4.content.LocalBroadcastManager; |
38 import android.util.Log; |
43 import android.util.Log; |
39 import android.view.View; |
44 import android.view.View; |
40 import android.view.View.OnClickListener; |
45 import android.view.View.OnClickListener; |
41 import android.widget.Button; |
46 import android.widget.Button; |
42 import android.widget.EditText; |
47 import android.widget.EditText; |
61 |
66 |
62 downloader.setOnClickListener(downloadClicker); |
67 downloader.setOnClickListener(downloadClicker); |
63 startGame.setOnClickListener(startGameClicker); |
68 startGame.setOnClickListener(startGameClicker); |
64 joinLobby.setOnClickListener(new OnClickListener() { |
69 joinLobby.setOnClickListener(new OnClickListener() { |
65 public void onClick(View v) { |
70 public void onClick(View v) { |
66 showDialog(DIALOG_START_NETGAME); |
71 if(!NetplayService.isActive()) { |
|
72 showDialog(DIALOG_START_NETGAME); |
|
73 } else { |
|
74 startActivity(new Intent(getApplicationContext(), LobbyActivity.class)); |
|
75 } |
67 } |
76 } |
68 }); |
77 }); |
69 |
78 |
70 if(!Utils.isDataPathAvailable()){ |
79 if(!Utils.isDataPathAvailable()){ |
71 showDialog(DIALOG_NO_SDCARD); |
80 showDialog(DIALOG_NO_SDCARD); |
139 if(playerName.length() > 0) { |
148 if(playerName.length() > 0) { |
140 Editor edit = prefs.edit(); |
149 Editor edit = prefs.edit(); |
141 edit.putString(PREF_PLAYERNAME, playerName); |
150 edit.putString(PREF_PLAYERNAME, playerName); |
142 edit.commit(); |
151 edit.commit(); |
143 |
152 |
144 // TODO actually use that name |
153 Intent netplayServiceIntent = new Intent(getApplicationContext(), NetplayService.class); |
145 Intent netplayIntent = new Intent(getApplicationContext(), LobbyActivity.class); |
154 netplayServiceIntent.putExtra(NetplayService.EXTRA_PLAYERNAME, playerName); |
146 netplayIntent.putExtra("playerName", playerName); |
155 startService(netplayServiceIntent); |
147 startActivity(netplayIntent); |
156 |
|
157 LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(connectedReceiver, new IntentFilter(NetplayService.ACTION_CONNECTED)); |
148 } |
158 } |
149 } |
159 } |
150 }); |
160 }); |
151 |
161 |
152 return builder.create(); |
162 return builder.create(); |
168 private OnClickListener startGameClicker = new OnClickListener(){ |
178 private OnClickListener startGameClicker = new OnClickListener(){ |
169 public void onClick(View v){ |
179 public void onClick(View v){ |
170 startActivity(new Intent(getApplicationContext(), StartGameActivity.class)); |
180 startActivity(new Intent(getApplicationContext(), StartGameActivity.class)); |
171 } |
181 } |
172 }; |
182 }; |
|
183 |
|
184 private BroadcastReceiver connectedReceiver = new BroadcastReceiver() { |
|
185 @Override |
|
186 public void onReceive(Context context, Intent intent) { |
|
187 startActivity(new Intent(getApplicationContext(), LobbyActivity.class)); |
|
188 } |
|
189 }; |
173 } |
190 } |