Skip to content

Commit 71083d5

Browse files
committed
Fixed issue with LayerType.SOFTWARE and LayerType.HARDWARE. +minor changes.
1 parent cf20561 commit 71083d5

File tree

1 file changed

+56
-20
lines changed

1 file changed

+56
-20
lines changed

circulartransform/src/main/java/hu/aut/utillib/circular/animation/ViewAnimationUtils.java

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.animation.Animator;
44
import android.animation.Animator.AnimatorListener;
55
import android.animation.ObjectAnimator;
6+
import android.os.Build;
67
import android.view.View;
78

89
import java.lang.ref.WeakReference;
@@ -84,7 +85,7 @@ public static ObjectAnimator createCircularTransform(View target, View source, i
8485
}
8586

8687
if (!(target.getParent() instanceof CircularAnimator)) {
87-
throw new IllegalArgumentException("View must be inside TransformFrameLayout");
88+
throw new IllegalArgumentException("View must be inside CircularFrameLayout");
8889
}
8990

9091
CircularAnimator transformLayout = (CircularAnimator) target.getParent();
@@ -95,16 +96,13 @@ public static ObjectAnimator createCircularTransform(View target, View source, i
9596

9697
ObjectAnimator transform = ObjectAnimator.ofFloat(transformLayout, CLIP_RADIUS, startRadius, endRadius);
9798

98-
if (mode == MANUAL) {
99-
return transform;
99+
if (source == null) {
100+
transform.addListener(new RevealListener(target, mode));
100101
} else {
101-
if (source == null) {
102-
transform.addListener(new RevealListener(target));
103-
} else {
104-
transform.addListener(new TransformListener(target, source));
105-
}
106-
return transform;
102+
transform.addListener(new TransformListener(target, source, mode));
107103
}
104+
105+
return transform;
108106
}
109107

110108

@@ -146,17 +144,36 @@ public static float hypo(int a, int b) {
146144
return (float) Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
147145
}
148146

147+
public static boolean isHWAsupportedForReveal() {
148+
return (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2 || Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT);
149+
}
150+
151+
public static boolean isHWAsupportedForTransform() {
152+
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2);
153+
}
149154

150-
static class RevealListener implements AnimatorListener {
151-
WeakReference<View> mTargetReference;
152155

153-
RevealListener(View target) {
154-
mTargetReference = new WeakReference<>(target);
156+
static class RevealListener implements AnimatorListener {
157+
int originalLayerType;
158+
int mode;
159+
WeakReference<View> targetReference;
160+
WeakReference<CircularFrameLayout> parentReference;
161+
162+
RevealListener(View target, int mode) {
163+
targetReference = new WeakReference<>(target);
164+
parentReference = new WeakReference<>((CircularFrameLayout) targetReference.get().getParent());
165+
originalLayerType = ((CircularFrameLayout)target.getParent()).getLayerType();
166+
this.mode = mode;
155167
}
156168

157169
@Override
158170
public void onAnimationStart(Animator animation) {
159-
mTargetReference.get().setVisibility(View.VISIBLE);
171+
if (!isHWAsupportedForReveal()) {
172+
parentReference.get().setLayerType(View.LAYER_TYPE_SOFTWARE, null);
173+
}
174+
if(mode == AUTOMATIC) {
175+
targetReference.get().setVisibility(View.VISIBLE);
176+
}
160177
}
161178

162179
@Override
@@ -166,7 +183,9 @@ public void onAnimationEnd(Animator animation) {
166183

167184
@Override
168185
public void onAnimationCancel(Animator animation) {
169-
186+
if (!isHWAsupportedForReveal()) {
187+
parentReference.get().setLayerType(originalLayerType, null);
188+
}
170189
}
171190

172191
@Override
@@ -176,16 +195,33 @@ public void onAnimationRepeat(Animator animation) {
176195
}
177196

178197
static class TransformListener extends RevealListener {
179-
WeakReference<View> mSourceReference;
198+
WeakReference<View> sourceReference;
180199

181-
TransformListener(View target, View source) {
182-
super(target);
183-
mSourceReference = new WeakReference<>(source);
200+
TransformListener(View target, View source, int mode) {
201+
super(target,mode);
202+
sourceReference = new WeakReference<>(source);
203+
}
204+
205+
206+
@Override
207+
public void onAnimationStart(Animator animation) {
208+
if (!isHWAsupportedForTransform()) {
209+
parentReference.get().setLayerType(View.LAYER_TYPE_SOFTWARE, null);
210+
}
211+
if(mode == AUTOMATIC) {
212+
targetReference.get().setVisibility(View.VISIBLE);
213+
}
184214
}
185215

186216
@Override
187217
public void onAnimationEnd(Animator animation) {
188-
mSourceReference.get().setVisibility(View.INVISIBLE);
218+
if (!isHWAsupportedForTransform()) {
219+
parentReference.get().setLayerType(originalLayerType, null);
220+
}
221+
if(mode == AUTOMATIC) {
222+
sourceReference.get().setVisibility(View.INVISIBLE);
223+
}
189224
}
190225
}
226+
191227
}

0 commit comments

Comments
 (0)