author | Medo <smaxein@googlemail.com> |
Thu, 23 Aug 2012 18:28:33 +0200 | |
changeset 7588 | 27e5857da6af |
parent 7584 | 7831c84cc644 |
child 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
1 |
/* |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
6700 | 3 |
* Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com> |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
4 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
5 |
* |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
6 |
* This program is free software; you can redistribute it and/or |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
7 |
* modify it under the terms of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
8 |
* as published by the Free Software Foundation; either version 2 |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
9 |
* of the License, or (at your option) any later version. |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
10 |
* |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
11 |
* This program is distributed in the hope that it will be useful, |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
14 |
* GNU General Public License for more details. |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
15 |
* |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
17 |
* along with this program; if not, write to the Free Software |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
19 |
*/ |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
20 |
package org.hedgewars.hedgeroid; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
21 |
|
7344
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
22 |
import java.io.File; |
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
23 |
import java.io.FileInputStream; |
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
24 |
import java.io.IOException; |
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
25 |
|
6350 | 26 |
import org.hedgewars.hedgeroid.Downloader.DownloadAssets; |
6343 | 27 |
import org.hedgewars.hedgeroid.Downloader.DownloadListActivity; |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
28 |
import org.hedgewars.hedgeroid.netplay.Netplay; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
29 |
import org.hedgewars.hedgeroid.netplay.Netplay.State; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
30 |
import org.hedgewars.hedgeroid.util.FileUtils; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
31 |
|
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
32 |
import android.app.AlertDialog; |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
33 |
import android.app.Dialog; |
6350 | 34 |
import android.app.ProgressDialog; |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
35 |
import android.content.BroadcastReceiver; |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
36 |
import android.content.Context; |
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
37 |
import android.content.DialogInterface; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
38 |
import android.content.Intent; |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
39 |
import android.content.IntentFilter; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
40 |
import android.os.Bundle; |
6350 | 41 |
import android.support.v4.app.FragmentActivity; |
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
42 |
import android.support.v4.app.FragmentManager; |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
43 |
import android.support.v4.content.LocalBroadcastManager; |
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
44 |
import android.view.Menu; |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
45 |
import android.view.MenuItem; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
46 |
import android.view.View; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
47 |
import android.view.View.OnClickListener; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
48 |
import android.widget.Button; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
49 |
import android.widget.Toast; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
50 |
|
6350 | 51 |
public class MainActivity extends FragmentActivity { |
7352
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
52 |
private static final int DIALOG_NO_SDCARD = 0; |
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
53 |
|
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
54 |
private LocalBroadcastManager broadcastManager; |
6350 | 55 |
private ProgressDialog assetsDialog; |
56 |
||
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
57 |
public void onCreate(Bundle sis){ |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
58 |
super.onCreate(sis); |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
59 |
setContentView(R.layout.activity_main); |
6350 | 60 |
|
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
61 |
broadcastManager = LocalBroadcastManager.getInstance(getApplicationContext()); |
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
62 |
Button startLocalGame = (Button)findViewById(R.id.startGame); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
63 |
Button startNetGame = (Button)findViewById(R.id.joinLobby); |
6350 | 64 |
|
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
65 |
startLocalGame.setOnClickListener(startGameListener); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
66 |
startNetGame.setOnClickListener(startNetGameListener); |
6350 | 67 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
68 |
if(!FileUtils.isDataPathAvailable()){ |
7352
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
69 |
showDialog(DIALOG_NO_SDCARD); |
7318
a446eafcddeb
Improved asset moving time by an order of magnitude (3s vs. 25s on my device)
Medo <smaxein@googlemail.com>
parents:
6842
diff
changeset
|
70 |
} else { |
7344
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
71 |
String existingVersion = ""; |
6623
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
72 |
try { |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
73 |
File versionFile = new File(FileUtils.getCachePath(this), "assetsversion.txt"); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
74 |
existingVersion = FileUtils.readToString(new FileInputStream(versionFile)); |
7344
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
75 |
} catch(IOException e) { |
6623
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
76 |
} |
7344
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
77 |
|
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
78 |
String newVersion = ""; |
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
79 |
try { |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
80 |
newVersion = FileUtils.readToString(getAssets().open("assetsversion.txt")); |
7344
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
81 |
} catch(IOException e) { |
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
82 |
} |
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
83 |
|
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
84 |
if(!existingVersion.equals(newVersion)) { |
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
85 |
DownloadAssets assetsAsyncTask = new DownloadAssets(this); |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
7328
diff
changeset
|
86 |
assetsDialog = ProgressDialog.show(this, "Please wait a moment", "Moving assets to SD card..."); |
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
7328
diff
changeset
|
87 |
assetsAsyncTask.execute(); |
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
88 |
} |
6350 | 89 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
90 |
} |
6350 | 91 |
|
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
92 |
@Override |
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
93 |
protected void onResume() { |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
94 |
super.onResume(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
95 |
broadcastManager.registerReceiver(connectedReceiver, new IntentFilter(Netplay.ACTION_CONNECTED)); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
96 |
broadcastManager.registerReceiver(connectionFailedReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED)); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
97 |
broadcastManager.registerReceiver(passwordRequestedReceiver, new IntentFilter(Netplay.ACTION_PASSWORD_REQUESTED)); |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
98 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
99 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
100 |
@Override |
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
101 |
protected void onPause() { |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
102 |
super.onPause(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
103 |
broadcastManager.unregisterReceiver(connectedReceiver); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
104 |
broadcastManager.unregisterReceiver(connectionFailedReceiver); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
105 |
broadcastManager.unregisterReceiver(passwordRequestedReceiver); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
106 |
Netplay netplay = Netplay.getAppInstance(getApplicationContext()); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
107 |
if(netplay.getState() == State.CONNECTING) { |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
108 |
netplay.disconnect(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
109 |
} |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
110 |
} |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
111 |
|
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
112 |
@Override |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
113 |
public boolean onCreateOptionsMenu(Menu menu) { |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
114 |
super.onCreateOptionsMenu(menu); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
115 |
getMenuInflater().inflate(R.menu.main_options, menu); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
116 |
return true; |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
117 |
} |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
118 |
|
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
119 |
@Override |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
120 |
public boolean onOptionsItemSelected(MenuItem item) { |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
121 |
switch(item.getItemId()) { |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
122 |
case R.id.download: |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
123 |
startActivityForResult(new Intent(this, DownloadListActivity.class), 0); |
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
124 |
return true; |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
125 |
case R.id.preferences: |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
126 |
Toast.makeText(this, R.string.not_implemented_yet, Toast.LENGTH_SHORT).show(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
127 |
return true; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
128 |
case R.id.edit_weaponsets: |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
129 |
startActivity(new Intent(this, WeaponsetListActivity.class)); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
130 |
return true; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
131 |
case R.id.edit_teams: |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
132 |
startActivity(new Intent(this, TeamListActivity.class)); |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
133 |
return true; |
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
134 |
default: |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
135 |
return super.onOptionsItemSelected(item); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
136 |
} |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
137 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
138 |
|
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
139 |
public Dialog onCreateDialog(int id, Bundle args){ |
7352
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
140 |
switch(id) { |
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
141 |
case DIALOG_NO_SDCARD: |
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
142 |
return createNoSdcardDialog(); |
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
143 |
default: |
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
144 |
throw new IndexOutOfBoundsException(); |
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
145 |
} |
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
146 |
} |
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
147 |
|
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
148 |
private Dialog createNoSdcardDialog() { |
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
149 |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
150 |
builder.setTitle(R.string.sdcard_not_mounted_title); |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
151 |
builder.setMessage(R.string.sdcard_not_mounted); |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
152 |
builder.setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener(){ |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
153 |
public void onClick(DialogInterface dialog, int which) { |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
154 |
finish(); |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
155 |
} |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
156 |
}); |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
157 |
|
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
158 |
return builder.create(); |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
159 |
} |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
160 |
|
6350 | 161 |
public void onAssetsDownloaded(boolean result){ |
7344
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
162 |
if(!result){ |
25b8906f901a
Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents:
7330
diff
changeset
|
163 |
Toast.makeText(this, R.string.download_failed, Toast.LENGTH_LONG).show(); |
6350 | 164 |
} |
165 |
assetsDialog.dismiss(); |
|
166 |
} |
|
167 |
||
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
168 |
private final OnClickListener startGameListener = new OnClickListener(){ |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
169 |
public void onClick(View v){ |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
170 |
startActivity(new Intent(getApplicationContext(), LocalRoomActivity.class)); |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
171 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
172 |
}; |
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
173 |
|
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
174 |
private final OnClickListener startNetGameListener = new OnClickListener() { |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
175 |
public void onClick(View v) { |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
176 |
State state = Netplay.getAppInstance(getApplicationContext()).getState(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
177 |
switch(state) { |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
178 |
case NOT_CONNECTED: |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
179 |
FragmentManager fm = getSupportFragmentManager(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
180 |
StartNetgameDialog startNetgameDialog = new StartNetgameDialog(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
181 |
startNetgameDialog.show(fm, "start_netgame_dialog"); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
182 |
break; |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
183 |
case CONNECTING: |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
184 |
onNetConnectingStarted(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
185 |
break; |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
186 |
default: |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
187 |
startActivity(new Intent(getApplicationContext(), LobbyActivity.class)); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
188 |
break; |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
189 |
} |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
190 |
} |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
191 |
}; |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
192 |
|
7355
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
193 |
private BroadcastReceiver connectedReceiver = new BroadcastReceiver() { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
194 |
@Override |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
195 |
public void onReceive(Context context, Intent intent) { |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
196 |
startActivity(new Intent(getApplicationContext(), LobbyActivity.class)); |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
197 |
} |
5673e95ef647
Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
198 |
}; |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
199 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
200 |
private BroadcastReceiver connectionFailedReceiver = new BroadcastReceiver() { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
201 |
@Override |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
202 |
public void onReceive(Context context, Intent intent) { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
203 |
if(intent.getBooleanExtra(Netplay.EXTRA_HAS_ERROR, true)) { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
204 |
Toast.makeText(getApplicationContext(), intent.getStringExtra(Netplay.EXTRA_MESSAGE), Toast.LENGTH_LONG).show(); |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
205 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
206 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
207 |
}; |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
208 |
|
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
209 |
private BroadcastReceiver passwordRequestedReceiver = new BroadcastReceiver() { |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
210 |
@Override |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
211 |
public void onReceive(Context context, Intent intent) { |
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
212 |
FragmentManager fm = getSupportFragmentManager(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
213 |
PasswordDialog passwordDialog = new PasswordDialog(intent.getStringExtra(Netplay.EXTRA_PLAYERNAME)); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
214 |
passwordDialog.show(fm, "fragment_password_dialog"); |
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
215 |
} |
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7355
diff
changeset
|
216 |
}; |
7444
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
217 |
|
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
218 |
public void onNetConnectingStarted() { |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
219 |
FragmentManager fm = getSupportFragmentManager(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
220 |
ConnectingDialog connectingDialog = new ConnectingDialog(); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
221 |
connectingDialog.show(fm, "fragment_connecting_dialog"); |
2e31f114f57e
Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
222 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
223 |
} |