├── app
├── .gitignore
├── karoo-kxradar.png
├── src
│ └── main
│ │ ├── res
│ │ ├── raw
│ │ │ └── beep.wav
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ └── ic_launcher_background.xml
│ │ ├── xml
│ │ │ └── extension_info.xml
│ │ └── drawable
│ │ │ └── ic_launcher.xml
│ │ ├── ic_launcher-playstore.png
│ │ ├── kotlin
│ │ └── org
│ │ │ └── itxsvv
│ │ │ └── kxradar
│ │ │ ├── Theme.kt
│ │ │ ├── ThreatsMonitor.kt
│ │ │ ├── MainActivity.kt
│ │ │ ├── screens
│ │ │ ├── BeepPanel.kt
│ │ │ └── MainScreen.kt
│ │ │ ├── Extensions.kt
│ │ │ └── KarooRadarExtension.kt
│ │ └── AndroidManifest.xml
├── manifest.json
├── proguard-rules.pro
└── build.gradle.kts
├── logo.png
├── audioalerts.jpg
├── kxradar_screen1.png
├── kxradar_screen2.png
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── libs.versions.toml
├── .gitignore
├── ICON_LICENSE
├── gradle.properties
├── settings.gradle.kts
├── README.md
├── .github
└── workflows
│ └── android.yml
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itxsvv/kxradar/HEAD/logo.png
--------------------------------------------------------------------------------
/audioalerts.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itxsvv/kxradar/HEAD/audioalerts.jpg
--------------------------------------------------------------------------------
/kxradar_screen1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itxsvv/kxradar/HEAD/kxradar_screen1.png
--------------------------------------------------------------------------------
/kxradar_screen2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itxsvv/kxradar/HEAD/kxradar_screen2.png
--------------------------------------------------------------------------------
/app/karoo-kxradar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itxsvv/kxradar/HEAD/app/karoo-kxradar.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/beep.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itxsvv/kxradar/HEAD/app/src/main/res/raw/beep.wav
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itxsvv/kxradar/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itxsvv/kxradar/HEAD/app/src/main/ic_launcher-playstore.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | KxRadar
3 | kxradar
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #000000
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 | .cxx
10 | local.properties
11 | /app/release
12 | keystore
13 | keystore.*
--------------------------------------------------------------------------------
/app/src/main/res/xml/extension_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
4 | networkTimeout=10000
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/org/itxsvv/kxradar/Theme.kt:
--------------------------------------------------------------------------------
1 | package org.itxsvv.kxradar
2 |
3 | import androidx.compose.material3.MaterialTheme
4 | import androidx.compose.runtime.Composable
5 |
6 | @Composable
7 | fun AppTheme(
8 | content: @Composable () -> Unit,
9 | ) {
10 | MaterialTheme(
11 | content = content,
12 | )
13 | }
14 |
--------------------------------------------------------------------------------
/app/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "label": "kxradar",
3 | "packageName": "org.itxsvv.kxradar",
4 | "iconUrl": "https://github.com/itxsvv/kxradar/releases/latest/download/karoo-kxradar.png",
5 | "latestApkUrl": "https://github.com/itxsvv/kxradar/releases/latest/download/app-release.apk",
6 | "latestVersionCode": 5,
7 | "latestVersion": "1.0.5",
8 | "developer": "itxsvv",
9 | "description": "Hammerhead Karoo extension that allows configuring radar alerts.",
10 | "releaseNotes": "1.0.5 karoo ext library updated"
11 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/org/itxsvv/kxradar/ThreatsMonitor.kt:
--------------------------------------------------------------------------------
1 | package org.itxsvv.kxradar
2 |
3 | import io.hammerhead.karooext.models.DataType
4 |
5 | /**
6 | * Main idea:
7 | * If previously not detected threat are approaching and the delay between it and
8 | * the previous threat is more than 2 seconds - make a new beep.
9 | */
10 | class ThreatsMonitor {
11 | private var targets = mapOf(
12 | DataType.Field.RADAR_TARGET_1_RANGE to 0L,
13 | DataType.Field.RADAR_TARGET_2_RANGE to 0L,
14 | DataType.Field.RADAR_TARGET_3_RANGE to 0L,
15 | DataType.Field.RADAR_TARGET_4_RANGE to 0L,
16 | DataType.Field.RADAR_TARGET_5_RANGE to 0L,
17 | DataType.Field.RADAR_TARGET_6_RANGE to 0L,
18 | DataType.Field.RADAR_TARGET_7_RANGE to 0L,
19 | DataType.Field.RADAR_TARGET_8_RANGE to 0L
20 | )
21 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.kts.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/kotlin/org/itxsvv/kxradar/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package org.itxsvv.kxradar
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import androidx.activity.ComponentActivity
6 | import androidx.activity.compose.setContent
7 | import androidx.datastore.core.DataStore
8 | import androidx.datastore.preferences.core.Preferences
9 | import androidx.datastore.preferences.preferencesDataStore
10 | import org.itxsvv.kxradar.screens.MainScreen
11 |
12 | val Context.dataStore: DataStore by preferencesDataStore(name = "settings")
13 |
14 | class MainActivity : ComponentActivity() {
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 |
18 | setContent {
19 | AppTheme {
20 | MainScreen()
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/ICON_LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015-2021 Aniket Suvarna
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | fun getLocalProperty(key: String, file: String = "local.properties"): String? {
2 | val properties = java.util.Properties()
3 | val localProperties = File(file)
4 | if (localProperties.isFile) {
5 | java.io.InputStreamReader(java.io.FileInputStream(localProperties), Charsets.UTF_8).use { reader ->
6 | properties.load(reader)
7 | }
8 | } else error("File from not found")
9 |
10 | return properties.getProperty(key)
11 | }
12 | pluginManagement {
13 | repositories {
14 | gradlePluginPortal()
15 | google()
16 | mavenCentral()
17 | }
18 | }
19 |
20 | val env: MutableMap = System.getenv()
21 | val gprUser = if(env.containsKey("GPR_USER")) env["GPR_USER"] else getLocalProperty("gpr.user")
22 | val gprKey = if(env.containsKey("GPR_KEY")) env["GPR_KEY"] else getLocalProperty("gpr.key")
23 |
24 | dependencyResolutionManagement {
25 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
26 | repositories {
27 | google()
28 | mavenCentral()
29 | // karoo-ext from Github Packages
30 | maven {
31 | url = uri("https://maven.pkg.github.com/hammerheadnav/karoo-ext")
32 | credentials {
33 | username = gprUser
34 | password = gprKey
35 | }
36 | }
37 | }
38 | }
39 |
40 | rootProject.name = "Karoo KxRadar"
41 | include("app")
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # Radar Sound Extension for Hammerhead Karoo
3 |
4 | [](https://github.com/itxsvv/kxradar/actions/workflows/android.yml)
5 | 
6 |
7 | Hammerhead Karoo extension that allows configuring radar alerts.
8 |
9 | ## Requirements
10 | **You must disable the default radar sound in the Karoo settings.\
11 | Go to Profiles -> Your profile -> Audio Alerts -> Disable RADAR**\
12 | \
13 | 
14 |
15 | ## Installation
16 | Karoo 3
17 | 1. [LINK to APK](https://github.com/itxsvv/kxradar/releases/latest/download/app-release.apk)\
18 | Share this link with the Hammerhead Companion App.
19 |
20 | Karoo 2:
21 |
22 | 1. Download the APK from the [releases page](https://github.com/itxsvv/kxradar/releases)
23 | 2. Set up your Karoo for sideloading. DC Rainmaker has a great [step-by-step guide](https://www.dcrainmaker.com/2021/02/how-to-sideload-android-apps-on-your-hammerhead-karoo-1-karoo-2.html).
24 | 3. Install the app by running `adb install app-release.apk`.
25 |
26 | ## Usage
27 | Set the frequency and duration of the sound, and tap ‘Save.’\
28 | 
29 |
30 |
31 | ## Links
32 | Official SDK
33 | [karoo-ext source](https://github.com/hammerheadnav/karoo-ext)\
34 | Specail thanks for examples to **timklge**
35 | [github](https://github.com/timklge?tab=repositories)
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
25 |
26 |
27 |
28 |
31 |
32 |
33 |
34 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | workflow_dispatch:
5 | push:
6 | branches: [ "master" ]
7 | tags: [ "*" ]
8 | pull_request:
9 | branches: [ "master" ]
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 | permissions:
15 | contents: write
16 | steps:
17 | - name: Set up environment variables
18 | run: |
19 | echo "GPR_USER=${{ github.actor }}" >> $GITHUB_ENV
20 | echo "GPR_KEY=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
21 | echo "KEY_ALIAS=${{ secrets.KEY_ALIAS }}" >> $GITHUB_ENV
22 | echo "KEY_PASSWORD=${{ secrets.KEY_PASSWORD }}" >> $GITHUB_ENV
23 | echo "KEYSTORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }}" >> $GITHUB_ENV
24 | echo "KEYSTORE_BASE64=${{ secrets.KEYSTORE_BASE64 }}" >> $GITHUB_ENV
25 |
26 | - uses: actions/checkout@v4
27 | - name: set up JDK 17
28 | uses: actions/setup-java@v4
29 | with:
30 | java-version: '17'
31 | distribution: 'temurin'
32 | cache: gradle
33 |
34 | - name: Grant execute permission for gradlew
35 | run: chmod +x gradlew
36 | - name: Build with Gradle
37 | run: ./gradlew build
38 |
39 | - name: Archive APK
40 | uses: actions/upload-artifact@v4
41 | with:
42 | name: app-release
43 | path: app/build/outputs/apk/release/app-release.apk
44 |
45 | - name: Create Release
46 | id: create_release
47 | uses: ncipollo/release-action@v1
48 | if: startsWith(github.ref, 'refs/tags/')
49 | with:
50 | name: ${{ github.ref_name }}
51 | prerelease: false
52 | generateReleaseNotes: true
53 | allowUpdates: true
54 | artifacts: app/build/outputs/apk/release/app-release.apk, app/manifest.json, app/karoo-kxradar.png
55 | env:
56 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57 |
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.jose4j.base64url.Base64
2 |
3 | plugins {
4 | alias(libs.plugins.android.application)
5 | alias(libs.plugins.jetbrains.kotlin.android)
6 | alias(libs.plugins.compose.compiler)
7 | kotlin("plugin.serialization") version "2.0.20"
8 | }
9 |
10 | android {
11 | namespace = "org.itxsvv.kxradar"
12 | compileSdk = 34
13 |
14 | defaultConfig {
15 | applicationId = "org.itxsvv.kxradar"
16 | minSdk = 26
17 | targetSdk = 34
18 | versionCode = 5
19 | versionName = "1.0.5"
20 | }
21 |
22 | signingConfigs {
23 | create("release") {
24 | val env: MutableMap = System.getenv()
25 | keyAlias = env["KEY_ALIAS"]
26 | keyPassword = env["KEY_PASSWORD"]
27 |
28 | val base64keystore: String = env["KEYSTORE_BASE64"] ?: ""
29 | val keystoreFile: File = File.createTempFile("keystore", ".jks")
30 | keystoreFile.writeBytes(Base64.decode(base64keystore))
31 | storeFile = keystoreFile
32 | storePassword = env["KEYSTORE_PASSWORD"]
33 | }
34 | }
35 | buildTypes {
36 | debug {
37 | isMinifyEnabled = false
38 | }
39 | release {
40 | signingConfig = signingConfigs.getByName("release")
41 | // isMinifyEnabled = false
42 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
43 | }
44 | }
45 | compileOptions {
46 | sourceCompatibility = JavaVersion.VERSION_1_8
47 | targetCompatibility = JavaVersion.VERSION_1_8
48 | }
49 | kotlinOptions {
50 | jvmTarget = "1.8"
51 | }
52 | buildFeatures {
53 | compose = true
54 | }
55 | }
56 |
57 | dependencies {
58 | implementation(libs.hammerhead.karoo.ext)
59 | implementation(libs.androidx.core.ktx)
60 | implementation(libs.bundles.androidx.lifeycle)
61 | implementation(libs.androidx.activity.compose)
62 | implementation(libs.bundles.compose.ui)
63 | implementation(libs.androidx.navigation.runtime.ktx)
64 | implementation(libs.androidx.navigation.compose)
65 | implementation(libs.kotlinx.serialization.json)
66 | implementation(libs.color)
67 | implementation(libs.androidx.datastore.preferences)
68 | }
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | agp = "8.5.0"
3 | color = "1.3.0"
4 | datastorePreferences = "1.1.1"
5 | kotlin = "2.0.0"
6 |
7 | androidxCore = "1.13.1"
8 | androidxLifecycle = "2.8.6"
9 | androidxActivity = "1.9.3"
10 | androidxComposeUi = "1.7.4"
11 | androidxComposeMaterial = "1.3.0"
12 | glance = "1.1.1"
13 | kotlinxSerializationJson = "1.7.3"
14 | navigationRuntimeKtx = "2.8.4"
15 | navigationCompose = "2.8.4"
16 |
17 | [plugins]
18 | android-application = { id = "com.android.application", version.ref = "agp" }
19 | jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
20 | compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
21 |
22 | [libraries]
23 | androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastorePreferences" }
24 | color = { module = "com.maxkeppeler.sheets-compose-dialogs:color", version.ref = "color" }
25 | hammerhead-karoo-ext = { group = "io.hammerhead", name = "karoo-ext", version = "1.1.5" }
26 |
27 | androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidxCore" }
28 |
29 | # compose
30 | androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidxLifecycle" }
31 | androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" }
32 |
33 | androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidxActivity" }
34 | androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "androidxComposeUi" }
35 | androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "androidxComposeUi" }
36 | androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidxComposeUi" }
37 | androidx-compose-material = { module = "androidx.compose.material3:material3", version.ref = "androidxComposeMaterial" }
38 |
39 | # Glance
40 | androidx-glance-appwidget = { group = "androidx.glance", name = "glance-appwidget", version.ref = "glance" }
41 | androidx-glance-preview = { group = "androidx.glance", name = "glance-preview", version.ref = "glance" }
42 | androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationRuntimeKtx" }
43 | androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
44 | kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
45 |
46 | [bundles]
47 | androidx-lifeycle = ["androidx-lifecycle-runtime-compose", "androidx-lifecycle-viewmodel-compose"]
48 | compose-ui = ["androidx-compose-ui", "androidx-compose-material", "androidx-compose-ui-tooling-preview", "androidx-compose-ui-tooling"]
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%"=="" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%"=="" set DIRNAME=.
29 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo.
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48 | echo.
49 | echo Please set the JAVA_HOME variable in your environment to match the
50 | echo location of your Java installation.
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo.
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62 | echo.
63 | echo Please set the JAVA_HOME variable in your environment to match the
64 | echo location of your Java installation.
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/org/itxsvv/kxradar/screens/BeepPanel.kt:
--------------------------------------------------------------------------------
1 | package org.itxsvv.kxradar.screens
2 |
3 | import androidx.compose.foundation.layout.Arrangement
4 | import androidx.compose.foundation.layout.Row
5 | import androidx.compose.foundation.layout.fillMaxWidth
6 | import androidx.compose.foundation.layout.height
7 | import androidx.compose.foundation.layout.padding
8 | import androidx.compose.foundation.shape.RoundedCornerShape
9 | import androidx.compose.foundation.text.KeyboardOptions
10 | import androidx.compose.material.icons.Icons
11 | import androidx.compose.material.icons.filled.PlayArrow
12 | import androidx.compose.material3.FilledTonalButton
13 | import androidx.compose.material3.Icon
14 | import androidx.compose.material3.OutlinedTextField
15 | import androidx.compose.material3.Text
16 | import androidx.compose.runtime.Composable
17 | import androidx.compose.ui.Alignment
18 | import androidx.compose.ui.Modifier
19 | import androidx.compose.ui.text.input.KeyboardType
20 | import androidx.compose.ui.unit.dp
21 | import io.hammerhead.karooext.KarooSystemService
22 | import kotlinx.coroutines.CoroutineScope
23 | import kotlinx.coroutines.launch
24 | import org.itxsvv.kxradar.Beep
25 | import org.itxsvv.kxradar.beep
26 |
27 | @Composable
28 | fun DrawBeepPanel(
29 | karooSystem: KarooSystemService,
30 | scope: CoroutineScope,
31 | beep: Beep,
32 | pattern: Regex,
33 | onFreqChange: (Int) -> Unit,
34 | onDurationChange: (Int) -> Unit,
35 | ) {
36 | Row(
37 | modifier = Modifier
38 | .fillMaxWidth()
39 | .padding(3.dp),
40 | verticalAlignment = Alignment.CenterVertically,
41 | horizontalArrangement = Arrangement.spacedBy(3.dp)
42 | ) {
43 | OutlinedTextField(
44 | value = beep.frequency.toString(),
45 | keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
46 | onValueChange = { newFreq ->
47 | if (!newFreq.isEmpty() && newFreq.matches(pattern)) {
48 | onFreqChange(newFreq.toInt())
49 | }
50 | },
51 | modifier = Modifier.weight(1f),
52 | singleLine = true,
53 | label = { Text(text = "Freq.") }
54 | )
55 | OutlinedTextField(
56 | value = beep.duration.toString(),
57 | keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
58 | onValueChange = { newDuration ->
59 | if (!newDuration.isEmpty() && newDuration.matches(pattern)) {
60 | onDurationChange((newDuration.toInt()))
61 | }
62 | },
63 | modifier = Modifier.weight(1f),
64 | singleLine = true,
65 | label = { Text(text = "Dur.") }
66 | )
67 | FilledTonalButton(modifier = Modifier
68 | .weight(0.8f)
69 | .height(65.dp), shape = RoundedCornerShape(8.dp), onClick = {
70 | scope.launch {
71 | karooSystem.beep(beep.frequency, beep.duration)
72 | }
73 | }) {
74 | Icon(Icons.Default.PlayArrow, contentDescription = "")
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/org/itxsvv/kxradar/Extensions.kt:
--------------------------------------------------------------------------------
1 | package org.itxsvv.kxradar
2 |
3 | import android.content.Context
4 | import android.util.Log
5 | import androidx.datastore.preferences.core.edit
6 | import androidx.datastore.preferences.core.stringPreferencesKey
7 | import io.hammerhead.karooext.KarooSystemService
8 | import io.hammerhead.karooext.models.OnStreamState
9 | import io.hammerhead.karooext.models.PlayBeepPattern
10 | import io.hammerhead.karooext.models.RideState
11 | import io.hammerhead.karooext.models.StreamState
12 | import kotlinx.coroutines.channels.awaitClose
13 | import kotlinx.coroutines.channels.trySendBlocking
14 | import kotlinx.coroutines.flow.Flow
15 | import kotlinx.coroutines.flow.callbackFlow
16 | import kotlinx.coroutines.flow.distinctUntilChanged
17 | import kotlinx.coroutines.flow.map
18 | import kotlinx.serialization.Serializable
19 | import kotlinx.serialization.encodeToString
20 | import kotlinx.serialization.json.Json
21 |
22 | val jsonWithUnknownKeys = Json { ignoreUnknownKeys = true }
23 |
24 | val settingsKey = stringPreferencesKey("settings_v2")
25 |
26 | @Serializable
27 | data class Beep(
28 | var frequency: Int,
29 | var duration: Int,
30 | )
31 |
32 | @Serializable
33 | data class RadarSettings(
34 | val threatBeep: Beep,
35 | val passedBeep: Beep,
36 | val inRideOnly: Boolean = false,
37 | val enabled: Boolean = true,
38 | val wakeUpScreen: Boolean = true,
39 | val redThreadAlert: Boolean = false
40 | ) {
41 | companion object {
42 | val defaultSettings = Json.encodeToString(RadarSettings())
43 | }
44 |
45 | constructor() : this(
46 | Beep(200, 100),
47 | Beep(0, 100),
48 | false, true, true, false
49 | )
50 | }
51 |
52 | suspend fun saveSettings(context: Context, settings: RadarSettings) {
53 | context.dataStore.edit { t ->
54 | t[settingsKey] = Json.encodeToString(settings)
55 | }
56 | }
57 |
58 | fun Context.streamSettings(): Flow {
59 | return dataStore.data.map { settingsJson ->
60 | try {
61 | jsonWithUnknownKeys.decodeFromString(
62 | settingsJson[settingsKey] ?: RadarSettings.defaultSettings
63 | )
64 | } catch (e: Throwable) {
65 | Log.e(KarooRadarExtension.TAG, "Failed to read preferences", e)
66 | RadarSettings()
67 | }
68 | }.distinctUntilChanged()
69 | }
70 |
71 | fun KarooSystemService.streamDataFlow(dataTypeId: String): Flow {
72 | return callbackFlow {
73 | val listenerId = addConsumer(OnStreamState.StartStreaming(dataTypeId)) { event: OnStreamState ->
74 | trySendBlocking(event.state)
75 | }
76 | awaitClose {
77 | removeConsumer(listenerId)
78 | }
79 | }
80 | }
81 |
82 | fun KarooSystemService.streamRideState(): Flow {
83 | return callbackFlow {
84 | val listenerId = addConsumer { rideState: RideState ->
85 | trySendBlocking(rideState)
86 | }
87 | awaitClose {
88 | removeConsumer(listenerId)
89 | }
90 | }
91 | }
92 |
93 | fun KarooSystemService.beep(freq: Int, duration: Int) {
94 | beep(freq, duration, 1)
95 | }
96 |
97 | fun KarooSystemService.beep(freq: Int, duration: Int, count: Int) {
98 | val beepList = mutableListOf(PlayBeepPattern.Tone(freq, duration))
99 | repeat(count - 1) {
100 | beepList.add(PlayBeepPattern.Tone(0, 50))
101 | beepList.add(PlayBeepPattern.Tone(freq, duration))
102 | }
103 | dispatch(PlayBeepPattern(beepList))
104 | }
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/org/itxsvv/kxradar/KarooRadarExtension.kt:
--------------------------------------------------------------------------------
1 | package org.itxsvv.kxradar
2 |
3 | import android.util.Log
4 | import io.hammerhead.karooext.KarooSystemService
5 | import io.hammerhead.karooext.extension.KarooExtension
6 | import io.hammerhead.karooext.models.DataType
7 | import io.hammerhead.karooext.models.RideState
8 | import io.hammerhead.karooext.models.StreamState
9 | import io.hammerhead.karooext.models.TurnScreenOn
10 | import kotlinx.coroutines.CoroutineScope
11 | import kotlinx.coroutines.Dispatchers
12 | import kotlinx.coroutines.Job
13 | import kotlinx.coroutines.flow.combine
14 | import kotlinx.coroutines.flow.mapNotNull
15 | import kotlinx.coroutines.launch
16 |
17 | class KarooRadarExtension : KarooExtension("kxradar", "1.0.5") {
18 | companion object {
19 | const val TAG = "kxradar"
20 | }
21 | private var DELAY_BEEP_ALL_CLEAR = 2000
22 | private lateinit var karooSystem: KarooSystemService
23 | private var serviceJob: Job? = null
24 | private var radarThreat = false
25 | private var passedDelay = 0L
26 |
27 | override fun onCreate() {
28 | super.onCreate()
29 | Log.i(TAG,"Radar extension initialized")
30 | karooSystem = KarooSystemService(applicationContext)
31 | serviceJob = CoroutineScope(Dispatchers.IO).launch {
32 | karooSystem.connect { connected ->
33 | if (connected) {
34 | Log.i(TAG, "karooSystem Connected")
35 | }
36 | }
37 | val prefs = applicationContext.streamSettings()
38 | val rideStateFlow = karooSystem.streamRideState()
39 | karooSystem.streamDataFlow(DataType.Type.RADAR)
40 | .mapNotNull { (it as? StreamState.Streaming)?.dataPoint?.values }
41 | .combine(rideStateFlow) { values, rideState ->
42 | values to rideState
43 | }
44 | .combine(prefs) { (values, rideState), settings ->
45 | Triple(values, rideState, settings)
46 | }
47 | .collect({ (values, rideState, settings) ->
48 | val threatLevel = values[DataType.Field.RADAR_THREAT_LEVEL] ?: 0.0
49 | if (settings.enabled &&
50 | ((settings.inRideOnly && rideState is RideState.Recording) || !settings.inRideOnly)
51 | ) {
52 | if (!radarThreat && threatLevel > 0) {
53 | Log.i(TAG, "Threat detected")
54 | passedDelay = 0
55 | if (settings.wakeUpScreen) {
56 | karooSystem.dispatch(TurnScreenOn)
57 | }
58 | var beepCount = if (threatLevel > 1.0) 2 else 1
59 | karooSystem.beep(settings.threatBeep.frequency, settings.threatBeep.duration, beepCount)
60 | }
61 | if(passedDelay > 0 && System.currentTimeMillis() - passedDelay > DELAY_BEEP_ALL_CLEAR) {
62 | Log.i(TAG, "All-clear")
63 | passedDelay = 0;
64 | karooSystem.beep(settings.passedBeep.frequency, settings.passedBeep.duration)
65 | }
66 | if (radarThreat && threatLevel == 0.0) {
67 | passedDelay = System.currentTimeMillis()
68 | }
69 | }
70 | radarThreat = threatLevel != 0.0
71 | })
72 | }
73 | }
74 |
75 | override fun onDestroy() {
76 | serviceJob?.cancel()
77 | serviceJob = null
78 | karooSystem.disconnect()
79 | super.onDestroy()
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | # This is normally unused
84 | # shellcheck disable=SC2034
85 | APP_BASE_NAME=${0##*/}
86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
87 |
88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 |
142 | # Increase the maximum file descriptors if we can.
143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144 | case $MAX_FD in #(
145 | max*)
146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147 | # shellcheck disable=SC3045
148 | MAX_FD=$( ulimit -H -n ) ||
149 | warn "Could not query maximum file descriptor limit"
150 | esac
151 | case $MAX_FD in #(
152 | '' | soft) :;; #(
153 | *)
154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155 | # shellcheck disable=SC3045
156 | ulimit -n "$MAX_FD" ||
157 | warn "Could not set maximum file descriptor limit to $MAX_FD"
158 | esac
159 | fi
160 |
161 | # Collect all arguments for the java command, stacking in reverse order:
162 | # * args from the command line
163 | # * the main class name
164 | # * -classpath
165 | # * -D...appname settings
166 | # * --module-path (only if needed)
167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
168 |
169 | # For Cygwin or MSYS, switch paths to Windows format before running java
170 | if "$cygwin" || "$msys" ; then
171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
173 |
174 | JAVACMD=$( cygpath --unix "$JAVACMD" )
175 |
176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
177 | for arg do
178 | if
179 | case $arg in #(
180 | -*) false ;; # don't mess with options #(
181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
182 | [ -e "$t" ] ;; #(
183 | *) false ;;
184 | esac
185 | then
186 | arg=$( cygpath --path --ignore --mixed "$arg" )
187 | fi
188 | # Roll the args list around exactly as many times as the number of
189 | # args, so each arg winds up back in the position where it started, but
190 | # possibly modified.
191 | #
192 | # NB: a `for` loop captures its iteration list before it begins, so
193 | # changing the positional parameters here affects neither the number of
194 | # iterations, nor the values presented in `arg`.
195 | shift # remove old arg
196 | set -- "$@" "$arg" # push replacement arg
197 | done
198 | fi
199 |
200 | # Collect all arguments for the java command;
201 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
202 | # shell script including quotes and variable substitutions, so put them in
203 | # double quotes to make sure that they get re-expanded; and
204 | # * put everything else in single quotes, so that it's not re-expanded.
205 |
206 | set -- \
207 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
208 | -classpath "$CLASSPATH" \
209 | org.gradle.wrapper.GradleWrapperMain \
210 | "$@"
211 |
212 | # Stop when "xargs" is not available.
213 | if ! command -v xargs >/dev/null 2>&1
214 | then
215 | die "xargs is not available"
216 | fi
217 |
218 | # Use "xargs" to parse quoted args.
219 | #
220 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
221 | #
222 | # In Bash we could simply go:
223 | #
224 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
225 | # set -- "${ARGS[@]}" "$@"
226 | #
227 | # but POSIX shell has neither arrays nor command substitution, so instead we
228 | # post-process each arg (as a line of input to sed) to backslash-escape any
229 | # character that might be a shell metacharacter, then use eval to reverse
230 | # that process (while maintaining the separation between arguments), and wrap
231 | # the whole thing up as a single "set" statement.
232 | #
233 | # This will of course break if any of these variables contains a newline or
234 | # an unmatched quote.
235 | #
236 |
237 | eval "set -- $(
238 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
239 | xargs -n1 |
240 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
241 | tr '\n' ' '
242 | )" '"$@"'
243 |
244 | exec "$JAVACMD" "$@"
245 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/org/itxsvv/kxradar/screens/MainScreen.kt:
--------------------------------------------------------------------------------
1 | package org.itxsvv.kxradar.screens
2 |
3 | import android.util.Log
4 | import androidx.compose.foundation.background
5 | import androidx.compose.foundation.clickable
6 | import androidx.compose.foundation.layout.Arrangement
7 | import androidx.compose.foundation.layout.Column
8 | import androidx.compose.foundation.layout.Row
9 | import androidx.compose.foundation.layout.Spacer
10 | import androidx.compose.foundation.layout.fillMaxSize
11 | import androidx.compose.foundation.layout.fillMaxWidth
12 | import androidx.compose.foundation.layout.height
13 | import androidx.compose.foundation.layout.padding
14 | import androidx.compose.foundation.layout.size
15 | import androidx.compose.foundation.layout.width
16 | import androidx.compose.foundation.shape.RoundedCornerShape
17 | import androidx.compose.foundation.text.KeyboardOptions
18 | import androidx.compose.material.icons.Icons
19 | import androidx.compose.material.icons.filled.Done
20 | import androidx.compose.material.icons.filled.PlayArrow
21 | import androidx.compose.material3.AlertDialog
22 | import androidx.compose.material3.Button
23 | import androidx.compose.material3.FilledTonalButton
24 | import androidx.compose.material3.HorizontalDivider
25 | import androidx.compose.material3.Icon
26 | import androidx.compose.material3.MaterialTheme
27 | import androidx.compose.material3.OutlinedTextField
28 | import androidx.compose.material3.Switch
29 | import androidx.compose.material3.Tab
30 | import androidx.compose.material3.TabRow
31 | import androidx.compose.material3.Text
32 | import androidx.compose.runtime.Composable
33 | import androidx.compose.runtime.LaunchedEffect
34 | import androidx.compose.runtime.getValue
35 | import androidx.compose.runtime.mutableStateOf
36 | import androidx.compose.runtime.remember
37 | import androidx.compose.runtime.rememberCoroutineScope
38 | import androidx.compose.runtime.setValue
39 | import androidx.compose.ui.Alignment
40 | import androidx.compose.ui.Modifier
41 | import androidx.compose.ui.platform.LocalContext
42 | import androidx.compose.ui.platform.LocalFocusManager
43 | import androidx.compose.ui.text.input.KeyboardType
44 | import androidx.compose.ui.unit.dp
45 | import io.hammerhead.karooext.KarooSystemService
46 | import kotlinx.coroutines.CoroutineScope
47 | import kotlinx.coroutines.launch
48 | import org.itxsvv.kxradar.Beep
49 | import org.itxsvv.kxradar.KarooRadarExtension.Companion.TAG
50 | import org.itxsvv.kxradar.RadarSettings
51 | import org.itxsvv.kxradar.beep
52 | import org.itxsvv.kxradar.saveSettings
53 | import org.itxsvv.kxradar.streamSettings
54 |
55 | @Composable
56 | fun MainScreen() {
57 | val pattern = remember { Regex("^\\d*\\d*\$") }
58 | val scope = rememberCoroutineScope()
59 | val ctx = LocalContext.current
60 | val focusManager = LocalFocusManager.current
61 | val karooSystem = remember { KarooSystemService(ctx) }
62 | var savedDialogVisible by remember { mutableStateOf(false) }
63 | var tabIndex by remember { mutableStateOf(0) }
64 | val tabs = listOf("Sounds", "Settings")
65 |
66 | var uiThreatBeep by remember { mutableStateOf(Beep(200, 100)) }
67 | var uiPassedBeep by remember { mutableStateOf(Beep(0, 0)) }
68 | var uiInRideOnlyEnabled by remember { mutableStateOf(false) }
69 | var uiBeepEnabled by remember { mutableStateOf(true) }
70 | var uiWakeUpScreen by remember { mutableStateOf(true) }
71 | var uiRedThreadAlert by remember { mutableStateOf(false) }
72 |
73 | fun saveUISettings() {
74 | scope.launch {
75 | val radarSettings = RadarSettings(
76 | threatBeep = uiThreatBeep,
77 | passedBeep = uiPassedBeep,
78 | inRideOnly = uiInRideOnlyEnabled,
79 | enabled = uiBeepEnabled,
80 | wakeUpScreen = uiWakeUpScreen,
81 | redThreadAlert = uiRedThreadAlert
82 | )
83 | Log.i(TAG, "" + radarSettings)
84 | saveSettings(ctx, radarSettings)
85 | }
86 | }
87 |
88 | @Composable
89 | fun drawSettingsScreen() {
90 | Row(
91 | Modifier
92 | .fillMaxWidth()
93 | .height(5.dp)) {}
94 | Row(verticalAlignment = Alignment.CenterVertically) {
95 | Switch(
96 | modifier = Modifier
97 | .weight(0.5f)
98 | .padding(5.dp),
99 | checked = uiInRideOnlyEnabled,
100 | onCheckedChange = {
101 | uiInRideOnlyEnabled = it
102 | scope.launch {
103 | saveUISettings()
104 | }
105 | }
106 | )
107 | Spacer(modifier = Modifier.width(10.dp))
108 | Text(modifier = Modifier.weight(1f), text = "In-ride only")
109 | }
110 | Row(verticalAlignment = Alignment.CenterVertically) {
111 | Switch(
112 | modifier = Modifier
113 | .weight(0.5f)
114 | .padding(5.dp),
115 | checked = uiWakeUpScreen,
116 | onCheckedChange = {
117 | uiWakeUpScreen = it
118 | scope.launch {
119 | saveUISettings()
120 | }
121 | }
122 | )
123 | Spacer(modifier = Modifier.width(10.dp))
124 | Text(modifier = Modifier.weight(1f), text = "Wake Up Screen")
125 | }
126 | Row(verticalAlignment = Alignment.CenterVertically) {
127 | Switch(
128 | modifier = Modifier
129 | .weight(0.5f)
130 | .padding(5.dp),
131 | checked = uiRedThreadAlert,
132 | onCheckedChange = {
133 | uiRedThreadAlert = it
134 | scope.launch {
135 | saveUISettings()
136 | }
137 | }
138 | )
139 | Spacer(modifier = Modifier.width(10.dp))
140 | Text(modifier = Modifier.weight(1f), text = "Two beep on first red")
141 | }
142 |
143 | HorizontalDivider(
144 | thickness = 2.dp, modifier = Modifier
145 | .padding(vertical = 10.dp)
146 | )
147 | Row(verticalAlignment = Alignment.CenterVertically) {
148 | Switch(
149 | modifier = Modifier.weight(0.5f),
150 | checked = uiBeepEnabled,
151 | onCheckedChange = {
152 | uiBeepEnabled = it
153 | scope.launch {
154 | saveUISettings()
155 | }
156 | }
157 | )
158 | Spacer(modifier = Modifier.width(10.dp))
159 | Text(modifier = Modifier.weight(1f), text = "Enabled")
160 | }
161 | }
162 |
163 | @Composable
164 | fun drawSoundScreen() {
165 | Row(
166 | Modifier
167 | .fillMaxWidth()
168 | .height(5.dp)) {}
169 | Text("Threat sound")
170 | DrawBeepPanel(karooSystem, scope, uiThreatBeep, pattern,
171 | onDurationChange = { newDur ->
172 | uiThreatBeep = uiThreatBeep.copy(duration = newDur)
173 | },
174 | onFreqChange = { newFreq ->
175 | uiThreatBeep = uiThreatBeep.copy(frequency = newFreq)
176 | })
177 | Text("All clear sound (0 disable)")
178 | DrawBeepPanel(karooSystem, scope, uiPassedBeep, pattern,
179 | onDurationChange = { newDur ->
180 | uiPassedBeep = uiPassedBeep.copy(duration = newDur)
181 | },
182 | onFreqChange = { newFreq ->
183 | uiPassedBeep = uiPassedBeep.copy(frequency = newFreq)
184 | })
185 | Spacer(modifier = Modifier.size(10.dp))
186 | FilledTonalButton(modifier = Modifier
187 | .fillMaxWidth()
188 | .height(50.dp), onClick = {
189 | scope.launch {
190 | saveUISettings()
191 | savedDialogVisible = true
192 | }
193 | }) {
194 | Icon(Icons.Default.Done, contentDescription = "")
195 | Spacer(modifier = Modifier.width(5.dp))
196 | Text("Save")
197 | }
198 | if (savedDialogVisible) {
199 | AlertDialog(onDismissRequest = { savedDialogVisible = false },
200 | confirmButton = {
201 | Button(onClick = {
202 | savedDialogVisible = false
203 | }) { Text("OK") }
204 | },
205 | text = { Text("Settings saved successfully.") }
206 | )
207 | }
208 | }
209 |
210 | LaunchedEffect(Unit) {
211 | ctx.streamSettings().collect { settings ->
212 | uiThreatBeep = settings.threatBeep
213 | uiPassedBeep = settings.passedBeep
214 | uiInRideOnlyEnabled = settings.inRideOnly
215 | uiBeepEnabled = settings.enabled
216 | uiWakeUpScreen = settings.wakeUpScreen
217 | uiRedThreadAlert = settings.redThreadAlert
218 | }
219 | }
220 |
221 | LaunchedEffect(Unit) {
222 | karooSystem.connect()
223 | }
224 |
225 | Column(
226 | modifier = Modifier
227 | .fillMaxWidth()
228 | .fillMaxSize()
229 | .padding(2.dp)
230 | .background(MaterialTheme.colorScheme.background)
231 | .clickable { focusManager.clearFocus() },
232 | verticalArrangement = Arrangement.spacedBy(2.dp),
233 | horizontalAlignment = Alignment.CenterHorizontally
234 | ) {
235 | TabRow(selectedTabIndex = tabIndex) {
236 | tabs.forEachIndexed { index, title ->
237 | Tab(text = { Text(title) },
238 | selected = tabIndex == index,
239 | onClick = { tabIndex = index }
240 | )
241 | }
242 | }
243 | when (tabIndex) {
244 | 0 -> {
245 | drawSoundScreen()
246 | }
247 | 1 -> {
248 | drawSettingsScreen()
249 | }
250 | }
251 | }
252 | }
253 |
254 |
255 |
256 |
257 |
258 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2024 Hammerhead Navigation, Inc. All Rights Reserved.
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------