diff --git a/Motion/app/build.gradle b/Motion/app/build.gradle index 0143a102..c03852e1 100644 --- a/Motion/app/build.gradle +++ b/Motion/app/build.gradle @@ -19,12 +19,12 @@ apply plugin: 'kotlin-android' apply plugin: "androidx.navigation.safeargs.kotlin" android { - compileSdk 31 + compileSdk 34 defaultConfig { - applicationId 'com.example.android.motion' - minSdk 14 - targetSdk 31 + namespace 'com.example.android.motion' + minSdk 19 + targetSdk 34 versionCode 1 versionName '1.0' testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' @@ -51,33 +51,33 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.fragment:fragment-ktx:1.4.1' - implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'androidx.core:core-ktx:1.12.0' + implementation 'androidx.fragment:fragment-ktx:1.6.2' + implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.transition:transition:1.4.1' implementation 'androidx.dynamicanimation:dynamicanimation:1.1.0-alpha03' - implementation 'androidx.recyclerview:recyclerview:1.2.1' + implementation 'androidx.recyclerview:recyclerview:1.3.2' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - def lifecycle_version = '2.4.1' + def lifecycle_version = '2.7.0' implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" - implementation 'androidx.paging:paging-runtime-ktx:3.1.1' + implementation 'androidx.paging:paging-runtime-ktx:3.2.1' - implementation 'com.google.android.material:material:1.6.0' + implementation 'com.google.android.material:material:1.11.0' implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version" implementation "androidx.navigation:navigation-ui-ktx:$navigation_version" - implementation 'com.github.bumptech.glide:glide:4.10.0' + implementation 'com.github.bumptech.glide:glide:4.15.1' testImplementation 'junit:junit:4.13.2' testImplementation 'com.google.truth:truth:1.1.3' - testImplementation 'androidx.test:core:1.4.0' - androidTestImplementation 'androidx.test.ext:truth:1.4.0' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + testImplementation 'androidx.test:core:1.5.0' + androidTestImplementation 'androidx.test.ext:truth:1.5.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } diff --git a/Motion/app/src/main/AndroidManifest.xml b/Motion/app/src/main/AndroidManifest.xml index 950d7a82..02cbd3a8 100644 --- a/Motion/app/src/main/AndroidManifest.xml +++ b/Motion/app/src/main/AndroidManifest.xml @@ -27,12 +27,14 @@ + tools:ignore="GoogleAppIndexingWarning" + tools:targetApi="34"> v.findNavController().popBackStack() } + + val predictiveBackMargin = resources.getDimensionPixelSize(R.dimen.predictive_back_margin) + var initialTouchY = -1f + requireActivity().onBackPressedDispatcher.addCallback( + viewLifecycleOwner, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + // This invokes the sharedElementReturnTransition, which is + // MaterialContainerTransform. + findNavController().popBackStack() + } + + override fun handleOnBackProgressed(backEvent: BackEventCompat) { + val progress = GestureInterpolator.getInterpolation(backEvent.progress) + if (initialTouchY < 0f) { + initialTouchY = backEvent.touchY + } + val progressY = GestureInterpolator.getInterpolation( + (backEvent.touchY - initialTouchY) / background.height + ) + + // See the motion spec about the calculations below. + // https://developer.android.com/design/ui/mobile/guides/patterns/predictive-back#motion-specs + + // Shift horizontally. + val maxTranslationX = (background.width / 20) - predictiveBackMargin + background.translationX = progress * maxTranslationX * + (if (backEvent.swipeEdge == BackEventCompat.EDGE_LEFT) 1 else -1) + + // Shift vertically. + val maxTranslationY = (background.height / 20) - predictiveBackMargin + background.translationY = progressY * maxTranslationY + + // Scale down from 100% to 90%. + val scale = 1f - (0.1f * progress) + background.scaleX = scale + background.scaleY = scale + } + + override fun handleOnBackCancelled() { + initialTouchY = -1f + background.run { + translationX = 0f + translationY = 0f + scaleX = 1f + scaleY = 1f + } + } + } + ) } } diff --git a/Motion/app/src/main/java/com/example/android/motion/demo/sharedelement/MirrorView.kt b/Motion/app/src/main/java/com/example/android/motion/demo/sharedelement/MirrorView.kt index 18140b47..193d40e0 100644 --- a/Motion/app/src/main/java/com/example/android/motion/demo/sharedelement/MirrorView.kt +++ b/Motion/app/src/main/java/com/example/android/motion/demo/sharedelement/MirrorView.kt @@ -47,7 +47,7 @@ class MirrorView @JvmOverloads constructor( setWillNotDraw(value == null) } - override fun onDraw(canvas: Canvas?) { + override fun onDraw(canvas: Canvas) { _substance?.draw(canvas) } } diff --git a/Motion/app/src/main/res/values/dimens.xml b/Motion/app/src/main/res/values/dimens.xml index a6158904..ac21ebca 100644 --- a/Motion/app/src/main/res/values/dimens.xml +++ b/Motion/app/src/main/res/values/dimens.xml @@ -21,4 +21,5 @@ 8dp 6dp 24dp + 8dp diff --git a/Motion/build.gradle b/Motion/build.gradle index 196a5b0b..18f9a479 100644 --- a/Motion/build.gradle +++ b/Motion/build.gradle @@ -15,14 +15,14 @@ */ buildscript { - ext.kotlin_version = '1.6.21' - ext.navigation_version = '2.4.2' + ext.kotlin_version = '1.9.22' + ext.navigation_version = '2.7.7' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.3.0' + classpath 'com.android.tools.build:gradle:8.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version" } diff --git a/Motion/gradle/wrapper/gradle-wrapper.properties b/Motion/gradle/wrapper/gradle-wrapper.properties index c116b369..caddf7c5 100644 --- a/Motion/gradle/wrapper/gradle-wrapper.properties +++ b/Motion/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Oct 28 16:25:10 JST 2020 +#Fri Feb 16 14:02:28 JST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip