Skip to content

Instantly share code, notes, and snippets.

@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) {
...
@yuriyskulskiy
yuriyskulskiy / NestedScrollView.java
Last active July 28, 2020 00:18
Overscrolling: add pulling hand
...
private Bitmap mBitmap;
...
private void initScrollView() {
...
Resources res = getResources();
mBitmap = BitmapFactory.decodeResource(res, R.drawable.hand_rope);
mBitmap = Bitmap.createScaledBitmap(mBitmap, mBitmap.getWidth() / 2,
mBitmap.getHeight() / 2, false);
}
@yuriyskulskiy
yuriyskulskiy / activity_main.xml
Created July 27, 2020 23:42
Overscrolling: add background and elevation
...
<com.example.replica.NestedScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/overscroll_background">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="8dp"
@yuriyskulskiy
yuriyskulskiy / NestedScrollView.java
Created July 27, 2020 23:01
Overscrolling: remove edge effect
private boolean useEdgeEffect = false;
...
@Override
public boolean onTouchEvent(MotionEvent ev) {
...
// if (canOverscroll) {
if (useEdgeEffect) {
deltaY -= mScrollConsumed[1];