Browse Source

- Main game layout updated

- User can now choose what was announced in an extra "window"
- Choosing activity adapts itself based on the choices made by the user
- After confirming the announcement is shown on the main game layout
- Some comments added for better documentation
master
Felix Kramer 6 years ago
parent
commit
a2455af788

+ 6
- 1
app/src/main/AndroidManifest.xml View File

android:name=".MainGameActivity" android:name=".MainGameActivity"
android:label="@string/title_activity_main_game" android:label="@string/title_activity_main_game"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".ChooseGame"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
></activity>
</application> </application>


</manifest> </manifest>

+ 293
- 0
app/src/main/java/project/schafkopfzaehler_2/ChooseGame.java View File

package project.schafkopfzaehler_2;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class ChooseGame extends AppCompatActivity {

RadioGroup style, call, soloPlay; // Radio groups init
RadioButton heart; // Heart button init for first invisibility
Button confirmChoice; // Confirm button init
TextView choice; // Choice view init for first choice
String playStyle, playCall, playerName; // Init for choice manipulation
private String names[] = {"", "", "", ""}; // Player names init

private RadioGroup.OnCheckedChangeListener startChangeListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
if (radioGroup == style) {
playStyle = getPlayStyle(checkedId);
playCall = getPlayCall(call.getCheckedRadioButtonId());
playerName = getSoloPlayer(soloPlay.getCheckedRadioButtonId());
} else if (radioGroup == call) {
playStyle = getPlayStyle(style.getCheckedRadioButtonId());
playCall = getPlayCall(checkedId);
playerName = getSoloPlayer(soloPlay.getCheckedRadioButtonId());
} else if (radioGroup == soloPlay) {
playStyle = getPlayStyle(style.getCheckedRadioButtonId());
playCall = getPlayCall(call.getCheckedRadioButtonId());
playerName = getSoloPlayer(checkedId);
}

configureChoice(playStyle, playCall, playerName);

}
};

private View.OnClickListener startClickListener = new View.OnClickListener() {

@Override
public void onClick (View v) {

if ( v == confirmChoice ) {
// Send choice to the previous activity
// and then finishes the current activity
Intent data = new Intent();
data.putExtra("choice", choice.getText().toString());
setResult(RESULT_OK, data);
finish();
}

}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.choosegame);

// Get player names from the activity that started this one
Intent intent = getIntent();
names = intent.getStringArrayExtra("playerNames");

// Fill in the player names in the solo choice
soloPlay = findViewById(R.id.soloplay);
for (int i = 0; i < soloPlay.getChildCount(); i++) {
((RadioButton) soloPlay.getChildAt(i)).setText(names[i]);
}

// Start click listener on confirm button
confirmChoice = findViewById(R.id.gameChoosed);
confirmChoice.setOnClickListener(startClickListener);

// Assign variables radio group and start the change listener
style = findViewById(R.id.playstyle);
style.setOnCheckedChangeListener(startChangeListener);
call = findViewById(R.id.calls);
call.setOnCheckedChangeListener(startChangeListener);
soloPlay.setOnCheckedChangeListener(startChangeListener);

// At first Sauspiel & Eichel is checked, that means that the
// heart can not be called and no solo is played. Therefore
// both options has to be invisible at first
heart = findViewById(R.id.herz);
heart.setVisibility(View.GONE);
TextView titleSolo = findViewById(R.id.title_soloplayer);
titleSolo.setVisibility(View.GONE);
soloPlay.setVisibility(View.GONE);
choice = findViewById(R.id.choice);
choice.setText(getString(R.string.sauspiel1));

}

