16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
17 */ |
17 */ |
18 |
18 |
19 package org.hedgewars.hedgeroid; |
19 package org.hedgewars.hedgeroid; |
20 |
20 |
21 import org.hedgewars.hedgeroid.Downloader.DownloadActivity; |
21 import org.hedgewars.hedgeroid.Downloader.DownloadAssets; |
|
22 import org.hedgewars.hedgeroid.Downloader.DownloadFragment; |
22 import org.hedgewars.hedgeroid.Downloader.DownloadListActivity; |
23 import org.hedgewars.hedgeroid.Downloader.DownloadListActivity; |
23 import org.hedgewars.hedgeroid.Downloader.DownloadService; |
24 import org.hedgewars.hedgeroid.Downloader.DownloadService; |
24 |
25 |
25 import android.app.Activity; |
26 import android.app.ProgressDialog; |
26 import android.content.Intent; |
27 import android.content.Intent; |
27 import android.os.Bundle; |
28 import android.os.Bundle; |
28 import android.preference.PreferenceManager; |
29 import android.preference.PreferenceManager; |
|
30 import android.support.v4.app.FragmentActivity; |
29 import android.view.View; |
31 import android.view.View; |
30 import android.view.View.OnClickListener; |
32 import android.view.View.OnClickListener; |
31 import android.widget.Button; |
33 import android.widget.Button; |
32 import android.widget.Toast; |
34 import android.widget.Toast; |
33 |
35 |
34 public class MainActivity extends Activity { |
36 public class MainActivity extends FragmentActivity { |
35 |
37 |
36 Button downloader, startGame; |
38 private Button downloader, startGame; |
37 |
39 private ProgressDialog assetsDialog; |
|
40 |
38 public void onCreate(Bundle sis){ |
41 public void onCreate(Bundle sis){ |
39 super.onCreate(sis); |
42 super.onCreate(sis); |
40 setContentView(R.layout.main); |
43 setContentView(R.layout.main); |
41 |
44 |
42 downloader = (Button)findViewById(R.id.downloader); |
45 downloader = (Button)findViewById(R.id.downloader); |
43 startGame = (Button)findViewById(R.id.startGame); |
46 startGame = (Button)findViewById(R.id.startGame); |
44 |
47 |
45 downloader.setOnClickListener(downloadClicker); |
48 downloader.setOnClickListener(downloadClicker); |
46 startGame.setOnClickListener(startGameClicker); |
49 startGame.setOnClickListener(startGameClicker); |
|
50 |
|
51 boolean assetsCopied = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("assetscopied", false); |
|
52 |
|
53 if(!assetsCopied){ |
|
54 DownloadAssets assetsAsyncTask = new DownloadAssets(this); |
|
55 assetsDialog = ProgressDialog.show(this, "Please wait a moment", "Moving assets..."); |
|
56 assetsAsyncTask.execute((Object[])null); |
|
57 } |
47 } |
58 } |
48 |
59 |
49 |
60 public void onAssetsDownloaded(boolean result){ |
50 |
61 if(result){ |
|
62 PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("assetscopied", true).commit(); |
|
63 }else{ |
|
64 Toast.makeText(this, R.string.download_failed, Toast.LENGTH_LONG); |
|
65 } |
|
66 assetsDialog.dismiss(); |
|
67 } |
|
68 |
51 private OnClickListener downloadClicker = new OnClickListener(){ |
69 private OnClickListener downloadClicker = new OnClickListener(){ |
52 public void onClick(View v){ |
70 public void onClick(View v){ |
53 //startActivityForResult(new Intent(getApplicationContext(), DownloadActivity.class), 0); |
71 //startActivityForResult(new Intent(getApplicationContext(), DownloadActivity.class), 0); |
54 startActivityForResult(new Intent(getApplicationContext(), DownloadListActivity.class), 0); |
72 startActivityForResult(new Intent(getApplicationContext(), DownloadListActivity.class), 0); |
55 } |
73 } |
56 }; |
74 }; |
57 |
75 |
58 private OnClickListener startGameClicker = new OnClickListener(){ |
76 private OnClickListener startGameClicker = new OnClickListener(){ |
59 public void onClick(View v){ |
77 public void onClick(View v){ |
60 if(PreferenceManager.getDefaultSharedPreferences(MainActivity.this).getBoolean(DownloadService.PREF_DOWNLOADED, false)) |
78 startActivity(new Intent(getApplicationContext(), StartGameActivity.class)); |
61 startActivity(new Intent(getApplicationContext(), StartGameActivity.class)); |
|
62 else { |
|
63 Toast.makeText(MainActivity.this, R.string.download_userexplain, Toast.LENGTH_LONG).show(); |
|
64 startActivityForResult(new Intent(getApplicationContext(), DownloadActivity.class), 0); |
|
65 } |
|
66 } |
79 } |
67 }; |
80 }; |
68 |
|
69 } |
81 } |