project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/MainActivity.java
author Xeli
Thu, 01 Sep 2011 14:55:31 +0200
branchhedgeroid
changeset 5671 ba4c3a4c8b09
parent 5621 ea796c83ea47
permissions -rw-r--r--
Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5621
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
     1
/*
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
     3
 * Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com>
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
     4
 *
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
     8
 *
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
    12
 * GNU General Public License for more details.
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
    13
 *
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
    15
 * along with this program; if not, write to the Free Software
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
    17
 */
ea796c83ea47 added licenses
Xeli
parents: 5416
diff changeset
    18
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    19
package org.hedgewars.mobile;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    20
5416
26a36326d199 Added a small example of the frontend still being worked but commited so the downloader now works
Xeli
parents: 5397
diff changeset
    21
import org.hedgewars.mobile.Downloader.DownloadActivity;
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5621
diff changeset
    22
import org.hedgewars.mobile.Downloader.DownloadService;
5416
26a36326d199 Added a small example of the frontend still being worked but commited so the downloader now works
Xeli
parents: 5397
diff changeset
    23
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    24
import android.app.Activity;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    25
import android.content.Intent;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    26
import android.os.Bundle;
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5621
diff changeset
    27
import android.preference.PreferenceManager;
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    28
import android.view.View;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    29
import android.view.View.OnClickListener;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    30
import android.widget.Button;
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5621
diff changeset
    31
import android.widget.Toast;
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    32
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    33
public class MainActivity extends Activity {
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    34
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    35
	Button downloader, startGame;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    36
	
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    37
	public void onCreate(Bundle sis){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    38
		super.onCreate(sis);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    39
		setContentView(R.layout.main);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    40
		
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    41
		downloader = (Button)findViewById(R.id.downloader);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    42
		startGame = (Button)findViewById(R.id.startGame);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    43
		
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    44
		downloader.setOnClickListener(downloadClicker);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    45
		startGame.setOnClickListener(startGameClicker);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    46
	}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    47
	
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    48
	
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    49
	
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    50
	private OnClickListener downloadClicker = new OnClickListener(){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    51
		public void onClick(View v){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    52
			startActivityForResult(new Intent(getApplicationContext(), DownloadActivity.class), 0);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    53
		}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    54
	};
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    55
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    56
	private OnClickListener startGameClicker = new OnClickListener(){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    57
		public void onClick(View v){
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5621
diff changeset
    58
			if(PreferenceManager.getDefaultSharedPreferences(MainActivity.this).getBoolean(DownloadService.PREF_DOWNLOADED, false))
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5621
diff changeset
    59
				startActivity(new Intent(getApplicationContext(), StartGameActivity.class));
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5621
diff changeset
    60
			else {
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5621
diff changeset
    61
				Toast.makeText(MainActivity.this, R.string.download_userexplain, Toast.LENGTH_LONG).show();
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5621
diff changeset
    62
				startActivityForResult(new Intent(getApplicationContext(), DownloadActivity.class), 0);
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5621
diff changeset
    63
			}
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    64
		}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    65
	};
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    66
	
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    67
}