Skip to content

Instantly share code, notes, and snippets.

View patrick-elmquist's full-sized avatar

Patrick Elmquist patrick-elmquist

View GitHub Profile
@patrick-elmquist
patrick-elmquist / example.java
Last active May 5, 2021 11:44
Enter animation demo: Re run LayoutAnimation
private void runLayoutAnimation(final RecyclerView recyclerView) {
final Context context = recyclerView.getContext();
final LayoutAnimationController controller =
AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation_fall_down);
recyclerView.setLayoutAnimation(controller);
recyclerView.getAdapter().notifyDataSetChanged();
recyclerView.scheduleLayoutAnimation();
}
@patrick-elmquist
patrick-elmquist / layout_animation_fall_down.xml
Last active July 26, 2017 18:05
Enter animation demo: Fall down LayoutAnimation
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation
xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/item_animation_fall_down"
android:delay="15%"
android:animationOrder="normal"
/>
@patrick-elmquist
patrick-elmquist / item_animation_fall_down.xml
Last active November 27, 2020 21:12
Enter animation demo: Fall Down item animation
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@integer/anim_duration_medium">
<translate
android:fromYDelta="-20%"
android:toYDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
/>
<alpha
@patrick-elmquist
patrick-elmquist / example.java
Last active July 26, 2017 18:04
Enter animation demo: Apply a LayoutAnimation
int resId = R.anim.layout_animation_fall_down;
LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(ctx, resId);
recyclerview.setLayoutAnimation(animation);
@patrick-elmquist
patrick-elmquist / SpinnerLoaderView.java
Last active July 12, 2017 13:26
Frame by frame #5
@Override
protected void onDraw(Canvas canvas) {
// 1. The size of the base circle
// 2. Where the arc starts in degrees
// 3. The size of the arc in degrees, starting at #2
// 4. If the arc should be drawn as a pie, false makes it a stroke
// 5. The paint to use
canvas.drawArc(mArcBounds, mArcStart, mArcSize, false, mPaint);
}
public class SpinnerLoaderView extends View {
private final RectF mArcBounds = new RectF();
private final Paint mPaint = new Paint();
// ...
@Override
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
super.onSizeChanged(width, height, oldWidth, oldHeight);
@patrick-elmquist
patrick-elmquist / SpinnerLoaderView.java
Last active August 18, 2019 12:33
Frame by frame #3
private float calculateArcSize(float animationProgress) {
final double adjustedProgress = Math.sin(animationProgress * Math.PI);
// ARC_MAX_DEGREES is the maximum size the arc will have in degrees.
// ARC_MAX_DEGREES = 180 means that at it's largest it will cover
// half the circle.
return (float) adjustedProgress * -ARC_MAX_DEGREES;
}
private float calculateArcStart(float animationProgress) {
final float deceleratedProgress = mDecelerateInterpolator.getInterpolation(animationProgress);
@patrick-elmquist
patrick-elmquist / SpinnerLoaderView.java
Last active July 12, 2017 13:57
Frame by frame #2
public class SpinnerLoaderView extends View {
private static final long ANIMATION_DURATION = 1250L;
private ValueAnimator mAnimator;
private float mArcStart;
private float mArcSize;
// ...
@patrick-elmquist
patrick-elmquist / SpinnerLoaderView.java
Last active July 11, 2017 19:51
Frame by frame #1
public class SpinnerLoaderView extends View {
private final Paint mPaint = new Paint();
/** @see View#View(Context) */
public SpinnerLoaderView(Context context) {
super(context);
init();
}
@patrick-elmquist
patrick-elmquist / pre-commit
Created March 8, 2017 18:41 — forked from kaushikgopal/pre-commit
pre-commit git hook - no "hacking"
#!/usr/bin/env ruby
# This pre-commit hook will prevent any commit to forbidden branches
# (by default, "staging" and "production").
# Put this file in your local repo, in the .git/hooks folder
# and make sure it is executable.
# The name of the file *must* be "pre-commit" for Git to pick it up.
def current_branch()
branches = `git branch --no-color`.split(/\n/)