Skip to content

Instantly share code, notes, and snippets.

@sephiroth74
Created March 4, 2015 05:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sephiroth74/6a9c4229a6099ad14fc6 to your computer and use it in GitHub Desktop.
Save sephiroth74/6a9c4229a6099ad14fc6 to your computer and use it in GitHub Desktop.
Circular Reveal Transition
<transition
class="it.sephiroth.android.library.myapplication.Reveal"
app:centerX="25%p"
app:centerY="50%p">
<targets>
<target android:targetId="@id/container" />
</targets>
</transition>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Reveal">
<attr name="centerX" format="fraction"/>
<attr name="centerY" format="fraction"/>
</declare-styleable>
</resources>
package it.sephiroth.android.library.myapplication;
import android.animation.Animator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.transition.TransitionValues;
import android.transition.Visibility;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
@TargetApi (Build.VERSION_CODES.LOLLIPOP)
public class Reveal extends Visibility {
private static final String TAG = "Reveal";
private static final float DEFAULT_CENTER = 0.5f;
private float centerX;
private float centerY;
public Reveal() {
setCenterX(DEFAULT_CENTER);
setCenterY(DEFAULT_CENTER);
}
public Reveal(final Context context, final AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Reveal);
float cx = a.getFraction(R.styleable.Reveal_centerX, 1, 1, DEFAULT_CENTER);
float cy = a.getFraction(R.styleable.Reveal_centerY, 1, 1, DEFAULT_CENTER);
a.recycle();
setCenterX(cx);
setCenterY(cy);
}
public void setCenterX(final float centerX) {
this.centerX = centerX;
}
public void setCenterY(final float centerY) {
this.centerY = centerY;
}
@Override
public Animator onAppear(
final ViewGroup sceneRoot, final View view, final TransitionValues startValues, final TransitionValues endValues) {
final int width = view.getWidth();
final int height = view.getHeight();
int cx = (int) ((width) * centerX);
int cy = (int) ((height) * centerY);
int distance;
if (width > height) {
distance = Math.max(width - cx, cx);
} else {
distance = Math.max(height - cy, cy);
}
return ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, (float) distance);
}
@Override
public Animator onDisappear(
final ViewGroup sceneRoot, final View view, final TransitionValues startValues, final TransitionValues endValues) {
final int width = view.getWidth();
final int height = view.getHeight();
int cx = (int) ((width) * centerX);
int cy = (int) ((height) * centerY);
int distance;
if (width > height) {
distance = Math.max(width - cx, cx);
} else {
distance = Math.max(height - cy, cy);
}
return ViewAnimationUtils.createCircularReveal(view, cx, cy, (float) distance, 0);
}
}
@ndorigatti
Copy link

seems to not work with Imageviews... any more sample?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment