Skip to content

Commit f92ea81

Browse files
committed
CircularTransform rewritten, it's now independent from the original lib. Demo still uses the original reveal.
1 parent 0a403d5 commit f92ea81

File tree

9 files changed

+361
-44
lines changed

9 files changed

+361
-44
lines changed

circulardemo/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ apply plugin: 'com.android.application'
33
android {
44
compileSdkVersion 22
55
buildToolsVersion "22.0.1"
6-
76
defaultConfig {
87
applicationId "hu.gordon.circulardemo"
9-
minSdkVersion 9
8+
minSdkVersion 11
109
targetSdkVersion 22
1110
versionCode 1
1211
versionName "1.0"
@@ -17,6 +16,8 @@ android {
1716
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1817
}
1918
}
19+
productFlavors {
20+
}
2021
}
2122

2223
repositories {
@@ -35,4 +36,5 @@ dependencies {
3536
compile 'com.wada811:android-material-design-colors:2.0.0'
3637
compile 'com.android.support:support-v4:22.1.1'
3738
compile 'com.android.support:cardview-v7:22.1.1'
39+
compile project(':circualreveal')
3840
}

circulardemo/src/main/java/hu/gordon/circulardemo/fragments/TransformFrameFragment.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hu.gordon.circulardemo.fragments;
22

33

4+
import android.animation.Animator;
45
import android.app.Activity;
56
import android.graphics.Point;
67
import android.os.Bundle;
@@ -15,15 +16,14 @@
1516

1617
import com.shamanland.fab.FloatingActionButton;
1718

19+
import hu.aut.utillib.circular.animation.ViewAnimationUtils;
1820
import hu.gordon.circulardemo.MainActivity;
1921
import hu.gordon.circulardemo.R;
20-
import io.codetail.animation.SupportAnimator;
21-
import io.codetail.animation.TransformViewAnimationUtils;
2222

2323
/**
2424
* A simple {@link Fragment} subclass.
2525
*/
26-
public class TransformFrameFragment extends Fragment implements SupportAnimator.AnimatorListener {
26+
public class TransformFrameFragment extends Fragment implements Animator.AnimatorListener {
2727

2828
public static final String TAG = TransformFrameFragment.class.getSimpleName();
2929

@@ -99,11 +99,11 @@ public void onClick(View view) {
9999
// Pre-calculations
100100
//
101101
// get the final radius for the clipping circle
102-
float finalRadius = TransformViewAnimationUtils.hypo(screenWidth, screenHeight);
103-
int[] center = TransformViewAnimationUtils.getCenter(fab,myTargetView);
102+
float finalRadius = ViewAnimationUtils.hypo(screenWidth, screenHeight);
103+
int[] center = ViewAnimationUtils.getCenter(fab,myTargetView);
104104

105-
SupportAnimator animator =
106-
TransformViewAnimationUtils.createCircularTransform(myTargetView, mySourceView, center[0], center[1], 0F, finalRadius);
105+
Animator animator =
106+
ViewAnimationUtils.createCircularTransform(myTargetView, mySourceView, center[0], center[1], 0F, finalRadius);
107107

108108
animator.addListener(TransformFrameFragment.this);
109109

@@ -123,26 +123,26 @@ public void onAttach(Activity activity) {
123123
}
124124

125125
@Override
126-
public void onAnimationStart() {
126+
public void onAnimationStart(Animator animator) {
127127
Log.d(TAG, "animation start");
128128
myTargetView.setVisibility(View.VISIBLE);
129129
animationInProgress = true;
130130
}
131131

132132
@Override
133-
public void onAnimationEnd() {
133+
public void onAnimationEnd(Animator animator) {
134134
Log.d(TAG, "animation end");
135135
mySourceView.setVisibility(View.INVISIBLE);
136136
animationInProgress = false;
137137
}
138138

139139
@Override
140-
public void onAnimationCancel() {
140+
public void onAnimationCancel(Animator animator) {
141141

142142
}
143143

144144
@Override
145-
public void onAnimationRepeat() {
145+
public void onAnimationRepeat(Animator animator) {
146146

147147
}
148148
}

circulardemo/src/main/res/layout/fragment_transform_frame.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
android:background="@color/md_amber_400"
77
tools:context="hu.gordon.circulardemo.fragments.RevealFrameFragment">
88

9-
<io.codetail.widget.TransformFrameLayout
9+
<hu.aut.utillib.circular.widget.TransformFrameLayout
1010
android:id="@+id/transform"
1111
android:layout_width="match_parent"
1212
android:layout_height="match_parent"
@@ -31,7 +31,7 @@
3131
tools:ignore="contentDescription" />
3232

3333

34-
</io.codetail.widget.TransformFrameLayout>
34+
</hu.aut.utillib.circular.widget.TransformFrameLayout>
3535

3636
<com.shamanland.fab.FloatingActionButton
3737
android:id="@+id/fab"

circulartransform/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ apply plugin: 'com.android.library'
33
android {
44
compileSdkVersion 22
55
buildToolsVersion "22.0.1"
6-
76
defaultConfig {
8-
minSdkVersion 9
7+
minSdkVersion 11
98
targetSdkVersion 22
109
versionCode 1
1110
versionName "1.0"
@@ -16,8 +15,9 @@ android {
1615
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1716
}
1817
}
18+
productFlavors {
19+
}
1920
}
2021

2122
dependencies {
22-
compile project(':circualreveal')
2323
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package hu.aut.utillib.circular.animation;
2+
3+
import android.animation.Animator;
4+
import android.annotation.TargetApi;
5+
import android.graphics.Rect;
6+
import android.os.Build;
7+
import android.view.View;
8+
9+
import java.lang.ref.WeakReference;
10+
11+
import static hu.aut.utillib.circular.animation.ViewAnimationUtils.SimpleAnimationListener;
12+
13+
/**
14+
* @hide
15+
*/
16+
public interface CircularAnimator {
17+
18+
19+
/**
20+
* Whether enable {@link android.graphics.Canvas} to clip
21+
* outlines of the certain or not
22+
*
23+
* @param clip Whether clip outlines or not
24+
*
25+
* @see #setCenter(int, int)
26+
* @see #setRevealRadius(float)
27+
* @see #setTarget(View)
28+
*/
29+
void setClipOutlines(boolean clip);
30+
31+
/**
32+
* Sets central points where to start clipping
33+
* certain child
34+
*
35+
* @param cx x point of child
36+
* @param cy y point of child
37+
*
38+
* @see #setClipOutlines(boolean) (float, float)
39+
* @see #setRevealRadius(float)
40+
* @see #setTarget(View)
41+
*/
42+
void setCenter(int cx, int cy);
43+
44+
/**
45+
* Reference the target of reveal animation
46+
*
47+
* @param target View to clip outlines
48+
*/
49+
void setTarget(View target);
50+
51+
/**
52+
* Used with animator to animate view clipping
53+
*
54+
* @param value clip radius
55+
*/
56+
void setRevealRadius(float value);
57+
58+
/**
59+
* Used with animator to animate view clipping
60+
*
61+
* @return current radius
62+
*/
63+
float getRevealRadius();
64+
65+
/**
66+
* Invalidate certain rectangle
67+
*
68+
* @param bounds bounds to redraw
69+
*/
70+
void invalidate(Rect bounds);
71+
72+
/**
73+
* Temporarily
74+
*/
75+
void setupStartValues();
76+
77+
/**
78+
* Keep this value for reverse animation
79+
*
80+
* @param start The start value of clip radius
81+
* @param end The end value
82+
*/
83+
void setRadius(float start, float end);
84+
85+
Rect getTargetBounds();
86+
87+
88+
//TODO WTF does this here?
89+
class RevealFinishedHoneycomb extends SimpleAnimationListener {
90+
WeakReference<CircularAnimator> mReference;
91+
volatile Rect mInvalidateBounds;
92+
93+
RevealFinishedHoneycomb(CircularAnimator target, Rect bounds) {
94+
mReference = new WeakReference<>(target);
95+
mInvalidateBounds = bounds;
96+
}
97+
98+
@Override
99+
public void onAnimationEnd(Animator animation) {
100+
CircularAnimator target = mReference.get();
101+
target.setupStartValues();
102+
target.invalidate(mInvalidateBounds);
103+
}
104+
}
105+
106+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
107+
class RevealFinishedIceCreamSandwich extends RevealFinishedHoneycomb {
108+
int mFeaturedLayerType;
109+
int mLayerType;
110+
111+
RevealFinishedIceCreamSandwich(CircularAnimator target, Rect bounds) {
112+
super(target, bounds);
113+
114+
mLayerType = ((View) target).getLayerType();
115+
mFeaturedLayerType = View.LAYER_TYPE_SOFTWARE;
116+
}
117+
118+
@Override
119+
public void onAnimationCancel(Animator animation) {
120+
onAnimationEnd(animation);
121+
}
122+
123+
@Override
124+
public void onAnimationStart(Animator animation) {
125+
((View) mReference.get()).setLayerType(mFeaturedLayerType, null);
126+
}
127+
128+
@Override
129+
public void onAnimationEnd(Animator animation) {
130+
((View) mReference.get()).setLayerType(mLayerType, null);
131+
super.onAnimationEnd(animation);
132+
}
133+
}
134+
135+
class RevealFinishedJellyBeanMr2 extends RevealFinishedIceCreamSandwich {
136+
137+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
138+
RevealFinishedJellyBeanMr2(CircularAnimator target, Rect bounds) {
139+
super(target, bounds);
140+
141+
mFeaturedLayerType = View.LAYER_TYPE_HARDWARE;
142+
}
143+
}
144+
145+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package hu.aut.utillib.circular.animation;
2+
3+
import android.view.View;
4+
5+
public interface TransformAnimator extends CircularAnimator {
6+
7+
void setSource(View target);
8+
9+
}

0 commit comments

Comments
 (0)