private String getPlayStyle (int checked) {

// Certain play styles do not allow a call
// In these cases the call view should be invisible
TextView titleCall = findViewById(R.id.title_playcall);
TextView titleSolo = findViewById(R.id.title_soloplayer);

// Return value
String returnStyle = "";

// Find which radio button is selected
switch (checked) {
case R.id.sauspiel:
// Sauspiel

// Toggle visibility
titleCall.setVisibility(View.VISIBLE);
titleCall.setText(getString(R.string.call));
call.setVisibility(View.VISIBLE);
heart.setVisibility(View.GONE);
titleSolo.setVisibility(View.GONE);
soloPlay.setVisibility(View.GONE);
// -----------------

Log.d("ChooseGame", "Sauspiel selected");

returnStyle = "Sauspiel";

break;

case R.id.wenz:
// Wenz

// Toggle visibility
titleCall.setVisibility(View.GONE);
call.setVisibility(View.GONE);
titleSolo.setVisibility(View.GONE);
soloPlay.setVisibility(View.GONE);
// -----------------

Log.d("ChooseGame", "Wenz selected");

returnStyle = "Wenz";

break;

case R.id.solo:
// Solo

// Toggle visibility
titleCall.setVisibility(View.VISIBLE);
titleCall.setText(getString(R.string.soloCall));
call.setVisibility(View.VISIBLE);
titleSolo.setVisibility(View.VISIBLE);
soloPlay.setVisibility(View.VISIBLE);
heart.setVisibility(View.VISIBLE);
// -----------------

Log.d("ChooseGame", "Solo selected");

returnStyle = "Solo";

break;

default:
Log.d("ChooseGame", "!! ERROR - Nothing is selected");
break;

}

return returnStyle;

}

private String getPlayCall (int checked) {

Log.d("ChooseGame", "Call changed");

// Return value
String returnCall = "";

switch (checked) {

case R.id.eichel:

Log.d("ChooseGame", "Eichel selected");
returnCall = "Eichel";

break;

case R.id.blatt:

Log.d("ChooseGame", "Blatt selected");
returnCall = "Blatt";

break;

case R.id.schelle:

Log.d("ChooseGame", "Schelle selected");
returnCall = "Schelle";

break;

case R.id.herz:

Log.d("ChooseGame", "Herz selected");
returnCall = "Herz";

break;

}

return returnCall;
}

private String getSoloPlayer (int checked) {

Log.d("ChooseGame", "Name changed");

// Return value
String name = "";

switch (checked) {

case R.id.player1:
name = ((RadioButton) soloPlay.getChildAt(0)).getText().toString();
break;

case R.id.player2:
name = ((RadioButton) soloPlay.getChildAt(1)).getText().toString();
break;

case R.id.player3:
name = ((RadioButton) soloPlay.getChildAt(2)).getText().toString();
break;

case R.id.player4:
name = ((RadioButton) soloPlay.getChildAt(3)).getText().toString();
break;

default:
// Do nothing
break;
}

return name;
}

private void configureChoice (String style, String call, String name) {

if ( style.equals("Wenz") ) {

choice.setText(style);

} else if ( style.equals("Sauspiel") ) {

switch (call) {
case "Eichel":
choice.setText(getString(R.string.sauspiel1));
break;
case "Blatt":
choice.setText(getString(R.string.sauspiel2));
break;
case "Schelle":
choice.setText(getString(R.string.sauspiel3));
break;
}

} else if ( style.equals("Solo") ) {

switch (call) {
case "Eichel":
choice.setText(getString(R.string.solo1));
choice.append(" " + name);
break;
case "Blatt":
choice.setText(getString(R.string.solo2));
choice.append(" " + name);
break;
case "Schelle":
choice.setText(getString(R.string.solo3));
choice.append(" " + name);
break;
case "Herz":
choice.setText(getString(R.string.solo4));
choice.append(" " + name);
break;
}
}


}
}

+ 49
- 9
app/src/main/java/project/schafkopfzaehler_2/MainGameActivity.java View File

import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView;


