author | Medo <smaxein@googlemail.com> |
Thu, 19 Jul 2012 18:58:18 +0200 | |
changeset 7342 | 0e29eec2df5c |
parent 7330 | 867e4fda496e |
child 7344 | 25b8906f901a |
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> |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
4 |
* |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
8 |
* |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
9 |
* 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
|
10 |
* 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
|
11 |
* 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
|
12 |
* 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
|
13 |
* |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
14 |
* 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
|
15 |
* along with this program; if not, write to the Free Software |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
17 |
*/ |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
18 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
19 |
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
|
20 |
|
6350 | 21 |
import org.hedgewars.hedgeroid.Downloader.DownloadAssets; |
6343 | 22 |
import org.hedgewars.hedgeroid.Downloader.DownloadListActivity; |
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
7318
diff
changeset
|
23 |
import org.hedgewars.hedgeroid.netplay.LobbyActivity; |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
7328
diff
changeset
|
24 |
import org.hedgewars.hedgeroid.netplay.TestActivity; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
25 |
|
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
26 |
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
|
27 |
import android.app.Dialog; |
6350 | 28 |
import android.app.ProgressDialog; |
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
29 |
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
|
30 |
import android.content.Intent; |
6623
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
31 |
import android.content.pm.PackageManager.NameNotFoundException; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
32 |
import android.os.Bundle; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
33 |
import android.preference.PreferenceManager; |
6350 | 34 |
import android.support.v4.app.FragmentActivity; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
|
6350 | 40 |
public class MainActivity extends FragmentActivity { |
41 |
private Button downloader, startGame; |
|
42 |
private ProgressDialog assetsDialog; |
|
43 |
||
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
44 |
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
|
45 |
super.onCreate(sis); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
46 |
setContentView(R.layout.main); |
6350 | 47 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
48 |
downloader = (Button)findViewById(R.id.downloader); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
49 |
startGame = (Button)findViewById(R.id.startGame); |
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
7318
diff
changeset
|
50 |
Button joinLobby = (Button)findViewById(R.id.joinLobby); |
6350 | 51 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
52 |
downloader.setOnClickListener(downloadClicker); |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
53 |
startGame.setOnClickListener(startGameClicker); |
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
7318
diff
changeset
|
54 |
joinLobby.setOnClickListener(new OnClickListener() { |
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
7318
diff
changeset
|
55 |
public void onClick(View v) { |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
7328
diff
changeset
|
56 |
startActivity(new Intent(getApplicationContext(), TestActivity.class)); |
7328
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
7318
diff
changeset
|
57 |
} |
cd919a2ead4e
Hedgeroid: Added experimental lobby chat
Medo <smaxein@googlemail.com>
parents:
7318
diff
changeset
|
58 |
}); |
6350 | 59 |
|
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
|
60 |
if(!Utils.isDataPathAvailable()){ |
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
61 |
showDialog(0); |
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
|
62 |
} else { |
6623
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
63 |
int versionCode = 0; |
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
64 |
try { |
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
65 |
versionCode = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode; |
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
66 |
} catch (NameNotFoundException e) { |
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
67 |
|
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
68 |
} |
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
69 |
boolean assetsCopied = PreferenceManager.getDefaultSharedPreferences(this).getInt("latestAssets", 0) >= versionCode; |
6350 | 70 |
|
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
71 |
if(!assetsCopied){ |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
72 |
DownloadAssets assetsAsyncTask = new DownloadAssets(this); |
7330
867e4fda496e
Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
7328
diff
changeset
|
73 |
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
|
74 |
assetsAsyncTask.execute(); |
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
75 |
} |
6350 | 76 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
77 |
} |
6350 | 78 |
|
6456
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
79 |
public Dialog onCreateDialog(int id, Bundle args){ |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
finish(); |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
86 |
} |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
87 |
}); |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
88 |
|
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
89 |
return builder.create(); |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
90 |
} |
fed715edc3ee
android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents:
6350
diff
changeset
|
91 |
|
6350 | 92 |
public void onAssetsDownloaded(boolean result){ |
93 |
if(result){ |
|
6623
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
94 |
try { |
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
95 |
int versionCode = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode; |
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
96 |
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("latestAssets", versionCode).commit(); |
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
97 |
} catch (NameNotFoundException e) {} |
6bf169f1e97c
check if the latest assets have been moved to the sdcard (compare with versionCode)
Xeli
parents:
6456
diff
changeset
|
98 |
|
6350 | 99 |
}else{ |
100 |
Toast.makeText(this, R.string.download_failed, Toast.LENGTH_LONG); |
|
101 |
} |
|
102 |
assetsDialog.dismiss(); |
|
103 |
} |
|
104 |
||
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
105 |
private OnClickListener downloadClicker = new OnClickListener(){ |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
106 |
public void onClick(View v){ |
6343 | 107 |
//startActivityForResult(new Intent(getApplicationContext(), DownloadActivity.class), 0); |
108 |
startActivityForResult(new Intent(getApplicationContext(), DownloadListActivity.class), 0); |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
109 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
110 |
}; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
111 |
|
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
112 |
private OnClickListener startGameClicker = new OnClickListener(){ |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
113 |
public void onClick(View v){ |
6350 | 114 |
startActivity(new Intent(getApplicationContext(), StartGameActivity.class)); |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
115 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
116 |
}; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
117 |
} |