Skip to content

Instantly share code, notes, and snippets.

@gabornovakp
Last active December 12, 2019 06:47
Show Gist options
  • Save gabornovakp/1d92c764dddf11d214ac9d782f39c895 to your computer and use it in GitHub Desktop.
Save gabornovakp/1d92c764dddf11d214ac9d782f39c895 to your computer and use it in GitHub Desktop.
Circular reveal animation
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);
}
}
@faisalahsan
Copy link

still getting same error.

@HashemDeveloper
Copy link

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 :))

@hardik073
Copy link

hardik073 commented Oct 8, 2019

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();
    }
}

}`

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