public class MainGameActivity extends AppCompatActivity { public class MainGameActivity extends AppCompatActivity {


private Button p1, p2, p3, p4;
private Button p1, p2, p3, p4, chooseGame; // Button init
private TextView choice;
private String playerNames[] = {"", "", "", ""}; // Player names init


private View.OnClickListener startClickListener = new View.OnClickListener() { private View.OnClickListener startClickListener = new View.OnClickListener() {


if (v == p1 || v == p2 || v == p3 || v == p4) { if (v == p1 || v == p2 || v == p3 || v == p4) {
playerButtonClicked(v); playerButtonClicked(v);
} }
if (v == chooseGame) {
gameChoosing();
}
} }
}; };


protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.d("MainGame", "onCreate"); Log.d("MainGame", "onCreate");

setContentView(R.layout.main_game_layout); setContentView(R.layout.main_game_layout);


// Get player names from the activity that started this one
Intent intent = getIntent(); Intent intent = getIntent();
String playerNames[] = intent.getStringArrayExtra("playerNames");
playerNames = intent.getStringArrayExtra("playerNames");


Log.d("MainGame", "Find Buttons");
p1 = findViewById(R.id.p1_game); p1 = findViewById(R.id.p1_game);
p2 = findViewById(R.id.p2_game); p2 = findViewById(R.id.p2_game);
p3 = findViewById(R.id.p3_game); p3 = findViewById(R.id.p3_game);
p4 = findViewById(R.id.p4_game); p4 = findViewById(R.id.p4_game);
chooseGame = findViewById(R.id.chooseGame);
choice = findViewById(R.id.announcement);


Log.d("MainGame", "Set player names into buttons");
// Set player names into buttons // Set player names into buttons
p1.setText(playerNames[0]); p1.setText(playerNames[0]);
Log.d("MainGame", "Zero works -> one");
p2.setText(playerNames[1]); p2.setText(playerNames[1]);
Log.d("MainGame", "one works -> two");
p3.setText(playerNames[2]); p3.setText(playerNames[2]);
Log.d("MainGame", "Two works -> three");
p4.setText(playerNames[3]); p4.setText(playerNames[3]);
Log.d("MainGame", "Three works");


// Start listening if buttons are clicked
chooseGame.setOnClickListener(startClickListener);
p1.setOnClickListener(startClickListener); p1.setOnClickListener(startClickListener);
p2.setOnClickListener(startClickListener); p2.setOnClickListener(startClickListener);
p3.setOnClickListener(startClickListener); p3.setOnClickListener(startClickListener);


} }


@Override
protected void onPause() {
super.onPause();
}

@Override
protected void onResume() {
super.onResume();
}

@Override
protected void onRestart() {
super.onRestart();
}

@Override
protected void onStart() {
super.onStart();
}

private void playerButtonClicked (View v) { private void playerButtonClicked (View v) {


Log.d("MainGame", v + " clicked..."); Log.d("MainGame", v + " clicked...");


} }


private void gameChoosing () {
Intent choose = new Intent(this, ChooseGame.class);
choose.putExtra("playerNames", playerNames);
startActivityForResult(choose, 0);
//startActivity(choose);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String announcement = data.getStringExtra("choice");
choice.setText(announcement);
}
}
}

} }

+ 7
- 9
app/src/main/java/project/schafkopfzaehler_2/StartActivity.java View File



