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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package project.schafkopfzaehler_2;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.provider.MediaStore;
  5. import android.support.design.widget.FloatingActionButton;
  6. import android.support.design.widget.Snackbar;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.support.v7.widget.Toolbar;
  9. import android.util.Log;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.TextView;
  13. public class MainGameActivity extends AppCompatActivity {
  14. private Button p1, p2, p3, p4, chooseGame; // Button init
  15. private TextView choice;
  16. private String playerNames[] = {"", "", "", ""}; // Player names init
  17. static final int REQUEST_VIDEO_CAPTURE = 1;
  18. private View.OnClickListener startClickListener = new View.OnClickListener() {
  19. @Override
  20. public void onClick (View v) {
  21. if (v == p1 || v == p2 || v == p3 || v == p4) {
  22. playerButtonClicked(v);
  23. }
  24. if (v == chooseGame) {
  25. gameChoosing();
  26. }
  27. }
  28. };
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. Log.d("MainGame", "onCreate");
  33. setContentView(R.layout.main_game_layout);
  34. // Get player names from the activity that started this one
  35. Intent intent = getIntent();
  36. playerNames = intent.getStringArrayExtra("playerNames");
  37. p1 = findViewById(R.id.p1_game);
  38. p2 = findViewById(R.id.p2_game);
  39. p3 = findViewById(R.id.p3_game);
  40. p4 = findViewById(R.id.p4_game);
  41. chooseGame = findViewById(R.id.chooseGame);
  42. choice = findViewById(R.id.announcement);
  43. // Set player names into buttons
  44. p1.setText(playerNames[0]);
  45. p2.setText(playerNames[1]);
  46. p3.setText(playerNames[2]);
  47. p4.setText(playerNames[3]);
  48. // Start listening if buttons are clicked
  49. chooseGame.setOnClickListener(startClickListener);
  50. p1.setOnClickListener(startClickListener);
  51. p2.setOnClickListener(startClickListener);
  52. p3.setOnClickListener(startClickListener);
  53. p4.setOnClickListener(startClickListener);
  54. }
  55. @Override
  56. protected void onPause() {
  57. super.onPause();
  58. }
  59. @Override
  60. protected void onResume() {
  61. super.onResume();
  62. }
  63. @Override
  64. protected void onRestart() {
  65. super.onRestart();
  66. }
  67. @Override
  68. protected void onStart() {
  69. super.onStart();
  70. }
  71. private void playerButtonClicked (View v) {
  72. Log.d("MainGame", v + " clicked...");
  73. Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
  74. if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
  75. startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
  76. }
  77. }
  78. private void gameChoosing () {
  79. Intent choose = new Intent(this, ChooseGame.class);
  80. choose.putExtra("playerNames", playerNames);
  81. startActivityForResult(choose, 0);
  82. //startActivity(choose);
  83. }
  84. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  85. if (requestCode == 0) {
  86. if (resultCode == RESULT_OK) {
  87. String announcement = data.getStringExtra("choice");
  88. choice.setText(announcement);
  89. }
  90. }
  91. if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
  92. // Do nothing...
  93. }
  94. }
  95. }