Skip to content

Commit

Permalink
Detect phone & send PTT on/off command
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpv committed Jan 25, 2025
1 parent 1d9eaa6 commit 89caacb
Show file tree
Hide file tree
Showing 24 changed files with 515 additions and 139 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build Android App (apk)

on:
push:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout code and submodule(s)
uses: actions/checkout@v4
with:
submodules: 'recursive'

# Set Current Date As Env Variable
- name: Set current date as env variable
run: echo "date_today=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

# Set Repository Name As Env Variable
- name: Set repository name as env variable
run: echo "repository_name=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV

- name: Set Up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '21'
cache: 'gradle'

- name: Change wrapper permissions
run: chmod +x ./gradlew

# Run Build Project
- name: Build gradle project
run: ./gradlew build

# Run Tests Build
- name: Run gradle tests
run: ./gradlew test

# Create APK Debug
- name: Build apk debug project (APK)
run: ./gradlew assembleDebug

# Create APK Release
- name: Build apk release project (APK)
run: ./gradlew assembleRelease

# Upload Artifact Build
# Noted For Output mobile/build/outputs/apk/debug/
- name: Upload mobile APK Debug - ${{ env.repository_name }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.date_today }} - ${{ env.repository_name }} - mobile - APK(s) debug generated
path: mobile/build/outputs/apk/debug/

# Noted For Output mobile/build/outputs/apk/release/
- name: Upload mobile APK Release - ${{ env.repository_name }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.date_today }} - ${{ env.repository_name }} - mobile - APK(s) release generated
path: mobile/build/outputs/apk/release/

# Noted For Output wear/build/outputs/apk/debug/
- name: Upload wear APK Debug - ${{ env.repository_name }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.date_today }} - ${{ env.repository_name }} - wear - APK(s) debug generated
path: wear/build/outputs/apk/debug/

# Noted For Output wear/build/outputs/apk/release/
- name: Upload wear APK Release - ${{ env.repository_name }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.date_today }} - ${{ env.repository_name }} - wear - APK(s) release generated
path: wear/build/outputs/apk/release/
17 changes: 4 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
*.iml
.gradle
/.gradle
/.idea
/.kotlin
/build
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/compiler.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/gradle.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/migrations.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/misc.xml

This file was deleted.

17 changes: 0 additions & 17 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
agp = "8.8.0"
kotlin = "2.0.0"
kotlin = "2.0.21"
coreKtx = "1.15.0"
junit = "4.13.2"
junitVersion = "1.2.1"
Expand All @@ -23,6 +23,7 @@ tilesToolingPreview = "1.4.0"
horologistComposeTools = "0.6.17"
horologistTiles = "0.6.17"
watchfaceComplicationsDataSourceKtx = "1.2.1"
wearPhoneInteractions = "1.0.1"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand Down Expand Up @@ -53,6 +54,8 @@ androidx-tiles-tooling-preview = { group = "androidx.wear.tiles", name = "tiles-
horologist-compose-tools = { group = "com.google.android.horologist", name = "horologist-compose-tools", version.ref = "horologistComposeTools" }
horologist-tiles = { group = "com.google.android.horologist", name = "horologist-tiles", version.ref = "horologistTiles" }
androidx-watchface-complications-data-source-ktx = { group = "androidx.wear.watchface", name = "watchface-complications-data-source-ktx", version.ref = "watchfaceComplicationsDataSourceKtx" }
androidx-wear-phone-interactions = { group = "androidx.wear", name = "wear-phone-interactions", version.ref = "wearPhoneInteractions" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jan 23 19:43:43 PST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
13 changes: 6 additions & 7 deletions mobile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ android {
compileSdk = 35

defaultConfig {
applicationId = "com.swooby.phonewearremote"
minSdk = 34
targetSdk = 35

applicationId = "com.swooby.phonewearremote"
versionCode = 1
versionName = "1.0"

Expand All @@ -27,11 +27,11 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
kotlinOptions {
jvmTarget = "11"
jvmTarget = "21"
}
}

Expand All @@ -45,5 +45,4 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
wearApp(project(":wear"))
}
}
8 changes: 4 additions & 4 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PhoneWearRemote"
tools:targetApi="31">
>
<activity
android:name=".MainActivity"
android:exported="true">
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -23,4 +23,4 @@
</activity>
</application>

</manifest>
</manifest>
38 changes: 37 additions & 1 deletion mobile/src/main/java/com/swooby/phonewearremote/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package com.swooby.phonewearremote

import android.os.Bundle
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.google.android.gms.wearable.MessageClient
import com.google.android.gms.wearable.MessageEvent
import com.google.android.gms.wearable.Wearable
import com.swooby.phonewearremote.Utils.quote

class MainActivity : AppCompatActivity(), MessageClient.OnMessageReceivedListener {
companion object {
private const val TAG = "MainActivity"
}

private val messageClient by lazy { Wearable.getMessageClient(this) }

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
Expand All @@ -16,5 +27,30 @@ class MainActivity : AppCompatActivity() {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

messageClient.addListener(this)
}

override fun onDestroy() {
super.onDestroy()
messageClient.removeListener(this)
}

override fun onMessageReceived(messageEvent: MessageEvent) {
val path = messageEvent.path
when (path) {
"/pushToTalk" -> handlePushToTalkCommand(messageEvent)
else -> Log.d(TAG, "Unhandled messageEvent.path=${quote(path)}")
}
}

private fun handlePushToTalkCommand(messageEvent: MessageEvent) {
val payload = messageEvent.data
val payloadString = String(payload)
Log.i(TAG, "handlePushToTalkCommand: PushToTalk command received! payloadString=${quote(payloadString)}")

// TODO: Start your "PushToTalk" action:
// e.g., open a microphone, start voice recognition, etc.
// ...
}
}
32 changes: 32 additions & 0 deletions mobile/src/main/java/com/swooby/phonewearremote/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.swooby.phonewearremote

import kotlin.reflect.KClass

object Utils {
fun getShortClassName(value: Any?): String {
return when (value) {
is KClass<*> -> value.simpleName ?: "null"
else -> value?.javaClass?.simpleName ?: "null"
}
}

fun quote(value: Any?, typeOnly: Boolean = false): String {
if (value == null) {
return "null"
}

if (typeOnly) {
return getShortClassName(value)
}

if (value is String) {
return "\"$value\""
}

if (value is CharSequence) {
return "\"$value\""
}

return value.toString()
}
}
9 changes: 9 additions & 0 deletions mobile/src/main/res/values/mobile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources
xmlns:tools="http://schemas.android.com/tools"
tools:keep="@array/android_wear_capabilities"
>
<string-array name="android_wear_capabilities">
<item>verify_remote_example_mobile_app</item>
</string-array>
</resources>
Loading

0 comments on commit 89caacb

Please sign in to comment.