From 2a4ee357cec46eb6edfb102a16db0cfe20f81af0 Mon Sep 17 00:00:00 2001
From: John Doe <222520099+haumlab@users.noreply.github.com>
Date: Thu, 25 Dec 2025 02:14:09 +0000
Subject: [PATCH] Migrate to FlatBuffers and unify Mobile/TV modules
---
.gitattributes | 2 +
.github/workflows/android.yml | 123 ++++++
.gitignore | 11 +
.idea/.gitignore | 3 +
.idea/AndroidProjectSystem.xml | 6 +
.idea/codeStyles/Project.xml | 29 ++
.idea/compiler.xml | 6 +
.idea/deploymentTargetSelector.xml | 13 +
.idea/gradle.xml | 21 ++
.idea/markdown.xml | 8 +
.idea/migrations.xml | 10 +
.idea/misc.xml | 34 ++
.idea/runConfigurations.xml | 20 +
.idea/vcs.xml | 6 +
CHANGELOG.md | 100 +++++
LICENSE.txt | 21 ++
README.md | 16 +
app/.gitignore | 1 +
app/build.gradle | 50 +++
app/proguard-rules.pro | 21 ++
app/src/main/AndroidManifest.xml | 98 +++++
.../grabber/AppCompatPreferenceActivity.java | 118 ++++++
.../com/hyperion/grabber/FadingImageView.java | 74 ++++
.../grabber/HyperionGrabberTileService.java | 147 ++++++++
.../com/hyperion/grabber/MainActivity.java | 241 ++++++++++++
.../hyperion/grabber/SettingsActivity.java | 158 ++++++++
.../tv/activities/LeanbackActivity.java | 10 +
.../grabber/tv/activities/MainActivity.java | 284 ++++++++++++++
.../tv/activities/ManualSetupActivity.java | 38 ++
.../tv/activities/NetworkScanActivity.java | 105 ++++++
.../tv/activities/ScanResultActivity.java | 204 ++++++++++
.../settings/BasicSettingsStepFragment.kt | 335 +++++++++++++++++
.../settings/SettingsStepBaseFragment.kt | 208 +++++++++++
.../fragments/settings/SettingsStepStylist.kt | 10 +
.../tv/views/SettingsRelativeLayout.java | 83 +++++
.../round_rectangle_background.xml | 13 +
.../ic_qr_android_tv_remote_short.png | Bin 0 -> 9230 bytes
app/src/main/res/drawable/banner.png | Bin 0 -> 25889 bytes
app/src/main/res/drawable/ic_network_scan.xml | 11 +
.../ic_settings_ethernet_white_128dp.xml | 10 +
app/src/main/res/layout/activity_main.xml | 85 +++++
.../main/res/layout/activity_network_scan.xml | 109 ++++++
.../main/res/layout/activity_scan_result.xml | 124 ++++++
app/src/main/res/layout/settings_guidance.xml | 46 +++
app/src/main/res/menu/options_menu.xml | 5 +
app/src/main/res/values-ar/strings.xml | 22 ++
app/src/main/res/values-cs/strings.xml | 20 +
app/src/main/res/values-de/strings.xml | 22 ++
app/src/main/res/values-es/strings.xml | 14 +
app/src/main/res/values-fr/strings.xml | 20 +
app/src/main/res/values-it/strings.xml | 20 +
app/src/main/res/values-nl/strings.xml | 20 +
app/src/main/res/values-no/strings.xml | 20 +
app/src/main/res/values-ru/strings.xml | 12 +
app/src/main/res/values/colors.xml | 13 +
app/src/main/res/values/strings.xml | 25 ++
app/src/main/res/values/styles.xml | 47 +++
.../com/hyperion/grabber/ExampleUnitTest.java | 17 +
build.gradle | 27 ++
common/.gitignore | 1 +
common/build.gradle | 49 +++
common/src/main/AndroidManifest.xml | 44 +++
.../src/main/flatbuffers/hyperion_reply.fbs | 9 +
.../src/main/flatbuffers/hyperion_request.fbs | 46 +++
.../com/hyperion/grabber/BootActivity.java | 51 +++
.../grabber/HyperionGrabberBootReceiver.java | 28 ++
.../grabber/HyperionNotification.java | 108 ++++++
.../grabber/HyperionScreenEncoder.java | 352 ++++++++++++++++++
.../grabber/HyperionScreenEncoderBase.java | 144 +++++++
.../grabber/HyperionScreenService.java | 340 +++++++++++++++++
.../com/hyperion/grabber/ToggleActivity.java | 97 +++++
.../grabber/network/HyperionClient.java | 14 +
.../grabber/network/HyperionFlatBuffers.java | 137 +++++++
.../grabber/network/HyperionThread.java | 124 ++++++
.../grabber/network/NetworkScanner.java | 171 +++++++++
.../grabber/util/BorderProcessor.java | 186 +++++++++
.../grabber/util/HyperionGrabberOptions.java | 84 +++++
.../grabber/util/HyperionScannerTask.java | 74 ++++
.../com/hyperion/grabber/util/Preferences.kt | 85 +++++
.../grabber/views/SweepGradientView.java | 69 ++++
common/src/main/java/hyperionnet/Clear.java | 28 ++
common/src/main/java/hyperionnet/Color.java | 31 ++
common/src/main/java/hyperionnet/Command.java | 14 +
common/src/main/java/hyperionnet/Image.java | 38 ++
.../src/main/java/hyperionnet/ImageType.java | 12 +
.../src/main/java/hyperionnet/RawImage.java | 38 ++
.../src/main/java/hyperionnet/Register.java | 38 ++
common/src/main/java/hyperionnet/Reply.java | 35 ++
common/src/main/java/hyperionnet/Request.java | 36 ++
.../drawable-v24/ic_launcher_foreground.xml | 19 +
.../main/res/drawable/ic_info_white_24dp.xml | 5 +
.../res/drawable/ic_launcher_background.xml | 237 ++++++++++++
.../res/drawable/ic_notification_icon.xml | 10 +
.../main/res/drawable/ic_power_black_72dp.xml | 9 +
.../res/drawable/ic_settings_black_72dp.xml | 9 +
.../res/drawable/ic_toggle_image_middle.xml | 31 ++
.../res/drawable/image_button_background.xml | 6 +
.../src/main/res/drawable/pill_background.xml | 8 +
.../drawable/round_rectangle_background.xml | 6 +
.../res/mipmap-anydpi-v26/ic_launcher.xml | 5 +
.../mipmap-anydpi-v26/ic_launcher_round.xml | 5 +
.../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 7792 bytes
.../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 7318 bytes
.../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 4113 bytes
.../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3771 bytes
.../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 11334 bytes
.../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 10937 bytes
.../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 21749 bytes
.../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 21625 bytes
.../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 27018 bytes
.../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 27421 bytes
common/src/main/res/values-ar/strings.xml | 68 ++++
common/src/main/res/values-cs/strings.xml | 68 ++++
common/src/main/res/values-de/strings.xml | 68 ++++
common/src/main/res/values-es/strings.xml | 39 ++
common/src/main/res/values-fr/strings.xml | 68 ++++
common/src/main/res/values-it/strings.xml | 68 ++++
common/src/main/res/values-nl/strings.xml | 68 ++++
common/src/main/res/values-no/strings.xml | 68 ++++
common/src/main/res/values-ru/strings.xml | 34 ++
common/src/main/res/values/colors.xml | 6 +
common/src/main/res/values/pref_values.xml | 37 ++
common/src/main/res/values/strings.xml | 68 ++++
common/src/main/res/values/styles.xml | 12 +
common/src/main/res/xml/pref_general.xml | 118 ++++++
common/variables.gradle | 1 +
gradle.properties | 24 ++
gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes
gradle/wrapper/gradle-wrapper.properties | 6 +
gradlew | 160 ++++++++
gradlew.bat | 90 +++++
privacy-policy.md | 63 ++++
settings.gradle | 1 +
133 files changed, 7284 insertions(+)
create mode 100644 .gitattributes
create mode 100644 .github/workflows/android.yml
create mode 100755 .gitignore
create mode 100644 .idea/.gitignore
create mode 100644 .idea/AndroidProjectSystem.xml
create mode 100644 .idea/codeStyles/Project.xml
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/deploymentTargetSelector.xml
create mode 100755 .idea/gradle.xml
create mode 100644 .idea/markdown.xml
create mode 100644 .idea/migrations.xml
create mode 100755 .idea/misc.xml
create mode 100755 .idea/runConfigurations.xml
create mode 100644 .idea/vcs.xml
create mode 100644 CHANGELOG.md
create mode 100644 LICENSE.txt
create mode 100644 README.md
create mode 100755 app/.gitignore
create mode 100755 app/build.gradle
create mode 100755 app/proguard-rules.pro
create mode 100755 app/src/main/AndroidManifest.xml
create mode 100755 app/src/main/java/com/hyperion/grabber/AppCompatPreferenceActivity.java
create mode 100644 app/src/main/java/com/hyperion/grabber/FadingImageView.java
create mode 100644 app/src/main/java/com/hyperion/grabber/HyperionGrabberTileService.java
create mode 100755 app/src/main/java/com/hyperion/grabber/MainActivity.java
create mode 100755 app/src/main/java/com/hyperion/grabber/SettingsActivity.java
create mode 100644 app/src/main/java/com/hyperion/grabber/tv/activities/LeanbackActivity.java
create mode 100644 app/src/main/java/com/hyperion/grabber/tv/activities/MainActivity.java
create mode 100644 app/src/main/java/com/hyperion/grabber/tv/activities/ManualSetupActivity.java
create mode 100644 app/src/main/java/com/hyperion/grabber/tv/activities/NetworkScanActivity.java
create mode 100644 app/src/main/java/com/hyperion/grabber/tv/activities/ScanResultActivity.java
create mode 100644 app/src/main/java/com/hyperion/grabber/tv/fragments/settings/BasicSettingsStepFragment.kt
create mode 100644 app/src/main/java/com/hyperion/grabber/tv/fragments/settings/SettingsStepBaseFragment.kt
create mode 100644 app/src/main/java/com/hyperion/grabber/tv/fragments/settings/SettingsStepStylist.kt
create mode 100644 app/src/main/java/com/hyperion/grabber/tv/views/SettingsRelativeLayout.java
create mode 100644 app/src/main/res/drawable-v21/round_rectangle_background.xml
create mode 100644 app/src/main/res/drawable-xhdpi/ic_qr_android_tv_remote_short.png
create mode 100644 app/src/main/res/drawable/banner.png
create mode 100644 app/src/main/res/drawable/ic_network_scan.xml
create mode 100644 app/src/main/res/drawable/ic_settings_ethernet_white_128dp.xml
create mode 100644 app/src/main/res/layout/activity_main.xml
create mode 100644 app/src/main/res/layout/activity_network_scan.xml
create mode 100644 app/src/main/res/layout/activity_scan_result.xml
create mode 100644 app/src/main/res/layout/settings_guidance.xml
create mode 100644 app/src/main/res/menu/options_menu.xml
create mode 100644 app/src/main/res/values-ar/strings.xml
create mode 100644 app/src/main/res/values-cs/strings.xml
create mode 100644 app/src/main/res/values-de/strings.xml
create mode 100644 app/src/main/res/values-es/strings.xml
create mode 100644 app/src/main/res/values-fr/strings.xml
create mode 100644 app/src/main/res/values-it/strings.xml
create mode 100644 app/src/main/res/values-nl/strings.xml
create mode 100644 app/src/main/res/values-no/strings.xml
create mode 100644 app/src/main/res/values-ru/strings.xml
create mode 100644 app/src/main/res/values/colors.xml
create mode 100755 app/src/main/res/values/strings.xml
create mode 100644 app/src/main/res/values/styles.xml
create mode 100755 app/src/test/java/com/hyperion/grabber/ExampleUnitTest.java
create mode 100755 build.gradle
create mode 100644 common/.gitignore
create mode 100644 common/build.gradle
create mode 100644 common/src/main/AndroidManifest.xml
create mode 100644 common/src/main/flatbuffers/hyperion_reply.fbs
create mode 100644 common/src/main/flatbuffers/hyperion_request.fbs
create mode 100644 common/src/main/java/com/hyperion/grabber/BootActivity.java
create mode 100644 common/src/main/java/com/hyperion/grabber/HyperionGrabberBootReceiver.java
create mode 100644 common/src/main/java/com/hyperion/grabber/HyperionNotification.java
create mode 100755 common/src/main/java/com/hyperion/grabber/HyperionScreenEncoder.java
create mode 100644 common/src/main/java/com/hyperion/grabber/HyperionScreenEncoderBase.java
create mode 100644 common/src/main/java/com/hyperion/grabber/HyperionScreenService.java
create mode 100644 common/src/main/java/com/hyperion/grabber/ToggleActivity.java
create mode 100644 common/src/main/java/com/hyperion/grabber/network/HyperionClient.java
create mode 100644 common/src/main/java/com/hyperion/grabber/network/HyperionFlatBuffers.java
create mode 100644 common/src/main/java/com/hyperion/grabber/network/HyperionThread.java
create mode 100644 common/src/main/java/com/hyperion/grabber/network/NetworkScanner.java
create mode 100644 common/src/main/java/com/hyperion/grabber/util/BorderProcessor.java
create mode 100644 common/src/main/java/com/hyperion/grabber/util/HyperionGrabberOptions.java
create mode 100644 common/src/main/java/com/hyperion/grabber/util/HyperionScannerTask.java
create mode 100644 common/src/main/java/com/hyperion/grabber/util/Preferences.kt
create mode 100644 common/src/main/java/com/hyperion/grabber/views/SweepGradientView.java
create mode 100644 common/src/main/java/hyperionnet/Clear.java
create mode 100644 common/src/main/java/hyperionnet/Color.java
create mode 100644 common/src/main/java/hyperionnet/Command.java
create mode 100644 common/src/main/java/hyperionnet/Image.java
create mode 100644 common/src/main/java/hyperionnet/ImageType.java
create mode 100644 common/src/main/java/hyperionnet/RawImage.java
create mode 100644 common/src/main/java/hyperionnet/Register.java
create mode 100644 common/src/main/java/hyperionnet/Reply.java
create mode 100644 common/src/main/java/hyperionnet/Request.java
create mode 100644 common/src/main/res/drawable-v24/ic_launcher_foreground.xml
create mode 100644 common/src/main/res/drawable/ic_info_white_24dp.xml
create mode 100644 common/src/main/res/drawable/ic_launcher_background.xml
create mode 100644 common/src/main/res/drawable/ic_notification_icon.xml
create mode 100644 common/src/main/res/drawable/ic_power_black_72dp.xml
create mode 100644 common/src/main/res/drawable/ic_settings_black_72dp.xml
create mode 100644 common/src/main/res/drawable/ic_toggle_image_middle.xml
create mode 100644 common/src/main/res/drawable/image_button_background.xml
create mode 100644 common/src/main/res/drawable/pill_background.xml
create mode 100644 common/src/main/res/drawable/round_rectangle_background.xml
create mode 100644 common/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
create mode 100644 common/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
create mode 100755 common/src/main/res/mipmap-hdpi/ic_launcher.png
create mode 100644 common/src/main/res/mipmap-hdpi/ic_launcher_round.png
create mode 100755 common/src/main/res/mipmap-mdpi/ic_launcher.png
create mode 100644 common/src/main/res/mipmap-mdpi/ic_launcher_round.png
create mode 100755 common/src/main/res/mipmap-xhdpi/ic_launcher.png
create mode 100644 common/src/main/res/mipmap-xhdpi/ic_launcher_round.png
create mode 100755 common/src/main/res/mipmap-xxhdpi/ic_launcher.png
create mode 100644 common/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
create mode 100644 common/src/main/res/mipmap-xxxhdpi/ic_launcher.png
create mode 100644 common/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
create mode 100644 common/src/main/res/values-ar/strings.xml
create mode 100644 common/src/main/res/values-cs/strings.xml
create mode 100644 common/src/main/res/values-de/strings.xml
create mode 100644 common/src/main/res/values-es/strings.xml
create mode 100644 common/src/main/res/values-fr/strings.xml
create mode 100644 common/src/main/res/values-it/strings.xml
create mode 100644 common/src/main/res/values-nl/strings.xml
create mode 100644 common/src/main/res/values-no/strings.xml
create mode 100644 common/src/main/res/values-ru/strings.xml
create mode 100644 common/src/main/res/values/colors.xml
create mode 100644 common/src/main/res/values/pref_values.xml
create mode 100755 common/src/main/res/values/strings.xml
create mode 100644 common/src/main/res/values/styles.xml
create mode 100644 common/src/main/res/xml/pref_general.xml
create mode 100644 common/variables.gradle
create mode 100755 gradle.properties
create mode 100755 gradle/wrapper/gradle-wrapper.jar
create mode 100755 gradle/wrapper/gradle-wrapper.properties
create mode 100755 gradlew
create mode 100755 gradlew.bat
create mode 100644 privacy-policy.md
create mode 100755 settings.gradle
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..dfe0770
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Auto detect text files and perform LF normalization
+* text=auto
diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml
new file mode 100644
index 0000000..ff8091a
--- /dev/null
+++ b/.github/workflows/android.yml
@@ -0,0 +1,123 @@
+name: Android CI
+
+on:
+ push:
+ branches: [ main ]
+ tags:
+ - 'v*'
+ pull_request:
+ branches: [ main ]
+ release:
+ types: [ published, created, edited ]
+ workflow_dispatch:
+
+permissions:
+ contents: write
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Set up JDK 17
+ uses: actions/setup-java@v4
+ with:
+ java-version: '17'
+ distribution: 'temurin'
+ cache: gradle
+
+ - name: Grant execute permission for gradlew
+ run: chmod +x gradlew
+
+ - name: Decode Keystore
+ run: |
+ echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > ${{ github.workspace }}/release.keystore
+
+ - name: Build Release APKs
+ run: ./gradlew assembleRelease
+
+ - name: Sign Mobile APK
+ env:
+ KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
+ KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
+ KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
+ run: |
+ $ANDROID_HOME/build-tools/34.0.0/apksigner sign --ks ${{ github.workspace }}/release.keystore \
+ --ks-key-alias "$KEY_ALIAS" \
+ --ks-pass "pass:$KEYSTORE_PASSWORD" \
+ --key-pass "pass:$KEY_PASSWORD" \
+ --out mobile/build/outputs/apk/release/mobile-release.apk \
+ mobile/build/outputs/apk/release/mobile-release-unsigned.apk
+
+ - name: Sign TV APK
+ env:
+ KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
+ KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
+ KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
+ run: |
+ $ANDROID_HOME/build-tools/34.0.0/apksigner sign --ks ${{ github.workspace }}/release.keystore \
+ --ks-key-alias "$KEY_ALIAS" \
+ --ks-pass "pass:$KEYSTORE_PASSWORD" \
+ --key-pass "pass:$KEY_PASSWORD" \
+ --out tv/build/outputs/apk/release/tv-release.apk \
+ tv/build/outputs/apk/release/tv-release-unsigned.apk
+
+ - name: Upload Mobile APK
+ uses: actions/upload-artifact@v4
+ with:
+ name: mobile-release
+ path: mobile/build/outputs/apk/release/mobile-release.apk
+
+ - name: Upload TV APK
+ uses: actions/upload-artifact@v4
+ with:
+ name: tv-release
+ path: tv/build/outputs/apk/release/tv-release.apk
+
+ - name: Get version
+ id: get_version
+ run: |
+ if [[ $GITHUB_REF == refs/tags/* ]]; then
+ echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
+ echo "IS_TAG=true" >> $GITHUB_OUTPUT
+ else
+ echo "VERSION=latest" >> $GITHUB_OUTPUT
+ echo "IS_TAG=false" >> $GITHUB_OUTPUT
+ fi
+
+ - name: Create Release (Tag)
+ if: startsWith(github.ref, 'refs/tags/')
+ uses: softprops/action-gh-release@v2
+ with:
+ tag_name: ${{ steps.get_version.outputs.VERSION }}
+ draft: false
+ prerelease: false
+ files: |
+ mobile/build/outputs/apk/release/mobile-release.apk
+ tv/build/outputs/apk/release/tv-release.apk
+
+ - name: Create Release (Latest)
+ if: github.ref == 'refs/heads/main'
+ uses: softprops/action-gh-release@v2
+ with:
+ tag_name: latest
+ name: Latest Build
+ body: |
+ **Automated development build** from `${{ github.sha }}`
+
+ This is a pre-release build from the main branch and may be unstable.
+
+ **[View Changelog](https://github.com/haumlab/hyperion-android-reborn/blob/main/CHANGELOG.md)** for recent changes.
+
+ ---
+ ### Downloads
+ - **mobile-release.apk** - For phones and tablets
+ - **tv-release.apk** - For Android TV devices
+ draft: false
+ prerelease: true
+ files: |
+ mobile/build/outputs/apk/release/mobile-release.apk
+ tv/build/outputs/apk/release/tv-release.apk
diff --git a/.gitignore b/.gitignore
new file mode 100755
index 0000000..9701502
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,11 @@
+*.iml
+.gradle
+/local.properties
+/.idea/workspace.xml
+/.idea/libraries
+/.idea/caches
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+.externalNativeBuild
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml
new file mode 100644
index 0000000..4a53bee
--- /dev/null
+++ b/.idea/AndroidProjectSystem.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
+
+
+# Hyperion Android Reborn
+Screen grabber for hyperion, updated for **Android 12** and **beyond**.
+
+This application will send the content of the android screen to a hyperion instance to handle the image.
+
+Info about hyperion can be found on their website:
+https://hyperion-project.org/
+
+---
+
+# Download
+Both **TV** and **Mobile** apps are within [releases page](https://github.com/haumlab/hyperion-android-reborn/releases)
diff --git a/app/.gitignore b/app/.gitignore
new file mode 100755
index 0000000..796b96d
--- /dev/null
+++ b/app/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/app/build.gradle b/app/build.gradle
new file mode 100755
index 0000000..a5961d6
--- /dev/null
+++ b/app/build.gradle
@@ -0,0 +1,50 @@
+plugins {
+ id 'com.android.application'
+ id 'kotlin-android'
+}
+
+apply from: project(':common').projectDir.absolutePath + '/variables.gradle'
+
+android {
+ namespace 'com.hyperion.grabber'
+ compileSdk 34
+
+ defaultConfig {
+ applicationId "com.hyperion.grabber"
+ minSdk 21
+ targetSdk 34
+ versionCode 2013
+ versionName "2.0"
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+
+ compileOptions {
+ targetCompatibility JavaVersion.VERSION_17
+ sourceCompatibility JavaVersion.VERSION_17
+ }
+
+ kotlinOptions {
+ jvmTarget = '17'
+ }
+}
+
+dependencies {
+ implementation fileTree(include: ['*.jar'], dir: 'libs')
+ api project(path: ':common')
+ implementation "androidx.appcompat:appcompat:1.6.1"
+ implementation "androidx.core:core-ktx:1.12.0"
+ implementation "androidx.constraintlayout:constraintlayout:2.1.4"
+ implementation "androidx.preference:preference-ktx:1.2.1"
+ implementation "androidx.localbroadcastmanager:localbroadcastmanager:1.1.0"
+
+ implementation "androidx.leanback:leanback:1.0.0"
+ implementation "androidx.leanback:leanback-preference:1.0.0"
+ implementation 'nl.dionsegijn:konfetti-xml:2.0.4'
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+}
\ No newline at end of file
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
new file mode 100755
index 0000000..f1b4245
--- /dev/null
+++ b/app/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
new file mode 100755
index 0000000..1ce0762
--- /dev/null
+++ b/app/src/main/AndroidManifest.xml
@@ -0,0 +1,98 @@
+
+
+ * See
+ * Android Design: Settings for design guidelines and the Settings
+ * API Guide for more information on developing a Settings UI.
+ */
+public class SettingsActivity extends AppCompatPreferenceActivity {
+ public static final String EXTRA_SHOW_TOAST_KEY = "extra_show_toast_key";
+ public static final int EXTRA_SHOW_TOAST_SETUP_REQUIRED_FOR_QUICK_TILE = 1;
+
+
+ /**
+ * A preference value change listener that updates the preference's summary
+ * to reflect its new value.
+ */
+ private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = (preference, value) -> {
+ final int prefResourceID = getResourceId(preference.getKey(), com.hyperion.grabber.common.R.string.class);
+
+ // verify we have a valid int value for the following preference keys
+ if (prefResourceID == com.hyperion.grabber.common.R.string.pref_key_port ||
+ prefResourceID == com.hyperion.grabber.common.R.string.pref_key_reconnect_delay ||
+ prefResourceID == com.hyperion.grabber.common.R.string.pref_key_priority ||
+ prefResourceID == com.hyperion.grabber.common.R.string.pref_key_x_led ||
+ prefResourceID == com.hyperion.grabber.common.R.string.pref_key_y_led ||
+ prefResourceID == com.hyperion.grabber.common.R.string.pref_key_framerate) {
+ try {
+ Integer.parseInt(value.toString());
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ String stringValue = value.toString();
+ preference.setSummary(stringValue);
+
+ return true;
+ };
+
+ /**
+ * Returns the resource ID of the provided string
+ */
+ public static int getResourceId(String resourceName, Class> c) {
+ try {
+ Field idField = c.getDeclaredField(resourceName);
+ return idField.getInt(idField);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return -1;
+ }
+
+ /**
+ * Binds a preference's summary to its value. More specifically, when the
+ * preference's value is changed, its summary (line of text below the
+ * preference title) is updated to reflect the value. The summary is also
+ * immediately updated upon calling this method. The exact display format is
+ * dependent on the type of preference.
+ *
+ * @see #sBindPreferenceSummaryToValueListener
+ */
+ private static void bindPreferenceSummaryToValue(Preference preference) {
+ if (preference == null) return;
+ // Set the listener to watch for value changes.
+ preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
+
+ // Trigger the listener immediately with the preference's
+ // current value.
+ sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
+ PreferenceManager
+ .getDefaultSharedPreferences(preference.getContext())
+ .getString(preference.getKey(), ""));
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ getFragmentManager().beginTransaction().replace(android.R.id.content,
+ new GeneralPreferenceFragment()).commit();
+
+ Bundle extras = getIntent().getExtras();
+ if (extras != null && extras.containsKey(EXTRA_SHOW_TOAST_KEY)){
+ if (extras.getInt(EXTRA_SHOW_TOAST_KEY) == EXTRA_SHOW_TOAST_SETUP_REQUIRED_FOR_QUICK_TILE){
+ Toast.makeText(getApplicationContext(), R.string.quick_tile_toast_setup_required, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ setupActionBar();
+ }
+
+ /**
+ * Set up the {@link android.app.ActionBar}, if the API is available.
+ */
+ private void setupActionBar() {
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ // Show the Up button in the action bar.
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+ }
+
+ /**
+ * This fragment shows general preferences only. It is used when the
+ * activity is showing a two-pane settings UI.
+ */
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
+ public static class GeneralPreferenceFragment extends PreferenceFragment {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(com.hyperion.grabber.common.R.xml.pref_general);
+ setHasOptionsMenu(true);
+
+ // Bind the summaries of EditText/List/Dialog/Ringtone preferences
+ // to their values. When their values change, their summaries are
+ // updated to reflect the new value, per the Android Design
+ // guidelines.
+ bindPreferenceSummaryToValue(findPreference(getString(com.hyperion.grabber.common.R.string.pref_key_host)));
+ bindPreferenceSummaryToValue(findPreference(getString(com.hyperion.grabber.common.R.string.pref_key_port)));
+ bindPreferenceSummaryToValue(findPreference(getString(com.hyperion.grabber.common.R.string.pref_key_priority)));
+ bindPreferenceSummaryToValue(findPreference(getString(com.hyperion.grabber.common.R.string.pref_key_framerate)));
+ bindPreferenceSummaryToValue(findPreference(getString(com.hyperion.grabber.common.R.string.pref_key_reconnect_delay)));
+ bindPreferenceSummaryToValue(findPreference(getString(com.hyperion.grabber.common.R.string.pref_key_x_led)));
+ bindPreferenceSummaryToValue(findPreference(getString(com.hyperion.grabber.common.R.string.pref_key_y_led)));
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ if (id == android.R.id.home) {
+ startActivity(new Intent(getActivity(), SettingsActivity.class));
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+ }
+}
diff --git a/app/src/main/java/com/hyperion/grabber/tv/activities/LeanbackActivity.java b/app/src/main/java/com/hyperion/grabber/tv/activities/LeanbackActivity.java
new file mode 100644
index 0000000..9bfa4ad
--- /dev/null
+++ b/app/src/main/java/com/hyperion/grabber/tv/activities/LeanbackActivity.java
@@ -0,0 +1,10 @@
+package com.hyperion.grabber.tv.activities;
+
+import androidx.fragment.app.FragmentActivity;
+
+public abstract class LeanbackActivity extends FragmentActivity {
+ @Override
+ public boolean onSearchRequested() {
+ return false;
+ }
+}
diff --git a/app/src/main/java/com/hyperion/grabber/tv/activities/MainActivity.java b/app/src/main/java/com/hyperion/grabber/tv/activities/MainActivity.java
new file mode 100644
index 0000000..d962a94
--- /dev/null
+++ b/app/src/main/java/com/hyperion/grabber/tv/activities/MainActivity.java
@@ -0,0 +1,284 @@
+package com.hyperion.grabber.tv.activities;
+
+import android.Manifest;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.graphics.Color;
+import android.media.projection.MediaProjectionManager;
+import android.os.Build;
+import android.os.Bundle;
+import androidx.annotation.NonNull;
+import androidx.annotation.RequiresApi;
+import androidx.core.app.ActivityCompat;
+import androidx.core.app.ActivityOptionsCompat;
+import androidx.core.content.ContextCompat;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
+import androidx.appcompat.app.AppCompatDelegate;
+import android.util.Log;
+import android.view.View;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.Toast;
+
+import com.hyperion.grabber.common.BootActivity;
+import com.hyperion.grabber.common.HyperionScreenService;
+import com.hyperion.grabber.common.util.Preferences;
+import com.hyperion.grabber.R;
+
+public class MainActivity extends LeanbackActivity implements ImageView.OnClickListener,
+ ImageView.OnFocusChangeListener {
+ public static final int REQUEST_MEDIA_PROJECTION = 1;
+ public static final int REQUEST_INITIAL_SETUP = 2;
+ private static final int REQUEST_NOTIFICATION_PERMISSION = 3;
+ public static final String BROADCAST_ERROR = "SERVICE_ERROR";
+ public static final String BROADCAST_TAG = "SERVICE_STATUS";
+ public static final String BROADCAST_FILTER = "SERVICE_FILTER";
+ private static final String TAG = "DEBUG";
+ private boolean mRecorderRunning = false;
+ private static MediaProjectionManager mMediaProjectionManager;
+
+ private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ boolean checked = intent.getBooleanExtra(BROADCAST_TAG, false);
+ mRecorderRunning = checked;
+ String error = intent.getStringExtra(BROADCAST_ERROR);
+ if (error != null) {
+ Toast.makeText(getBaseContext(), error, Toast.LENGTH_SHORT).show();
+ }
+ setImageViews(checked, true);
+ }
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (!initIfConfigured()){
+ startSetup();
+ }
+
+ // Request notification permission for Android 13+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ requestNotificationPermission();
+ }
+ }
+
+ private void requestNotificationPermission() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS)
+ != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(this,
+ new String[]{Manifest.permission.POST_NOTIFICATIONS},
+ REQUEST_NOTIFICATION_PERMISSION);
+ }
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ if (requestCode == REQUEST_NOTIFICATION_PERMISSION) {
+ if (grantResults.length > 0 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
+ Toast.makeText(this, "Notification permission is needed for the foreground service", Toast.LENGTH_LONG).show();
+ }
+ }
+ }
+
+ /** @return whether the activity was initialized */
+ private boolean initIfConfigured() {
+ // Do we have a valid server config?
+ Preferences preferences = new Preferences(getApplicationContext());
+ String host = preferences.getString(com.hyperion.grabber.common.R.string.pref_key_host, null);
+ int port = preferences.getInt(com.hyperion.grabber.common.R.string.pref_key_port, -1);
+
+ if (host == null || port == -1){
+ return false;
+ }
+
+ initActivity();
+ return true;
+ }
+
+ private void startSetup() {
+ // Start onboarding (setup)
+ Intent intent = new Intent(this, NetworkScanActivity.class);
+ startActivityForResult(intent, REQUEST_INITIAL_SETUP);
+ }
+
+ // Prepare activity for display
+ private void initActivity() {
+ // assume the recorder is not running until we are notified otherwise
+ mRecorderRunning = false;
+
+ setContentView(R.layout.activity_main);
+ AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
+ mMediaProjectionManager = (MediaProjectionManager)
+ getSystemService(Context.MEDIA_PROJECTION_SERVICE);
+
+ ImageView iv = findViewById(R.id.power_toggle);
+ iv.setOnClickListener(this);
+ iv.setOnFocusChangeListener(this);
+ iv.setFocusable(true);
+ iv.requestFocus();
+
+ ImageButton ib = findViewById(R.id.settingsButton);
+ ib.setOnClickListener(this);
+ ib.setOnFocusChangeListener(this);
+ ib.setFocusable(true);
+
+ setImageViews(mRecorderRunning, false);
+
+ LocalBroadcastManager.getInstance(this).registerReceiver(
+ mMessageReceiver, new IntentFilter(BROADCAST_FILTER));
+
+ // request an update on the running status
+ checkForInstance();
+ }
+
+ @Override
+ public void onClick(View view) {
+ int id = view.getId();
+ if (id == R.id.power_toggle) {
+ if (!mRecorderRunning) {
+ startActivityForResult(mMediaProjectionManager.createScreenCaptureIntent(),
+ REQUEST_MEDIA_PROJECTION);
+ } else {
+ stopScreenRecorder();
+ }
+ mRecorderRunning = !mRecorderRunning;
+ } else if (id == R.id.settingsButton) {
+ startSettings();
+ }
+ }
+
+ @Override
+ public void onFocusChange(View view, boolean focused) {
+ int clr = Color.argb(255, 0, 0, 150);
+ if (!focused) {
+ clr = Color.argb(255, 0, 0, 0);
+ }
+ int id = view.getId();
+ if (id == R.id.power_toggle) {
+ ((ImageView) view).setColorFilter(clr);
+ } else if (id == R.id.settingsButton) {
+ ((ImageButton) view).setColorFilter(clr);
+ }
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.M)
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == REQUEST_INITIAL_SETUP){
+ if (resultCode == RESULT_OK){
+ if (!initIfConfigured()){
+ startSetup();
+ }
+ } else {
+ finish();
+ }
+
+ return;
+ }
+ if (requestCode == REQUEST_MEDIA_PROJECTION) {
+ if (resultCode != Activity.RESULT_OK) {
+ Toast.makeText(this, com.hyperion.grabber.common.R.string.toast_must_give_permission, Toast.LENGTH_SHORT).show();
+ if (mRecorderRunning) {
+ stopScreenRecorder();
+ }
+ setImageViews(false, true);
+ return;
+ }
+ Log.i(TAG, "Starting screen capture");
+ startScreenRecorder(resultCode, (Intent) data.clone());
+ mRecorderRunning = true;
+ }
+ }
+
+ private void startSettings() {
+ stopScreenRecorder();
+ Intent intent = new Intent(this, ManualSetupActivity.class);
+ Bundle bundle =
+ ActivityOptionsCompat.makeSceneTransitionAnimation(this)
+ .toBundle();
+ startActivity(intent, bundle);
+ }
+
+ private void checkForInstance() {
+ if (isServiceRunning()) {
+ Intent intent = new Intent(this, HyperionScreenService.class);
+ intent.setAction(HyperionScreenService.GET_STATUS);
+ startService(intent);
+ }
+ }
+
+ private void setImageViews(boolean running, boolean animated) {
+ View rainbow = findViewById(R.id.sweepGradientView);
+ View message = findViewById(R.id.grabberStartedText);
+ if (running) {
+ if (animated){
+ fadeView(rainbow, true);
+ fadeView(message, true);
+ } else {
+ rainbow.setVisibility(View.VISIBLE);
+ message.setVisibility(View.VISIBLE);
+ }
+ } else {
+ if (animated){
+ fadeView(rainbow, false);
+ fadeView(message, false);
+ } else {
+ rainbow.setVisibility(View.INVISIBLE);
+ message.setVisibility(View.INVISIBLE);
+ }
+ }
+ }
+
+ public void startScreenRecorder(int resultCode, Intent data) {
+ BootActivity.startScreenRecorder(this, resultCode, data);
+ }
+
+ public void stopScreenRecorder() {
+ if (mRecorderRunning) {
+ Intent intent = new Intent(this, HyperionScreenService.class);
+ intent.setAction(HyperionScreenService.ACTION_EXIT);
+ startService(intent);
+ }
+ }
+
+ private boolean isServiceRunning() {
+ ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+ assert manager != null;
+ for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (HyperionScreenService.class.getName().equals(service.service.getClassName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void fadeView(View view, boolean visible){
+ float alpha = visible ? 1f : 0f;
+ int endVisibility = visible ? View.VISIBLE : View.INVISIBLE;
+ view.setVisibility(View.VISIBLE);
+ view.animate()
+ .alpha(alpha)
+ .setListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ view.setVisibility(endVisibility);
+ }
+ })
+ .start();
+
+
+ }
+}
diff --git a/app/src/main/java/com/hyperion/grabber/tv/activities/ManualSetupActivity.java b/app/src/main/java/com/hyperion/grabber/tv/activities/ManualSetupActivity.java
new file mode 100644
index 0000000..22dfc2e
--- /dev/null
+++ b/app/src/main/java/com/hyperion/grabber/tv/activities/ManualSetupActivity.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.hyperion.grabber.tv.activities;
+
+import android.os.Bundle;
+import androidx.leanback.app.GuidedStepSupportFragment;
+import androidx.fragment.app.FragmentActivity;
+
+import com.hyperion.grabber.tv.fragments.settings.BasicSettingsStepFragment;
+
+/**
+ * Allows to set all preferences manually
+ */
+public class ManualSetupActivity extends FragmentActivity {
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (null == savedInstanceState) {
+ GuidedStepSupportFragment.addAsRoot(this, new BasicSettingsStepFragment(), android.R.id.content);
+ }
+ }
+}
diff --git a/app/src/main/java/com/hyperion/grabber/tv/activities/NetworkScanActivity.java b/app/src/main/java/com/hyperion/grabber/tv/activities/NetworkScanActivity.java
new file mode 100644
index 0000000..0660319
--- /dev/null
+++ b/app/src/main/java/com/hyperion/grabber/tv/activities/NetworkScanActivity.java
@@ -0,0 +1,105 @@
+package com.hyperion.grabber.tv.activities;
+
+import android.annotation.SuppressLint;
+import android.content.Intent;
+import android.os.Bundle;
+import androidx.annotation.Nullable;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import com.hyperion.grabber.common.network.NetworkScanner;
+import com.hyperion.grabber.common.util.HyperionScannerTask;
+import com.hyperion.grabber.R;
+
+
+public class NetworkScanActivity extends LeanbackActivity implements HyperionScannerTask.Listener {
+ private boolean isScanning = false;
+
+ private Button startScanButton;
+ private Button manualSetupButton;
+ private ProgressBar progressBar;
+ private TextView descriptionText;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_network_scan);
+
+ startScanButton = findViewById(R.id.startScanButton);
+ manualSetupButton = findViewById(R.id.manualSetupButton);
+ progressBar = findViewById(R.id.progressBar);
+ descriptionText = findViewById(R.id.scannerDescriptionText);
+
+ // only if back was pressed on this Activity will we not be configured when we finish
+ setResult(RESULT_OK);
+
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == MainActivity.REQUEST_INITIAL_SETUP){
+ if (resultCode == RESULT_OK){
+ // when the setup completed successfully, we completed successfully.
+ setResult(RESULT_OK);
+ finish();
+ }
+ }
+ }
+
+ public void onClick(View v){
+ if (v.getId() == R.id.startScanButton){
+ if (!isScanning){
+ new HyperionScannerTask(this).execute();
+ }
+
+ } else if (v.getId() == R.id.manualSetupButton){
+ Intent intent = new Intent(this, ManualSetupActivity.class);
+ startActivityForResult(intent, MainActivity.REQUEST_INITIAL_SETUP);
+ }
+
+ }
+
+ @Override
+ public void onBackPressed() {
+ setResult(RESULT_CANCELED);
+ super.onBackPressed();
+ }
+
+ @SuppressLint("StringFormatInvalid")
+ @Override
+ public void onScannerProgress(float progress) {
+ if (!isScanning){
+ isScanning = true;
+ startScanButton.setText(com.hyperion.grabber.common.R.string.scanner_scan_in_progress_button);
+ descriptionText.setGravity(Gravity.CENTER);
+ descriptionText.setText(getString(com.hyperion.grabber.common.R.string.scanner_scan_in_progress_text, "\uD83D\uDD75️")); // todo: 🕵️
+ }
+
+ progressBar.setProgress(Math.round(progress * 100));
+ }
+
+ @SuppressLint("StringFormatInvalid")
+ @Override
+ public void onScannerCompleted(@Nullable String foundIpAddress) {
+ isScanning = false;
+
+ if (foundIpAddress == null){
+ startScanButton.setText(com.hyperion.grabber.common.R.string.scanner_retry_button);
+ manualSetupButton.requestFocus();
+ descriptionText.setText(getString(com.hyperion.grabber.common.R.string.scanner_no_results, "\uD83D\uDE29")); // 😩
+ } else {
+ Intent intent = new Intent(this, ScanResultActivity.class);
+ intent.putExtra(ScanResultActivity.EXTRA_RESULT_HOST_NAME, foundIpAddress);
+
+ intent.putExtra(ScanResultActivity.EXTRA_RESULT_PORT, String.valueOf(NetworkScanner.PORT));
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ finish(); // Finish the current activity
+ }
+ }
+
+}
diff --git a/app/src/main/java/com/hyperion/grabber/tv/activities/ScanResultActivity.java b/app/src/main/java/com/hyperion/grabber/tv/activities/ScanResultActivity.java
new file mode 100644
index 0000000..753c0e6
--- /dev/null
+++ b/app/src/main/java/com/hyperion/grabber/tv/activities/ScanResultActivity.java
@@ -0,0 +1,204 @@
+package com.hyperion.grabber.tv.activities;
+
+import android.animation.Animator;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
+import android.content.Intent;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.view.View;
+import android.view.animation.DecelerateInterpolator;
+import android.widget.TextView;
+
+import com.hyperion.grabber.common.network.HyperionFlatBuffers;
+import com.hyperion.grabber.common.util.Preferences;
+import com.hyperion.grabber.R;
+
+import java.io.IOException;
+import java.util.Random;
+
+import nl.dionsegijn.konfetti.xml.KonfettiView;
+import nl.dionsegijn.konfetti.core.Party;
+import nl.dionsegijn.konfetti.core.PartyFactory;
+import nl.dionsegijn.konfetti.core.emitter.Emitter;
+import nl.dionsegijn.konfetti.core.emitter.EmitterConfig;
+import nl.dionsegijn.konfetti.core.models.Shape;
+import nl.dionsegijn.konfetti.core.models.Size;
+
+import java.util.concurrent.TimeUnit;
+
+/** Shows the result of a network scan and allows to save the result to Preferences */
+public class ScanResultActivity extends LeanbackActivity {
+ public static final String EXTRA_RESULT_HOST_NAME = "EXTRA_RESULT_HOST_NAME";
+ public static final String EXTRA_RESULT_PORT = "EXTRA_RESULT_PORT";
+
+
+ private KonfettiView konfettiView;
+ private TextView descriptionText;
+ private TextView hostNameText;
+ private TextView emojiText;
+ private String hostName;
+ private int port;
+
+ private final int ORANGE = Color.rgb(253, 104, 40);
+ private final int[] COLORS = {Color.RED, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, ORANGE};
+ /** the amount of variation in R, G, B components of a confetti burst */
+ private final int BURST_COLOR_SPREAD = 200;
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_scan_result);
+
+ konfettiView = findViewById(R.id.konfetti);
+ descriptionText = findViewById(R.id.scanResultDescriptionText);
+ hostNameText = findViewById(R.id.scanResultHostName);
+ emojiText = findViewById(R.id.scanResultEmojiText);
+
+ emojiText.setText("\uD83D\uDC4F"); // 👏Clapping Hands
+ String partyPopper = "\uD83C\uDF89";
+ descriptionText.setText(getResources().getString(com.hyperion.grabber.common.R.string.scan_result_description, partyPopper));
+ Bundle extras = getIntent().getExtras();
+ if (extras != null){
+ hostName = extras.getString(EXTRA_RESULT_HOST_NAME);
+ port = Integer.parseInt(extras.getString(EXTRA_RESULT_PORT));
+ hostNameText.setText(hostName);
+ } else {
+ hostNameText.setText(com.hyperion.grabber.common.R.string.error_no_host_name_extra);
+ }
+
+ // Animate the appearance of the scan result
+ Animator fadeInAnimator = ObjectAnimator.ofFloat(hostNameText, "alpha", 0f, 1f);
+ Animator scaleXAnimator = ObjectAnimator
+ .ofFloat(hostNameText, "scaleX", .8f, 1f);
+ Animator scaleYAnimator = ObjectAnimator
+ .ofFloat(hostNameText, "scaleY", .8f, 1f);
+ AnimatorSet hostNameSet = new AnimatorSet();
+ hostNameSet.playTogether(fadeInAnimator, scaleXAnimator, scaleYAnimator);
+ hostNameSet.setInterpolator(new DecelerateInterpolator());
+ hostNameSet.setDuration(6000L);
+ hostNameSet.start();
+
+ konfettiView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
+ startKonfetti();
+ konfettiView.removeOnLayoutChangeListener(this);
+ }
+ });
+
+
+
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ setHyperionColor(hostName, port, Color.BLACK);
+
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ setHyperionColor(hostName, port, Color.MAGENTA);
+ }
+
+ public void onClick(View v){
+ if (v.getId() == R.id.confirmButton){
+ saveResult();
+
+ Intent intent = new Intent(this, MainActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ finish(); // call this to finish the current activity
+ } else if (v.getId() == R.id.changeColorButton){
+ int color = COLORS[new Random().nextInt(COLORS.length)];
+ setHyperionColor(hostName, port, color);
+ burstKonfetti(color);
+ }
+ }
+
+ /** Save scan result to Preferences */
+ private void saveResult() {
+ Preferences prefs = new Preferences(getApplicationContext());
+ prefs.putString(com.hyperion.grabber.common.R.string.pref_key_host, hostName);
+ prefs.putInt(com.hyperion.grabber.common.R.string.pref_key_port, port);
+ }
+
+ private void startKonfetti() {
+ EmitterConfig emitterConfig = new Emitter(Long.MAX_VALUE, TimeUnit.MILLISECONDS).perSecond(300);
+ Party party = new PartyFactory(emitterConfig)
+ .colors(java.util.Arrays.asList(Color.YELLOW, Color.GREEN, Color.MAGENTA))
+ .setSpeedBetween(1f, 5f)
+ .fadeOutEnabled(true)
+ .timeToLive(400L)
+ .shapes(java.util.Arrays.asList(Shape.Square.INSTANCE, Shape.Circle.INSTANCE))
+ .sizes(java.util.Arrays.asList(new Size(12, 5f, 0f)))
+ .position(-50f, konfettiView.getWidth() + 50f, -50f, -50f)
+ .build();
+ konfettiView.start(party);
+ }
+
+ /** Start a one-shot burst of confetti from a random location of a single color
+ *
+ * @param color a color int such as Color.RED, NOT a color resource
+ */
+ private void burstKonfetti(int color){
+ int r = Color.red(color);
+ int g = Color.green(color);
+ int b = Color.blue(color);
+
+ Random random = new Random();
+ java.util.List H7BZ+uNjPr?`Sb
z?4EO;y7fF79`gj4%Oe=lnseuLT*-eOCdq+w!CFSZHnyz1bnEx`n^zY_D}gXc*|#Du
zzRf2-v$rh42~&Y5kl?uo%hy(wdoOI}uSb8Zqfn&XENeE6^2ry#&2Ax`i;jZ|s8;LD
zbu4jZAV^50As%vhhjSZlc6`ro%D<-6{DkC6XV2LVr`zlOC-Qn J3WFiI|JPPjutbR>
z5Fdr$D1@Bg=mM7t&d1oJ2Yd~@Rsj_}Ug%1KYY)bEVf7t|qV*yRp_@=>K_iI95E^|&
zxJIiEjWHMv!ob(8;&zD=-xTyH?DfMQAXS3%BDmK;9kb~IyFkATxIlJ6hYq!ISPjEy
z@k(#mY5*1BJPxYRn8(RWl%mLEDuIh}c(ZG~Hs8b|2_;H=UC}ooa?fz@DXrjY1lI`2
zc4a#xfl&!YQ%B{dGH8xNWDlMOZSC7uumQ}@!Wb%2m3=30DG6!>9tYuGQLa*=L j&=a>e{(I1Fbyc*{Y40#Y$kStW2>G>*s;D|%7eg7_r3225|mqK*1JpA6Sk
zc(MY)0$wbK1Rr?d!7FP$SuU5u@)E2B#pgH`xax%mf)W8mhOP>DFrI&`EWwou7?{XE
zw&x7=esS~|NrEN~UgfEO)_oD~{v#0n4FrFbwMaSCZ1GVSeD?Q8uk-DXp#L*iqXIpv
zhL4~BikttyogNtLJ$juJ%@CV|e4p;Fk6`w*qsIW8xekGW{ObXG>2i#e&O*Y#fa+51dPm2zoN`M
aRu
zrK1B653e2iumT;Ej#d)|oU4E50wl0|1mZf5Vx{7#;F3!G_&2^@-fvAW-cs9C;-&k2;~`uNlDm+{j8`#LP>|^95D`3_qAbcK`Q;`
zI_QzoF_IERAv(QiQrES5&C`sQQUxJp+!A>C|3&Sb_*YnoH_PzKsUSDe6=;|I$LdAs
zCM`2|R0AJ=`ThEvrvzn?Dw5`qw9q2am3kpYMJg?fXBcUB|G>{wy#=g|hcB36P}CNp
zwk()2|2pN9dvdm5e3oJ|tq&TKW$?JD1f0VWe}y~Ir~H
q*B(2iHYA28$M^7UHR?peBW$sRq50E
z`}-46gJ_qPS~5*81R0%znwtKFL%;*40!&)|9c8KhhvsBrRW>
zQ%<-p8Pb*w8>B61F8IN-1CMPmsAtL`wqdSuQ8s4F*=O@XBMi@)pC{VmHyhEWN12>E
z1$!pz*l89V@v2Efu@{BoCVg#T!KO*sJbwsf7J5)Dj2aEetzf0Bel}JcF6Clv5Vlo|
zo#+lBww;p9bb=~a#oH|V8p0Ux5y+n{+Sj``o3ym$%`!YODa|;FbceQy8Cb9(IFoK%
zv|K=Ud$Z;2-+Bzk;d6^+{?1gGH)J5*^eB@`3&&Z-!X4d8^wL{xe$Kju&rdWAW#aV?
z4)E+Q)LQJ6W~HqDTWh2nE?u_1#{ODMMkhKukHi3*&tYXXC7H27ke!S8wo!`A_F@QW
z+TCzAo|3lMSm4m_fcM?zo01>KdlniOWn-nBeJ15DSX+dIh39j&9{Mb#KZ!Oy$|hpL
zz*{=eSeUeHp|HiciKa=JJo^HU2{u&EL{GxvGPo=@BDYdjKby!l%#K-WxRgyYo@&m1
z!&-Cp!$?F7$xQeZXayYo^I^LIOiNoP=V8?52y(k0DuVE!fB;1%AJ)Qv$;L(5I234e
z!dL;v@beY$+G;&QtQk(xrbpSBmDzyd!!nB%AF5e#cA9bv$E{=nu=pBoE`g_jW9ZT-
zDCa;aV0TnV!=+p-KT0)cx7k<)CSh?TC7CH8CVKp4Vy5X)Ce6oT&B87>X3}Q}5Vc@5S6ASeh4ihl
z5%ESynT$Mw;}(2~0Aml}L?QB)LGaxGy?}s0Aq|&u5qb^tTNW_I()E=i2McZO-)?
ziXQ-sOqu{v52jpDp(%=Hb`KWqvYmdC`T&&VJTkRF3PDngfAthk>1RW}3wp?~pblKe
zIPiU-IpE(BP%>P|UBbU4db5
z65pk{7qG)fe4A8Zg^~6(>>I+C13=h?p{MTx5GGhYp&mPd?K#K@dbXLJg>P#E#AzJ0
z4p5;%^BwIPuqy);BXK8OEA0J7dmoNH1hP{qqhVXciMAa;t%m2MALoE}&Qm?=*7s%M
zT?Q^dnW4-zP3r>A1*Yc5+~<^EHwmUuHvi1DNxa_Sz9Z^szK!4E{D$p0{!D*0Woy#b
zJ