public class StartActivity extends AppCompatActivity { public class StartActivity extends AppCompatActivity {


private Button startButton;
private Button nextButton;
private String players[] = {"", "", "", ""};
private Button startButton, nextButton; // Button init
private String players[] = {"", "", "", ""}; // Player names array init


private View.OnClickListener startClickListener = new View.OnClickListener() { private View.OnClickListener startClickListener = new View.OnClickListener() {


@Override @Override
public void onClick (View v) { public void onClick (View v) {
// Distinguish between the start button and the next button
if (v == startButton) { if (v == startButton) {
startButtonClicked(); startButtonClicked();
} }
players[3] = player4.getText().toString(); players[3] = player4.getText().toString();
} }


Log.d("Start", "nextButtonClicked --> Intent follows");

Intent intent = new Intent(this, MainGameActivity.class);
intent.putExtra("playerNames", players);
startActivity(intent);

// Start main game activity and add the player names to the intent
Intent intent = new Intent(this, MainGameActivity.class);
intent.putExtra("playerNames", players);
startActivity(intent);


} }



+ 246
- 0
app/src/main/res/layout/choosegame.xml View File

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/woodentable"
tools:context=".ChooseGame">

<RelativeLayout
android:id="@+id/realtivelayout_game"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">

<TextView
android:id="@+id/title_choosegame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:fontFamily="@font/germania_one"
android:lineSpacingExtra="0sp"
android:text="@string/chooseGame"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="@android:color/black"
android:textSize="30sp" />

<TextView
android:id="@+id/title_playstyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title_choosegame"
android:layout_centerHorizontal="false"
android:layout_marginTop="10dp"
android:fontFamily="@font/germania_one"
android:lineSpacingExtra="0sp"
android:text="@string/gamestyle"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="@android:color/black"
android:textSize="24sp" />

<RadioGroup
android:id="@+id/playstyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title_playstyle"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:paddingTop="5dp">

<RadioButton
android:id="@+id/sauspiel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:fontFamily="sans-serif-condensed"
android:text="@string/sauspiel"
android:textColor="@android:color/black"
android:textSize="18sp" />

<RadioButton
android:id="@+id/wenz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-condensed"
android:text="@string/wenz"
android:textColor="@android:color/black"
android:textSize="18sp" />

<RadioButton
android:id="@+id/solo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:text="@string/solo"
android:textColor="@android:color/black"
android:textSize="18sp" />

</RadioGroup>

<TextView
android:id="@+id/title_playcall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/playstyle"
android:layout_centerHorizontal="false"
android:layout_marginTop="10dp"
android:fontFamily="@font/germania_one"
android:lineSpacingExtra="0sp"
android:text="@string/call"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="@android:color/black"
android:textSize="24sp" />

<RadioGroup
android:id="@+id/calls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title_playcall"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:paddingTop="5dp">

<RadioButton
android:id="@+id/eichel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:drawableEnd="@drawable/eichel" />

<RadioButton
android:id="@+id/blatt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:drawableEnd="@drawable/blatt"
android:fontFamily="sans-serif-condensed"
android:textColor="@android:color/black"
android:textSize="18sp" />

<RadioButton
android:id="@+id/schelle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableEnd="@drawable/schelle" />

<RadioButton
android:id="@+id/herz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:drawableEnd="@drawable/herz"
android:fontFamily="sans-serif-condensed"
android:textColor="@android:color/black"
android:textSize="18sp" />
</RadioGroup>

<TextView
android:id="@+id/title_soloplayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/calls"
android:layout_centerHorizontal="false"
android:layout_marginTop="10dp"
android:fontFamily="@font/germania_one"
android:lineSpacingExtra="0sp"
android:text="@string/soloPlayer"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="@android:color/black"
android:textSize="24sp" />

<RadioGroup
android:id="@+id/soloplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title_soloplayer"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:paddingTop="5dp">

<RadioButton
android:id="@+id/player1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="@string/Player1" />

<RadioButton
android:id="@+id/player2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Player2" />

<RadioButton
android:id="@+id/player3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Player3" />

<RadioButton
android:id="@+id/player4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Player4" />

</RadioGroup>

<TextView
android:id="@+id/title_choice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/soloplay"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:fontFamily="@font/germania_one"
android:lineSpacingExtra="0sp"
android:text="@string/choice"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="@android:color/black"
android:textSize="24sp" />

<TextView
android:id="@+id/choice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title_choice"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:fontFamily="sans-serif-condensed"
android:lineSpacingExtra="0sp"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="@android:color/black"
android:textSize="24sp" />

<Button
android:id="@+id/gameChoosed"
style="?android:borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@android:color/holo_green_dark"
android:fontFamily="@font/germania_one"
android:text="@string/confirm"
android:textColor="@android:color/black"
android:textSize="24sp" />

</RelativeLayout>

</android.support.design.widget.CoordinatorLayout>

+ 35
- 16
app/src/main/res/layout/main_game_layout.xml View File

android:background="@drawable/woodentable" android:background="@drawable/woodentable"
tools:context=".MainGameActivity"> tools:context=".MainGameActivity">


<TextView
android:id="@+id/title_game"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:fontFamily="@font/germania_one"
android:lineSpacingExtra="0sp"
android:text="TEST"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="@android:color/black"
android:textSize="36sp" />

<RelativeLayout <RelativeLayout
android:id="@+id/realtivelayout_game" android:id="@+id/realtivelayout_game"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center"> android:gravity="center">


<TextView
android:id="@+id/title_announcement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/germania_one"
android:gravity="fill_horizontal"
android:paddingStart="10dp"
android:paddingTop="10dp"
android:text="@string/announcementMade"
android:textAlignment="center"
android:textColor="@android:color/black"
android:textSize="30sp" />

<TextView
android:id="@+id/announcement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title_announcement"
android:layout_gravity="center_horizontal|fill_horizontal"
android:fontFamily="sans-serif-condensed"
android:gravity="fill_horizontal"
android:paddingBottom="10dp"
android:text="@string/noChoice"
android:textAlignment="center"
android:textColor="@android:color/black"
android:textSize="24sp" />

<TableLayout <TableLayout
android:id="@+id/table" android:id="@+id/table"
android:layout_width="match_parent" android:layout_width="match_parent"
android:gravity="center" android:gravity="center"
android:stretchColumns="1"> android:stretchColumns="1">


<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >

</TableRow>

<TableRow <TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
</TableLayout> </TableLayout>


<Button <Button
android:id="@+id/testButton"
android:id="@+id/chooseGame"
style="?android:borderlessButtonStyle" style="?android:borderlessButtonStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:background="@android:color/holo_green_dark" android:background="@android:color/holo_green_dark"
android:fontFamily="@font/germania_one" android:fontFamily="@font/germania_one"
android:text="Test Button"
android:text="@string/announcement"
android:textColor="@android:color/black" android:textColor="@android:color/black"
android:textSize="24sp" /> android:textSize="24sp" />



+ 21
- 1
app/src/main/res/values/strings.xml View File

<string name="Player3">Spieler 3</string> <string name="Player3">Spieler 3</string>
<string name="Player4">Spieler 4</string> <string name="Player4">Spieler 4</string>
<string name="emptyName">Bitte geben Sie einen Namen ein!</string> <string name="emptyName">Bitte geben Sie einen Namen ein!</string>
<string name="title_activity_main_game">MainGameActivity</string>
<string name="chooseGame">Was wurde gespielt?</string>
<string name="gamestyle">Spielart</string>
<string name="sauspiel">Sauspiel</string>
<string name="wenz">Wenz</string>
<string name="solo">Solo</string>
<string name="call">Was wurde gerufen?</string>
<string name="soloCall">Was war die Trumpffarbe?</string>
<string name="title_activity_main_game">ActivityMainGame</string>
<string name="announcement">Neue Ansage</string>
<string name="announcementMade">Angesagt\:</string>
<string name="noChoice">Es wurde noch nichts angesagt...</string>
<string name="soloPlayer">Wer hat das Solo gespielt?</string>
<string name="choice">-- Ihre Auswahl --</string>
<string name="confirm">Bestätigen</string>
<string name="sauspiel1">Alte</string>
<string name="sauspiel2">Blaue</string>
<string name="sauspiel3">Runde</string>
<string name="solo1">Eichel Solo</string>
<string name="solo2">Blatt Solo</string>
<string name="solo3">Schellen Solo</string>
<string name="solo4">Herz Solo</string>
</resources> </resources>

Loading…
Cancel
Save