-
-
Save gabornovakp/1d92c764dddf11d214ac9d782f39c895 to your computer and use it in GitHub Desktop.
public class AnimationUtils { | |
public static void registerCircularRevealAnimation(final Context context, final View view, final RevealAnimationSetting revealSettings, final int startColor, final int endColor) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { | |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
@Override | |
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { | |
v.removeOnLayoutChangeListener(this); | |
int cx = revealSettings.getCenterX(); | |
int cy = revealSettings.getCenterY(); | |
int width = revealSettings.getWidth(); | |
int height = revealSettings.getHeight(); | |
int duration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime); | |
//Simply use the diagonal of the view | |
float finalRadius = (float) Math.sqrt(width * width + height * height); | |
Animator anim = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, finalRadius).setDuration(duration); | |
anim.setInterpolator(new FastOutSlowInInterpolator()); | |
anim.start(); | |
startColorAnimation(view, startColor, endColor, duration); | |
} | |
}); | |
} | |
} | |
static void startColorAnimation(final View view, final int startColor, final int endColor, int duration) { | |
ValueAnimator anim = new ValueAnimator(); | |
anim.setIntValues(startColor, endColor); | |
anim.setEvaluator(new ArgbEvaluator()); | |
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | |
@Override | |
public void onAnimationUpdate(ValueAnimator valueAnimator) { | |
view.setBackgroundColor((Integer) valueAnimator.getAnimatedValue()); | |
} | |
}); | |
anim.setDuration(duration); | |
anim.start(); | |
} | |
} | |
//... | |
// Parcelable RevealAnimationSettings with AutoValue | |
@AutoValue | |
public abstract class RevealAnimationSetting implements Parcelable { | |
public abstract int getCenterX(); | |
public abstract int getCenterY(); | |
public abstract int getWidth(); | |
public abstract int getHeight(); | |
public static RevealAnimationSetting with(int centerX, int centerY, int width, int height) { | |
return new AutoValue_RevealAnimationSetting(centerX, centerY, width, height); | |
} | |
} |
I get the same error too. Any idea how to fix it?
-
Add these to your app level gradle file.
annotationProcessor 'com.google.auto.value:auto-value:1.4'
provided 'com.jakewharton.auto.value:auto-value-annotations:1.4'
annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
- also the abstract class must be made
static
- build the project (to let AutoValue do its thing)
- type the
return new AutoValue_
and look for suggestions by the IDE and choose the appropriate one.
This should help you out!!
still getting same error.
Whoever is getting error please create your own class like this inner or separate whatever you prefer:
first listen to what Rumaan said, add this to your gradle:
annotationProcessor 'com.google.auto.value:auto-value:1.4'
provided 'com.jakewharton.auto.value:auto-value-annotations:1.4'
annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
and then create an abstract class:
private abstract static class AutoValue_RevealAnimationSetting extends RevealAnimationSetting {
AutoValue_RevealAnimationSetting(int centerX, int centerY, int width, int height) {
super();
}
}
and then just implement the methods when returning like this:
public static RevealAnimationSetting with(int centerX, int centerY, int width, int height) {
return new AutoValue_RevealAnimationSetting(centerX, centerY, width, height) {
@OverRide
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
@Override
public int getCenterX() {
return 0;
}
@Override
public int getCenterY() {
return 0;
}
@Override
public int getWidth() {
return 0;
}
@Override
public int getHeight() {
return 0;
}
};
}
Now the error should go away. Happy coding :))
I solved this issue by following the above solutions,
Added in my build.gradle
annotationProcessor 'com.google.auto.value:auto-value:1.5.2'
compileOnly 'com.jakewharton.auto.value:auto-value-annotations:1.4'
annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
My class RevealAnimationSetting looks like,
`@AutoValue
public abstract class RevealAnimationSetting implements Parcelable {
public abstract int getCenterX();
public abstract int getCenterY();
public abstract int getWidth();
public abstract int getHeight();
public static RevealAnimationSetting with(int centerX, int centerY, int width, int height) {
return new AutoValue_RevealAnimationSetting(centerX, centerY, width, height) {
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
@Override
public int getCenterX() {
return centerX;
}
@Override
public int getCenterY() {
return centerY;
}
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
};
}
private abstract static class AutoValue_RevealAnimationSetting extends RevealAnimationSetting {
AutoValue_RevealAnimationSetting(int centerX, int centerY, int width, int height) {
super();
}
}
}`
This class gives me the following error:
Any idea how to fix this @gabornovakp ?