commit 2d3cc0912fc807e3f77ab77323d74e0a23bf77ce Author: Kyant0 Date: Wed Jun 18 18:15:41 2025 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/Kyant.xml b/.idea/dictionaries/Kyant.xml new file mode 100644 index 0000000..b9bc167 --- /dev/null +++ b/.idea/dictionaries/Kyant.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..1580500 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..a5b6b9a --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,53 @@ + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..12cf726 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..cfc0c81 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + + Android Lint: Correctness + + + Java interop issuesKotlin + + + Kotlin + + + Kotlin Android + + + LoggingKotlin + + + Other problemsKotlin + + + Probable bugsKotlin + + + Style issuesKotlin + + + + + Android Lint: Correctness + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e29d7cc --- /dev/null +++ b/LICENSE @@ -0,0 +1,191 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + Copyright 2025 Kyant + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d286684 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Android Liquid Glass + +An Android app that simulates Apple's Liquid Glass effect, Android 13 and above is required. + +## About shaders + +You mustn't use the shaders in the project for commercial purposes, they are only for educational purposes. diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..6499f9d --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,95 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion + +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.compose) +} + +android { + namespace = "com.kyant.glass" + compileSdk = 36 + buildToolsVersion = "36.0.0" + + defaultConfig { + applicationId = "com.kyant.glass" + minSdk = 33 + targetSdk = 36 + versionCode = 1 + versionName = "1.0.0-dev" + ndk.abiFilters += arrayOf("arm64-v8a", "x86_64") + androidResources.localeFilters += arrayOf("en", "zh-rCN") + } + + buildTypes { + release { + isMinifyEnabled = true + isShrinkResources = true + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + signingConfigs { + create("release") { + enableV1Signing = false + enableV2Signing = false + enableV3Signing = true + enableV4Signing = false + } + } + signingConfig = signingConfigs.getByName("release") + vcsInfo.include = false + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 + } + kotlin { + compilerOptions { + apiVersion = KotlinVersion.KOTLIN_2_3 + languageVersion = KotlinVersion.KOTLIN_2_3 + jvmTarget = JvmTarget.JVM_21 + } + } + buildFeatures { + compose = true + } + packaging { + resources { + excludes += arrayOf( + "DebugProbesKt.bin", + "kotlin-tooling-metadata.json", + "kotlin/**", + "META-INF/*.version", + "META-INF/**/LICENSE.txt" + ) + } + dex { + useLegacyPackaging = true + } + jniLibs { + useLegacyPackaging = true + } + } + dependenciesInfo { + includeInApk = false + includeInBundle = false + } + lint { + checkReleaseBuilds = false + } +} + +dependencies { + implementation(files("libs/expressa-core-release.aar")) + implementation(files("libs/expressa-components-release.aar")) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.androidx.compose.foundation) + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.graphics) + implementation(libs.androidx.compose.material.ripple) + implementation(libs.androidx.compose.material.icons) + implementation(libs.androidx.graphics.shapes) +} diff --git a/app/libs/expressa-components-release.aar b/app/libs/expressa-components-release.aar new file mode 100644 index 0000000..952b3ec Binary files /dev/null and b/app/libs/expressa-components-release.aar differ diff --git a/app/libs/expressa-core-release.aar b/app/libs/expressa-core-release.aar new file mode 100644 index 0000000..3f3246e Binary files /dev/null and b/app/libs/expressa-core-release.aar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..96b7c0f --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,27 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile + +-dontobfuscate + +-assumenosideeffects class kotlin.jvm.internal.Intrinsics { + public static void check*(...); +} diff --git a/app/release/app-release.apk b/app/release/app-release.apk new file mode 100644 index 0000000..daf7583 Binary files /dev/null and b/app/release/app-release.apk differ diff --git a/app/release/baselineProfiles/0/app-release.dm b/app/release/baselineProfiles/0/app-release.dm new file mode 100644 index 0000000..4b86501 Binary files /dev/null and b/app/release/baselineProfiles/0/app-release.dm differ diff --git a/app/release/baselineProfiles/1/app-release.dm b/app/release/baselineProfiles/1/app-release.dm new file mode 100644 index 0000000..d02aea0 Binary files /dev/null and b/app/release/baselineProfiles/1/app-release.dm differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json new file mode 100644 index 0000000..5c44629 --- /dev/null +++ b/app/release/output-metadata.json @@ -0,0 +1,37 @@ +{ + "version": 3, + "artifactType": { + "type": "APK", + "kind": "Directory" + }, + "applicationId": "com.kyant.glass", + "variantName": "release", + "elements": [ + { + "type": "SINGLE", + "filters": [], + "attributes": [], + "versionCode": 1, + "versionName": "1.0.0-dev", + "outputFile": "app-release.apk" + } + ], + "elementType": "File", + "baselineProfiles": [ + { + "minApi": 28, + "maxApi": 30, + "baselineProfiles": [ + "baselineProfiles/1/app-release.dm" + ] + }, + { + "minApi": 31, + "maxApi": 2147483647, + "baselineProfiles": [ + "baselineProfiles/0/app-release.dm" + ] + } + ], + "minSdkVersionForDexing": 33 +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ef3ca6c --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png new file mode 100644 index 0000000..1858e63 Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ diff --git a/app/src/main/java/com/kyant/glass/MainActivity.kt b/app/src/main/java/com/kyant/glass/MainActivity.kt new file mode 100644 index 0000000..491bfaa --- /dev/null +++ b/app/src/main/java/com/kyant/glass/MainActivity.kt @@ -0,0 +1,67 @@ +package com.kyant.glass + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.LocalIndication +import androidx.compose.foundation.LocalOverscrollFactory +import androidx.compose.material.ripple.RippleAlpha +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalView +import androidx.core.graphics.drawable.toDrawable +import androidx.core.view.WindowCompat +import com.kyant.expressa.m3.LocalColorScheme +import com.kyant.expressa.m3.color.ColorScheme +import com.kyant.expressa.overscroll.rememberOffsetOverscrollFactory +import com.kyant.expressa.prelude.* +import com.kyant.expressa.ripple.LocalRippleConfiguration +import com.kyant.expressa.ripple.RippleConfiguration +import com.kyant.expressa.ripple.ripple +import com.kyant.expressa.ui.LocalContentColor +import com.kyant.glass.playground.Preview +import com.kyant.glass.playground.PreviewState + +class MainActivity : ComponentActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + WindowCompat.setDecorFitsSystemWindows(window, false) + + setContent { + val rippleConfiguration = remember { + RippleConfiguration( + rippleAlpha = RippleAlpha( + hoveredAlpha = 2f * 0.08f, + focusedAlpha = 2f * 0.10f, + pressedAlpha = 2f * 0.10f, + draggedAlpha = 2f * 0.16f + ) + ) + } + val overscrollFactory = rememberOffsetOverscrollFactory() + + CompositionLocalProvider( + LocalColorScheme provides ColorScheme.systemDynamic() + ) { + CompositionLocalProvider( + LocalContentColor provides onSurface, + LocalRippleConfiguration provides rippleConfiguration, + LocalIndication provides ripple(), + LocalOverscrollFactory provides overscrollFactory, + ) { + val view = LocalView.current + val background = surfaceContainer + LaunchedEffect(view, background) { + view.rootView.background = background.toArgb().toDrawable() + } + + val previewState = remember { PreviewState() } + Preview(previewState) + } + } + } + } +} diff --git a/app/src/main/java/com/kyant/glass/playground/BlurredAnimatedContent.kt b/app/src/main/java/com/kyant/glass/playground/BlurredAnimatedContent.kt new file mode 100644 index 0000000..f8acd28 --- /dev/null +++ b/app/src/main/java/com/kyant/glass/playground/BlurredAnimatedContent.kt @@ -0,0 +1,72 @@ +package com.kyant.glass.playground + +import android.graphics.RenderEffect +import android.graphics.Shader +import androidx.compose.animation.AnimatedContent +import androidx.compose.animation.AnimatedContentScope +import androidx.compose.animation.AnimatedContentTransitionScope +import androidx.compose.animation.ContentTransform +import androidx.compose.animation.core.Animatable +import androidx.compose.animation.core.spring +import androidx.compose.animation.core.tween +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.scaleIn +import androidx.compose.animation.togetherWith +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.runtime.snapshotFlow +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.asComposeRenderEffect +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.unit.dp +import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.drop + +@Composable +fun BlurredAnimatedContent( + targetState: () -> S, + modifier: Modifier = Modifier, + transitionSpec: AnimatedContentTransitionScope.() -> ContentTransform = { + (fadeIn(animationSpec = tween(220, delayMillis = 90)) + + scaleIn(initialScale = 0.92f, animationSpec = tween(220, delayMillis = 90))) + .togetherWith(fadeOut(animationSpec = tween(90))) + }, + contentAlignment: Alignment = Alignment.TopStart, + label: String = "AnimatedContent", + contentKey: (targetState: S) -> Any? = { it }, + content: @Composable() AnimatedContentScope.(targetState: S) -> Unit +) { + val blurRadius = remember { Animatable(0f) } + + LaunchedEffect(Unit) { + snapshotFlow { targetState() } + .drop(1) + .collectLatest { + blurRadius.animateTo(24f, spring(stiffness = 2000f)) + blurRadius.animateTo(0f, spring(stiffness = 2000f)) + } + } + + AnimatedContent( + targetState(), + modifier = modifier.graphicsLayer { + val blurRadiusPx = blurRadius.value.dp.toPx() + if (blurRadiusPx > 0f) { + renderEffect = + RenderEffect.createBlurEffect( + blurRadiusPx, + blurRadiusPx, + Shader.TileMode.DECAL + ).asComposeRenderEffect() + } + }, + transitionSpec = transitionSpec, + contentAlignment = contentAlignment, + label = label, + contentKey = contentKey, + content = content + ) +} diff --git a/app/src/main/java/com/kyant/glass/playground/BottomSheet.kt b/app/src/main/java/com/kyant/glass/playground/BottomSheet.kt new file mode 100644 index 0000000..ed58bb0 --- /dev/null +++ b/app/src/main/java/com/kyant/glass/playground/BottomSheet.kt @@ -0,0 +1,103 @@ +package com.kyant.glass.playground + +import androidx.compose.foundation.background +import androidx.compose.foundation.gestures.Orientation +import androidx.compose.foundation.gestures.draggable +import androidx.compose.foundation.gestures.rememberDraggableState +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.safeDrawingPadding +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableFloatStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.shadow +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.Layout +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.dp +import androidx.compose.ui.util.fastCoerceIn +import androidx.compose.ui.util.fastRoundToInt +import com.kyant.expressa.m3.shape.CornerShape +import com.kyant.expressa.prelude.* + +@Composable +fun BottomSheet( + modifier: Modifier = Modifier, + content: @Composable () -> Unit +) { + val density = LocalDensity.current + + var maxExpandedHeight by remember { mutableFloatStateOf(0f) } + val peekHeight = with(density) { 44.dp.toPx() } + var offset by rememberSaveable { mutableFloatStateOf(with(density) { -256.dp.toPx() }) } + + Box( + modifier + .fillMaxSize() + .safeDrawingPadding() + ) { + Layout( + { + Box( + Modifier + .draggable( + rememberDraggableState { delta -> + offset = (offset + delta).fastCoerceIn(-maxExpandedHeight, -peekHeight) + }, + Orientation.Vertical + ) + .padding(vertical = 12.dp) + .fillMaxWidth(), + contentAlignment = Alignment.Center + ) { + Box( + Modifier + .clip(CornerShape.full) + .background(primary) + .size(48.dp, 6.dp) + ) + } + + Box( + Modifier + .shadow( + elevation = 8.dp, + shape = CornerShape.extraLarge, + ambientColor = Color.Black.copy(alpha = 0.3f), + spotColor = Color.Black.copy(alpha = 0.3f) + ) + .background(surface) + ) { + content() + } + } + ) { measurables, constraints -> + val dragHandlePlaceable = measurables[0].measure(constraints) + val dragHandleHeight = dragHandlePlaceable.height + + val sheetHeight = (peekHeight - offset).fastRoundToInt() + val sheetPlaceable = measurables[1].measure( + constraints.copy( + minHeight = sheetHeight, + maxHeight = sheetHeight + ) + ) + + maxExpandedHeight = constraints.maxHeight - peekHeight - dragHandleHeight + + layout(constraints.maxWidth, constraints.maxHeight) { + dragHandlePlaceable.place(0, constraints.maxHeight - sheetHeight - dragHandleHeight) + sheetPlaceable.place(0, constraints.maxHeight - sheetHeight) + } + } + } +} diff --git a/app/src/main/java/com/kyant/glass/playground/ButtonGroup.kt b/app/src/main/java/com/kyant/glass/playground/ButtonGroup.kt new file mode 100644 index 0000000..bcb0355 --- /dev/null +++ b/app/src/main/java/com/kyant/glass/playground/ButtonGroup.kt @@ -0,0 +1,139 @@ +package com.kyant.glass.playground + +import androidx.activity.compose.rememberLauncherForActivityResult +import androidx.activity.result.PickVisualMediaRequest +import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.foundation.horizontalScroll +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.wrapContentWidth +import androidx.compose.foundation.rememberScrollState +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Build +import androidx.compose.material.icons.outlined.Palette +import androidx.compose.material.icons.outlined.Photo +import androidx.compose.material.icons.outlined.Restore +import androidx.compose.material.icons.outlined.Visibility +import androidx.compose.material.icons.outlined.VisibilityOff +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.rememberVectorPainter +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.kyant.expressa.components.iconbutton.IconButton +import com.kyant.expressa.components.iconbutton.IconButtonColors +import com.kyant.expressa.components.iconbutton.IconButtonSizes +import com.kyant.expressa.prelude.* +import com.kyant.expressa.ui.Icon +import com.kyant.glass.R +import kotlinx.coroutines.launch + +@Composable +fun ButtonGroup( + state: PreviewState, + modifier: Modifier = Modifier +) { + val scope = rememberCoroutineScope() + + Row( + modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically + ) { + IconButton( + { scope.launch { state.reset() } }, + sizes = IconButtonSizes.medium, + colors = IconButtonColors.tonal( + containerColor = tertiaryContainer, + contentColor = onTertiaryContainer + ) + ) { + Icon( + rememberVectorPainter(Icons.Outlined.Restore), + stringResource(R.string.reset), + ) + } + + Box(Modifier.weight(1f)) { + Row( + modifier + .fillMaxWidth() + .wrapContentWidth(Alignment.CenterHorizontally) + .horizontalScroll(rememberScrollState()), + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically + ) { + IconButton( + { state.displayControls = !state.displayControls }, + sizes = IconButtonSizes.medium, + colors = + if (state.displayControls) IconButtonColors.filled() + else IconButtonColors.tonal() + ) { + Icon( + rememberVectorPainter( + if (state.displayControls) Icons.Outlined.Visibility + else Icons.Outlined.VisibilityOff + ), + stringResource( + if (state.displayControls) R.string.hide_controls + else R.string.show_controls + ) + ) + } + IconButton( + { state.configurationMode = ConfigurationMode.Color }, + sizes = IconButtonSizes.medium, + colors = IconButtonColors.tonal() + ) { + Icon( + rememberVectorPainter(Icons.Outlined.Palette), + stringResource(R.string.color) + ) + } + IconButton( + { state.configurationMode = ConfigurationMode.Advanced }, + sizes = IconButtonSizes.medium, + colors = IconButtonColors.tonal( + containerColor = primaryContainer, + contentColor = onPrimaryContainer + ) + ) { + Icon( + rememberVectorPainter(Icons.Outlined.Build), + stringResource(R.string.advanced_settings) + ) + } + } + } + + val context = LocalContext.current + val pickMedia = rememberLauncherForActivityResult( + ActivityResultContracts.PickVisualMedia() + ) { uri -> + if (uri != null) { + state.loadImage(context, uri) + } + } + IconButton( + { + pickMedia.launch( + PickVisualMediaRequest( + ActivityResultContracts.PickVisualMedia.ImageOnly + ) + ) + }, + sizes = IconButtonSizes.medium + ) { + Icon( + rememberVectorPainter(Icons.Outlined.Photo), + stringResource(R.string.pick_an_image) + ) + } + } +} diff --git a/app/src/main/java/com/kyant/glass/playground/ConfigurationBottomSheet.kt b/app/src/main/java/com/kyant/glass/playground/ConfigurationBottomSheet.kt new file mode 100644 index 0000000..6af27fa --- /dev/null +++ b/app/src/main/java/com/kyant/glass/playground/ConfigurationBottomSheet.kt @@ -0,0 +1,118 @@ +package com.kyant.glass.playground + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.BlurOn +import androidx.compose.material.icons.outlined.Close +import androidx.compose.material.icons.outlined.ColorLens +import androidx.compose.material.icons.outlined.Opacity +import androidx.compose.material.icons.outlined.Radar +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.runtime.snapshots.Snapshot +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.shadow +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.vector.rememberVectorPainter +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.kyant.expressa.components.iconbutton.IconButton +import com.kyant.expressa.m3.shape.CornerShape +import com.kyant.expressa.prelude.* +import com.kyant.expressa.ui.Icon +import com.kyant.expressa.ui.Text +import com.kyant.glass.R + +@Composable +fun ConfigurationBottomSheet( + state: PreviewState, + modifier: Modifier = Modifier +) { + Column( + modifier + .shadow( + elevation = 8.dp, + shape = CornerShape.extraLarge, + ambientColor = Color.Black.copy(alpha = 0.3f), + spotColor = Color.Black.copy(alpha = 0.3f) + ) + .background(surface) + .padding(16.dp) + .fillMaxWidth(), + verticalArrangement = Arrangement.spacedBy(16.dp) + ) { + Row( + modifier + .fillMaxWidth() + .padding(start = 8.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Text( + when (state.configurationMode) { + ConfigurationMode.Color -> stringResource(R.string.color) + ConfigurationMode.Advanced -> stringResource(R.string.advanced_settings) + null -> "" + }, + titleMedium, + Modifier.weight(1f) + ) + + IconButton( + { state.configurationMode = null } + ) { + Icon( + rememberVectorPainter(Icons.Outlined.Close), + stringResource(R.string.close) + ) + } + } + + Column( + verticalArrangement = Arrangement.spacedBy(16.dp) + ) { + val retainedConfigurationMode = remember { + Snapshot.withoutReadObservation { state.configurationMode } + } + when (retainedConfigurationMode) { + ConfigurationMode.Color -> { + SliderChip( + state.blurRadius, + stringResource(R.string.blur_radius), + { Icon(rememberVectorPainter(Icons.Outlined.BlurOn)) }, + Modifier.fillMaxWidth() + ) + SliderChip( + state.opacity, + stringResource(R.string.opacity), + { Icon(rememberVectorPainter(Icons.Outlined.Opacity)) }, + Modifier.fillMaxWidth() + ) + SliderChip( + state.chromaMultiplier, + stringResource(R.string.chroma_multiplier), + { Icon(rememberVectorPainter(Icons.Outlined.ColorLens)) }, + Modifier.fillMaxWidth() + ) + } + + ConfigurationMode.Advanced -> { + SliderChip( + state.eccentricFactor, + stringResource(R.string.eccentric_factor), + { Icon(rememberVectorPainter(Icons.Outlined.Radar)) }, + Modifier.fillMaxWidth() + ) + } + + null -> {} + } + } + } +} diff --git a/app/src/main/java/com/kyant/glass/playground/ConfigurationMode.kt b/app/src/main/java/com/kyant/glass/playground/ConfigurationMode.kt new file mode 100644 index 0000000..35dc163 --- /dev/null +++ b/app/src/main/java/com/kyant/glass/playground/ConfigurationMode.kt @@ -0,0 +1,6 @@ +package com.kyant.glass.playground + +enum class ConfigurationMode { + Color, + Advanced +} diff --git a/app/src/main/java/com/kyant/glass/playground/Preview.kt b/app/src/main/java/com/kyant/glass/playground/Preview.kt new file mode 100644 index 0000000..ef2dd94 --- /dev/null +++ b/app/src/main/java/com/kyant/glass/playground/Preview.kt @@ -0,0 +1,363 @@ +package com.kyant.glass.playground + +import android.graphics.RenderEffect +import android.graphics.RuntimeShader +import android.graphics.Shader +import androidx.compose.foundation.Image +import androidx.compose.foundation.gestures.detectTransformGestures +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.safeDrawingPadding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.draw.drawWithContent +import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.asComposeRenderEffect +import androidx.compose.ui.graphics.drawscope.translate +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.graphics.layer.drawLayer +import androidx.compose.ui.graphics.painter.BitmapPainter +import androidx.compose.ui.graphics.rememberGraphicsLayer +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.layout.boundsInParent +import androidx.compose.ui.layout.layout +import androidx.compose.ui.layout.onGloballyPositioned +import androidx.compose.ui.platform.LocalWindowInfo +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.Constraints +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.coerceIn +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.roundToIntSize +import androidx.compose.ui.util.fastCoerceAtMost +import com.kyant.expressa.prelude.* +import com.kyant.glass.R + +@Composable +fun Preview(state: PreviewState) { + val graphicsLayer = rememberGraphicsLayer() + val backgroundColor = surfaceContainerLowest + val containerSize = LocalWindowInfo.current.containerSize + + var rect by remember { mutableStateOf(Rect.Zero) } + + val painter = + state.imageBitmap?.let { BitmapPainter(it) } + ?: painterResource(R.drawable.homescreen) + + Box( + Modifier.fillMaxSize() + ) { + // background + Image( + painter, null, + Modifier + .fillMaxSize() + .drawWithContent { + drawContent() + + graphicsLayer.record { + drawRect(backgroundColor) + this@drawWithContent.drawContent() + } + }, + contentScale = ContentScale.Crop + ) + + // glass + Box( + Modifier + .graphicsLayer { // transform and clip + translationX = state.offset.x + translationY = state.offset.y + clip = true + shape = RoundedCornerShape(state.cornerRadius.value) + } + .graphicsLayer { // dispersion effect + renderEffect = RenderEffect.createRuntimeShaderEffect( + RuntimeShader( + """// This file belongs to Kyant. You must not use it without permission. + uniform shader image; + + uniform float2 size; + uniform float cornerRadius; + uniform float dispersionHeight; + + float lerp(float a, float b, float t) { + return a + (b - a) * t; + } + + float2 normalToTangent(float2 normal) { + return float2(normal.y, -normal.x); + } + + float circleMap(float x) { + return 1.0 - sqrt(1.0 - x * x); + } + + float sdRectangle(float2 coord, float2 halfSize) { + float2 d = abs(coord) - halfSize; + float outside = length(max(d, 0.0)); + float inside = min(max(d.x, d.y), 0.0); + return outside + inside; + } + + float sdRoundedRectangle(float2 coord, float2 halfSize, float radius) { + return sdRectangle(coord, halfSize) - radius; + } + + const float eps = 0.5; + const float2 epsX = float2(eps, 0.0); + const float2 epsY = float2(0.0, eps); + + float2 gradSdRoundedRectangle(float2 coord, float2 halfSize, float radius) { + float dx = sdRoundedRectangle(coord + epsX, halfSize, radius) + - sdRoundedRectangle(coord - epsX, halfSize, radius); + float dy = sdRoundedRectangle(coord + epsY, halfSize, radius) + - sdRoundedRectangle(coord - epsY, halfSize, radius); + return normalize(float2(dx, dy)); + } + + half4 main(float2 coord) { + float2 halfSize = size * 0.5; + float2 centeredCoord = coord - halfSize; + float2 innerHalfSize = halfSize - float2(cornerRadius); + float sd = sdRoundedRectangle(centeredCoord, innerHalfSize, cornerRadius); + + if (sd < 0.0 && -sd < dispersionHeight) { + float2 normal = gradSdRoundedRectangle(centeredCoord, innerHalfSize, cornerRadius); + float2 tangent = normalToTangent(normal); + + half4 dispersedColor = half4(0.0); + half4 weight = half4(0.0); + + float dispersionFraction = 1.0 - -sd / dispersionHeight; + float dispersionWidth = dispersionHeight * 2.0 * pow(circleMap(dispersionFraction), 2.0); + if (dispersionWidth < 2.0) { + half4 color = image.eval(coord); + return color; + } + float maxI = min(dispersionWidth, 100.0); + for (float i = 0.0; i < 100.0; i++) { + float t = i / maxI; + if (t > 1.0) break; + half4 color = image.eval(coord + tangent * float2(t - 0.5) * dispersionWidth); + if (t >= 0.0 && t < 0.5) { + dispersedColor.b += color.b; + weight.b += 1.0; + } + if (t > 0.25 && t < 0.75) { + dispersedColor.g += color.g; + weight.g += 1.0; + } + if (t > 0.5 && t <= 1.0) { + dispersedColor.r += color.r; + weight.r += 1.0; + } + } + dispersedColor /= weight; + + half4 color = image.eval(coord); + dispersedColor.a = color.a; + half4 blendedColor = dispersedColor; + return blendedColor; + } else { + half4 color = image.eval(coord); + return color; + } + }""" + ).apply { + val cornerRadius = + state.cornerRadius.value.toPx() + .fastCoerceAtMost(size.minDimension / 2f) + + setFloatUniform("size", size.width, size.height) + setFloatUniform("cornerRadius", cornerRadius) + setFloatUniform("dispersionHeight", state.dispersionHeight.value.toPx()) + }, + "image" + ).asComposeRenderEffect() + } + .graphicsLayer { // chroma boost + renderEffect = RenderEffect.createRuntimeShaderEffect( + RuntimeShader( + """// This file belongs to Kyant. You must not use it without permission. + uniform shader image; + + uniform float chromaMultiplier; + + const half3 rgbToY = half3(0.299, 0.587, 0.114); + + half3 saturateColor(half3 color, float amount) { + half luma = dot(color, rgbToY); + return clamp(mix(half3(luma), color, amount), 0.0, 1.0); + } + + half4 main(float2 coord) { + half4 color = image.eval(coord); + color.rgb = saturateColor(color.rgb, chromaMultiplier); + return color; + } + """ + ).apply { + setFloatUniform("chromaMultiplier", state.chromaMultiplier.value) + }, + "image" + ).asComposeRenderEffect() + } + .graphicsLayer { // glass effect + renderEffect = RenderEffect.createRuntimeShaderEffect( + RuntimeShader( + """// This file belongs to Kyant. You must not use it without permission. + uniform shader image; + + uniform float2 size; + uniform float cornerRadius; + uniform float refractionHeight; + uniform float refractionAmount; + uniform float eccentricFactor; + + float circleMap(float x) { + return 1.0 - sqrt(1.0 - x * x); + } + + float sdRectangle(float2 coord, float2 halfSize) { + float2 d = abs(coord) - halfSize; + float outside = length(max(d, 0.0)); + float inside = min(max(d.x, d.y), 0.0); + return outside + inside; + } + + float sdRoundedRectangle(float2 coord, float2 halfSize, float radius) { + return sdRectangle(coord, halfSize) - radius; + } + + const float eps = 0.5; + const float2 epsX = float2(eps, 0.0); + const float2 epsY = float2(0.0, eps); + + float2 gradSdRoundedRectangle(float2 coord, float2 halfSize, float radius) { + float dx = sdRoundedRectangle(coord + epsX, halfSize, radius) + - sdRoundedRectangle(coord - epsX, halfSize, radius); + float dy = sdRoundedRectangle(coord + epsY, halfSize, radius) + - sdRoundedRectangle(coord - epsY, halfSize, radius); + return normalize(float2(dx, dy)); + } + + half4 main(float2 coord) { + float2 halfSize = size * 0.5; + float2 centeredCoord = coord - halfSize; + float2 innerHalfSize = halfSize - float2(cornerRadius); + float sd = sdRoundedRectangle(centeredCoord, innerHalfSize, cornerRadius); + + if (sd < 0.0 && -sd < refractionHeight) { + float2 normal = gradSdRoundedRectangle(centeredCoord, innerHalfSize, cornerRadius); + float refractedDistance = circleMap(1.0 - -sd / refractionHeight) * refractionAmount; + float2 refractedDirection = normalize(normal + eccentricFactor * normalize(centeredCoord)); + float2 refractedCoord = coord + refractedDistance * refractedDirection; + half4 refractedColor = image.eval(refractedCoord); + return refractedColor; + } else { + half4 color = image.eval(coord); + return color; + } + }""" + ).apply { + val cornerRadius = + state.cornerRadius.value.toPx() + .fastCoerceAtMost(size.minDimension / 2f) + + setFloatUniform("size", size.width, size.height) + setFloatUniform("cornerRadius", cornerRadius) + setFloatUniform("refractionHeight", state.refractionHeight.value.toPx()) + setFloatUniform("refractionAmount", state.refractionAmount.value.toPx()) + setFloatUniform("eccentricFactor", state.eccentricFactor.value) + }, + "image" + ).asComposeRenderEffect() + } + .graphicsLayer { // blur + val blurRadiusPx = state.blurRadius.value.toPx() + if (blurRadiusPx > 0f) { + renderEffect = + RenderEffect.createBlurEffect( + blurRadiusPx, + blurRadiusPx, + Shader.TileMode.DECAL + ).asComposeRenderEffect() + } + } + .drawBehind { + translate(-rect.left, -rect.top) { + drawLayer(graphicsLayer) + } + drawRect( + Color.Black, + alpha = state.opacity.value + ) + } + .onGloballyPositioned { layoutCoordinates -> + rect = layoutCoordinates.boundsInParent() + } + .pointerInput(Unit) { + detectTransformGestures { _, pan, zoom, _ -> + state.offset += pan + state.size = DpSize( + (state.size.width * zoom).coerceIn( + state.minSize.width, + containerSize.width.toDp() + ), + (state.size.height * zoom).coerceIn( + state.minSize.height, + containerSize.height.toDp() + ) + ) + } + } + .layout { measurable, constraints -> + val size = state.size.toSize().roundToIntSize() + val width = size.width.coerceAtMost(constraints.maxWidth) + val height = size.height.coerceAtMost(constraints.maxHeight) + val placeable = measurable.measure(Constraints.fixed(width, height)) + + layout(width, height) { + placeable.place(0, 0) + } + } + .align(Alignment.Center) + ) + + BlurredAnimatedContent({ state.displayControls }) { visible -> + if (visible) { + PreviewControls( + state, + { rect } + ) + } + } + + BlurredAnimatedContent( + { state.isInConfigurationMode }, + Modifier + .padding(16.dp) + .safeDrawingPadding() + .align(Alignment.BottomCenter) + ) { isInConfigurationMode -> + if (!isInConfigurationMode) { + ButtonGroup(state) + } else { + ConfigurationBottomSheet(state) + } + } + } +} diff --git a/app/src/main/java/com/kyant/glass/playground/PreviewControls.kt b/app/src/main/java/com/kyant/glass/playground/PreviewControls.kt new file mode 100644 index 0000000..a93c298 --- /dev/null +++ b/app/src/main/java/com/kyant/glass/playground/PreviewControls.kt @@ -0,0 +1,175 @@ +package com.kyant.glass.playground + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.gestures.detectDragGestures +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.IntrinsicSize +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Height +import androidx.compose.material.icons.outlined.Lens +import androidx.compose.material.icons.outlined.RoundedCorner +import androidx.compose.material.icons.outlined.WaterDrop +import androidx.compose.material.icons.outlined.Window +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.graphics.vector.rememberVectorPainter +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.coerceAtLeast +import androidx.compose.ui.unit.dp +import com.kyant.expressa.m3.shape.CornerShape +import com.kyant.expressa.prelude.* +import com.kyant.expressa.ui.Icon +import com.kyant.glass.R +import kotlin.math.sqrt + +@Composable +fun PreviewControls( + state: PreviewState, + rect: () -> Rect, + modifier: Modifier = Modifier +) { + Box(modifier.fillMaxSize()) { + // width + Icon( + rememberVectorPainter(Icons.Outlined.Height), + stringResource(R.string.width), + onTertiaryContainer, + Modifier + .graphicsLayer { + val rect = rect() + translationX = rect.right + 8.dp.toPx() + translationY = rect.center.y - size.height / 2 + } + .border( + 2.dp, + tertiary, + CornerShape.full + ) + .clip(CornerShape.full) + .background(tertiaryContainer) + .pointerInput(Unit) { + detectDragGestures { change, dragAmount -> + val delta = dragAmount.x * 2 + state.size = + state.size.copy( + width = + (state.size.width + delta.toDp()) + .coerceAtLeast(state.minSize.width) + ) + } + } + .padding(12.dp) + .size(24.dp) + .graphicsLayer { + rotationZ = 90f + } + ) + + // height + Icon( + rememberVectorPainter(Icons.Outlined.Height), + stringResource(R.string.height), + onTertiaryContainer, + Modifier + .graphicsLayer { + val rect = rect() + translationX = rect.center.x - size.width / 2 + translationY = rect.bottom + 8.dp.toPx() + } + .border( + 2.dp, + tertiary, + CornerShape.full + ) + .clip(CornerShape.full) + .background(tertiaryContainer) + .pointerInput(Unit) { + detectDragGestures { change, dragAmount -> + val delta = dragAmount.y * 2 + state.size = + state.size.copy( + height = + (state.size.height + delta.toDp()) + .coerceAtLeast(state.minSize.height) + ) + } + } + .padding(12.dp) + .size(24.dp) + ) + + // corner radius + SliderChip( + state.cornerRadius, + null, + { + Icon( + rememberVectorPainter(Icons.Outlined.RoundedCorner), + stringResource(R.string.corner_radius), + Modifier.graphicsLayer { + rotationX = 180f + } + ) + }, + Modifier + .graphicsLayer { + val rect = rect() + val cornerRadiusOffset = + (-state.cornerRadius.value.toPx() + 8.dp.toPx()) / (2 * sqrt(2f)) + translationX = rect.right + cornerRadiusOffset + translationY = rect.bottom + cornerRadiusOffset + } + .border( + 2.dp, + primary, + CornerShape.full + ), + dragDelta = { dragAmount -> (-dragAmount.x - dragAmount.y) / sqrt(2f) } + ) + + // refraction + Column( + Modifier + .width(IntrinsicSize.Max) + .graphicsLayer { + val rect = rect() + translationX = rect.center.x - size.width / 2 + translationY = rect.top - size.height - 8.dp.toPx() + }, + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(8.dp) + ) { + SliderChip( + state.dispersionHeight, + stringResource(R.string.dispersion_height), + { Icon(rememberVectorPainter(Icons.Outlined.Lens)) }, + Modifier.fillMaxWidth() + ) + SliderChip( + state.refractionAmount, + stringResource(R.string.refraction_amount), + { Icon(rememberVectorPainter(Icons.Outlined.WaterDrop)) }, + Modifier.fillMaxWidth() + ) + SliderChip( + state.refractionHeight, + stringResource(R.string.refraction_height), + { Icon(rememberVectorPainter(Icons.Outlined.Window)) }, + Modifier.fillMaxWidth() + ) + } + } +} diff --git a/app/src/main/java/com/kyant/glass/playground/PreviewState.kt b/app/src/main/java/com/kyant/glass/playground/PreviewState.kt new file mode 100644 index 0000000..ff71080 --- /dev/null +++ b/app/src/main/java/com/kyant/glass/playground/PreviewState.kt @@ -0,0 +1,212 @@ +package com.kyant.glass.playground + +import android.content.Context +import android.graphics.BitmapFactory +import android.net.Uri +import androidx.compose.animation.core.AnimationState +import androidx.compose.animation.core.AnimationVector1D +import androidx.compose.animation.core.AnimationVector2D +import androidx.compose.animation.core.TwoWayConverter +import androidx.compose.animation.core.VectorConverter +import androidx.compose.animation.core.animateTo +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.asImageBitmap +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.min +import androidx.compose.ui.util.fastRoundToInt +import androidx.compose.ui.util.lerp +import com.kyant.expressa.m3.motion.MotionScheme +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch + +class PreviewState { + + var configurationMode: ConfigurationMode? by mutableStateOf(null) + val isInConfigurationMode: Boolean by derivedStateOf { + configurationMode != null + } + + var displayControls: Boolean by mutableStateOf(true) + + var imageBitmap: ImageBitmap? by mutableStateOf(null) + + val minSize: DpSize = DpSize(24.dp, 24.dp) + var size: DpSize by mutableStateOf(DpSize(200.dp, 200.dp)) + var offset: Offset by mutableStateOf(Offset.Zero) + + val blurRadius: LiquidGlassParamValue = + LiquidGlassParamValue( + initialValue = 0.dp, + valueRange = { 0.dp..24.dp }, + typeConverter = Dp.VectorConverter, + valueLabel = { "${it.value.fastRoundToInt()} dp" } + ) + val opacity: LiquidGlassParamValue = + LiquidGlassParamValue( + initialValue = 0f, + valueRange = { 0f..0.2f }, + typeConverter = Float.VectorConverter, + valueLabel = { "${(it * 100).fastRoundToInt()}%" } + ) + val chromaMultiplier: LiquidGlassParamValue = + LiquidGlassParamValue( + initialValue = 1f, + valueRange = { 0.5f..2f }, + typeConverter = Float.VectorConverter, + valueLabel = { "%.2f".format(it) } + ) + + val cornerRadius: LiquidGlassParamValue = + LiquidGlassParamValue( + initialValue = 32.dp, + valueRange = { 0.dp..min(size.width, size.height) / 2 }, + typeConverter = Dp.VectorConverter, + valueLabel = { "${it.value.fastRoundToInt()} dp" } + ) + val refractionHeight: LiquidGlassParamValue = + LiquidGlassParamValue( + initialValue = 24.dp, + valueRange = { 0.dp..cornerRadius.value }, + typeConverter = Dp.VectorConverter, + valueLabel = { "${it.value.fastRoundToInt()} dp" } + ) + val refractionAmount: LiquidGlassParamValue = + LiquidGlassParamValue( + initialValue = (-32).dp, + valueRange = { (-512).dp..0.dp }, + typeConverter = Dp.VectorConverter, + valueLabel = { "${it.value.fastRoundToInt()} dp" } + ) + val dispersionHeight: LiquidGlassParamValue = + LiquidGlassParamValue( + initialValue = 0.dp, + valueRange = { 0.dp..cornerRadius.value }, + typeConverter = Dp.VectorConverter, + valueLabel = { "${it.value.fastRoundToInt()} dp" } + ) + val eccentricFactor: LiquidGlassParamValue = + LiquidGlassParamValue( + initialValue = 1f, + valueRange = { 0f..1f }, + typeConverter = Float.VectorConverter, + valueLabel = { "%.2f".format(it) } + ) + + fun loadImage(context: Context, uri: Uri) { + try { + context.contentResolver.openInputStream(uri)?.use { inputStream -> + val bitmap = BitmapFactory.decodeStream(inputStream) + imageBitmap = bitmap.asImageBitmap() + } + } catch (e: Exception) { + e.printStackTrace() + } + } + + suspend fun reset() { + imageBitmap = null + coroutineScope { + launch { + AnimationState( + TwoWayConverter( + convertToVector = { AnimationVector2D(it.width.value, it.height.value) }, + convertFromVector = { DpSize(it.v1.dp, it.v2.dp) }, + ), size + ) + .animateTo(DpSize(200.dp, 200.dp), MotionScheme.slowSpatial()) { + size = value + } + } + launch { + AnimationState(Offset.VectorConverter, offset) + .animateTo(Offset.Zero, MotionScheme.slowSpatial()) { + offset = value + } + } + + launch { blurRadius.reset() } + launch { opacity.reset() } + launch { chromaMultiplier.reset() } + + launch { cornerRadius.reset() } + launch { refractionHeight.reset() } + launch { refractionAmount.reset() } + launch { dispersionHeight.reset() } + launch { eccentricFactor.reset() } + } + } + + inner class LiquidGlassParamValue>( + val initialValue: T, + private val valueRange: () -> ClosedRange, + private val typeConverter: TwoWayConverter, + private val valueLabel: (T) -> String + ) { + + private var state: T by mutableStateOf(initialValue) + + val value: T by derivedStateOf { + state.coerceIn(valueRange()) + } + + val unsafeValue: T + get() = state + + val isValid: Boolean by derivedStateOf { + state in valueRange() + } + + val progress: Float by derivedStateOf { + val range = valueRange() + if (range.isEmpty()) { + 0f + } else { + val current = typeConverter.convertToVector(value).value + val start = typeConverter.convertToVector(range.start).value + val end = typeConverter.convertToVector(range.endInclusive).value + if (start == end) { + 0f + } else { + (current - start) / (end - start) + } + } + } + + val label: String by derivedStateOf { + valueLabel(value) + } + + val unsafeLabel: String by derivedStateOf { + valueLabel(unsafeValue) + } + + fun setValue(value: T) { + state = value.coerceIn(valueRange()) + } + + fun setFloatValue(value: Float) { + setValue(typeConverter.convertFromVector(AnimationVector1D(value))) + } + + fun setProgress(progress: Float) { + val range = valueRange() + val start = typeConverter.convertToVector(range.start).value + val end = typeConverter.convertToVector(range.endInclusive).value + setFloatValue(lerp(start, end, progress)) + } + + suspend fun reset() { + AnimationState(typeConverter, state) + .animateTo(initialValue, MotionScheme.slowSpatial()) { + setValue(value) + } + } + } +} diff --git a/app/src/main/java/com/kyant/glass/playground/SliderChip.kt b/app/src/main/java/com/kyant/glass/playground/SliderChip.kt new file mode 100644 index 0000000..47c8e68 --- /dev/null +++ b/app/src/main/java/com/kyant/glass/playground/SliderChip.kt @@ -0,0 +1,95 @@ +package com.kyant.glass.playground + +import androidx.compose.animation.animateContentSize +import androidx.compose.foundation.gestures.detectDragGestures +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.text.style.TextDecoration +import androidx.compose.ui.unit.dp +import com.kyant.expressa.m3.motion.MotionScheme +import com.kyant.expressa.m3.shape.CornerShape +import com.kyant.expressa.prelude.* +import com.kyant.expressa.ui.LocalTextStyle +import com.kyant.expressa.ui.ProvideTextStyle +import com.kyant.expressa.ui.Text + +@Composable +fun > SliderChip( + value: PreviewState.LiquidGlassParamValue, + label: String?, + icon: @Composable () -> Unit, + modifier: Modifier = Modifier, + dragDelta: (dragAmount: Offset) -> Float = { it.x } +) { + val containerColor = surfaceContainer + val sliderColor = primaryContainer + val errorColor = errorContainer + + Row( + modifier + .clip(CornerShape.full) + .drawBehind { + if (value.isValid) { + drawRect(containerColor) + drawRect( + sliderColor, + size = size.copy(width = size.width * value.progress) + ) + } else { + drawRect(errorColor) + } + } + .pointerInput(Unit) { + detectDragGestures { change, dragAmount -> + val delta = dragDelta(dragAmount) / size.width + value.setProgress(value.progress + delta) + } + } + .padding(12.dp, 8.dp) + .animateContentSize(MotionScheme.fastSpatial()), + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically + ) { + icon() + + Column { + if (label != null) { + Text( + label, + bodyMedium + ) + } + + ProvideTextStyle( + if (label != null) labelMedium + else labelLarge + ) { + if (value.isValid) { + Text( + value.label, + primary + ) + } else { + Row { + Text( + value.unsafeLabel, + LocalTextStyle.current.copy(textDecoration = TextDecoration.LineThrough), + error + ) + Text(" -> ") + Text(value.label) + } + } + } + } + } +} diff --git a/app/src/main/res/drawable/homescreen.webp b/app/src/main/res/drawable/homescreen.webp new file mode 100644 index 0000000..cd4f19d Binary files /dev/null and b/app/src/main/res/drawable/homescreen.webp differ diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..d77fd60 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/app/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 0000000..ef071a6 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/bools.xml b/app/src/main/res/values-night/bools.xml new file mode 100644 index 0000000..aa5c2df --- /dev/null +++ b/app/src/main/res/values-night/bools.xml @@ -0,0 +1,4 @@ + + + false + \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml new file mode 100644 index 0000000..452ecbe --- /dev/null +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -0,0 +1,22 @@ + + + 液态玻璃 + + 高级设置 + 模糊半径 + 彩度增强系数 + 关闭 + 颜色 + 圆角半径 + 色散高度 + 离心系数 + 高度 + 隐藏控件 + 不透明度 + 选择图像 + 折射高度 + 折射量 + 重置 + 显示控件 + 宽度 + \ No newline at end of file diff --git a/app/src/main/res/values/bools.xml b/app/src/main/res/values/bools.xml new file mode 100644 index 0000000..b5e2f93 --- /dev/null +++ b/app/src/main/res/values/bools.xml @@ -0,0 +1,4 @@ + + + true + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..120cd6b --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,22 @@ + + + Liquid Glass + + Advanced settings + Blur radius + Chroma multiplier + Close + Color + Corner radius + Dispersion height + Eccentric factor + Height + Hide controls + Opacity + Pick an image + Refraction height + Refraction amount + Reset + Show controls + Width + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..f435115 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/backup_rules.xml b/app/src/main/res/xml/backup_rules.xml new file mode 100644 index 0000000..4df9255 --- /dev/null +++ b/app/src/main/res/xml/backup_rules.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/data_extraction_rules.xml b/app/src/main/res/xml/data_extraction_rules.xml new file mode 100644 index 0000000..9ee9997 --- /dev/null +++ b/app/src/main/res/xml/data_extraction_rules.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..5c98ad0 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,6 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + alias(libs.plugins.android.application) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.kotlin.compose) apply false +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..20e2a01 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,23 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. For more details, visit +# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..14dc808 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,25 @@ +[versions] +agp = "8.10.1" +kotlin = "2.2.0-RC3" +core = "1.16.0" +lifecycle = "2.9.1" +activity = "1.12.0-alpha02" +composeBom = "2025.06.00" +graphicsShapes = "1.1.0-alpha01" + +[libraries] +androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core" } +androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle" } +androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity" } +androidx-compose-bom = { group = "androidx.compose", name = "compose-bom-alpha", version.ref = "composeBom" } +androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" } +androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" } +androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } +androidx-compose-material-ripple = { group = "androidx.compose.material", name = "material-ripple" } +androidx-compose-material-icons = { group = "androidx.compose.material", name = "material-icons-extended" } +androidx-graphics-shapes = { group = "androidx.graphics", name = "graphics-shapes", version.ref = "graphicsShapes" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..1b33c55 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..ff23a68 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..8ece87e --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,24 @@ +pluginManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "Glass" +include(":app") + \ No newline at end of file