StarterNameActivity code

This commit is contained in:
adrienmalin 2018-12-01 14:42:04 +01:00
parent 2982096e47
commit 8b8aecb1c6
11 changed files with 154 additions and 15 deletions

47
.idea/assetWizardSettings.xml generated Normal file
View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WizardSettings">
<option name="children">
<map>
<entry key="vectorWizard">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="vectorAssetStep">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="clipartAsset">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="url" value="jar:file:/C:/Program%20Files/Android/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/action/ic_swap_vert_black_24dp.xml" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
<option name="values">
<map>
<entry key="color" value="ffffff" />
<entry key="outputName" value="ic_swap_vert" />
<entry key="sourceFile" value="C:\Users\adima" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</component>
</project>

Binary file not shown.

View File

@ -13,6 +13,7 @@ android {
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary true
} }
buildTypes { buildTypes {
release { release {

View File

@ -9,7 +9,9 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme" > android:theme="@style/AppTheme" >
<activity android:name=".StarterNameActivity" > <activity
android:name=".StarterNameActivity"
android:windowSoftInputMode="adjustResize" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -1,12 +1,76 @@
package adrienmalin.pingpoints package adrienmalin.pingpoints
import android.content.Context
import android.content.SharedPreferences
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.View
import android.widget.*
class StarterNameActivity : AppCompatActivity() { class StarterNameActivity : AppCompatActivity() {
var player1NameInput: AutoCompleteTextView = null
var player2NameInput: AutoCompleteTextView = null
var starterRadioGroup: RadioGroup = null
var previousMatch: SharedPreferences = null
var previousPlayers: Set<String> = emptySet()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_starter_name) setContentView(R.layout.activity_starter_name)
previousMatch = getPreferences(Context.MODE_PRIVATE)
previousPlayers = previousMatch.getStringSet("previousPlayers", emptySet())
val previousPlayersAdapter = ArrayAdapter<String>(
this,
R.layout.activity_starter_name,
previousPlayers.toList())
player1NameInput = findViewById<AutoCompleteTextView>(R.id.player1Name)
player1NameInput?.run {
setText(
previousMatch.getString(
"previousPlayer2",
getString(R.string.player_1_default_name)),
TextView.BufferType.EDITABLE)
setAdapter(previousPlayersAdapter)
threshold = 1
}
player2NameInput = findViewById<AutoCompleteTextView>(R.id.player2Name)
player2NameInput?.run{
setText(
previousMatch.getString(
"previousPlayer1",
getString(R.string.player_2_default_name)),
TextView.BufferType.EDITABLE)
setAdapter(previousPlayersAdapter)
threshold = 1
}
starterRadioGroup = findViewById<RadioGroup>(R.id.starterRadioGroup)
starterRadioGroup?.check(previousMatch.getInt("previousStarterId", 0))
}
fun swapNames(view: View) {
player1NameInput?.text = player2NameInput?.text.also {
player2NameInput?.text = player1NameInput?.text
}
}
fun startMatch(view: View) {
val player1Name = player1NameInput?.text.toString()
val player2Name = player2NameInput?.text.toString()
// Save
previousMatch.edit().run{
putString("previousPlayer1", player1Name)
putString("previousPlayer2", player2Name)
putInt("previousStarterId", starterRadioGroup?.checkedRadioButtonId)
putStringSet(
"previousPlayers",
previousPlayers.plus(player1Name).plus(player2Name))
commit()
}
} }
} }

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M6.99,11L3,15l3.99,4v-3H14v-2H6.99v-3zM21,9l-3.99,-4v3H10v2h7.01v3L21,9z"/>
</vector>

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M16,17.01V10h-2v7.01h-3L15,21l4,-3.99h-3zM9,3L5,6.99h3V14h2V6.99h3L9,3z"/>
</vector>

View File

@ -20,15 +20,16 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/button2" android:id="@+id/button2"
android:drawableLeft="@drawable/ic_new_match" android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginEnd="8dp" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="8dp"
style="@style/Widget.AppCompat.Button.Colored"/> style="@style/Widget.AppCompat.Button.Colored" android:drawableStart="@drawable/ic_new_match"
android:onClick="startMatch"/>
<RadioGroup <RadioGroup
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/WhoStarts" android:id="@+id/radioGroup" app:layout_constraintTop_toBottomOf="@+id/WhoStarts" android:id="@+id/starterRadioGroup"
android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp" android:layout_marginLeft="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
android:layout_marginRight="8dp" android:orientation="horizontal"> android:layout_marginRight="8dp" android:orientation="horizontal">
@ -43,6 +44,11 @@
android:id="@+id/player1Name" android:id="@+id/player1Name"
tools:layout_editor_absoluteX="143dp" android:hint="@string/player_name_hint" tools:layout_editor_absoluteX="143dp" android:hint="@string/player_name_hint"
android:layout_weight="1"/> android:layout_weight="1"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:srcCompat="@drawable/ic_swap_horiz"
android:layout_weight="0" android:id="@+id/swapNamesButton"
android:contentDescription="@string/swap_names" android:onClick="swapNames"/>
<RadioButton <RadioButton
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" tools:layout_editor_absoluteY="93dp" android:layout_height="wrap_content" tools:layout_editor_absoluteY="93dp"
@ -55,21 +61,21 @@
android:hint="@string/player_name_hint" android:layout_height="wrap_content" android:layout_weight="1"/> android:hint="@string/player_name_hint" android:layout_height="wrap_content" android:layout_weight="1"/>
</RadioGroup> </RadioGroup>
<Switch <Switch
android:text="Switch" android:text="@string/TTS"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/enableTTS" tools:text="@string/TTS" android:id="@+id/enableTTS"
android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/radioGroup" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/starterRadioGroup"
android:layout_marginEnd="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="8dp" android:layout_marginEnd="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="8dp"
android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp"/> android:layout_marginLeft="8dp"/>
<Switch <Switch
android:text="Switch" android:text="@string/STT"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/enableSTT" android:layout_marginTop="8dp" android:id="@+id/enableSTT" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/enableTTS" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@+id/enableTTS" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:layout_marginRight="8dp" android:layout_marginEnd="8dp" android:layout_marginRight="8dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp" app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp"
android:layout_marginStart="8dp" tools:text="@string/STT"/> android:layout_marginStart="8dp"/>
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>

View File

@ -23,25 +23,27 @@
app:layout_constraintTop_toBottomOf="@+id/WhoStarts" app:layout_constraintTop_toBottomOf="@+id/WhoStarts"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp" android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginLeft="8dp" android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:layout_marginRight="8dp" android:id="@+id/linearLayout"> android:layout_marginEnd="8dp" android:layout_marginRight="8dp" android:id="@+id/linearLayout"
android:layout_margin="8dp">
<RadioGroup <RadioGroup
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/WhoStarts" android:id="@+id/radioGroup" app:layout_constraintTop_toBottomOf="@+id/WhoStarts" android:id="@+id/starterRadioGroup"
android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginLeft="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"> android:layout_marginRight="8dp" android:layout_marginBottom="8dp">
<RadioButton <RadioButton
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" tools:layout_editor_absoluteY="93dp" android:layout_height="wrap_content" tools:layout_editor_absoluteY="93dp"
tools:layout_editor_absoluteX="16dp" android:id="@+id/radioPlayer1Starts" tools:layout_editor_absoluteX="16dp" android:id="@+id/radioPlayer1Starts"
android:layout_weight="1"/> android:layout_weight="1" android:gravity="top"/>
<RadioButton <RadioButton
android:layout_height="wrap_content" tools:layout_editor_absoluteY="93dp" android:layout_height="wrap_content" tools:layout_editor_absoluteY="93dp"
tools:layout_editor_absoluteX="16dp" android:id="@+id/radioPlayer2Starts" tools:layout_editor_absoluteX="16dp" android:id="@+id/radioPlayer2Starts"
android:layout_width="wrap_content" android:layout_weight="1"/> android:layout_width="wrap_content" android:layout_weight="1"
android:gravity="bottom"/>
</RadioGroup> </RadioGroup>
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
@ -54,6 +56,11 @@
android:id="@+id/player1Name" android:id="@+id/player1Name"
tools:layout_editor_absoluteX="143dp" android:hint="@string/player_name_hint" tools:layout_editor_absoluteX="143dp" android:hint="@string/player_name_hint"
android:selectAllOnFocus="true"/> android:selectAllOnFocus="true"/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content" app:srcCompat="@drawable/ic_swap_vert"
android:id="@+id/swapNamesButton" android:contentDescription="@string/swap_names"
android:onClick="swapNames"/>
<AutoCompleteTextView <AutoCompleteTextView
android:text="@string/player_2_default_name" android:text="@string/player_2_default_name"
tools:layout_editor_absoluteX="136dp" android:id="@+id/player2Name" tools:layout_editor_absoluteX="136dp" android:id="@+id/player2Name"
@ -87,5 +94,5 @@
style="@style/Widget.AppCompat.Button.Colored" style="@style/Widget.AppCompat.Button.Colored"
android:layout_marginEnd="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="8dp" android:layout_marginEnd="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="8dp"
android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent"
android:drawableStart="@drawable/ic_new_match"/> android:drawableStart="@drawable/ic_new_match" android:onClick="startMatch"/>
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>

View File

@ -8,4 +8,5 @@
<string name="TTS">Synthèse vocale</string> <string name="TTS">Synthèse vocale</string>
<string name="STT">Reconnaissance vocale</string> <string name="STT">Reconnaissance vocale</string>
<string name="start">Allons-y !</string> <string name="start">Allons-y !</string>
<string name="swap_names">Échanger les noms</string>
</resources> </resources>

View File

@ -7,4 +7,5 @@
<string name="TTS">Text to speech</string> <string name="TTS">Text to speech</string>
<string name="STT">Voice recognizer</string> <string name="STT">Voice recognizer</string>
<string name="start">Let\'s go!</string> <string name="start">Let\'s go!</string>
<string name="swap_names">Swap names</string>
</resources> </resources>