├── .idea
├── .name
├── .gitignore
├── compiler.xml
├── kotlinc.xml
├── render.experimental.xml
├── vcs.xml
├── misc.xml
├── deploymentTargetDropDown.xml
├── gradle.xml
└── inspectionProfiles
│ └── Project_Default.xml
├── touchbar
├── .gitignore
├── consumer-rules.pro
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── oxy
│ │ └── touchbar
│ │ ├── TouchbarDefaults.kt
│ │ ├── locals
│ │ └── Infos.kt
│ │ ├── TouchbarBackground.kt
│ │ ├── Touchbar.kt
│ │ ├── TouchbarState.kt
│ │ ├── TouchbarPanel.kt
│ │ └── TouchbarSelector.kt
├── proguard-rules.pro
└── build.gradle
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── colors.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── oxy
│ │ │ │ └── mmr
│ │ │ │ ├── ui
│ │ │ │ ├── theme
│ │ │ │ │ ├── Color.kt
│ │ │ │ │ ├── Type.kt
│ │ │ │ │ └── Theme.kt
│ │ │ │ └── Background.kt
│ │ │ │ ├── MainActivity.kt
│ │ │ │ ├── components
│ │ │ │ ├── TimeZone.kt
│ │ │ │ ├── VideoViewer.kt
│ │ │ │ └── VideoAlbum.kt
│ │ │ │ ├── App.kt
│ │ │ │ ├── wrapper
│ │ │ │ └── Shared.kt
│ │ │ │ ├── feature
│ │ │ │ ├── album
│ │ │ │ │ └── AlbumScreen.kt
│ │ │ │ └── touchbar
│ │ │ │ │ └── TouchBarScreen.kt
│ │ │ │ └── util
│ │ │ │ └── MediaUtils.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── oxy
│ │ │ └── mmr
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── oxy
│ │ └── mmr
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── jitpack.yml
├── .gitignore
├── settings.gradle
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | touchbar
--------------------------------------------------------------------------------
/touchbar/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/touchbar/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /release
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/touchbar/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MediaMetadataRetrieverDemo
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oxyroid/touchbar/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk17
3 | before_install:
4 | - sdk install java 17.0.1-open
5 | - sdk use java 17.0.1-open
6 | - ./scripts/prepareJitpackEnvironment.sh
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/render.experimental.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jul 09 19:56:48 CST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.ui.theme
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | val Purple80 = Color(0xFFD0BCFF)
6 | val PurpleGrey80 = Color(0xFFCCC2DC)
7 | val Pink80 = Color(0xFFEFB8C8)
8 |
9 | val Purple40 = Color(0xFF6650a4)
10 | val PurpleGrey40 = Color(0xFF625b71)
11 | val Pink40 = Color(0xFF7D5260)
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/oxy/mmr/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | maven { url "https://jitpack.io" }
14 | }
15 | }
16 | rootProject.name = "touchbar"
17 | include ":app"
18 | include ":touchbar"
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/ui/Background.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.ui
2 |
3 | import androidx.compose.material.Surface
4 | import androidx.compose.material3.MaterialTheme
5 | import androidx.compose.runtime.Composable
6 |
7 | @Composable
8 | fun Background(
9 | content: @Composable () -> Unit
10 | ) {
11 | Surface(
12 | color = MaterialTheme.colorScheme.background,
13 | contentColor = MaterialTheme.colorScheme.onBackground,
14 | content = content
15 | )
16 | }
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/touchbar/src/main/java/com/oxy/touchbar/TouchbarDefaults.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.touchbar
2 |
3 | import androidx.compose.ui.graphics.Color
4 | import androidx.compose.ui.unit.dp
5 |
6 | object TouchbarDefaults {
7 | val HeightDp = 64.dp
8 | const val BackgroundRadiusPercent = 25
9 | const val HandleRadius = 18f
10 |
11 | val EdgeColor = Color.White
12 | val ActiveEdgeColor = Color(0xffffc773)
13 |
14 | val IndicatorColor = Color.White
15 | val ActiveIndicatorColor = Color(0xffffc773)
16 |
17 | const val VerticalHandle = 48f
18 | const val ActiveVerticalHandle = 64f
19 |
20 | const val HandleInset = 12f
21 | const val ActiveHandleInset = 16f
22 |
23 | const val HorizontalHandle = 18f
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/oxy/mmr/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.oxy.mmr", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
--------------------------------------------------------------------------------
/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.
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
--------------------------------------------------------------------------------
/touchbar/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.
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/java/com/oxy/mmr/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.compose.setContent
6 | import androidx.compose.foundation.layout.fillMaxSize
7 | import androidx.compose.material3.Surface
8 | import androidx.compose.ui.Modifier
9 | import com.oxy.mmr.ui.theme.MediaMetadataRetrieverDemoTheme
10 |
11 | class MainActivity : ComponentActivity() {
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | setContent {
15 | MediaMetadataRetrieverDemoTheme {
16 | Surface {
17 | App(
18 | modifier = Modifier.fillMaxSize()
19 | )
20 | }
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.ui.theme
2 |
3 | import androidx.compose.material3.Typography
4 | import androidx.compose.ui.text.TextStyle
5 | import androidx.compose.ui.text.font.FontFamily
6 | import androidx.compose.ui.text.font.FontWeight
7 | import androidx.compose.ui.unit.sp
8 |
9 | // Set of Material typography styles to start with
10 | val Typography = Typography(
11 | bodyLarge = TextStyle(
12 | fontFamily = FontFamily.Default,
13 | fontWeight = FontWeight.Normal,
14 | fontSize = 16.sp,
15 | lineHeight = 24.sp,
16 | letterSpacing = 0.5.sp
17 | )
18 | /* Other default text styles to override
19 | titleLarge = TextStyle(
20 | fontFamily = FontFamily.Default,
21 | fontWeight = FontWeight.Normal,
22 | fontSize = 22.sp,
23 | lineHeight = 28.sp,
24 | letterSpacing = 0.sp
25 | ),
26 | labelSmall = TextStyle(
27 | fontFamily = FontFamily.Default,
28 | fontWeight = FontWeight.Medium,
29 | fontSize = 11.sp,
30 | lineHeight = 16.sp,
31 | letterSpacing = 0.5.sp
32 | )
33 | */
34 | )
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
15 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/touchbar/src/main/java/com/oxy/touchbar/locals/Infos.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.touchbar.locals
2 |
3 | import androidx.compose.runtime.Immutable
4 | import androidx.compose.runtime.compositionLocalOf
5 | import androidx.compose.ui.graphics.Color
6 | import com.oxy.touchbar.TouchbarDefaults
7 |
8 | @Immutable
9 | internal data class Infos(
10 | val enableZHandle: Boolean = false,
11 | val bottomPaddingPresent: Float = 0.25f,
12 | val backgroundRadius: Int = TouchbarDefaults.BackgroundRadiusPercent,
13 | val handleRadius: Float = TouchbarDefaults.HandleRadius,
14 | val verticalHandle: Float = TouchbarDefaults.VerticalHandle,
15 | val activeVerticalHandle: Float = TouchbarDefaults.ActiveVerticalHandle,
16 | val horizontalHandle: Float = TouchbarDefaults.HorizontalHandle,
17 | val handleInset: Float = TouchbarDefaults.HandleInset,
18 | val activeHandleInset: Float = TouchbarDefaults.ActiveHandleInset,
19 | val edgeColor: Color = TouchbarDefaults.EdgeColor,
20 | val activeEdgeColor: Color = TouchbarDefaults.ActiveEdgeColor,
21 | val indicatorColor: Color = TouchbarDefaults.IndicatorColor,
22 | val activeIndicatorColor: Color = TouchbarDefaults.ActiveIndicatorColor,
23 | )
24 |
25 | internal val LocalInfos = compositionLocalOf {
26 | Infos()
27 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/components/TimeZone.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.components
2 |
3 | import androidx.compose.material3.Text
4 | import androidx.compose.runtime.Composable
5 | import androidx.compose.runtime.remember
6 | import androidx.compose.ui.Modifier
7 | import androidx.compose.ui.graphics.Color
8 | import androidx.compose.ui.unit.TextUnit
9 | import androidx.compose.ui.unit.sp
10 |
11 | @Composable
12 | internal fun TimeZone(
13 | millisecond: Long,
14 | modifier: Modifier = Modifier,
15 | fontSize: TextUnit = 12.sp,
16 | color: Color = Color.Unspecified
17 | ) {
18 | Text(
19 | text = remember(millisecond) {
20 | millisecond.mss()
21 | },
22 | fontSize = fontSize,
23 | color = color,
24 | modifier = modifier
25 | )
26 | }
27 |
28 | private fun Long.mss(): String {
29 | if (this < 0L) return "--:--"
30 | var seconds = this / 1000
31 | var minutes = 0L
32 | while (seconds >= 60) {
33 | seconds -= 60
34 | minutes++
35 | }
36 | val formattedSeconds = minutes.toString().let {
37 | when (it.length) {
38 | 1 -> "0$it"
39 | else -> it
40 | }
41 | }
42 | val formattedMinutes = seconds.toString().let {
43 | when (it.length) {
44 | 1 -> "0$it"
45 | else -> it
46 | }
47 | }
48 | return "$formattedSeconds:$formattedMinutes"
49 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.ui.theme
2 |
3 | import android.app.Activity
4 | import android.os.Build
5 | import androidx.compose.material3.MaterialTheme
6 | import androidx.compose.material3.darkColorScheme
7 | import androidx.compose.material3.dynamicDarkColorScheme
8 | import androidx.compose.runtime.Composable
9 | import androidx.compose.runtime.SideEffect
10 | import androidx.compose.ui.graphics.toArgb
11 | import androidx.compose.ui.platform.LocalContext
12 | import androidx.compose.ui.platform.LocalView
13 | import androidx.core.view.WindowCompat
14 |
15 | private val DarkColorScheme = darkColorScheme(
16 | primary = Purple80,
17 | secondary = PurpleGrey80,
18 | tertiary = Pink80
19 | )
20 |
21 | @Composable
22 | fun MediaMetadataRetrieverDemoTheme(
23 | dynamicColor: Boolean = true,
24 | content: @Composable () -> Unit
25 | ) {
26 | val colorScheme = when {
27 | dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
28 | val context = LocalContext.current
29 | dynamicDarkColorScheme(context)
30 | }
31 |
32 | else -> DarkColorScheme
33 | }
34 | val view = LocalView.current
35 | if (!view.isInEditMode) {
36 | SideEffect {
37 | val window = (view.context as Activity).window
38 | window.statusBarColor = colorScheme.primary.toArgb()
39 | WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = true
40 | }
41 | }
42 |
43 | MaterialTheme(
44 | colorScheme = colorScheme,
45 | typography = Typography,
46 | content = content
47 | )
48 | }
--------------------------------------------------------------------------------
/touchbar/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.android.library"
3 | id "org.jetbrains.kotlin.android"
4 | id "maven-publish"
5 | }
6 |
7 | android {
8 | namespace "com.oxy.touchbar"
9 | compileSdk 33
10 |
11 | defaultConfig {
12 | minSdk 21
13 | targetSdk 33
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | consumerProguardFiles "consumer-rules.pro"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_17
27 | targetCompatibility JavaVersion.VERSION_17
28 | }
29 | kotlinOptions {
30 | jvmTarget = "17"
31 | }
32 | buildFeatures {
33 | compose true
34 | }
35 | composeOptions {
36 | kotlinCompilerExtensionVersion "1.5.0"
37 | }
38 | }
39 |
40 | dependencies {
41 | implementation "androidx.compose.animation:animation:1.4.3"
42 | implementation "androidx.compose.foundation:foundation:1.4.3"
43 | implementation "androidx.compose.material:material:1.4.3"
44 | implementation "androidx.compose.material3:material3:1.1.1"
45 | implementation "androidx.compose.runtime:runtime:1.4.3"
46 | implementation "androidx.compose.ui:ui:1.4.3"
47 | }
48 |
49 | afterEvaluate {
50 | publishing {
51 | publications {
52 | release(MavenPublication) {
53 | groupId = "com.github.realOxy"
54 | artifactId = "touchbar"
55 | version = "1.6"
56 |
57 | from components.release
58 | }
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/components/VideoViewer.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.components
2 |
3 | import android.graphics.Bitmap
4 | import androidx.compose.foundation.Image
5 | import androidx.compose.foundation.clickable
6 | import androidx.compose.foundation.layout.fillMaxSize
7 | import androidx.compose.foundation.layout.size
8 | import androidx.compose.foundation.shape.RoundedCornerShape
9 | import androidx.compose.material3.Card
10 | import androidx.compose.runtime.Composable
11 | import androidx.compose.runtime.remember
12 | import androidx.compose.ui.Modifier
13 | import androidx.compose.ui.graphics.asImageBitmap
14 | import androidx.compose.ui.graphics.graphicsLayer
15 | import androidx.compose.ui.layout.ContentScale
16 | import androidx.compose.ui.unit.dp
17 | import com.oxy.mmr.wrapper.Shared
18 | import com.oxy.mmr.wrapper.SharedHandler
19 |
20 | @Composable
21 | internal fun VideoViewer(
22 | shared: Shared,
23 | onClick: () -> Unit
24 | ) {
25 | SharedHandler(shared) {
26 | Card(
27 | shape = RoundedCornerShape(8.dp),
28 | modifier = Modifier
29 | .graphicsLayer {
30 | translationX = it.offset.x.toFloat()
31 | translationY = it.offset.y.toFloat()
32 | }
33 | .size(
34 | width = it.size.width.dp,
35 | height = it.size.height.dp
36 | )
37 | .clickable {
38 | onClick()
39 | }
40 | ) {
41 | Image(
42 | bitmap = remember(shared.data) { shared.data.asImageBitmap() },
43 | contentDescription = null,
44 | contentScale = ContentScale.Crop,
45 | modifier = Modifier.fillMaxSize()
46 | )
47 | }
48 | }
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/touchbar/src/main/java/com/oxy/touchbar/TouchbarBackground.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.touchbar
2 |
3 | import androidx.compose.foundation.Canvas
4 | import androidx.compose.foundation.layout.BoxWithConstraints
5 | import androidx.compose.foundation.layout.fillMaxSize
6 | import androidx.compose.foundation.layout.padding
7 | import androidx.compose.foundation.shape.RoundedCornerShape
8 | import androidx.compose.runtime.Composable
9 | import androidx.compose.ui.Modifier
10 | import androidx.compose.ui.draw.clip
11 | import androidx.compose.ui.geometry.Offset
12 | import androidx.compose.ui.graphics.Color
13 | import androidx.compose.ui.graphics.ImageBitmap
14 | import androidx.compose.ui.platform.LocalDensity
15 | import androidx.compose.ui.unit.dp
16 | import com.oxy.touchbar.locals.LocalInfos
17 |
18 | @Composable
19 | internal fun TouchbarBackground(
20 | background: ImageBitmap?,
21 | modifier: Modifier = Modifier
22 | ) {
23 | val infos = LocalInfos.current
24 | val density = LocalDensity.current
25 | val radius = infos.backgroundRadius
26 | BoxWithConstraints {
27 | Canvas(
28 | modifier
29 | .padding(
30 | bottom = with(density) {
31 | if (!infos.enableZHandle) 0.dp
32 | else constraints.maxHeight.toDp() * infos.bottomPaddingPresent
33 | }
34 | )
35 | .clip(RoundedCornerShape(radius))
36 | .fillMaxSize()
37 | ) {
38 | drawRect(Color.Black)
39 | if (background != null) {
40 | drawImage(
41 | background,
42 | topLeft = Offset(
43 | x = 0f,
44 | y = (this.size.height - background.height) / 2
45 | )
46 | )
47 | }
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.android.application"
3 | id "org.jetbrains.kotlin.android"
4 | }
5 |
6 | android {
7 | namespace "com.oxy.mmr"
8 | compileSdk 33
9 |
10 | defaultConfig {
11 | applicationId "com.oxy.mmr"
12 | minSdk 26
13 | targetSdk 33
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | vectorDrawables {
19 | useSupportLibrary true
20 | }
21 | }
22 |
23 | buildTypes {
24 | release {
25 | minifyEnabled true
26 | proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
27 | signingConfig signingConfigs.debug
28 | }
29 | }
30 | compileOptions {
31 | sourceCompatibility JavaVersion.VERSION_17
32 | targetCompatibility JavaVersion.VERSION_17
33 | }
34 | kotlinOptions {
35 | jvmTarget = "17"
36 | }
37 | buildFeatures {
38 | compose true
39 | }
40 | composeOptions {
41 | kotlinCompilerExtensionVersion "1.5.0"
42 | }
43 | packagingOptions {
44 | resources {
45 | excludes += "/META-INF/{AL2.0,LGPL2.1}"
46 | }
47 | }
48 | }
49 |
50 | dependencies {
51 | implementation "androidx.core:core-ktx:1.10.1"
52 | implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
53 | implementation "androidx.activity:activity-compose:1.7.2"
54 |
55 | implementation "androidx.compose.animation:animation:1.4.3"
56 | implementation "androidx.compose.foundation:foundation:1.4.3"
57 | implementation "androidx.compose.material:material:1.4.3"
58 | implementation "androidx.compose.material3:material3:1.1.1"
59 | implementation "androidx.compose.runtime:runtime:1.4.3"
60 | implementation "androidx.compose.ui:ui:1.4.3"
61 |
62 | implementation "androidx.compose.material:material-icons-extended:1.4.3"
63 |
64 | implementation project(":touchbar")
65 | }
--------------------------------------------------------------------------------
/touchbar/src/main/java/com/oxy/touchbar/Touchbar.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.touchbar
2 |
3 | import androidx.compose.foundation.layout.BoxWithConstraints
4 | import androidx.compose.foundation.layout.fillMaxWidth
5 | import androidx.compose.foundation.layout.height
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.runtime.CompositionLocalProvider
8 | import androidx.compose.ui.Modifier
9 | import androidx.compose.ui.graphics.Color
10 | import androidx.compose.ui.unit.Dp
11 | import com.oxy.touchbar.locals.Infos
12 | import com.oxy.touchbar.locals.LocalInfos
13 |
14 | @Composable
15 | fun Touchbar(
16 | modifier: Modifier = Modifier,
17 | state: TouchbarState = rememberTouchbarState(),
18 | height: Dp = TouchbarDefaults.HeightDp,
19 | backgroundRadius: Int = TouchbarDefaults.BackgroundRadiusPercent,
20 | handleRadius: Float = TouchbarDefaults.HandleRadius,
21 | verticalHandle: Float = TouchbarDefaults.VerticalHandle,
22 | activeVerticalHandle: Float = TouchbarDefaults.ActiveVerticalHandle,
23 | horizontalHandle: Float = TouchbarDefaults.HorizontalHandle,
24 | handleInset: Float = TouchbarDefaults.HandleInset,
25 | activeHandleInset: Float = TouchbarDefaults.ActiveHandleInset,
26 | edgeColor: Color = TouchbarDefaults.EdgeColor,
27 | activeEdgeColor: Color = TouchbarDefaults.ActiveEdgeColor,
28 | indicatorColor: Color = TouchbarDefaults.IndicatorColor,
29 | activeIndicatorColor: Color = TouchbarDefaults.ActiveIndicatorColor,
30 | // experimental
31 | enableZHandle: Boolean = false,
32 | ) {
33 | val infos = Infos(
34 | enableZHandle = enableZHandle,
35 | backgroundRadius = backgroundRadius,
36 | handleRadius = handleRadius,
37 | verticalHandle = verticalHandle,
38 | activeVerticalHandle = activeVerticalHandle,
39 | activeHandleInset = activeHandleInset,
40 | handleInset = handleInset,
41 | edgeColor = edgeColor,
42 | activeEdgeColor = activeEdgeColor,
43 | indicatorColor = indicatorColor,
44 | activeIndicatorColor = activeIndicatorColor,
45 | horizontalHandle = horizontalHandle
46 | )
47 | CompositionLocalProvider(
48 | LocalInfos provides infos
49 | ) {
50 | BoxWithConstraints(
51 | modifier = modifier
52 | .fillMaxWidth()
53 | .height(height)
54 | ) {
55 | TouchbarBackground(state.background)
56 | TouchbarSelector(state)
57 | TouchbarPanel(state)
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Compose TouchBar
2 |
3 | TouchBar is a Video Clipper component made by Jetpack Compose.
4 |
5 | (control the clipper handles and display video thumbnails only)
6 |
7 | [](https://android-arsenal.com/api?level=21)
8 |
9 | [](https://jitpack.io/#realOxy/touchbar)
10 |
11 | # Installation
12 |
13 | Add the JitPack repository to your build file,
14 | add it in your root build.gradle at the end of repositories:
15 |
16 | ```groovy
17 | allprojects {
18 | repositories {
19 | ...
20 | maven { url 'https://jitpack.io' }
21 | }
22 | }
23 | ```
24 |
25 | Add the dependency
26 |
27 | ```groovy
28 | dependencies {
29 | implementation 'com.github.realOxy:touchbar:(insert latest version)'
30 | }
31 | ```
32 |
33 | # Quick Start
34 |
35 | ```kotlin
36 | var duration: Long by remember { mutableStateOf(-1L) }
37 | val touchbarState = rememberTouchbarState(
38 | enabled = duration >= 0L
39 | )
40 | TouchBar(
41 | state = touchbarState,
42 | // enableZHandle = true,
43 | modifier = Modifier.fillMathWidth()
44 | )
45 | // MediaUtils is available in the project app module.
46 | // It is an android platform utils.
47 | LaunchEffect(uri) {
48 | // loadThumbs is a flow-returned method actually but not list.
49 | // if you wanna a correct way to use it, just see app module demo.
50 | val newBitmaps: List = MediaUtils.loadThumbs(uri)
51 | duration = if (uri == null) -1
52 | else MediaUtils.getDuration(context, uri)
53 | MediaUtils.recycleNullableUseless(bitmaps, newBitmaps)
54 | bitmaps = newBitmaps
55 | if (bitmaps.size == thumbCount) {
56 | touchbarState.background?.asAndroidBitmap()?.recycle()
57 | touchbarState.notifyBackground(
58 | MediaUtils.merge(bitmaps, Orientation.Horizontal)?.asImageBitmap()
59 | )
60 | }
61 | }
62 | // recycle all bitmaps
63 | DisposableEffect(Unit) {
64 | onDispose {
65 | bitmaps.forEach {
66 | it?.recycle()
67 | }
68 | }
69 | }
70 | ```
71 |
72 | # TouchBarState
73 |
74 | - `enabled: Boolean` handles is enabled.
75 | - `x: Float` left handle percentage(0f ~ 1f allowed).
76 | - `y: Float` right handle percentage(0f ~ 1f allowed).
77 | - `z: Float` mid handle percentage(0f ~ 1f allowed).
78 | - `isXFocus: Boolean` is left handle is pressing.
79 | - `isYFocus: Boolean` is right handle is pressing.
80 | - `isZFocus: Boolean` is mid handle is pressing.
81 | - `notify()` change x, y, z, isXFocus, isYFocus or isZFocus.
82 | - `notifyBackground()` change background bitmap.
83 |
84 | # Demo
85 |
86 | [Video Editor](app/src/main/java/com/oxy/mmr/feature/touchbar/TouchBarScreen.kt)
87 |
88 |
89 | https://github.com/realOxy/touchbar/assets/70512220/35be7389-e5c0-4cf7-9a3f-2df0b348b5ee
90 |
91 | # Versions
92 |
93 | - Kotlin 1.9.0
94 | - Jetpack Compose 1.4.3
95 | - Jetpack Compose Material3 1.1.1
96 | - Compose Kotlin Compiler Extension 1.5.0
97 |
--------------------------------------------------------------------------------
/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 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/App.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr
2 |
3 | import androidx.activity.compose.BackHandler
4 | import androidx.compose.animation.AnimatedVisibility
5 | import androidx.compose.animation.slideInHorizontally
6 | import androidx.compose.animation.slideOutHorizontally
7 | import androidx.compose.foundation.layout.Arrangement
8 | import androidx.compose.foundation.layout.Box
9 | import androidx.compose.foundation.layout.Column
10 | import androidx.compose.foundation.layout.fillMaxSize
11 | import androidx.compose.foundation.layout.fillMaxWidth
12 | import androidx.compose.foundation.layout.padding
13 | import androidx.compose.material3.Button
14 | import androidx.compose.material3.Text
15 | import androidx.compose.runtime.Composable
16 | import androidx.compose.runtime.getValue
17 | import androidx.compose.runtime.mutableStateOf
18 | import androidx.compose.runtime.remember
19 | import androidx.compose.runtime.setValue
20 | import androidx.compose.ui.Modifier
21 | import androidx.compose.ui.unit.dp
22 | import com.oxy.mmr.feature.album.AlbumScreen
23 | import com.oxy.mmr.feature.touchbar.TouchBarScreen
24 | import com.oxy.mmr.ui.Background
25 |
26 | sealed class Destination {
27 | object Home : Destination()
28 | object Album : Destination()
29 | object TouchBar : Destination()
30 | }
31 |
32 | @Composable
33 | fun App(
34 | modifier: Modifier = Modifier
35 | ) {
36 | var destination: Destination by remember { mutableStateOf(Destination.Home) }
37 |
38 | Box(modifier) {
39 | Column(
40 | modifier = Modifier
41 | .fillMaxSize()
42 | .padding(16.dp),
43 | verticalArrangement = Arrangement.spacedBy(8.dp)
44 | ) {
45 | Button(
46 | onClick = { destination = Destination.Album },
47 | modifier = Modifier.fillMaxWidth()
48 | ) {
49 | Text(text = "Album")
50 | }
51 | Button(
52 | onClick = { destination = Destination.TouchBar },
53 | modifier = Modifier.fillMaxWidth()
54 | ) {
55 | Text(text = "TouchBar")
56 | }
57 | }
58 | AnimatedVisibility(
59 | visible = destination == Destination.Album,
60 | enter = slideInHorizontally { it },
61 | exit = slideOutHorizontally { it }
62 | ) {
63 | Background {
64 | AlbumScreen(
65 | modifier = Modifier.fillMaxSize()
66 | )
67 | }
68 | }
69 | AnimatedVisibility(
70 | visible = destination == Destination.TouchBar,
71 | enter = slideInHorizontally { it },
72 | exit = slideOutHorizontally { it }
73 | ) {
74 | Background {
75 | TouchBarScreen(
76 | modifier = Modifier.fillMaxSize()
77 | )
78 | }
79 | }
80 | }
81 |
82 | BackHandler(destination != Destination.Home) {
83 | destination = Destination.Home
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/wrapper/Shared.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.wrapper
2 |
3 | import android.content.res.Configuration
4 | import androidx.compose.animation.core.AnimationSpec
5 | import androidx.compose.animation.core.VisibilityThreshold
6 | import androidx.compose.animation.core.animateIntOffsetAsState
7 | import androidx.compose.animation.core.animateSizeAsState
8 | import androidx.compose.animation.core.spring
9 | import androidx.compose.runtime.Composable
10 | import androidx.compose.runtime.LaunchedEffect
11 | import androidx.compose.runtime.getValue
12 | import androidx.compose.runtime.mutableStateOf
13 | import androidx.compose.runtime.remember
14 | import androidx.compose.runtime.setValue
15 | import androidx.compose.ui.geometry.Size
16 | import androidx.compose.ui.platform.LocalConfiguration
17 | import androidx.compose.ui.unit.IntOffset
18 |
19 | internal interface Shared {
20 | val data: T
21 | val offset: IntOffset
22 | val size: Size
23 | fun copy(
24 | data: T = this.data,
25 | offset: IntOffset = this.offset,
26 | size: Size = this.size
27 | ): Shared = of(
28 | { data },
29 | { offset },
30 | { size }
31 | )
32 |
33 | companion object {
34 | fun of(
35 | data: T,
36 | offset: IntOffset,
37 | size: Size
38 | ): Shared = object : Shared {
39 | override val data: T get() = data
40 | override val offset: IntOffset get() = offset
41 | override val size: Size get() = size
42 | }
43 |
44 | // lazy
45 | fun of(
46 | data: () -> T,
47 | offset: () -> IntOffset,
48 | size: () -> Size
49 | ): Shared {
50 | return object : Shared {
51 | override val data: T get() = data()
52 | override val offset: IntOffset get() = offset()
53 | override val size: Size get() = size()
54 | }
55 | }
56 | }
57 | }
58 |
59 | internal fun Configuration.shared(): Shared = Shared.of(
60 | data = { error("Do not get configuration shared data!") },
61 | offset = { IntOffset.Zero },
62 | size = {
63 | Size(
64 | screenWidthDp.toFloat(),
65 | screenHeightDp.toFloat()
66 | )
67 | }
68 | )
69 |
70 | @Composable
71 | internal fun SharedHandler(
72 | initial: Shared,
73 | target: Shared = LocalConfiguration.current.shared(),
74 | intOffsetAnimationSpec: AnimationSpec = intOffsetDefaultSpring,
75 | sizeAnimationSpec: AnimationSpec = sizeDefaultSpring,
76 | content: @Composable (Shared) -> Unit
77 | ) {
78 | var actualOffset by remember(initial.offset) { mutableStateOf(initial.offset) }
79 | var actualSize by remember(initial.size) { mutableStateOf(initial.size) }
80 | val animatedOffset by animateIntOffsetAsState(actualOffset, intOffsetAnimationSpec)
81 | val animatedSize by animateSizeAsState(actualSize, sizeAnimationSpec)
82 |
83 | LaunchedEffect(Unit) {
84 | actualOffset = target.offset
85 | actualSize = target.size
86 | }
87 | content(
88 | initial.copy(
89 | offset = animatedOffset,
90 | size = animatedSize
91 | )
92 | )
93 | }
94 |
95 | private val intOffsetDefaultSpring = spring(visibilityThreshold = IntOffset.VisibilityThreshold)
96 |
97 | private val sizeDefaultSpring = spring(visibilityThreshold = Size.VisibilityThreshold)
98 |
--------------------------------------------------------------------------------
/touchbar/src/main/java/com/oxy/touchbar/TouchbarState.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.touchbar
2 |
3 | import androidx.compose.runtime.Composable
4 | import androidx.compose.runtime.Immutable
5 | import androidx.compose.runtime.getValue
6 | import androidx.compose.runtime.mutableStateOf
7 | import androidx.compose.runtime.remember
8 | import androidx.compose.runtime.setValue
9 | import androidx.compose.ui.graphics.ImageBitmap
10 |
11 | @Composable
12 | fun rememberTouchbarState(
13 | enabled: Boolean = true,
14 | initialX: Float = 0f,
15 | initialY: Float = 1f,
16 | initialZ: Float = 0f
17 | ): TouchbarState {
18 | check(0f <= initialX) { "initialX should not less than 0" }
19 | check(initialX <= initialY) { "initialY should not less than initialX" }
20 | check(initialY <= 1) { "initialY should not higher than 1" }
21 | return remember(enabled, initialX, initialY, initialZ) {
22 | TouchbarState(
23 | enabled = enabled,
24 | initialX = initialX,
25 | initialY = initialY,
26 | initialZ = initialZ
27 | )
28 | }
29 | }
30 |
31 | @Immutable
32 | class TouchbarState(
33 | val enabled: Boolean,
34 | initialX: Float,
35 | initialY: Float,
36 | initialZ: Float
37 | ) {
38 | private var _x: Float by mutableStateOf(initialX)
39 | private var _y: Float by mutableStateOf(initialY)
40 | private var _z: Float by mutableStateOf(initialZ)
41 | private var _isXFocus: Boolean by mutableStateOf(false)
42 | private var _isYFocus: Boolean by mutableStateOf(false)
43 | private var _isZFocus: Boolean by mutableStateOf(false)
44 | private var _background: ImageBitmap? by mutableStateOf(null)
45 |
46 | fun notify(
47 | x: Float? = null,
48 | y: Float? = null,
49 | z: Float? = null,
50 | isXFocus: Boolean? = null,
51 | isYFocus: Boolean? = null,
52 | isZFocus: Boolean? = null
53 | ) {
54 | x?.let { _x = it }
55 | y?.let { _y = it }
56 | z?.let { _z = it }
57 | isXFocus?.let { _isXFocus = it }
58 | isYFocus?.let { _isYFocus = it }
59 | isZFocus?.let { _isZFocus = it }
60 | }
61 |
62 | fun notifyBackground(bitmap: ImageBitmap?) {
63 | _background = bitmap
64 | }
65 |
66 | override fun equals(other: Any?): Boolean {
67 | if (this === other) return true
68 | if (javaClass != other?.javaClass) return false
69 |
70 | other as TouchbarState
71 |
72 | if (enabled != other.enabled) return false
73 | if (background != other.background) return false
74 | if (x != other.x) return false
75 | if (y != other.y) return false
76 | if (z != other.z) return false
77 | if (isXFocus != other.isXFocus) return false
78 | if (isYFocus != other.isYFocus) return false
79 | if (isZFocus != other.isZFocus) return false
80 |
81 | return true
82 | }
83 |
84 | override fun hashCode(): Int {
85 | var result = enabled.hashCode()
86 | result = 31 * result + background.hashCode()
87 | result = 31 * result + x.hashCode()
88 | result = 31 * result + y.hashCode()
89 | result = 31 * result + z.hashCode()
90 | result = 31 * result + isXFocus.hashCode()
91 | result = 31 * result + isYFocus.hashCode()
92 | result = 31 * result + isZFocus.hashCode()
93 | return result
94 | }
95 |
96 | override fun toString(): String {
97 | return "TouchBarState(enabled=$enabled, x=$x, y=$y, z=$z, isXFocus=$isXFocus, isYFocus=$isYFocus, isZFocus=$isZFocus)"
98 | }
99 |
100 | val x: Float get() = _x
101 | val y: Float get() = _y
102 | val z: Float get() = _z
103 | val isXFocus: Boolean get() = _isXFocus
104 | val isYFocus: Boolean get() = _isYFocus
105 | val isZFocus: Boolean get() = _isZFocus
106 | val background: ImageBitmap? get() = _background
107 | }
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/feature/album/AlbumScreen.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.feature.album
2 |
3 | import android.graphics.Bitmap
4 | import android.net.Uri
5 | import androidx.activity.compose.rememberLauncherForActivityResult
6 | import androidx.activity.result.contract.ActivityResultContracts
7 | import androidx.compose.foundation.background
8 | import androidx.compose.foundation.layout.Box
9 | import androidx.compose.foundation.layout.fillMaxSize
10 | import androidx.compose.foundation.layout.fillMaxWidth
11 | import androidx.compose.foundation.layout.padding
12 | import androidx.compose.material3.Button
13 | import androidx.compose.material3.MaterialTheme
14 | import androidx.compose.material3.Text
15 | import androidx.compose.runtime.Composable
16 | import androidx.compose.runtime.DisposableEffect
17 | import androidx.compose.runtime.getValue
18 | import androidx.compose.runtime.mutableStateOf
19 | import androidx.compose.runtime.produceState
20 | import androidx.compose.runtime.remember
21 | import androidx.compose.runtime.setValue
22 | import androidx.compose.ui.Alignment
23 | import androidx.compose.ui.Modifier
24 | import androidx.compose.ui.platform.LocalConfiguration
25 | import androidx.compose.ui.platform.LocalContext
26 | import androidx.compose.ui.platform.LocalDensity
27 | import androidx.compose.ui.unit.dp
28 | import com.oxy.mmr.components.VideoAlbum
29 | import com.oxy.mmr.components.VideoViewer
30 | import com.oxy.mmr.util.MediaUtils.loadThumbs
31 | import com.oxy.mmr.util.MediaUtils.recycleNullableUseless
32 | import com.oxy.mmr.wrapper.Shared
33 | import kotlin.math.min
34 | import kotlin.math.roundToInt
35 |
36 | private const val MIME_VIDEO = "video/*"
37 |
38 | @Composable
39 | internal fun AlbumScreen(
40 | modifier: Modifier = Modifier
41 | ) {
42 | val configuration = LocalConfiguration.current
43 | val density = LocalDensity.current
44 | val thumbWidth = with(density) {
45 | configuration.screenWidthDp.dp.toPx().roundToInt() / 3
46 | }
47 | val context = LocalContext.current
48 | var uri: Uri? by remember { mutableStateOf(null) }
49 | val launcher = rememberLauncherForActivityResult(
50 | ActivityResultContracts.GetContent()
51 | ) { newUri ->
52 | uri = newUri
53 | }
54 | val bitmaps by produceState(
55 | emptyList(),
56 | uri,
57 | thumbWidth
58 | ) {
59 | loadThumbs(
60 | context = context,
61 | uri = uri,
62 | dstWidth = { w, _ -> min(w, thumbWidth) },
63 | dstHeight = { w, h ->
64 | val aw = min(w, thumbWidth).toFloat()
65 | (aw / w * h).roundToInt()
66 | }
67 | ).collect { newBitmaps ->
68 | recycleNullableUseless(value, newBitmaps)
69 | value = newBitmaps
70 | }
71 | }
72 |
73 | DisposableEffect(Unit) {
74 | onDispose {
75 | bitmaps.forEach {
76 | it?.recycle()
77 | }
78 | }
79 | }
80 |
81 | var element: Shared? by remember { mutableStateOf(null) }
82 | Box(
83 | modifier = Modifier
84 | .background(MaterialTheme.colorScheme.background)
85 | .then(modifier)
86 | ) {
87 | Box(
88 | modifier = Modifier.fillMaxSize()
89 | ) {
90 | VideoAlbum(
91 | bitmaps = bitmaps,
92 | onClick = { newElement ->
93 | element = newElement
94 | },
95 | modifier = Modifier.fillMaxSize()
96 | )
97 | }
98 |
99 | Button(
100 | onClick = {
101 | launcher.launch(MIME_VIDEO)
102 | },
103 | modifier = Modifier
104 | .padding(16.dp)
105 | .fillMaxWidth()
106 | .align(Alignment.BottomCenter)
107 | ) {
108 | Text(
109 | text = "PICK VIDEO"
110 | )
111 | }
112 |
113 | element?.let { innerShared ->
114 | VideoViewer(
115 | shared = innerShared,
116 | onClick = {
117 | element = null
118 | }
119 | )
120 | }
121 | }
122 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/components/VideoAlbum.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.components
2 |
3 | import android.graphics.Bitmap
4 | import androidx.compose.foundation.Image
5 | import androidx.compose.foundation.clickable
6 | import androidx.compose.foundation.layout.PaddingValues
7 | import androidx.compose.foundation.layout.aspectRatio
8 | import androidx.compose.foundation.layout.fillMaxSize
9 | import androidx.compose.foundation.layout.padding
10 | import androidx.compose.foundation.lazy.grid.GridCells
11 | import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
12 | import androidx.compose.foundation.lazy.grid.itemsIndexed
13 | import androidx.compose.foundation.lazy.grid.rememberLazyGridState
14 | import androidx.compose.foundation.shape.RoundedCornerShape
15 | import androidx.compose.material3.Card
16 | import androidx.compose.material3.Surface
17 | import androidx.compose.runtime.Composable
18 | import androidx.compose.runtime.remember
19 | import androidx.compose.ui.Modifier
20 | import androidx.compose.ui.geometry.Size
21 | import androidx.compose.ui.graphics.Color
22 | import androidx.compose.ui.graphics.asImageBitmap
23 | import androidx.compose.ui.layout.ContentScale
24 | import androidx.compose.ui.platform.LocalDensity
25 | import androidx.compose.ui.unit.dp
26 | import com.oxy.mmr.wrapper.Shared
27 |
28 | @Composable
29 | internal fun VideoAlbum(
30 | bitmaps: List,
31 | onClick: (Shared) -> Unit,
32 | modifier: Modifier = Modifier,
33 | cellsCount: Int = 3
34 | ) {
35 | val density = LocalDensity.current.density
36 | val state = rememberLazyGridState()
37 | LazyVerticalGrid(
38 | state = state,
39 | columns = GridCells.Fixed(cellsCount),
40 | contentPadding = PaddingValues(4.dp),
41 | modifier = modifier
42 | ) {
43 | itemsIndexed(bitmaps) { index, nullableBitmap ->
44 | VideoAlbumItem(
45 | nullableBitmap = nullableBitmap,
46 | onClick = { bitmap ->
47 | val actualIndex = index - state.firstVisibleItemIndex
48 | val info = state.layoutInfo.visibleItemsInfo[actualIndex]
49 | onClick(
50 | Shared.of(
51 | offset = info.offset,
52 | size = with(info.size) {
53 | Size(
54 | width.toFloat() / density,
55 | height.toFloat() / density
56 | )
57 | },
58 | data = bitmap
59 | )
60 | )
61 | }
62 | )
63 | }
64 | items(bitmaps.calculatePlaceholderCount(cellsCount)) {
65 | VideoAlbumPlaceholder()
66 | }
67 | }
68 | }
69 |
70 | @Composable
71 | internal fun VideoAlbumItem(
72 | nullableBitmap: Bitmap?,
73 | modifier: Modifier = Modifier,
74 | onClick: (Bitmap) -> Unit,
75 | ) {
76 | if (nullableBitmap != null) {
77 | Card(
78 | shape = RoundedCornerShape(8.dp),
79 | modifier = Modifier.padding(4.dp) then modifier
80 | ) {
81 | Image(
82 | bitmap = remember(nullableBitmap) { nullableBitmap.asImageBitmap() },
83 | contentDescription = null,
84 | contentScale = ContentScale.Crop,
85 | modifier = Modifier
86 | .aspectRatio(1f)
87 | .clickable {
88 | onClick(nullableBitmap)
89 | }
90 | )
91 | }
92 | } else {
93 | VideoAlbumPlaceholder()
94 | }
95 | }
96 |
97 | @Composable
98 | internal fun VideoAlbumPlaceholder(
99 | modifier: Modifier = Modifier
100 | ) {
101 | Surface(
102 | shape = RoundedCornerShape(8.dp),
103 | modifier = Modifier
104 | .padding(4.dp)
105 | .fillMaxSize()
106 | .aspectRatio(1f)
107 | .then(modifier),
108 | color = Color.Transparent
109 | ) {}
110 | }
111 |
112 | private fun List<*>.calculatePlaceholderCount(cellsCount: Int): Int =
113 | if (isEmpty()) 0 else (size % cellsCount) + cellsCount
114 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/util/MediaUtils.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.util
2 |
3 | import android.content.Context
4 | import android.graphics.Bitmap
5 | import android.graphics.Canvas
6 | import android.graphics.Rect
7 | import android.media.MediaMetadataRetriever
8 | import android.net.Uri
9 | import androidx.compose.foundation.gestures.Orientation
10 | import kotlinx.coroutines.Dispatchers
11 | import kotlinx.coroutines.coroutineScope
12 | import kotlinx.coroutines.flow.Flow
13 | import kotlinx.coroutines.flow.channelFlow
14 | import kotlinx.coroutines.withContext
15 |
16 | object MediaUtils {
17 | fun loadThumbs(
18 | context: Context,
19 | uri: Uri?,
20 | totalCount: Int = 28,
21 | oneByOne: Boolean = true,
22 | dstWidth: (width: Int, height: Int) -> Int = { it, _ -> it },
23 | dstHeight: (width: Int, height: Int) -> Int = { _, it -> it }
24 | ): Flow> = channelFlow {
25 | try {
26 | var bitmaps = emptyList()
27 | MediaMetadataRetriever().use { retriever ->
28 | retriever.setDataSource(context, uri)
29 | val duration = retriever.extractMetadata(
30 | MediaMetadataRetriever.METADATA_KEY_DURATION
31 | )?.toInt() ?: -1
32 |
33 | val deltaTime = duration / totalCount * 1000
34 |
35 | withContext(Dispatchers.IO) {
36 | repeat(totalCount) { i ->
37 | val bitmap = retriever.getFrameAtTime(
38 | (deltaTime.toLong() * i),
39 | MediaMetadataRetriever.OPTION_CLOSEST_SYNC
40 | )
41 | bitmaps = bitmaps + bitmap?.let {
42 | Bitmap.createScaledBitmap(
43 | it,
44 | dstWidth(it.width, it.height),
45 | dstHeight(it.width, it.height),
46 | true
47 | )
48 | }
49 | bitmap?.recycle()
50 | if (oneByOne) send(bitmaps)
51 | }
52 | }
53 | if (!oneByOne) send(bitmaps)
54 |
55 | }
56 | } catch (ignored: Exception) {
57 |
58 | }
59 | }
60 |
61 | suspend fun getDuration(
62 | context: Context,
63 | uri: Uri?
64 | ): Long = coroutineScope {
65 | MediaMetadataRetriever().use { retriever ->
66 | withContext(Dispatchers.IO) {
67 | retriever.setDataSource(context, uri)
68 | retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)?.toLong()
69 | ?: -1L
70 | }
71 | }
72 | }
73 |
74 | suspend fun recycleUseless(old: List, new: List) = coroutineScope {
75 | withContext(Dispatchers.IO) {
76 | old.forEach { bitmap ->
77 | if (bitmap !in new) bitmap.recycle()
78 | }
79 | }
80 | }
81 |
82 | suspend fun recycleNullableUseless(old: List, new: List) = coroutineScope {
83 | recycleUseless(old.filterNotNull(), new.filterNotNull())
84 | }
85 |
86 | suspend fun merge(
87 | bitmaps: List,
88 | orientation: Orientation = Orientation.Horizontal,
89 | shortPixel: Int = 48,
90 | ): Bitmap? = coroutineScope {
91 | if (bitmaps.all { it == null }) null
92 | else withContext(Dispatchers.IO) {
93 | when (orientation) {
94 | Orientation.Vertical -> bitmaps.mergeVertical(shortPixel)
95 | Orientation.Horizontal -> bitmaps.mergeHorizontal(shortPixel)
96 | }
97 | }
98 | }
99 |
100 | private fun List.mergeHorizontal(shortPixel: Int): Bitmap? {
101 | val oh = maxOf { it?.height ?: 0 }
102 | val ow = sumOf { it?.width ?: 0 }
103 | val h = shortPixel
104 | val r = oh / h
105 | val w = ow / r
106 | val pw = w / size
107 | return Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888).apply {
108 | Canvas(this).apply {
109 | var total = 0
110 | forEach {
111 | it?.let { drawBitmap(it, null, Rect(total, 0, total + pw, h), null) }
112 | total += pw
113 | }
114 | }
115 | }
116 | }
117 |
118 | private fun List.mergeVertical(shortPixel: Int): Bitmap? {
119 | val ow = maxOf { it?.width ?: 0 }
120 | val oh = sumOf { it?.height ?: 0 }
121 | val w = shortPixel
122 | val r = ow / w
123 | val h = oh / r
124 | val ph = h / size
125 |
126 | return Bitmap.createBitmap(w, h, Bitmap.Config.RGBA_F16).apply {
127 | Canvas(this).apply {
128 | var total = 0
129 | forEach {
130 | it?.let { drawBitmap(it, null, Rect(0, total, h, total + ph), null) }
131 | total += ph
132 | }
133 | }
134 | }
135 | }
136 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or 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 UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/touchbar/src/main/java/com/oxy/touchbar/TouchbarPanel.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.touchbar
2 |
3 | import androidx.compose.foundation.gestures.detectDragGestures
4 | import androidx.compose.foundation.layout.Box
5 | import androidx.compose.foundation.layout.fillMaxSize
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.ui.Modifier
8 | import androidx.compose.ui.input.pointer.pointerInput
9 | import com.oxy.touchbar.locals.LocalInfos
10 | import kotlin.math.abs
11 | import kotlin.math.max
12 | import kotlin.math.min
13 |
14 | @Composable
15 | internal fun TouchbarPanel(
16 | state: TouchbarState,
17 | modifier: Modifier = Modifier
18 | ) {
19 | val infos = LocalInfos.current
20 | Box(
21 | modifier = modifier
22 | .fillMaxSize()
23 | .pointerInput(
24 | state.enabled,
25 | infos.enableZHandle
26 | ) {
27 | val area = infos.activeVerticalHandle / this.size.width
28 | var position: Position? = null
29 | detectDragGestures(
30 | onDragStart = { offset ->
31 | position = Position(
32 | offset.x / this.size.width,
33 | offset.y / this.size.height
34 | )
35 | },
36 | onDragEnd = {
37 | position = null
38 | state.notify(
39 | isXFocus = false,
40 | isYFocus = false,
41 | isZFocus = false
42 | )
43 | },
44 | onDragCancel = {
45 | position = null
46 | state.notify(
47 | isXFocus = false,
48 | isYFocus = false,
49 | isZFocus = false
50 | )
51 | },
52 | onDrag = { change, dragAmount ->
53 | if (!state.enabled) return@detectDragGestures
54 | change.consume()
55 | val delta = dragAmount.x / this.size.width
56 | position?.let { touched ->
57 | fun notifyX() {
58 | val target = (delta + state.x).coerceIn(0f, state.y)
59 | state.notify(
60 | x = target,
61 | z = max(target, state.z),
62 | isXFocus = true
63 | )
64 | position = touched + delta
65 | }
66 |
67 | fun notifyY() {
68 | val target = (delta + state.y).coerceIn(state.x, 1f)
69 | state.notify(
70 | y = target,
71 | z = min(state.z, target),
72 | isYFocus = true
73 | )
74 | position = touched + delta
75 | }
76 |
77 | fun notifyXY() {
78 | val targetX = (delta + state.x).coerceIn(0f, state.y)
79 | val targetY = (delta + state.y).coerceIn(state.x, 1f)
80 | state.notify(
81 | x = targetX,
82 | y = targetY,
83 | z = if (infos.enableZHandle) state.z.coerceIn(targetX, targetY)
84 | else state.z,
85 | isXFocus = true,
86 | isYFocus = true
87 | )
88 | position = touched + delta
89 | }
90 |
91 | fun notifyZ() {
92 | if (!infos.enableZHandle) return
93 | state.notify(
94 | z = (delta + state.z).coerceIn(state.x, state.y),
95 | isZFocus = true
96 | )
97 | position = touched + delta
98 | }
99 |
100 | when {
101 | state.notifyX -> notifyX()
102 | state.notifyY -> notifyY()
103 | infos.enableZHandle && state.notifyZ -> notifyZ()
104 |
105 | infos.enableZHandle && touched.vertical in (1 - infos.bottomPaddingPresent..1f) &&
106 | abs(touched.horizontal - state.z) <= area -> notifyZ()
107 |
108 | state.notifyX(area, touched.horizontal) -> notifyX()
109 | state.notifyY(area, touched.horizontal) -> notifyY()
110 | touched.horizontal in (state.x..state.y) -> {
111 | if ((delta < 0f) && (state.x + delta) > 0f) {
112 | notifyXY()
113 | } else if ((delta > 0f) && (state.y + delta) < 1f) {
114 | notifyXY()
115 | }
116 | }
117 | }
118 | }
119 | }
120 | )
121 | }
122 | )
123 | }
124 |
125 | private data class Position(
126 | val horizontal: Float,
127 | val vertical: Float
128 | ) {
129 | operator fun plus(horizontal: Float): Position {
130 | return this.copy(
131 | horizontal = this.horizontal + horizontal
132 | )
133 | }
134 | }
135 |
136 | private val TouchbarState.notifyX: Boolean get() = isXFocus && !isYFocus && !isZFocus
137 |
138 | private val TouchbarState.notifyY: Boolean get() = !isXFocus && isYFocus && !isZFocus
139 |
140 | private val TouchbarState.notifyZ: Boolean get() = !isXFocus && !isYFocus && isZFocus
141 |
142 | private fun TouchbarState.notifyX(
143 | area: Float,
144 | current: Float
145 | ): Boolean = abs(current - x) <= area
146 |
147 | private fun TouchbarState.notifyY(
148 | area: Float,
149 | current: Float
150 | ): Boolean = abs(current - y) <= area
151 |
--------------------------------------------------------------------------------
/touchbar/src/main/java/com/oxy/touchbar/TouchbarSelector.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.touchbar
2 |
3 | import androidx.compose.animation.animateColorAsState
4 | import androidx.compose.animation.core.animateFloatAsState
5 | import androidx.compose.animation.core.tween
6 | import androidx.compose.foundation.Canvas
7 | import androidx.compose.foundation.layout.fillMaxSize
8 | import androidx.compose.runtime.Composable
9 | import androidx.compose.runtime.LaunchedEffect
10 | import androidx.compose.runtime.getValue
11 | import androidx.compose.ui.Modifier
12 | import androidx.compose.ui.geometry.CornerRadius
13 | import androidx.compose.ui.geometry.Offset
14 | import androidx.compose.ui.graphics.BlendMode
15 | import androidx.compose.ui.graphics.Color
16 | import androidx.compose.ui.graphics.StrokeCap
17 | import androidx.compose.ui.hapticfeedback.HapticFeedbackType
18 | import androidx.compose.ui.platform.LocalHapticFeedback
19 | import com.oxy.touchbar.locals.LocalInfos
20 | import kotlin.math.roundToInt
21 |
22 | @Composable
23 | internal fun TouchbarSelector(
24 | state: TouchbarState,
25 | modifier: Modifier = Modifier,
26 | ) {
27 | val infos = LocalInfos.current
28 | val feedback = LocalHapticFeedback.current
29 |
30 | val handleRadius: Float = infos.handleRadius
31 | val verticalHandle: Float = infos.verticalHandle
32 | val activeVerticalHandle: Float = infos.activeVerticalHandle
33 | val handleInset: Float = infos.handleInset
34 | val activeHandleInset: Float = infos.activeHandleInset
35 | val horizontalHandle: Float = infos.horizontalHandle
36 | val edgeColor: Color = infos.edgeColor
37 | val activeEdgeColor: Color = infos.activeEdgeColor
38 | val indicatorColor: Color = infos.indicatorColor
39 | val activeIndicatorColor: Color = infos.activeIndicatorColor
40 |
41 | val color by animateColorAsState(
42 | if (state.enabled && (state.isXFocus || state.isYFocus)) activeEdgeColor
43 | else edgeColor,
44 | tween(400)
45 | )
46 | val zColor by animateColorAsState(
47 | if (state.enabled && state.isZFocus) activeIndicatorColor
48 | else indicatorColor,
49 | tween(400)
50 | )
51 | val xHandleInset by animateFloatAsState(
52 | if (state.isXFocus) activeHandleInset else handleInset
53 | )
54 | val yHandleInset by animateFloatAsState(
55 | if (state.isYFocus) activeHandleInset else handleInset
56 | )
57 |
58 | val xHandle by animateFloatAsState(
59 | if (state.isXFocus) activeVerticalHandle else verticalHandle
60 | )
61 | val yHandle by animateFloatAsState(
62 | if (state.isYFocus) activeVerticalHandle else verticalHandle
63 | )
64 |
65 | val zHandlePresent by animateFloatAsState(
66 | if (state.isZFocus) 0.85f else 0.65f
67 | )
68 |
69 | LaunchedEffect(state.isXFocus, state.isYFocus) {
70 | if (state.isXFocus || state.isYFocus) {
71 | feedback.performHapticFeedback(HapticFeedbackType.LongPress)
72 | }
73 | }
74 | LaunchedEffect((state.z * 100).roundToInt()) {
75 | if (state.isZFocus) feedback.performHapticFeedback(HapticFeedbackType.TextHandleMove)
76 | }
77 | Canvas(
78 | modifier = modifier.fillMaxSize()
79 | ) {
80 | val bottomPadding = when {
81 | infos.enableZHandle -> this.size.height * infos.bottomPaddingPresent
82 | else -> 0f
83 | }
84 | // x panel v
85 | drawRoundRect(
86 | color = color,
87 | topLeft = Offset(
88 | x = state.x * this.size.width - xHandle / 2,
89 | y = 0f
90 | ),
91 | size = this.size.copy(
92 | width = xHandle,
93 | height = this.size.height - bottomPadding
94 | ),
95 | cornerRadius = CornerRadius(handleRadius)
96 | )
97 | // x panel v inner
98 | drawLine(
99 | color = Color.Transparent,
100 | start = Offset(
101 | x = state.x * this.size.width,
102 | y = (this.size.height - bottomPadding) * 0.25f
103 | ),
104 | end = Offset(
105 | x = state.x * this.size.width,
106 | y = (this.size.height - bottomPadding) * 0.75f
107 | ),
108 | cap = StrokeCap.Round,
109 | strokeWidth = xHandleInset,
110 | blendMode = BlendMode.Clear
111 | )
112 | // y panel v
113 | drawRoundRect(
114 | color = color,
115 | topLeft = Offset(
116 | x = state.y * this.size.width - yHandle / 2,
117 | y = 0f
118 | ),
119 | size = this.size.copy(
120 | width = yHandle,
121 | height = this.size.height - bottomPadding
122 | ),
123 | cornerRadius = CornerRadius(handleRadius)
124 | )
125 | // y panel v inner
126 | drawLine(
127 | color = Color.Transparent,
128 | start = Offset(
129 | x = state.y * this.size.width,
130 | y = (this.size.height - bottomPadding) * 0.25f
131 | ),
132 | end = Offset(
133 | x = state.y * this.size.width,
134 | y = (this.size.height - bottomPadding) * 0.75f
135 | ),
136 | cap = StrokeCap.Round,
137 | strokeWidth = yHandleInset,
138 | blendMode = BlendMode.Clear
139 | )
140 | // h1
141 | drawRoundRect(
142 | color = color,
143 | topLeft = Offset(
144 | x = state.x * this.size.width,
145 | y = 0f
146 | ),
147 | size = this.size.copy(
148 | width = this.size.width * (state.y - state.x),
149 | height = horizontalHandle
150 | ),
151 | cornerRadius = CornerRadius(handleRadius)
152 | )
153 | // h2
154 | drawRoundRect(
155 | color = color,
156 | topLeft = Offset(
157 | x = state.x * this.size.width,
158 | y = this.size.height - horizontalHandle - bottomPadding
159 | ),
160 | size = this.size.copy(
161 | width = this.size.width * (state.y - state.x),
162 | height = horizontalHandle
163 | ),
164 | cornerRadius = CornerRadius(handleRadius)
165 | )
166 |
167 | if (infos.enableZHandle) {
168 | // z panel v
169 | drawCircle(
170 | color = zColor,
171 | radius = (bottomPadding / 2) * zHandlePresent,
172 | center = Offset(
173 | x = state.z * this.size.width,
174 | y = this.size.height * (1 - infos.bottomPaddingPresent / 2)
175 | )
176 | )
177 | }
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/app/src/main/java/com/oxy/mmr/feature/touchbar/TouchBarScreen.kt:
--------------------------------------------------------------------------------
1 | package com.oxy.mmr.feature.touchbar
2 |
3 | import android.graphics.Bitmap
4 | import android.net.Uri
5 | import androidx.activity.compose.rememberLauncherForActivityResult
6 | import androidx.activity.result.contract.ActivityResultContracts
7 | import androidx.compose.animation.AnimatedVisibility
8 | import androidx.compose.foundation.Image
9 | import androidx.compose.foundation.background
10 | import androidx.compose.foundation.clickable
11 | import androidx.compose.foundation.gestures.Orientation
12 | import androidx.compose.foundation.layout.Arrangement
13 | import androidx.compose.foundation.layout.Box
14 | import androidx.compose.foundation.layout.Column
15 | import androidx.compose.foundation.layout.Row
16 | import androidx.compose.foundation.layout.Spacer
17 | import androidx.compose.foundation.layout.aspectRatio
18 | import androidx.compose.foundation.layout.fillMaxSize
19 | import androidx.compose.foundation.layout.fillMaxWidth
20 | import androidx.compose.foundation.layout.height
21 | import androidx.compose.foundation.layout.padding
22 | import androidx.compose.foundation.shape.RoundedCornerShape
23 | import androidx.compose.material.icons.Icons
24 | import androidx.compose.material.icons.rounded.Pause
25 | import androidx.compose.material.icons.rounded.PlayArrow
26 | import androidx.compose.material3.ButtonDefaults
27 | import androidx.compose.material3.Checkbox
28 | import androidx.compose.material3.Icon
29 | import androidx.compose.material3.LocalContentColor
30 | import androidx.compose.material3.MaterialTheme
31 | import androidx.compose.material3.Surface
32 | import androidx.compose.material3.Text
33 | import androidx.compose.material3.TextButton
34 | import androidx.compose.runtime.Composable
35 | import androidx.compose.runtime.DisposableEffect
36 | import androidx.compose.runtime.LaunchedEffect
37 | import androidx.compose.runtime.getValue
38 | import androidx.compose.runtime.mutableStateOf
39 | import androidx.compose.runtime.produceState
40 | import androidx.compose.runtime.remember
41 | import androidx.compose.runtime.rememberCoroutineScope
42 | import androidx.compose.runtime.setValue
43 | import androidx.compose.ui.Alignment
44 | import androidx.compose.ui.Modifier
45 | import androidx.compose.ui.graphics.Color
46 | import androidx.compose.ui.graphics.asAndroidBitmap
47 | import androidx.compose.ui.graphics.asImageBitmap
48 | import androidx.compose.ui.platform.LocalConfiguration
49 | import androidx.compose.ui.platform.LocalContext
50 | import androidx.compose.ui.platform.LocalDensity
51 | import androidx.compose.ui.text.TextStyle
52 | import androidx.compose.ui.unit.dp
53 | import androidx.compose.ui.unit.sp
54 | import com.oxy.mmr.components.TimeZone
55 | import com.oxy.mmr.util.MediaUtils.getDuration
56 | import com.oxy.mmr.util.MediaUtils.loadThumbs
57 | import com.oxy.mmr.util.MediaUtils.merge
58 | import com.oxy.mmr.util.MediaUtils.recycleNullableUseless
59 | import com.oxy.touchbar.Touchbar
60 | import com.oxy.touchbar.TouchbarDefaults
61 | import com.oxy.touchbar.rememberTouchbarState
62 | import kotlinx.coroutines.Dispatchers
63 | import kotlinx.coroutines.delay
64 | import kotlinx.coroutines.launch
65 | import kotlin.math.min
66 | import kotlin.math.roundToInt
67 | import kotlin.math.roundToLong
68 |
69 | private const val MIME_VIDEO = "video/*"
70 | private const val thumbCount = 28
71 |
72 | @Composable
73 | internal fun TouchBarScreen(
74 | modifier: Modifier = Modifier
75 | ) {
76 | val configuration = LocalConfiguration.current
77 | val density = LocalDensity.current
78 | var duration by remember { mutableStateOf(-1L) }
79 | val context = LocalContext.current
80 | var uri: Uri? by remember { mutableStateOf(null) }
81 |
82 | var enableZHandle by remember { mutableStateOf(false) }
83 |
84 | val touchBarState = rememberTouchbarState(
85 | enabled = duration >= 0L
86 | )
87 |
88 | val launcher = rememberLauncherForActivityResult(
89 | ActivityResultContracts.GetContent()
90 | ) { newUri ->
91 | uri = newUri
92 | }
93 |
94 | val thumbWidth = with(density) {
95 | configuration.screenWidthDp.dp.toPx().roundToInt()
96 | }
97 |
98 | val bitmaps by produceState(
99 | emptyList(),
100 | uri,
101 | thumbWidth
102 | ) {
103 | loadThumbs(
104 | context = context,
105 | uri = uri,
106 | totalCount = thumbCount,
107 | dstWidth = { w, _ -> min(w, thumbWidth) },
108 | dstHeight = { w, h ->
109 | val aw = min(w, thumbWidth).toFloat()
110 | (aw / w * h).roundToInt()
111 | }
112 | ).collect { newBitmaps ->
113 | recycleNullableUseless(value, newBitmaps)
114 | value = newBitmaps
115 | }
116 | }
117 |
118 | LaunchedEffect(bitmaps) {
119 | if (bitmaps.size == thumbCount) {
120 | touchBarState.background?.asAndroidBitmap()?.recycle()
121 | val merged = merge(bitmaps, Orientation.Horizontal)
122 | touchBarState.notifyBackground(merged?.asImageBitmap())
123 | }
124 | }
125 |
126 | var currentX: Int by remember { mutableStateOf(-1) }
127 | var currentY: Int by remember { mutableStateOf(-1) }
128 | var currentZ: Int by remember { mutableStateOf(-1) }
129 |
130 | val bitmap by produceState(
131 | null,
132 | enableZHandle,
133 | bitmaps,
134 | currentX,
135 | currentY,
136 | currentZ,
137 | touchBarState.isXFocus,
138 | touchBarState.isYFocus
139 | ) {
140 | value = bitmaps.getOrNull(
141 | if (enableZHandle) {
142 | if (touchBarState.isYFocus && touchBarState.isXFocus) currentZ
143 | else if (touchBarState.isYFocus) currentY
144 | else if (touchBarState.isXFocus) currentX
145 | else currentZ
146 | } else {
147 | if (touchBarState.isYFocus) currentY
148 | else currentX
149 | }
150 | )
151 | }
152 |
153 | DisposableEffect(Unit) {
154 | onDispose {
155 | bitmaps.forEach {
156 | it?.recycle()
157 | }
158 | }
159 | }
160 |
161 | LaunchedEffect(uri) {
162 | duration = if (uri == null) -1
163 | else getDuration(context, uri)
164 | }
165 |
166 | Column(
167 | modifier = Modifier
168 | .fillMaxSize()
169 | .background(MaterialTheme.colorScheme.background)
170 | .then(modifier)
171 | ) {
172 | Row(
173 | modifier = Modifier.padding(16.dp)
174 | ) {
175 | Spacer(modifier = Modifier.weight(1f))
176 | TextButton(
177 | colors = ButtonDefaults.buttonColors(),
178 | onClick = {
179 | launcher.launch(MIME_VIDEO)
180 | }
181 | ) {
182 | Text(
183 | text = "OPEN",
184 | style = TextStyle(
185 | fontSize = 12.sp,
186 | color = LocalContentColor.current
187 | )
188 | )
189 | }
190 | }
191 | Box(
192 | modifier = Modifier
193 | .fillMaxWidth()
194 | .weight(1f)
195 | ) {
196 | bitmap?.let {
197 | Image(
198 | bitmap = remember(it) { it.asImageBitmap() },
199 | contentDescription = null,
200 | modifier = Modifier.fillMaxSize()
201 | )
202 | }
203 | }
204 |
205 | Row(
206 | horizontalArrangement = Arrangement.SpaceBetween,
207 | modifier = Modifier
208 | .fillMaxWidth()
209 | .padding(horizontal = 16.dp, vertical = 12.dp)
210 | ) {
211 | TimeZone(
212 | millisecond = remember(duration, touchBarState.x) {
213 | if (duration == -1L) -1L
214 | else (duration * touchBarState.x).roundToLong()
215 | }
216 | )
217 | TimeZone(
218 | millisecond = remember(duration, touchBarState.z) {
219 | if (duration == -1L) -1L
220 | else (duration * touchBarState.z).roundToLong()
221 | }
222 | )
223 | TimeZone(
224 | millisecond = remember(duration, touchBarState.y) {
225 | if (duration == -1L) -1L
226 | else (duration * touchBarState.y).roundToLong()
227 | }
228 | )
229 | }
230 |
231 | var playing by remember { mutableStateOf(false) }
232 | val scope = rememberCoroutineScope()
233 |
234 | DisposableEffect(enableZHandle, playing, duration) {
235 | val job = if (enableZHandle && playing) {
236 | scope.launch(Dispatchers.IO) {
237 | val delta = 5f / duration
238 | while (true) {
239 | delay(5L)
240 | val target = (touchBarState.z + delta).coerceIn(0f, 1f)
241 | touchBarState.notify(
242 | z = target
243 | )
244 | if (target == 1f) {
245 | playing = false
246 | touchBarState.notify(
247 | z = 0f
248 | )
249 | }
250 | }
251 | }
252 | } else null
253 | onDispose {
254 | job?.cancel()
255 | }
256 | }
257 |
258 | Row(
259 | verticalAlignment = Alignment.CenterVertically,
260 | horizontalArrangement = Arrangement.spacedBy(16.dp),
261 | modifier = Modifier.padding(horizontal = 16.dp)
262 | ) {
263 | AnimatedVisibility(
264 | visible = enableZHandle
265 | ) {
266 | Surface(
267 | onClick = { playing = !playing },
268 | color = Color.Transparent,
269 | contentColor = TouchbarDefaults.EdgeColor,
270 | shape = RoundedCornerShape(15),
271 | modifier = Modifier
272 | .height(TouchbarDefaults.HeightDp)
273 | .aspectRatio(4 / 3f)
274 | ) {
275 | Icon(
276 | imageVector = if (playing) Icons.Rounded.Pause
277 | else Icons.Rounded.PlayArrow,
278 | contentDescription = null,
279 | modifier = Modifier.padding(8.dp)
280 | )
281 | }
282 | }
283 | Touchbar(
284 | state = touchBarState,
285 | enableZHandle = enableZHandle,
286 | modifier = Modifier.weight(1f)
287 | )
288 | }
289 |
290 | Row(
291 | modifier = Modifier
292 | .padding(horizontal = 16.dp)
293 | .align(Alignment.End),
294 | verticalAlignment = Alignment.CenterVertically
295 | ) {
296 | Checkbox(
297 | checked = enableZHandle,
298 | onCheckedChange = { enableZHandle = it }
299 | )
300 | Text(
301 | text = "Z-HANDLE",
302 | fontSize = 10.sp,
303 | )
304 | }
305 |
306 | LaunchedEffect(touchBarState.x) {
307 | val target = (touchBarState.x * thumbCount).roundToInt()
308 | if (currentX != target) currentX = target
309 | }
310 | LaunchedEffect(touchBarState.y) {
311 | val target = (touchBarState.y * thumbCount).roundToInt()
312 | if (currentY != target) currentY = target
313 | }
314 | LaunchedEffect(touchBarState.z) {
315 | val target = (touchBarState.z * thumbCount).roundToInt()
316 | if (currentZ != target) currentZ = target
317 | }
318 | }
319 | }
320 |
321 |
--------------------------------------------------------------------------------