Projekt Schafkopfpunktezähler: Erster Prototyp einer App, die dem Benutzer die Notwendigkeit des Punktezählens beim Schafkopfspiel abnimmt.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainGameActivity.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package project.schafkopfzaehler_2;
  2. import android.content.Intent;
  3. import android.hardware.camera2.CameraMetadata;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.provider.MediaStore;
  7. import android.support.design.widget.FloatingActionButton;
  8. import android.support.design.widget.Snackbar;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.support.v7.widget.Toolbar;
  11. import android.util.Log;
  12. import android.view.View;
  13. import android.widget.Button;
  14. import android.widget.TextView;
  15. import android.widget.VideoView;
  16. public class MainGameActivity extends AppCompatActivity {
  17. private Button p1, p2, p3, p4, chooseGame; // Button init
  18. private TextView choice;
  19. private String playerNames[] = {"", "", "", ""}; // Player names init
  20. private View.OnClickListener startClickListener = new View.OnClickListener() {
  21. @Override
  22. public void onClick (View v) {
  23. if (v == p1 || v == p2 || v == p3 || v == p4) {
  24. playerButtonClicked(v);
  25. }
  26. if (v == chooseGame) {
  27. gameChoosing();
  28. }
  29. }
  30. };
  31. @Override
  32. protected void onCreate(Bundle savedInstanceState) {
  33. super.onCreate(savedInstanceState);
  34. Log.d("MainGame", "onCreate");
  35. setContentView(R.layout.main_game_layout);
  36. // Get player names from the activity that started this one
  37. Intent intent = getIntent();
  38. playerNames = intent.getStringArrayExtra("playerNames");
  39. p1 = findViewById(R.id.p1_game);
  40. p2 = findViewById(R.id.p2_game);
  41. p3 = findViewById(R.id.p3_game);
  42. p4 = findViewById(R.id.p4_game);
  43. chooseGame = findViewById(R.id.chooseGame);
  44. choice = findViewById(R.id.announcement);
  45. // Set player names into buttons
  46. p1.setText(playerNames[0]);
  47. p2.setText(playerNames[1]);
  48. p3.setText(playerNames[2]);
  49. p4.setText(playerNames[3]);
  50. // Start listening if buttons are clicked
  51. chooseGame.setOnClickListener(startClickListener);
  52. p1.setOnClickListener(startClickListener);
  53. p2.setOnClickListener(startClickListener);
  54. p3.setOnClickListener(startClickListener);
  55. p4.setOnClickListener(startClickListener);
  56. }
  57. @Override
  58. protected void onPause() {
  59. super.onPause();
  60. }
  61. @Override
  62. protected void onResume() {
  63. super.onResume();
  64. }
  65. @Override
  66. protected void onRestart() {
  67. super.onRestart();
  68. }
  69. @Override
  70. protected void onStart() {
  71. super.onStart();
  72. }
  73. private void playerButtonClicked (View v) {
  74. String playerNumber = "";
  75. Log.d("MainGame", v + " clicked...");
  76. // Start card capture activity with the camera preview
  77. Intent cardCaptureIntent = new Intent(this, CardCaptureActivity.class);
  78. // Get which player button was pressed
  79. if ( findViewById(R.id.p1_game) == v ) {
  80. playerNumber = "p1";
  81. }
  82. if ( findViewById(R.id.p2_game) == v ) {
  83. playerNumber = "p2";
  84. }
  85. if ( findViewById(R.id.p3_game) == v ) {
  86. playerNumber = "p3";
  87. }
  88. if ( findViewById(R.id.p4_game) == v ) {
  89. playerNumber = "p4";
  90. }
  91. cardCaptureIntent.putExtra("playerName", playerNumber );
  92. startActivityForResult(cardCaptureIntent, 1);
  93. // startActivity(cardCaptureIntent);
  94. }
  95. private void gameChoosing () {
  96. Intent choose = new Intent(this, ChooseGame.class);
  97. choose.putExtra("playerNames", playerNames);
  98. startActivityForResult(choose, 0);
  99. //startActivity(choose);
  100. }
  101. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  102. if (requestCode == 0 && data != null) {
  103. if (resultCode == RESULT_OK) {
  104. String announcement = data.getStringExtra("choice");
  105. choice.setText(announcement);
  106. }
  107. }
  108. if (requestCode == 1 && data != null) {
  109. if (resultCode == RESULT_OK) {
  110. int points = data.getIntExtra("points", 0);
  111. String player = data.getStringExtra("playerNo");
  112. switch (player) {
  113. case "p1":
  114. TextView points_p1 = findViewById(R.id.p1_points);
  115. points_p1.setText(getString(R.string.points) + points);
  116. break;
  117. case "p2":
  118. TextView points_p2 = findViewById(R.id.p2_points);
  119. points_p2.setText(getString(R.string.points) + points);
  120. break;
  121. case "p3":
  122. TextView points_p3 = findViewById(R.id.p3_points);
  123. points_p3.setText(getString(R.string.points) + points);
  124. break;
  125. case "p4":
  126. TextView points_p4 = findViewById(R.id.p4_points);
  127. points_p4.setText(getString(R.string.points) + points);
  128. break;
  129. }
  130. }
  131. }
  132. }
  133. }