Skip to content

Instantly share code, notes, and snippets.

@yuriyskulskiy
yuriyskulskiy / AnimatedLayout.java
Last active August 20, 2020 22:52
AnimatedLayout part 3: add additional const and fields
private float MIN_FLING_START_VELOCITY_DP = 500;
private float mCurrentMinFlingVelocityPx;
private VelocityTracker mVelocityTracker;
private boolean isTouching = false;
private FlingAnimation mFling = new FlingAnimation(this,
new FloatPropertyCompat<AnimatedLayout>("offset") {
@Override
public float getValue(AnimatedLayout object) {
@yuriyskulskiy
yuriyskulskiy / AnimatedLayout.java
Created August 14, 2020 17:49
AnimatedLayout_part_2 update child during scrolling
private void updateOffset(float newOffsetValue) {
...
updateIconView();
}
private void updateIconView() {
float oldTranslatePosition = mWeatherIcon.getTranslationX();
float newTranslatePosition;
float newAlpha;
@yuriyskulskiy
yuriyskulskiy / AnimatedLayout.java
Last active August 14, 2020 17:16
AnimatedLayout_part_2 exclude from screenshot and clipping
public class AnimatedLayout extends ConstraintLayout {
...
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
if (canvas instanceof ScreenShotCanvas) {
if (isChildExcluded(child)) {
// do not draw this child to the screenshot canvas
return false;
}
return super.drawChild(canvas, child, drawingTime);
@yuriyskulskiy
yuriyskulskiy / AnimatedLayout.java
Last active August 16, 2020 00:28
AnimatedLayout part 2: add additional view into the layout class.
public class AnimatedLayout extends ConstraintLayout {
...
private CircleImageView mWeatherIcon;
...
@Override
protected void onFinishInflate() {
super.onFinishInflate();
...
mWeatherIcon = findViewById(R.id.weatherIconIV);
@yuriyskulskiy
yuriyskulskiy / tranform_item.xml
Created August 14, 2020 16:30
AnimatedLayout part 2: add additional child to layout
<?xml version="1.0" encoding="utf-8"?>
<com.example.animated.article.custom.AnimatedLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/transformItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@yuriyskulskiy
yuriyskulskiy / GlowingEdgeEffect.java
Created August 13, 2020 13:32
GlowingEdgeEffect: modify draw()
public boolean draw(Canvas canvas) {
canvas.clipRect(mBounds.left,
mBounds.top,
mBounds.right,
mBounds.bottom + mBounds.bottom * BlUR_RADIUS_FACTOR);
...
// mPaint.setAlpha((int) (0xff * mGlowAlpha)); alpha is not going to be changed during animation
...
}
public void setSize(int width, int height) {
...
mPaint.setMaskFilter(new BlurMaskFilter(mBounds.bottom * BlUR_RADIUS_FACTOR,
BlurMaskFilter.Blur.NORMAL));
}
@yuriyskulskiy
yuriyskulskiy / GlowingEdgeEffectFactory.java
Created August 13, 2020 13:00
GlowingEdgeEffect: add custom faotory
public class GlowingEdgeEffectFactory extends RecyclerView.EdgeEffectFactory {
@NonNull
@Override
protected EdgeEffect createEdgeEffect(@NonNull RecyclerView view, int direction) {
return new GlowingEdgeEffect(view.getContext());
}
}
@yuriyskulskiy
yuriyskulskiy / DistortEdgeEffect.java
Created August 11, 2020 15:20
Distort edge effect: implement distorting
public class DistortEdgeEffect {
...
private static final float RADIUS_FACTOR = 1f; //not nessesary but I have changed it from 0.6 to 1
private final int HORIZONTAL_STEPS_COUNT = 40; // as more steps as more smoother it looks
private float[] mDistrotedVertices;
private float mStepWidth;
...
public void setSize(int width, int height) {
...
@yuriyskulskiy
yuriyskulskiy / DistortEdgeEffect.java
Created August 11, 2020 11:05
Distort edge effect: custom circular edge equation
public class DistortEdgeEffect {
...
private int mFulHeight;
private int mFullWidth;
private float maxDistortionHeight;
...
public void setSize(int width, int height) {
...