project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java
changeset 7344 25b8906f901a
parent 7330 867e4fda496e
child 7349 12fdfd2038d4
equal deleted inserted replaced
7342:0e29eec2df5c 7344:25b8906f901a
    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 java.io.File;
       
    22 import java.io.FileInputStream;
       
    23 import java.io.IOException;
       
    24 
    21 import org.hedgewars.hedgeroid.Downloader.DownloadAssets;
    25 import org.hedgewars.hedgeroid.Downloader.DownloadAssets;
    22 import org.hedgewars.hedgeroid.Downloader.DownloadListActivity;
    26 import org.hedgewars.hedgeroid.Downloader.DownloadListActivity;
    23 import org.hedgewars.hedgeroid.netplay.LobbyActivity;
    27 import org.hedgewars.hedgeroid.netplay.LobbyActivity;
    24 import org.hedgewars.hedgeroid.netplay.TestActivity;
    28 import org.hedgewars.hedgeroid.netplay.TestActivity;
    25 
    29 
    30 import android.content.Intent;
    34 import android.content.Intent;
    31 import android.content.pm.PackageManager.NameNotFoundException;
    35 import android.content.pm.PackageManager.NameNotFoundException;
    32 import android.os.Bundle;
    36 import android.os.Bundle;
    33 import android.preference.PreferenceManager;
    37 import android.preference.PreferenceManager;
    34 import android.support.v4.app.FragmentActivity;
    38 import android.support.v4.app.FragmentActivity;
       
    39 import android.util.Log;
    35 import android.view.View;
    40 import android.view.View;
    36 import android.view.View.OnClickListener;
    41 import android.view.View.OnClickListener;
    37 import android.widget.Button;
    42 import android.widget.Button;
    38 import android.widget.Toast;
    43 import android.widget.Toast;
    39 
    44 
    58 		});
    63 		});
    59 
    64 
    60 		if(!Utils.isDataPathAvailable()){
    65 		if(!Utils.isDataPathAvailable()){
    61 			showDialog(0);
    66 			showDialog(0);
    62 		} else {
    67 		} else {
    63 			int versionCode = 0;
    68 			String existingVersion = "";
    64 			try {
    69 			try {
    65 				versionCode = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode;
    70 				File versionFile = new File(Utils.getCachePath(this), "assetsversion.txt");
    66 			} catch (NameNotFoundException e) {
    71 				existingVersion = Utils.readToString(new FileInputStream(versionFile));
    67 
    72 			} catch(IOException e) {
    68 			}
    73 			}
    69 			boolean assetsCopied = PreferenceManager.getDefaultSharedPreferences(this).getInt("latestAssets", 0) >= versionCode;
    74 			
    70 
    75 			String newVersion = "";
    71 			if(!assetsCopied){
    76 			try {
       
    77 				newVersion = Utils.readToString(getAssets().open("assetsversion.txt"));
       
    78 			} catch(IOException e) {
       
    79 			}
       
    80 			
       
    81 			if(!existingVersion.equals(newVersion)) {
    72 				DownloadAssets assetsAsyncTask = new DownloadAssets(this);
    82 				DownloadAssets assetsAsyncTask = new DownloadAssets(this);
    73 				assetsDialog = ProgressDialog.show(this, "Please wait a moment", "Moving assets to SD card...");
    83 				assetsDialog = ProgressDialog.show(this, "Please wait a moment", "Moving assets to SD card...");
    74 				assetsAsyncTask.execute();
    84 				assetsAsyncTask.execute();
    75 			}
    85 			}
    76 		}
    86 		}
    88 
    98 
    89 		return builder.create();
    99 		return builder.create();
    90 	}
   100 	}
    91 
   101 
    92 	public void onAssetsDownloaded(boolean result){
   102 	public void onAssetsDownloaded(boolean result){
    93 		if(result){
   103 		if(!result){
    94 			try {
   104 			Toast.makeText(this, R.string.download_failed, Toast.LENGTH_LONG).show();
    95 				int versionCode = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode;
       
    96 				PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("latestAssets", versionCode).commit();
       
    97 			} catch (NameNotFoundException e) {}
       
    98 			
       
    99 		}else{
       
   100 			Toast.makeText(this, R.string.download_failed, Toast.LENGTH_LONG);
       
   101 		}
   105 		}
   102 		assetsDialog.dismiss();
   106 		assetsDialog.dismiss();
   103 	}
   107 	}
   104 
   108 
   105 	private OnClickListener downloadClicker = new OnClickListener(){
   109 	private OnClickListener downloadClicker = new OnClickListener(){
   106 		public void onClick(View v){
   110 		public void onClick(View v){
   107 			//startActivityForResult(new Intent(getApplicationContext(), DownloadActivity.class), 0);
       
   108 			startActivityForResult(new Intent(getApplicationContext(), DownloadListActivity.class), 0);
   111 			startActivityForResult(new Intent(getApplicationContext(), DownloadListActivity.class), 0);
   109 		}
   112 		}
   110 	};
   113 	};
   111 
   114 
   112 	private OnClickListener startGameClicker = new OnClickListener(){
   115 	private OnClickListener startGameClicker = new OnClickListener(){