Aperture: Implement camera mode switcher animation
Change-Id: If42b048f551c392bbac1991566f453287d5dc544
diff --git a/app/src/main/java/org/lineageos/aperture/MainActivity.kt b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
index 74b29e9..0bdc97b 100644
--- a/app/src/main/java/org/lineageos/aperture/MainActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
@@ -57,6 +57,7 @@
import androidx.core.view.WindowCompat.getInsetsController
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
+import androidx.core.view.doOnLayout
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
@@ -85,6 +86,7 @@
class MainActivity : AppCompatActivity() {
private val aspectRatioButton by lazy { findViewById<ToggleButton>(R.id.aspectRatioButton) }
private val bottomButtonsLayout by lazy { findViewById<ConstraintLayout>(R.id.bottomButtonsLayout) }
+ private val cameraModeHighlight by lazy { findViewById<MaterialButton>(R.id.cameraModeHighlight) }
private val effectButton by lazy { findViewById<ImageButton>(R.id.effectButton) }
private val flashButton by lazy { findViewById<ImageButton>(R.id.flashButton) }
private val flipCameraButton by lazy { findViewById<ImageButton>(R.id.flipCameraButton) }
@@ -117,7 +119,8 @@
private lateinit var cameraController: LifecycleCameraController
- private lateinit var cameraMode: CameraMode
+ private val cameraMode: CameraMode
+ get() = sharedPreferences.lastCameraMode
private lateinit var camera: PhysicalCamera
@@ -229,6 +232,15 @@
micButton.setOnClickListener { toggleMicrophoneMode() }
settingsButton.setOnClickListener { openSettings() }
+ // Initialize camera mode highlight position
+ (cameraModeHighlight.parent as View).doOnLayout {
+ cameraModeHighlight.x = when (cameraMode) {
+ CameraMode.QR -> qrModeButton.x
+ CameraMode.PHOTO -> photoModeButton.x
+ CameraMode.VIDEO -> videoModeButton.x
+ }
+ }
+
// Attach CameraController to PreviewView
viewFinder.controller = cameraController
@@ -524,7 +536,6 @@
gridView.alpha = 0f
// Select front/back camera
- cameraMode = sharedPreferences.lastCameraMode
var cameraSelector = when (cameraMode) {
CameraMode.QR -> CameraSelector.DEFAULT_BACK_CAMERA
else -> when (sharedPreferences.lastCameraFacing) {
@@ -662,6 +673,21 @@
qrModeButton.isEnabled = cameraMode != CameraMode.QR
photoModeButton.isEnabled = cameraMode != CameraMode.PHOTO
videoModeButton.isEnabled = cameraMode != CameraMode.VIDEO
+
+ // Animate camera mode change
+ (cameraModeHighlight.parent as View).doOnLayout {
+ ValueAnimator.ofFloat(
+ cameraModeHighlight.x, when (cameraMode) {
+ CameraMode.QR -> qrModeButton.x
+ CameraMode.PHOTO -> photoModeButton.x
+ CameraMode.VIDEO -> videoModeButton.x
+ }
+ ).apply {
+ addUpdateListener {
+ cameraModeHighlight.x = it.animatedValue as Float
+ }
+ }.start()
+ }
}
private fun cycleAspectRatio() {
diff --git a/app/src/main/res/color/camera_mode_selector_icon.xml b/app/src/main/res/color/camera_mode_selector_icon.xml
index a80b3b4..3daf122 100644
--- a/app/src/main/res/color/camera_mode_selector_icon.xml
+++ b/app/src/main/res/color/camera_mode_selector_icon.xml
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:color="@android:color/transparent" android:state_enabled="true" />
- <item android:color="?attr/colorSecondaryContainer" android:state_enabled="false" />
-</selector>
\ No newline at end of file
+ <item android:color="@android:color/transparent" />
+</selector>
diff --git a/app/src/main/res/color/camera_mode_selector_icon_highlight.xml b/app/src/main/res/color/camera_mode_selector_icon_highlight.xml
new file mode 100644
index 0000000..3dc9bf7
--- /dev/null
+++ b/app/src/main/res/color/camera_mode_selector_icon_highlight.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:color="?attr/colorSecondaryContainer" />
+</selector>
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index cef25d8..1be0acf 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -275,11 +275,26 @@
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.button.MaterialButton
+ android:id="@+id/cameraModeHighlight"
+ style="@style/ApertureModeSelectorButtonHighlight"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:enabled="false"
+ android:padding="0dp"
+ app:iconPadding="0dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toStartOf="@+id/videoModeButton"
+ app:layout_constraintHorizontal_bias="0.5"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ <com.google.android.material.button.MaterialButton
android:id="@+id/photoModeButton"
style="@style/ApertureModeSelectorButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/photo_mode_button_description"
+ android:enabled="false"
android:padding="0dp"
android:text="@string/selector_photo"
app:iconPadding="0dp"
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 687192e..7ee2641 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -43,6 +43,11 @@
<item name="android:typeface">monospace</item>
</style>
+ <!-- Bottom bar icons highlight theme -->
+ <style name="ApertureModeSelectorButtonHighlight" parent="@style/ApertureModeSelectorButton">
+ <item name="android:backgroundTint">@color/camera_mode_selector_icon_highlight</item>
+ </style>
+
<!-- Shutter button theme -->
<style name="ApertureShutterButton">
<item name="android:background">@drawable/shutter_button_background</item>