Skip to content

Commit e200e7b

Browse files
author
Paul Ruiz
committed
Added Android L animations demo
1 parent 35cbd20 commit e200e7b

37 files changed

+1019
-0
lines changed

Animations/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.gradle
2+
/local.properties
3+
/.idea/workspace.xml
4+
/.idea/libraries
5+
.DS_Store
6+
/build

Animations/app/.gitignore

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

Animations/app/build.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 'android-L'
5+
buildToolsVersion "20.0.0"
6+
7+
defaultConfig {
8+
applicationId "com.ptrprograms.animations"
9+
minSdkVersion 'L'
10+
targetSdkVersion 'L'
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
runProguard false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
}

Animations/app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ptrprograms.animations;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.ptrprograms.animations" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@drawable/ic_launcher"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme.Base" >
10+
<activity
11+
android:name=".activity.MainActivity"
12+
android:label="@string/app_name" >
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
<activity android:name=".activity.CircularRevealActivity"
20+
android:label="@string/title_activity_circular_reveal"/>
21+
22+
<activity
23+
android:name=".activity.ExplodeAnimationActivity"
24+
android:label="@string/title_activity_explode_animation" />
25+
<activity
26+
android:name=".activity.FadeAnimationActivity"
27+
android:label="@string/title_activity_fade_animation" >
28+
</activity>
29+
<activity
30+
android:name=".activity.SlidingAnimationActivity"
31+
android:label="@string/title_activity_sliding_animation" >
32+
</activity>
33+
<activity
34+
android:name=".activity.SharedElementAnimationActivity"
35+
android:label="@string/title_activity_shared_element_animation" >
36+
</activity>
37+
38+
<activity
39+
android:name=".activity.SharedElementSecondAnimationActivity"
40+
android:label="@string/title_activity_shared_element_animation_second" >
41+
</activity>
42+
</application>
43+
44+
</manifest>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.ptrprograms.animations.activity;
2+
3+
import android.animation.Animator;
4+
import android.animation.AnimatorListenerAdapter;
5+
import android.animation.ValueAnimator;
6+
import android.app.Activity;
7+
import android.os.Bundle;
8+
import android.view.View;
9+
import android.view.ViewAnimationUtils;
10+
import android.widget.Button;
11+
import android.widget.ImageView;
12+
13+
import com.ptrprograms.animations.R;
14+
15+
/**
16+
* Created by paulruiz on 8/18/14.
17+
*/
18+
public class CircularRevealActivity extends Activity {
19+
20+
private ImageView mImageView;
21+
private Button mButton;
22+
23+
@Override
24+
protected void onCreate(Bundle savedInstanceState) {
25+
super.onCreate(savedInstanceState);
26+
setContentView( R.layout.activity_circular_reveal);
27+
mImageView = (ImageView) findViewById( R.id.image );
28+
mButton = (Button) findViewById( R.id.button );
29+
mButton.setOnClickListener( new View.OnClickListener() {
30+
@Override
31+
public void onClick(View view) {
32+
if( mImageView.getVisibility() == View.VISIBLE ) {
33+
hideImageCircular();
34+
} else {
35+
revealImageCircular();
36+
}
37+
}
38+
});
39+
}
40+
41+
private void hideImageCircular() {
42+
int x = getX();
43+
int y = getY();
44+
int radius = getRadius();
45+
46+
ValueAnimator anim =
47+
ViewAnimationUtils.createCircularReveal(mImageView, x, y, radius, 0);
48+
49+
anim.addListener(new AnimatorListenerAdapter() {
50+
51+
@Override
52+
public void onAnimationEnd(Animator animation) {
53+
super.onAnimationEnd(animation);
54+
mImageView.setVisibility( View.INVISIBLE );
55+
}
56+
});
57+
58+
anim.start();
59+
}
60+
61+
private void revealImageCircular() {
62+
int x = getX();
63+
int y = getY();
64+
int radius = getRadius();
65+
66+
ValueAnimator anim =
67+
ViewAnimationUtils.createCircularReveal(mImageView, x, y, 0, radius);
68+
69+
anim.setDuration( 1000 );
70+
anim.addListener( new AnimatorListenerAdapter() {
71+
@Override
72+
public void onAnimationStart(Animator animation) {
73+
super.onAnimationStart(animation);
74+
mImageView.setVisibility( View.VISIBLE );
75+
}
76+
});
77+
78+
anim.start();
79+
}
80+
81+
private int getX() {
82+
return ( mImageView.getLeft() + mImageView.getRight() ) / 2;
83+
}
84+
85+
private int getY() {
86+
return ( mImageView.getTop() + mImageView.getBottom() ) / 2;
87+
}
88+
89+
private int getRadius() {
90+
return mImageView.getWidth();
91+
}
92+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.ptrprograms.animations.activity;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.transition.Explode;
6+
import android.view.Menu;
7+
import android.view.MenuItem;
8+
import android.view.Window;
9+
10+
import com.ptrprograms.animations.R;
11+
12+
public class ExplodeAnimationActivity extends Activity {
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
18+
getWindow().setEnterTransition( new Explode() );
19+
getWindow().setExitTransition( new Explode() );
20+
setContentView(R.layout.activity_explode_animation);
21+
}
22+
23+
@Override
24+
public void onBackPressed() {
25+
super.onBackPressed();
26+
finishAfterTransition();
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.ptrprograms.animations.activity;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.transition.Fade;
6+
import android.view.Window;
7+
8+
import com.ptrprograms.animations.R;
9+
10+
public class FadeAnimationActivity extends Activity {
11+
12+
@Override
13+
protected void onCreate(Bundle savedInstanceState) {
14+
super.onCreate(savedInstanceState);
15+
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
16+
getWindow().setEnterTransition( new Fade() );
17+
getWindow().setExitTransition( new Fade() );
18+
setContentView(R.layout.activity_fade_animation);
19+
}
20+
21+
@Override
22+
public void onBackPressed() {
23+
super.onBackPressed();
24+
finishAfterTransition();
25+
}
26+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.ptrprograms.animations.activity;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.transition.Transition;
6+
import android.view.Window;
7+
8+
import com.ptrprograms.animations.R;
9+
import com.ptrprograms.animations.fragment.SelectionListFragment;
10+
11+
12+
public class MainActivity extends Activity implements Transition.TransitionListener {
13+
14+
@Override
15+
protected void onCreate( Bundle savedInstanceState ) {
16+
super.onCreate( savedInstanceState );
17+
getWindow().requestFeature( Window.FEATURE_CONTENT_TRANSITIONS );
18+
setContentView( R.layout.activity_main );
19+
getFragmentManager().beginTransaction().replace( R.id.container, SelectionListFragment.getInstance() ).commit();
20+
21+
//Can add listeners for the transition state
22+
getWindow().getEnterTransition().addListener( this );
23+
}
24+
25+
@Override
26+
public void onTransitionStart(Transition transition) {
27+
28+
}
29+
30+
@Override
31+
public void onTransitionEnd(Transition transition) {
32+
33+
}
34+
35+
@Override
36+
public void onTransitionCancel(Transition transition) {
37+
38+
}
39+
40+
@Override
41+
public void onTransitionPause(Transition transition) {
42+
43+
}
44+
45+
@Override
46+
public void onTransitionResume(Transition transition) {
47+
48+
}
49+
50+
@Override
51+
protected void onDestroy() {
52+
super.onDestroy();
53+
getWindow().getEnterTransition().removeListener( this );
54+
}
55+
}

0 commit comments

Comments
 (0)