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

Commit 698a8a4

Browse files
authored
DrawableAnimations: Add a new sample. (#41)
* DrawableAnimations: Add a new sample. This will be a collection of samples related to drawable animations. For this initial version, it has AnimatedVectorDrawableCompat and SeekableAnimatedVectorDrawable. * DrawableAnimations: Add GIF images
1 parent 49fb422 commit 698a8a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1524
-0
lines changed

DrawableAnimations/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# GOOGLE SAMPLE PACKAGING DATA
16+
#
17+
# This file is used by Google as part of our samples packaging process.
18+
# End users may safely ignore this file. It has no relevance to other systems.
19+
---
20+
status: PUBLISHED
21+
technologies: [Android]
22+
categories: [Animation]
23+
languages: [Kotlin]
24+
solutions: [Mobile]
25+
github: android/animation
26+
level: INTERMEDIATE
27+
icon: screenshots/icon-web.png
28+
apiRefs:
29+
- androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
30+
- androidx.vectordrawable.graphics.drawable.SeekableAnimatedVectorDrawable
31+
license: apache2

DrawableAnimations/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Android DrawableAnimations Sample
2+
=================================
3+
4+
A collection of demos for drawable animation APIs.
5+
6+
<img src="screenshots/ss-home.png" height="400" alt="Home screen">
7+
<img src="screenshots/ss-seekable.png" height="400" alt="SeekableAnimatedDrawable sample">
8+
9+
## APIs
10+
11+
### AnimatedVectorDrawableCompat
12+
13+
![AnimatedVectorDrawableCompat](screenshots/animated.gif)
14+
15+
[AnimatedVectorDrawableCompat](https://developer.android.com/reference/android/support/graphics/drawable/AnimatedVectorDrawableCompat)
16+
is backport of
17+
[AnimatedVectorDrawable](https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable)
18+
introduced in API level 21.
19+
20+
See
21+
[AnimatedFragment.kt](app/src/main/java/com/example/android/drawableanimations/demo/animated/AnimatedFragment.kt)
22+
for how to use AnimatedVectorDrawableCompat.
23+
24+
#### When to use AnimatedVectorDrawableCompat instead of SeekableAnimatedVectorDrawable
25+
26+
When you use `app:srcCompat` in your layout XML, AppCompat instantiates
27+
AnimatedVectorDrawableCompat for older APIs. If you don't need to pause/resume
28+
or seek, this should be sufficient.
29+
30+
### SeekableAnimatedVectorDrawable
31+
32+
![SeekableAnimatedVectorDrawable](screenshots/seekable.gif)
33+
34+
[SeekableAnimatedVectorDrawable](https://developer.android.com/reference/androidx/vectordrawable/graphics/drawable/SeekableAnimatedVectorDrawable)
35+
is an alternative to AnimatedVectorDrawableCompat that supports the same XML
36+
format. SeekableAnimatedVectorDrawable allows more control over animation,
37+
namely pause/resume and seek. It also provides animation callbacks for those
38+
additional events.
39+
40+
See
41+
[SeekableFragment.kt](app/src/main/java/com/example/android/drawableanimations/demo/seekable/SeekableFragment.kt)
42+
for how to use SeekableAnimatedVectorDrawable.
43+
44+
## Support
45+
46+
- Stack Overflow: https://stackoverflow.com/questions/tagged/android
47+
48+
If you've found an error in this sample, please
49+
[file an issue](https://github.com/android/animation-samples/issues/new).
50+
51+
Patches are encouraged, and may be submitted by forking this project and
52+
submitting a pull request through GitHub. Please see
53+
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.

DrawableAnimations/app/.gitignore

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

DrawableAnimations/app/build.gradle

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2020 Google LLC
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+
apply plugin: 'com.android.application'
18+
apply plugin: 'kotlin-android'
19+
20+
android {
21+
compileSdkVersion 29
22+
buildToolsVersion '29.0.3'
23+
24+
defaultConfig {
25+
applicationId 'com.example.android.drawableanimations'
26+
minSdkVersion 14
27+
targetSdkVersion 29
28+
versionCode 1
29+
versionName '1.0'
30+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
31+
vectorDrawables {
32+
useSupportLibrary = true
33+
}
34+
}
35+
36+
compileOptions {
37+
sourceCompatibility JavaVersion.VERSION_1_8
38+
targetCompatibility JavaVersion.VERSION_1_8
39+
}
40+
41+
kotlinOptions {
42+
jvmTarget = '1.8'
43+
}
44+
45+
viewBinding {
46+
enabled = true
47+
}
48+
49+
buildTypes {
50+
release {
51+
minifyEnabled false
52+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
53+
}
54+
}
55+
}
56+
57+
dependencies {
58+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
59+
60+
implementation 'androidx.activity:activity-ktx:1.1.0'
61+
implementation 'androidx.fragment:fragment-ktx:1.2.4'
62+
implementation 'androidx.appcompat:appcompat:1.1.0'
63+
implementation 'androidx.core:core-ktx:1.2.0'
64+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
65+
implementation 'androidx.recyclerview:recyclerview:1.1.0'
66+
implementation "androidx.vectordrawable:vectordrawable-seekable:1.0.0-alpha01"
67+
68+
testImplementation 'junit:junit:4.12'
69+
androidTestImplementation 'com.google.truth:truth:1.0'
70+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
71+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
72+
debugImplementation 'androidx.fragment:fragment-testing:1.2.4'
73+
androidTestImplementation 'androidx.core:core-animation-testing:1.0.0-alpha01'
74+
}
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2020 Google LLC
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.drawableanimations
18+
19+
import androidx.fragment.app.testing.launchFragmentInContainer
20+
import androidx.test.espresso.Espresso.onView
21+
import androidx.test.espresso.action.ViewActions.click
22+
import androidx.test.espresso.assertion.ViewAssertions.matches
23+
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
24+
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
25+
import androidx.test.espresso.matcher.ViewMatchers.withId
26+
import androidx.test.ext.junit.runners.AndroidJUnit4
27+
import com.example.android.drawableanimations.demo.animated.AnimatedFragment
28+
import org.hamcrest.CoreMatchers.not
29+
import org.junit.Test
30+
import org.junit.runner.RunWith
31+
32+
@RunWith(AndroidJUnit4::class)
33+
class AnimatedFragmentTest {
34+
35+
@Test
36+
fun start() {
37+
launchFragmentInContainer { AnimatedFragment() }
38+
39+
onView(withId(R.id.icon)).check(matches(isDisplayed()))
40+
41+
onView(withId(R.id.start))
42+
.check(matches(isEnabled()))
43+
.perform(click())
44+
.check(matches(not(isEnabled())))
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2020 Google LLC
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.drawableanimations
18+
19+
import android.widget.Button
20+
import androidx.core.animation.AnimatorTestRule
21+
import androidx.fragment.app.testing.launchFragmentInContainer
22+
import androidx.test.ext.junit.runners.AndroidJUnit4
23+
import com.example.android.drawableanimations.demo.seekable.SeekableFragment
24+
import com.google.common.truth.Truth.assertThat
25+
import org.junit.ClassRule
26+
import org.junit.Test
27+
import org.junit.runner.RunWith
28+
29+
@RunWith(AndroidJUnit4::class)
30+
class SeekableFragmentTest {
31+
32+
companion object {
33+
@ClassRule
34+
@JvmField
35+
val animatorTestRule = AnimatorTestRule()
36+
}
37+
38+
@Test
39+
fun start() {
40+
launchFragmentInContainer { SeekableFragment() }.onFragment { fragment ->
41+
val view = fragment.view!!
42+
val start: Button = view.findViewById(R.id.start)
43+
44+
assertThat(start.text.toString()).isEqualTo("Start")
45+
start.performClick()
46+
animatorTestRule.advanceTimeBy(800L)
47+
assertThat(start.text.toString()).isEqualTo("Pause")
48+
start.performClick()
49+
assertThat(start.text.toString()).isEqualTo("Resume")
50+
}
51+
}
52+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2020 Google LLC
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+
package="com.example.android.drawableanimations">
20+
21+
<application
22+
android:allowBackup="false"
23+
android:icon="@mipmap/ic_launcher"
24+
android:label="@string/app_name"
25+
android:roundIcon="@mipmap/ic_launcher_round"
26+
android:supportsRtl="true"
27+
android:theme="@style/AppTheme">
28+
29+
<activity android:name=".MainActivity">
30+
<intent-filter>
31+
<action android:name="android.intent.action.MAIN" />
32+
<category android:name="android.intent.category.LAUNCHER" />
33+
</intent-filter>
34+
</activity>
35+
</application>
36+
37+
</manifest>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2020 Google LLC
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.drawableanimations
18+
19+
import android.os.Bundle
20+
import androidx.appcompat.app.AppCompatActivity
21+
import androidx.fragment.app.commitNow
22+
import com.example.android.drawableanimations.ui.home.HomeFragment
23+
24+
class MainActivity : AppCompatActivity(R.layout.main_activity) {
25+
26+
override fun onCreate(savedInstanceState: Bundle?) {
27+
super.onCreate(savedInstanceState)
28+
if (savedInstanceState == null) {
29+
supportFragmentManager.commitNow {
30+
replace(R.id.main, HomeFragment())
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)