PageRenderTime 133ms CodeModel.GetById 40ms app.highlight 15ms RepoModel.GetById 75ms app.codeStats 0ms

/TheElements/src/sand/falling/opengl/Menu.java

http://thelements.googlecode.com/
Java | 230 lines | 196 code | 26 blank | 8 comment | 5 complexity | dda94d12a8750e576ebd98700c70362d MD5 | raw file
  1package sand.falling.opengl;
  2
  3import java.io.BufferedReader;
  4import java.io.IOException;
  5import java.io.InputStream;
  6import java.io.InputStreamReader;
  7
  8import sand.falling.opengl.custom.CustomMaker;
  9import sand.falling.opengl.network.networklogin;
 10import sand.falling.opengl.MainActivity;
 11
 12import android.app.Activity;
 13import android.app.AlertDialog;
 14import android.app.Dialog;
 15import android.content.Intent;
 16import android.os.Bundle;
 17//import android.util.Log;
 18import android.view.View;
 19import android.view.Window;
 20import android.view.View.OnClickListener;
 21import android.webkit.WebView;
 22import android.widget.Button;
 23import android.widget.Toast;
 24
 25import com.mobclix.android.sdk.MobclixAdView;
 26import com.mobclix.android.sdk.MobclixMMABannerXLAdView;
 27
 28public class Menu extends Activity
 29{
 30	public static MobclixMMABannerXLAdView banner_adview;
 31	public static Button start_game_button;
 32	public static Button how_to_play_button;
 33	public static Button custom_button;
 34	public static Button about_button;
 35	public static Button login_button;
 36	public static Button exit_button;
 37	public static Button clear_button;
 38	public static boolean loaded = false;
 39	public long stime;
 40	
 41	@Override
 42	public void onCreate(Bundle savedInstanceState)
 43	{
 44		
 45		super.onCreate(savedInstanceState); //Call the super method
 46		
 47		requestWindowFeature(Window.FEATURE_NO_TITLE); //Get rid of title bar
 48		stime = System.currentTimeMillis();
 49		
 50		setContentView(R.layout.main_menu);
 51		
 52		try
 53		{
 54			//Define all the objects
 55			banner_adview = (MobclixMMABannerXLAdView) findViewById(R.id.banner_adview);
 56		}
 57		catch (NullPointerException e)
 58		{
 59			e.printStackTrace();
 60		}
 61		
 62		
 63		start_game_button = (Button) findViewById(R.id.start_game_button);
 64		how_to_play_button = (Button) findViewById(R.id.how_to_play_button);
 65		custom_button = (Button) findViewById(R.id.custom_button);
 66		about_button = (Button) findViewById(R.id.about_button);
 67		exit_button = (Button) findViewById(R.id.exit_button);
 68		clear_button = (Button) findViewById(R.id.clear_button);
 69		login_button = (Button) findViewById(R.id.login_button);
 70		
 71		try
 72		{
 73			banner_adview.getAd();
 74		}
 75		catch(Exception e)
 76		{
 77			e.printStackTrace();
 78		}
 79		
 80		
 81		start_game_button.setOnClickListener
 82		(
 83			new OnClickListener()
 84			{
 85				public void onClick(View v)
 86				{
 87					if (System.currentTimeMillis() - stime >= 1000)
 88					{
 89					//Start the main app activity
 90						startActivity(new Intent(Menu.this, Splash.class));
 91					}
 92				}
 93			}
 94		);
 95		
 96		how_to_play_button.setOnClickListener
 97		(
 98			new OnClickListener()
 99			{
100				public void onClick(View v)
101				{
102					//Show the instructions
103					how_to_play();
104				}
105			}
106		);
107		
108		about_button.setOnClickListener
109		(
110			new OnClickListener()
111			{
112				public void onClick(View v)
113				{
114					//Show the about dialog
115					showDialog(1);
116				}
117			}
118		);
119		login_button.setOnClickListener
120		(
121			new OnClickListener()
122			{
123				public void onClick(View v)
124				{
125					
126					startActivity(new Intent(Menu.this, networklogin.class)); //start login activity
127					
128				}
129			}
130		);
131		custom_button.setOnClickListener
132		(
133			new OnClickListener()
134			{
135				public void onClick(View v)
136				{
137					//Show the about dialog
138					 startActivity(new Intent(Menu.this, CustomMaker.class));
139				}
140			}
141		);
142		clear_button.setOnClickListener
143		(
144			new OnClickListener()
145			{
146				public void onClick(View v)
147				{
148					//Show the about dialog
149					MainActivity.clearQuickSave();
150					Toast.makeText(getBaseContext(), "Quicksave file erased", Toast.LENGTH_SHORT).show();
151				}
152			}
153		);
154		
155		exit_button.setOnClickListener
156		(
157			new OnClickListener()
158			{
159				public void onClick(View v)
160				{
161					//Quit the program
162					System.exit(0);
163				}
164			}
165		);
166	}
167	public void onSuccessfulLoad(MobclixAdView view)
168	{
169		loaded = true;
170	}
171	@Override
172	public void onResume()
173	{
174		stime = System.currentTimeMillis();
175		super.onResume(); //Call the super method
176	}
177	
178	@Override
179	public void onPause()
180	{
181		super.onPause(); //Call the super method
182	}
183	
184	public void how_to_play()
185	{
186		StringBuffer data = new StringBuffer();
187		try
188		{
189			InputStream stream = getAssets().open("instructions.html");
190			BufferedReader in = new BufferedReader(new InputStreamReader(stream), 8192);
191			while(true)
192			{
193				String line = in.readLine();
194				if(line == null)
195				{
196					break;
197				}
198				data.append(line).append("\n");
199			}
200		}
201		catch (IOException e)
202		{
203			e.printStackTrace();
204			return;
205		}
206		
207		WebView how_to_play = new WebView(this);
208		how_to_play.setBackgroundColor(0x00000000);
209		how_to_play.loadData(data.toString(), "text/html", "ascii");
210		
211		AlertDialog.Builder builder = new AlertDialog.Builder(this);
212		builder.setCancelable(true);
213		builder.setTitle("How to Play The Elements");
214		builder.setView(how_to_play);
215		builder.show();
216	}
217	
218	protected Dialog onCreateDialog(int id)  // This is called when showDialog is called
219	{
220	   	if (id == 1) //Copyright message
221		{
222			AlertDialog.Builder builder = new AlertDialog.Builder(this); //Declare the object
223			builder.setMessage("Element Works is created by IDKJava Copyright 2010");			      
224			AlertDialog alert = builder.create(); //Create object
225			return alert; //Return handle
226		}
227		
228		return null; //No need to return anything, just formality
229	}
230}