From 6c841a629f607a48e2ef0edffa872c6fcf945ee6 Mon Sep 17 00:00:00 2001 From: Zhengyu Peng Date: Sun, 13 Feb 2022 21:14:46 -0500 Subject: [PATCH] update --- software/android/.idea/misc.xml | 1 + software/android/app/build.gradle | 2 +- .../android/app/src/main/AndroidManifest.xml | 6 ++ .../com/rookiedev/hexapod/ControlActivity.kt | 75 +++++++++++++++++++ .../com/rookiedev/hexapod/MainActivity.kt | 4 + .../src/main/res/layout/activity_control.xml | 9 +++ .../app/src/main/res/values/themes.xml | 14 ++++ 7 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 software/android/app/src/main/java/com/rookiedev/hexapod/ControlActivity.kt create mode 100644 software/android/app/src/main/res/layout/activity_control.xml diff --git a/software/android/.idea/misc.xml b/software/android/.idea/misc.xml index 6bb132a..0dafa39 100644 --- a/software/android/.idea/misc.xml +++ b/software/android/.idea/misc.xml @@ -3,6 +3,7 @@ diff --git a/software/android/app/build.gradle b/software/android/app/build.gradle index 1e92f5a..d838980 100644 --- a/software/android/app/build.gradle +++ b/software/android/app/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { applicationId "com.rookiedev.hexapod" - minSdk 29 + minSdk 30 targetSdk 31 versionCode 1 versionName "1.0" diff --git a/software/android/app/src/main/AndroidManifest.xml b/software/android/app/src/main/AndroidManifest.xml index 5f02da6..0d29843 100644 --- a/software/android/app/src/main/AndroidManifest.xml +++ b/software/android/app/src/main/AndroidManifest.xml @@ -9,6 +9,12 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.Hexapod"> + diff --git a/software/android/app/src/main/java/com/rookiedev/hexapod/ControlActivity.kt b/software/android/app/src/main/java/com/rookiedev/hexapod/ControlActivity.kt new file mode 100644 index 0000000..a5d80e4 --- /dev/null +++ b/software/android/app/src/main/java/com/rookiedev/hexapod/ControlActivity.kt @@ -0,0 +1,75 @@ +package com.rookiedev.hexapod + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.view.WindowInsets +import android.view.WindowInsetsController + +/** + * Behaviors of immersive mode. + */ +enum class BehaviorOption( + val title: String, + val value: Int +) { + // Swipe from the edge to show a hidden bar. Gesture navigation works regardless of visibility + // of the navigation bar. + Default( + "BEHAVIOR_DEFAULT", + WindowInsetsController.BEHAVIOR_DEFAULT + ), + // "Sticky immersive mode". Swipe from the edge to temporarily reveal the hidden bar. + ShowTransientBarsBySwipe( + "BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE", + WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + ) +} + +/** + * Type of system bars to hide or show. + */ +enum class TypeOption( + val title: String, + val value: Int +) { + // Both the status bar and the navigation bar + SystemBars( + "systemBars()", + WindowInsets.Type.systemBars() + ), + // The status bar only. + StatusBar( + "statusBars()", + WindowInsets.Type.statusBars() + ), + // The navigation bar only + NavigationBar( + "navigationBars()", + WindowInsets.Type.navigationBars() + ) +} + +class ControlActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_control) + + controlWindowInsets(true) + } + + private fun controlWindowInsets(hide: Boolean) { + // WindowInsetsController can hide or show specified system bars. + val insetsController = window.decorView.windowInsetsController ?: return + // The behavior of the immersive mode. + val behavior = BehaviorOption.values()[1].value + // The type of system bars to hide or show. + val type = TypeOption.values()[0].value + insetsController.systemBarsBehavior = behavior + if (hide) { + insetsController.hide(type) + } else { + insetsController.show(type) + } + } +} + diff --git a/software/android/app/src/main/java/com/rookiedev/hexapod/MainActivity.kt b/software/android/app/src/main/java/com/rookiedev/hexapod/MainActivity.kt index 6bc700b..5aa1b77 100644 --- a/software/android/app/src/main/java/com/rookiedev/hexapod/MainActivity.kt +++ b/software/android/app/src/main/java/com/rookiedev/hexapod/MainActivity.kt @@ -1,5 +1,6 @@ package com.rookiedev.hexapod +import android.content.Intent import android.net.InetAddresses.isNumericAddress import androidx.appcompat.app.AppCompatActivity import android.os.Bundle @@ -26,6 +27,9 @@ class MainActivity : AppCompatActivity() { // your code to perform when the user clicks on the button Toast.makeText(this@MainActivity, "You clicked me.", Toast.LENGTH_SHORT).show() + val intent = Intent(this, ControlActivity::class.java).apply { + } + startActivity(intent) } diff --git a/software/android/app/src/main/res/layout/activity_control.xml b/software/android/app/src/main/res/layout/activity_control.xml new file mode 100644 index 0000000..507f201 --- /dev/null +++ b/software/android/app/src/main/res/layout/activity_control.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/software/android/app/src/main/res/values/themes.xml b/software/android/app/src/main/res/values/themes.xml index 5dd53ce..eb64fe1 100644 --- a/software/android/app/src/main/res/values/themes.xml +++ b/software/android/app/src/main/res/values/themes.xml @@ -13,4 +13,18 @@ ?attr/colorPrimaryVariant + + \ No newline at end of file