-
Notifications
You must be signed in to change notification settings - Fork 0
Margaux/local game screen #53
Changes from all commits
4909d3b
9e1fcd4
dff3d28
0e5da8c
28fd49c
d515691
52b1bc7
a6c7a32
064d9bd
10f227f
8020d7a
abe9cff
4c50fbe
9b296aa
e378528
54e86fd
1955da4
f6ab218
2c57f5c
5094e91
7cf1b67
b4f916a
86e9abc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ch.sdp.vibester | ||
|
||
import android.app.AlertDialog | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.intent.Intents | ||
import androidx.test.espresso.intent.matcher.IntentMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers.* | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.hamcrest.CoreMatchers.allOf | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
|
||
class GamescreenActivityTest { | ||
|
||
@get:Rule | ||
val testRule = ActivityScenarioRule( | ||
GamescreenActivity::class.java | ||
) | ||
|
||
@Before | ||
fun setUp() { | ||
Intents.init() | ||
} | ||
|
||
@After | ||
fun clean() { | ||
Intents.release() | ||
} | ||
|
||
@Test | ||
fun buzzerLayoutIsDisplayed() { | ||
onView(withId(R.id.buzzersLayout)).check(matches(isDisplayed())) | ||
} | ||
|
||
@Test | ||
fun scoresLayoutIsDisplayed() { | ||
onView(withId(R.id.scoresTable)).check(matches(isDisplayed())) | ||
} | ||
|
||
// FIXME: Find a way to test the popup showing despite not being a component / make robolectric work | ||
/* | ||
@Test | ||
fun clickingButtonLaunchesPopup() { | ||
|
||
|
||
} | ||
*/ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="ch.sdp.vibester"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.MyApplication"> | ||
<activity | ||
android:name=".profile.ProfileSetup" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MusicTemporary" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".GameSetupScreen" | ||
android:exported="false" /> | ||
<activity android:name=".scoreboard.ScoreBoardActivity" | ||
android:theme="@style/AppTheme.NoActionBar" /> | ||
<activity | ||
android:name=".WelcomeScreen" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".GreetingActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="ch.sdp.vibester"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.MyApplication"> | ||
<activity | ||
android:name="ch.sdp.vibester.GamescreenActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".profile.ProfileSetup" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MusicTemporary" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".GameSetupScreen" | ||
android:exported="false" /> | ||
<activity android:name=".scoreboard.ScoreBoardActivity" | ||
android:theme="@style/AppTheme.NoActionBar" /> | ||
<activity | ||
android:name=".WelcomeScreen" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".GreetingActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package ch.sdp.vibester | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.Gravity | ||
import android.widget.* | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.appcompat.widget.AlertDialogLayout | ||
|
||
|
||
class GamescreenActivity: AppCompatActivity() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add javadoc for whole class ? |
||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_gamescreen) | ||
|
||
/* number of players for the game | ||
currently hardcoded as a placeholder | ||
will be retrieved from intent launched from the game setup screen | ||
*/ | ||
val players = arrayOf("Kamila", "Jiabao", "Arda", "Laurynas") | ||
|
||
val gamescreenIntent = Intent(this, GamescreenActivity::class.java) | ||
|
||
// hardcoded test values | ||
val song = "Demo" | ||
val artist = "The Placeholders" | ||
|
||
val buildPopup = AlertDialog.Builder(this) | ||
buildPopup.setTitle("Solution") | ||
buildPopup.setMessage("The song was " + song + " by " + artist) | ||
|
||
buildPopup.setPositiveButton("Correct") { dialog, which -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 2 locations. Consider refactoring. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not urgent now but should consider creating a method to send toast(...) |
||
Toast.makeText(applicationContext, | ||
"Congrats!", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
buildPopup.setNegativeButton("Wrong") { dialog, which -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 2 locations. Consider refactoring. |
||
Toast.makeText(applicationContext, | ||
"Too bad!", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
val allPoints = arrayOf(1, 2, 3, 4) | ||
|
||
buildScores(players, allPoints) | ||
buildBuzzers(players, buildPopup) | ||
|
||
} | ||
|
||
/* | ||
Programmatically builds the table of scores according to the number of players | ||
*/ | ||
private fun buildScores(players: Array<String>, allPoints: Array<Int>) { | ||
|
||
val scores = findViewById<LinearLayout>(R.id.scoresTable) | ||
val viewsOfPoints = arrayOfNulls<TableRow>(players.size) | ||
|
||
var i = 0 | ||
|
||
for (pName in players) { | ||
|
||
val score = TableRow(this) | ||
score.gravity = Gravity.CENTER | ||
|
||
val nameView = TextView(this) | ||
nameView.text = pName | ||
nameView.height = 75 | ||
nameView.width = 300 | ||
nameView.gravity = Gravity.LEFT | ||
|
||
val points = TextView(this) | ||
points.text = allPoints[i].toString() | ||
points.height = 75 | ||
points.width = 150 | ||
points.gravity = Gravity.RIGHT | ||
|
||
score.addView(nameView) | ||
score.addView(points) | ||
viewsOfPoints.set(i, score) | ||
scores.addView(score) | ||
|
||
i = i + 1 | ||
} | ||
} | ||
|
||
/* | ||
Programmatically builds the buzzers according to the number and names of players. | ||
*/ | ||
private fun buildBuzzers(players: Array<String>, popup: AlertDialog.Builder) { | ||
|
||
val buzzers = findViewById<LinearLayout>(R.id.buzzersLayout) | ||
val buttons = arrayOfNulls<Button>(players.size) | ||
|
||
var i = 0 | ||
|
||
for (pName in players) { | ||
|
||
val button = Button(this) | ||
button.text = pName | ||
button.width = 100 | ||
button.height = 150 | ||
buttons.set(i, button) | ||
button.setOnClickListener { | ||
popup.show() | ||
} | ||
buzzers.addView(button) | ||
|
||
i = i + 1 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout 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"> | ||
|
||
<LinearLayout | ||
android:id="@+id/buzzersLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_marginStart="20dp" | ||
android:layout_marginEnd="20dp" | ||
android:layout_marginBottom="16dp" | ||
android:gravity="center" | ||
android:orientation="vertical" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/scoresTable" /> | ||
|
||
<TableLayout | ||
android:id="@+id/scoresTable" | ||
android:layout_width="0dp" | ||
android:layout_height="200dp" | ||
android:layout_marginTop="1dp" | ||
android:layout_marginBottom="14dp" | ||
android:gravity="center" | ||
app:layout_constraintBottom_toTopOf="@+id/buzzersLayout" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"> | ||
</TableLayout> | ||
|
||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove empty test in comment maybe ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's why she leaves the FIXME here