Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Android CI

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
build:
Expand All @@ -24,11 +24,11 @@ jobs:
run: ./gradlew clean && ./gradlew assembleDebug
- uses: actions/upload-artifact@v2
with:
name: app-debug-mobile.apk
path: app/build/outputs/apk/debug/app-debug-mobile.apk
name: mobile-debug.apk
path: mobile/build/outputs/apk/debug/mobile-debug.apk
- name: Build wear with Gradle
run: ./gradlew clean && ./gradlew :mobile:assembleDebug
run: ./gradlew clean && ./gradlew :wear:assembleDebug
- uses: actions/upload-artifact@v2
with:
name: app-debug-wear.apk
path: app/build/outputs/apk/debug/app-debug-wear.apk
name: wear-debug.apk
path: wear/build/outputs/apk/debug/wear-debug.apk
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.5.31'
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
6 changes: 3 additions & 3 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "es.hegocre.scorecounter"
minSdkVersion 24
targetSdkVersion 31
versionCode 311030000
versionName "1.0.3"
versionCode 311040000
versionName "1.0.4"
}

buildTypes {
Expand Down Expand Up @@ -42,6 +42,6 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.preference:preference-ktx:1.1.1'
testImplementation 'junit:junit:4.13.2'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.core:core-ktx:1.7.0'
}
7 changes: 4 additions & 3 deletions wear/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ android {

defaultConfig {
applicationId "es.hegocre.scorecounter"
minSdkVersion 24
minSdkVersion 25
targetSdkVersion 31
versionCode 311030101
versionName "1.0.3"
versionCode 311040100
versionName "1.0.4"
}

buildTypes {
Expand Down Expand Up @@ -45,4 +45,5 @@ dependencies {
implementation 'androidx.wear:wear:1.2.0'
compileOnly 'com.google.android.wearable:wearable:2.8.1'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.wear:wear-input:1.1.0'
}
1 change: 1 addition & 0 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-feature android:name="android.hardware.type.watch" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
android:allowBackup="true"
Expand Down
108 changes: 107 additions & 1 deletion wear/src/main/java/es/hegocre/scorecounter/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package es.hegocre.scorecounter

import android.os.Bundle
import android.content.Context
import android.os.*
import android.view.KeyEvent
import android.view.View
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.FragmentActivity
import androidx.preference.PreferenceManager
import androidx.wear.ambient.AmbientModeSupport
import androidx.wear.input.WearableButtons
import es.hegocre.scorecounter.data.Score
import es.hegocre.scorecounter.databinding.ActivityMainBinding

Expand All @@ -16,6 +19,8 @@ class MainActivity : FragmentActivity(), AmbientModeSupport.AmbientCallbackProvi
private lateinit var ambientController: AmbientModeSupport.AmbientController
private var needsBurnProtect = false

private val buttonsAvailable = mutableListOf(false, false, false)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
Expand All @@ -30,6 +35,10 @@ class MainActivity : FragmentActivity(), AmbientModeSupport.AmbientCallbackProvi
loadScore(score, binding.add2Layout, binding.sub2Layout)
}

buttonsAvailable[0] = WearableButtons.getButtonInfo(this, KeyEvent.KEYCODE_STEM_1) != null
buttonsAvailable[1] = WearableButtons.getButtonInfo(this, KeyEvent.KEYCODE_STEM_2) != null
buttonsAvailable[2] = WearableButtons.getButtonInfo(this, KeyEvent.KEYCODE_STEM_3) != null

ambientController = AmbientModeSupport.attach(this)
}

Expand Down Expand Up @@ -103,6 +112,103 @@ class MainActivity : FragmentActivity(), AmbientModeSupport.AmbientCallbackProvi
}
}

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
return when (event?.repeatCount ?: 0) {
0 -> {
when (keyCode) {
KeyEvent.KEYCODE_STEM_1 -> {
binding.score1?.inc()
vibrate()
true
}
KeyEvent.KEYCODE_STEM_2 -> {
if (buttonsAvailable[0]) binding.score2?.inc()
else binding.score1?.inc()
vibrate()
true
}
KeyEvent.KEYCODE_STEM_3 -> {
if (!(buttonsAvailable[0] && buttonsAvailable[1])) {
if (buttonsAvailable[0] || buttonsAvailable[1])
//Button 1 or 2 available
binding.score2?.inc()
else
//No other button available
binding.score1?.inc()
}
vibrate()
true
}
else -> {
super.onKeyDown(keyCode, event)
}
}
}
1 -> onKeyLongPress(keyCode, event)
else -> super.onKeyDown(keyCode, event)
}
}

override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
return when (keyCode) {
KeyEvent.KEYCODE_STEM_1 -> {
binding.score1?.reset()
vibrate()
true
}
KeyEvent.KEYCODE_STEM_2 -> {
if (buttonsAvailable[0])
//Button 1 available
binding.score2?.reset()
else
//Buttons 2 and/or 3 available
binding.score1?.reset()

vibrate()
true
}
KeyEvent.KEYCODE_STEM_3 -> {
if (!(buttonsAvailable[0] && buttonsAvailable[1])) {
if (buttonsAvailable[0] || buttonsAvailable[1])
//Button 1 or 2 available
binding.score2?.reset()
else
//No other button available
binding.score1?.reset()
}
vibrate()
true
}
else -> {
super.onKeyDown(keyCode, event)
}
}
}

@Suppress("deprecation")
private fun Context.vibrate() {
val vibrator =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val vibratorManager =
getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
vibratorManager.defaultVibrator
} else {
getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
}
if (vibrator.hasVibrator()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(
VibrationEffect.createOneShot(
250,
VibrationEffect.DEFAULT_AMPLITUDE
)
)
} else {
vibrator.vibrate(250)
}
}
}

companion object {
private const val BURN_IN_OFFSET_PX = 10
}
Expand Down