project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java
branchhedgeroid
changeset 6047 10011f051f9c
child 6049 7bc38086d771
equal deleted inserted replaced
6045:9a7cc0f29430 6047:10011f051f9c
       
     1 /*
       
     2  * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    17  */
       
    18 
       
    19 package org.hedgewars.hedgeroid;
       
    20 
       
    21 import org.hedgewars.hedgeroid.Downloader.DownloadActivity;
       
    22 import org.hedgewars.hedgeroid.Downloader.DownloadService;
       
    23 import org.hedgewars.mobile.R;
       
    24 
       
    25 import android.app.Activity;
       
    26 import android.content.Intent;
       
    27 import android.os.Bundle;
       
    28 import android.preference.PreferenceManager;
       
    29 import android.view.View;
       
    30 import android.view.View.OnClickListener;
       
    31 import android.widget.Button;
       
    32 import android.widget.Toast;
       
    33 
       
    34 public class MainActivity extends Activity {
       
    35 
       
    36 	Button downloader, startGame;
       
    37 	
       
    38 	public void onCreate(Bundle sis){
       
    39 		super.onCreate(sis);
       
    40 		setContentView(R.layout.main);
       
    41 		
       
    42 		downloader = (Button)findViewById(R.id.downloader);
       
    43 		startGame = (Button)findViewById(R.id.startGame);
       
    44 		
       
    45 		downloader.setOnClickListener(downloadClicker);
       
    46 		startGame.setOnClickListener(startGameClicker);
       
    47 	}
       
    48 	
       
    49 	
       
    50 	
       
    51 	private OnClickListener downloadClicker = new OnClickListener(){
       
    52 		public void onClick(View v){
       
    53 			startActivityForResult(new Intent(getApplicationContext(), DownloadActivity.class), 0);
       
    54 		}
       
    55 	};
       
    56 
       
    57 	private OnClickListener startGameClicker = new OnClickListener(){
       
    58 		public void onClick(View v){
       
    59 			if(PreferenceManager.getDefaultSharedPreferences(MainActivity.this).getBoolean(DownloadService.PREF_DOWNLOADED, false))
       
    60 				startActivity(new Intent(getApplicationContext(), StartGameActivity.class));
       
    61 			else {
       
    62 				Toast.makeText(MainActivity.this, R.string.download_userexplain, Toast.LENGTH_LONG).show();
       
    63 				startActivityForResult(new Intent(getApplicationContext(), DownloadActivity.class), 0);
       
    64 			}
       
    65 		}
       
    66 	};
       
    67 	
       
    68 }