Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 343a5b4

Browse files
committed
MotionCompose: Create a new sample
This sample will demonstrate several animation patterns implemented in Compose. This CL contains the first demo: fade-through. Change-Id: Ied6027f027300c5da5db897e269663dd557e374b
1 parent 05259b7 commit 343a5b4

38 files changed

+1516
-0
lines changed

MotionCompose/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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

MotionCompose/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Android Compose Motion Sample
2+
=============================
3+
4+
A collection of demos for Material Design Motion implemented in
5+
[Jetpack Compose](https://developer.android.com/jetpack/compose).
6+
7+
[Material Design](https://material.io) provides a lot of examples about motion design. This sample
8+
shows how to implement them on Android.
9+
10+
- [Understanding motion](https://material.io/design/motion/understanding-motion.html)
11+
- [The motion system](https://material.io/design/motion/the-motion-system.html)
12+
- [Speed](https://material.io/design/motion/speed.html)
13+
- [Choreography](https://material.io/design/motion/choreography.html)
14+
- [Customization](https://material.io/design/motion/customization.html)
15+
16+
The [Animation](https://developer.android.com/jetpack/compose/animation) doc how to use various
17+
animation APIs in Jetpack Compose.
18+
19+
All the source codes for demos are in the
20+
[demo](app/src/main/java/com/example/android/compose/motion/demo)
21+
package.
22+
23+
### [Layout > Fade through](app/src/main/java/com/example/android/compose/motion/demo/fadethrough)
24+
25+
https://user-images.githubusercontent.com/1237536/142538271-480a5573-4231-414a-88cd-9fd9951fc792.mp4

MotionCompose/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

MotionCompose/app/build.gradle

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id 'com.android.application'
19+
id 'org.jetbrains.kotlin.android'
20+
}
21+
22+
android {
23+
compileSdk 31
24+
25+
defaultConfig {
26+
applicationId 'com.example.android.compose.motion'
27+
minSdk 21
28+
targetSdk 31
29+
versionCode 1
30+
versionName '1.0'
31+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
32+
}
33+
34+
buildTypes {
35+
release {
36+
minifyEnabled false
37+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
38+
}
39+
}
40+
compileOptions {
41+
sourceCompatibility JavaVersion.VERSION_1_8
42+
targetCompatibility JavaVersion.VERSION_1_8
43+
}
44+
kotlinOptions {
45+
freeCompilerArgs += '-Xopt-in=kotlin.RequiresOptIn'
46+
freeCompilerArgs += '-Xopt-in=kotlin.Experimental'
47+
jvmTarget = '1.8'
48+
}
49+
buildFeatures {
50+
compose true
51+
}
52+
composeOptions {
53+
kotlinCompilerExtensionVersion compose_version
54+
}
55+
packagingOptions {
56+
resources {
57+
excludes += '/META-INF/{AL2.0,LGPL2.1}'
58+
}
59+
}
60+
}
61+
62+
dependencies {
63+
implementation 'androidx.core:core-ktx:1.7.0'
64+
implementation "androidx.compose.ui:ui:$compose_version"
65+
implementation 'androidx.compose.material3:material3:1.0.0-alpha01'
66+
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
67+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
68+
implementation 'androidx.activity:activity-compose:1.4.0'
69+
70+
def accompanist_version = '0.21.2-beta'
71+
implementation "com.google.accompanist:accompanist-flowlayout:$accompanist_version"
72+
implementation "com.google.accompanist:accompanist-insets-ui:$accompanist_version"
73+
74+
testImplementation 'junit:junit:4.13.2'
75+
androidTestImplementation 'com.google.truth:truth:1.1.3'
76+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
77+
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
78+
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
79+
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
80+
}

MotionCompose/app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.compose.motion
18+
19+
import androidx.test.core.app.ActivityScenario
20+
import androidx.test.ext.junit.runners.AndroidJUnit4
21+
import com.google.common.truth.Truth.assertThat
22+
import org.junit.Test
23+
import org.junit.runner.RunWith
24+
25+
@RunWith(AndroidJUnit4::class)
26+
class MainActivityTest {
27+
28+
@Test
29+
fun launches() {
30+
val scenario = ActivityScenario.launch(MainActivity::class.java)
31+
scenario.onActivity { activity ->
32+
assertThat(activity.title).isEqualTo("Motion Compose")
33+
}
34+
}
35+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2021 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<manifest
18+
xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:tools="http://schemas.android.com/tools"
20+
package="com.example.android.compose.motion">
21+
22+
<application
23+
android:allowBackup="false"
24+
android:icon="@mipmap/ic_launcher"
25+
android:label="@string/app_name"
26+
android:roundIcon="@mipmap/ic_launcher_round"
27+
android:supportsRtl="true"
28+
android:theme="@style/Theme.MotionCompose">
29+
30+
<activity
31+
android:name=".MainActivity"
32+
android:exported="true"
33+
android:theme="@style/Theme.MotionCompose">
34+
<intent-filter>
35+
<action android:name="android.intent.action.MAIN" />
36+
<category android:name="android.intent.category.LAUNCHER" />
37+
</intent-filter>
38+
</activity>
39+
40+
</application>
41+
42+
</manifest>
31.9 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.compose.motion
18+
19+
import android.os.Bundle
20+
import androidx.activity.ComponentActivity
21+
import androidx.activity.compose.setContent
22+
import androidx.core.view.WindowCompat
23+
import com.example.android.compose.motion.ui.Main
24+
25+
class MainActivity : ComponentActivity() {
26+
27+
override fun onCreate(savedInstanceState: Bundle?) {
28+
super.onCreate(savedInstanceState)
29+
WindowCompat.setDecorFitsSystemWindows(window, false)
30+
setContent {
31+
Main()
32+
}
33+
}
34+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.compose.motion.demo
18+
19+
import androidx.compose.runtime.Composable
20+
import com.example.android.compose.motion.demo.fadethrough.FadeThroughDemo
21+
22+
enum class Demo(
23+
val title: String,
24+
val description: String,
25+
val apis: List<String>,
26+
val content: @Composable () -> Unit
27+
) {
28+
FadeThrough(
29+
title = "Layout > Fade through",
30+
description = """
31+
Fade through involves one element fading out completely before a new one fades in. These
32+
transitions can be applied to text, icons, and other elements that don't perfectly
33+
overlap. This technique lets the background show through during a transition, and it can
34+
provide continuity between screens when paired with a shared transformation.
35+
""".trimIndent().replace('\n', ' '),
36+
apis = listOf(
37+
"AnimatedContent"
38+
),
39+
content = { FadeThroughDemo() }
40+
)
41+
}

0 commit comments

Comments
 (0)