diff --git a/app/src/main/java/com/mintris/MainActivity.kt b/app/src/main/java/com/mintris/MainActivity.kt index c084f6c..e16ef0b 100644 --- a/app/src/main/java/com/mintris/MainActivity.kt +++ b/app/src/main/java/com/mintris/MainActivity.kt @@ -688,29 +688,27 @@ class MainActivity : AppCompatActivity() { // Add an on back pressed callback to handle back button/gesture if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - onBackPressedDispatcher.addCallback(this, object : androidx.activity.OnBackPressedCallback(true) { - override fun handleOnBackPressed() { - // If we're playing the game, handle it as a pause action instead of exiting - if (gameView.visibility == View.VISIBLE && !gameView.isPaused && !gameView.isGameOver()) { - gameView.pause() - gameMusic.pause() - showPauseMenu() - binding.pauseStartButton.visibility = View.GONE - binding.resumeButton.visibility = View.VISIBLE - } else if (binding.pauseContainer.visibility == View.VISIBLE) { - // If pause menu is showing, handle as a resume - resumeGame() - } else if (binding.gameOverContainer.visibility == View.VISIBLE) { - // If game over is showing, go back to title - hideGameOver() - showTitleScreen() - } else if (titleScreen.visibility == View.VISIBLE) { - // If title screen is showing, allow normal back behavior (exit app) - isEnabled = false - onBackPressedDispatcher.onBackPressed() - } + onBackPressedDispatcher.addCallback(this) { + // If we're playing the game, handle it as a pause action instead of exiting + if (gameView.visibility == View.VISIBLE && !gameView.isPaused && !gameView.isGameOver()) { + gameView.pause() + gameMusic.pause() + showPauseMenu() + binding.pauseStartButton.visibility = View.GONE + binding.resumeButton.visibility = View.VISIBLE + } else if (binding.pauseContainer.visibility == View.VISIBLE) { + // If pause menu is showing, handle as a resume + resumeGame() + } else if (binding.gameOverContainer.visibility == View.VISIBLE) { + // If game over is showing, go back to title + hideGameOver() + showTitleScreen() + } else if (titleScreen.visibility == View.VISIBLE) { + // If title screen is showing, allow normal back behavior (exit app) + isEnabled = false + onBackPressedDispatcher.onBackPressed() } - }) + } } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { // For Android 11 (R) to Android 12 (S), use the WindowInsetsController to disable gestures window.insetsController?.systemBarsBehavior = diff --git a/app/src/main/java/com/mintris/game/GameHaptics.kt b/app/src/main/java/com/mintris/game/GameHaptics.kt index 44e5011..7a46482 100644 --- a/app/src/main/java/com/mintris/game/GameHaptics.kt +++ b/app/src/main/java/com/mintris/game/GameHaptics.kt @@ -5,26 +5,27 @@ import android.os.Build import android.os.VibrationEffect import android.os.Vibrator import android.os.VibratorManager +import android.util.Log import android.view.HapticFeedbackConstants import android.view.View -import android.util.Log +import androidx.core.content.getSystemService /** * Handles haptic feedback for game events */ class GameHaptics(private val context: Context) { - companion object { - private const val TAG = "GameHaptics" - } + private val TAG = "GameHaptics" // Vibrator service - private val vibrator: Vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - val vibratorManager = context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager - vibratorManager.defaultVibrator - } else { - @Suppress("DEPRECATION") - context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + private val vibrator: Vibrator by lazy { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + val vibratorManager = context.getSystemService() + vibratorManager?.defaultVibrator ?: throw IllegalStateException("No vibrator available") + } else { + @Suppress("DEPRECATION") + context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + } } // Vibrate for line clear (more intense for more lines) diff --git a/app/src/main/java/com/mintris/game/GameView.kt b/app/src/main/java/com/mintris/game/GameView.kt index e4d7625..74273f8 100644 --- a/app/src/main/java/com/mintris/game/GameView.kt +++ b/app/src/main/java/com/mintris/game/GameView.kt @@ -820,6 +820,7 @@ class GameView @JvmOverloads constructor( } } lastTapTime = currentTime + return true } MotionEvent.ACTION_MOVE -> { @@ -877,6 +878,7 @@ class GameView @JvmOverloads constructor( // No direction lock yet, don't process movement } } + return true } MotionEvent.ACTION_UP -> { @@ -909,21 +911,16 @@ class GameView @JvmOverloads constructor( } else if (moveTime < minTapTime && abs(deltaY) < maxTapMovement && abs(deltaX) < maxTapMovement) { - // Quick tap with minimal movement (rotation) - if (currentTime - lastRotationTime >= rotationCooldown) { - Log.d("GameView", "Rotation detected") - gameBoard.rotate() - lastRotationTime = currentTime - invalidate() - } + // This was a tap, perform click + performClick() } // Reset direction lock lockedDirection = null + return true } } - - return true + return super.onTouchEvent(event) } /**