Guest User

Untitled

a guest
Apr 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. package com.uml.youmath;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.os.Bundle;
  7. import android.preference.PreferenceManager;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.view.Window;
  11. import android.widget.ImageButton;
  12. import android.widget.TextView;
  13.  
  14. /**
  15. * This class is the Activity that takes care of the Game Type selection
  16. * screen/view. The Game Type we are defining as the choice of math questions to
  17. * be served up (addition, multiplication, etc)
  18. *
  19. * @author cdietsch
  20. */
  21.  
  22. public class GameTypeSelect extends Activity implements OnClickListener {
  23.  
  24. ImageButton btn_addition, btn_subtraction;
  25. ImageButton btn_multiplication, btn_division, btn_identity;
  26. int gameType = 0, currentPos = 0;
  27. TextView gameTypeText, playerNameText;
  28.  
  29. @Override
  30. public void onClick(View v) {
  31.  
  32. if (v == btn_addition) {
  33. // Send addition choice along to stage select
  34. gameType = ProblemMaker.ADDITION;
  35. }
  36. if (v == btn_subtraction) {
  37. gameType = ProblemMaker.SUBTRACTION;
  38. }
  39. if (v == btn_multiplication) {
  40. gameType = ProblemMaker.MULTIPLICATION;
  41. }
  42. if (v == btn_division) {
  43. gameType = ProblemMaker.DIVISION;
  44. }
  45. if (v == btn_identity) {
  46. gameType = ProblemMaker.NUMBER_IDENTITY;
  47. }
  48.  
  49. Intent i = new Intent(GameTypeSelect.this, StageSelection.class);
  50. i.putExtra("gametype", gameType);
  51. startActivity(i);
  52. }
  53.  
  54. @Override
  55. public void onCreate(Bundle savedInstanceState) {
  56. super.onCreate(savedInstanceState);
  57.  
  58. this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  59. setContentView(R.layout.gametypeselect);
  60.  
  61. // Find the playerNameText view, grab the Shared Preferences and grab
  62. // the username
  63. // to populate this text field.
  64. playerNameText = (TextView) findViewById(R.id.playerNameText);
  65. SharedPreferences prefs = PreferenceManager
  66. .getDefaultSharedPreferences(this);
  67. String username = prefs.getString(getResources().getString(
  68. R.string.username_pref), getResources().getString(
  69. R.string.username_pref_default));
  70. playerNameText.setText(username);
  71.  
  72. btn_addition = (ImageButton) findViewById(R.id.btn_addition);
  73. btn_subtraction = (ImageButton) findViewById(R.id.btn_subtraction);
  74. btn_multiplication = (ImageButton) findViewById(R.id.btn_multiplication);
  75. btn_division = (ImageButton) findViewById(R.id.btn_division);
  76. btn_identity = (ImageButton) findViewById(R.id.btn_identity);
  77.  
  78. btn_addition.setOnClickListener(this);
  79. btn_subtraction.setOnClickListener(this);
  80. btn_multiplication.setOnClickListener(this);
  81. btn_division.setOnClickListener(this);
  82. btn_identity.setOnClickListener(this);
  83. }
  84.  
  85. @Override
  86. public void onPause() {
  87. currentPos = SoundService.musicPlayer.getCurrentPosition();
  88. SoundService.currentPos = currentPos;
  89. SoundService.musicPlayer.pause();
  90. super.onPause();
  91. }
  92.  
  93. @Override
  94. public void onResume() {
  95. SoundService.resumeAt();
  96. super.onResume();
  97. }
  98. }
Add Comment
Please, Sign In to add comment