/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

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