Skip to content

Commit

Permalink
Added fade animation when changing activities (not great).
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-w committed Feb 26, 2015
1 parent 43b539f commit 289f15e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.tonyw.sampleapps.palettecolorextraction;

import android.animation.Animator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.ClipData;
Expand All @@ -10,15 +8,11 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.GradientDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.support.v7.graphics.Palette;
import android.view.Display;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.widget.Toast;

/**
Expand Down Expand Up @@ -134,33 +128,12 @@ public void onClick(View v) {
colorWithTextIntent.putExtra(ColorWithTextActivity.EXTRA_BODY_TEXT_COLOR,
bodyTextColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
startRevealAnimation(v); // currently doesn't work right!
//startRevealAnimation(v); // currently doesn't work right!
mContext.startActivity(colorWithTextIntent,
ActivityOptions.makeSceneTransitionAnimation((Activity) mContext).toBundle());
} else {
mContext.startActivity(colorWithTextIntent);
}
}
};

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void startRevealAnimation(View view) {
int cx = (view.getLeft() + view.getRight()) / 2;
int cy = (view.getTop() + view.getBottom()) / 2;

// get the final radius for the clipping circle
Display display = ((Activity) mContext).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
view.setClipBounds(new Rect(0, 0, width, height));
int finalRadius = Math.max(width, height);

// create the animator for this view (the start radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);

anim.start();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


if (savedInstanceState != null) {
mBitmaps = savedInstanceState.getParcelableArrayList(BUNDLE_SAVED_BITMAPS);
} else {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/card_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
android:id="@+id/vibrant"
android:layout_width="@dimen/circle_size"
android:layout_height="@dimen/circle_size"

android:background="@drawable/circle" />
</LinearLayout>

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/transition/fade.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<fade
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000">
<targets>
<target android:excludeId="@android:id/statusBarBackground" />
<target android:excludeId="@android:id/navigationBarBackground" />
</targets>
</fade>
8 changes: 8 additions & 0 deletions app/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@
<item name="android:colorPrimaryDark">#1976D2</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#A5D6A7</item>

<!-- enable window content transitions -->
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>

<!-- specify enter and exit transitions -->
<item name="android:windowEnterTransition">@transition/fade</item>
<item name="android:windowExitTransition">@transition/fade</item>
</style>
</resources>

0 comments on commit 289f15e

Please sign in to comment.