Skip to content

Commit

Permalink
Haptic Feedback (#39)
Browse files Browse the repository at this point in the history
* Add animation to text in Player Board

* Clean up animation

* Add animation for round score insertion

* Add logic to insert single rounds to Scoreboard instead of resetting entire score

* Animate EndGame screen transitions

* Add haptic feedback across the app
  • Loading branch information
askariya authored Aug 17, 2024
1 parent c79572a commit 60a8255
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.askariya.lostcitiesscorecalculator
import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle
import android.view.HapticFeedbackConstants
import android.view.Menu
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -101,6 +102,8 @@ class MainActivity : AppCompatActivity() {

// Handle toolbar button clicks
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Trigger haptic feedback
findViewById<View>(R.id.header_toolbar)?.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
return when (item.itemId) {
R.id.submit_button -> {
onSubmitButtonPressed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class PlayerBoardFragment : Fragment() {
wagerButton?.tag = viewModel.wagerCounts.value?.get(col) ?: 0
wagerButton?.setColorFilter(buttonColor)
wagerButton?.setOnClickListener {
it.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
viewModel.toggleWagerCountCommand(col)
}

Expand All @@ -166,6 +167,7 @@ class PlayerBoardFragment : Fragment() {
button?.tag = viewModel.buttonStates.value?.get(col)?.get(row) ?: false
button?.setTextColor(buttonColor)
button?.setOnClickListener {
it.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
viewModel.toggleButtonStateCommand(row, col)
}
}
Expand All @@ -174,6 +176,7 @@ class PlayerBoardFragment : Fragment() {
// set the resetButton functionality
val resetButton : Button = binding.resetButton
resetButton.setOnClickListener{
it.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
onResetButtonPressed()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ class EndGameFragment : Fragment() {
// set the restartButton functionality
val restartGameButton : Button = binding.restartGameButton
restartGameButton.setOnClickListener{
it.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
onRestartGameButtonPressed()
}

// set the reloadButton functionality
val reloadGameButton : Button = binding.reloadGameButton
reloadGameButton.setOnClickListener{
it.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
onReloadGameButtonPressed()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ class ScoreboardFragment : Fragment() {
// set the submitButton functionality
val submitScoreButton : Button = binding.submitScoreButton
submitScoreButton.setOnClickListener{
it.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
onSubmitButtonPressed()
}

// set the restartButton functionality
val restartGameButton : Button = binding.restartGameButton
restartGameButton.setOnClickListener{
it.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
onRestartGameButtonPressed()
}

// set the endGameButton functionality
val endGameButton : Button = binding.endGameButton
endGameButton.setOnClickListener{
it.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
onEndGameButtonPressed()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,31 @@ object DialogUtils {
builder.setTitle(title)
builder.setMessage(Html.fromHtml(message, Html.FROM_HTML_MODE_COMPACT))

builder.setPositiveButton(positiveButtonText) { dialog, which ->
onConfirm()
}
// Set null for button action initially
builder.setPositiveButton(positiveButtonText, null)

builder.setNegativeButton(negativeButtonText) { dialog, which ->
dialog.dismiss()
}

val dialog: AlertDialog = builder.create()
dialog.setOnShowListener {
val positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
val negativeButton = dialog.getButton(AlertDialog.BUTTON_NEGATIVE)

// Set a click listener to perform haptic feedback and dismiss the dialog
positiveButton.setOnClickListener {
positiveButton.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
onConfirm()
dialog.dismiss() // Close the dialog
}

// Set a click listener to perform haptic feedback and dismiss the dialog
negativeButton.setOnClickListener {
negativeButton.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
dialog.dismiss() // Close the dialog
}
}
dialog.show()
}

Expand All @@ -40,12 +56,23 @@ object DialogUtils {
val builder = AlertDialog.Builder(context)
builder.setTitle(title)
builder.setMessage(Html.fromHtml(message, Html.FROM_HTML_MODE_COMPACT))
builder.setCancelable(false) // Prevent notification from closing when clicking elsewhere.
builder.setPositiveButton(positiveButtonText) { dialog, which ->
onConfirm()
}
// Prevent notification from closing when clicking elsewhere.
builder.setCancelable(false)

// Set null for button action initially
builder.setPositiveButton(positiveButtonText, null)

val dialog: AlertDialog = builder.create()
dialog.setOnShowListener {
val positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)

// Set a click listener to perform haptic feedback and dismiss the dialog
positiveButton.setOnClickListener {
positiveButton.performHapticFeedback(android.view.HapticFeedbackConstants.VIRTUAL_KEY)
onConfirm()
dialog.dismiss() // Close the dialog
}
}
dialog.show()
}

Expand Down

0 comments on commit 60a8255

Please sign in to comment.