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 / GridRecyclerView
Last active December 21, 2015 17:03 — forked from Musenkishi/GridRecyclerView
GridRecyclerView. A Grid-specific RecyclerView that can use gridLayoutAnimation.
/*
* Copyright (C) 2014 Freddie (Musenkishi) Lust-Hed
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Unless specified otherwise, all of the below tinting applies to both Lollipop and pre-Lollipop using AppCompat v21.
To use the support version of these attributes, remove the android namespace.
For instance, "android:colorControlNormal" becomes "colorControlNormal".
These attributes will be propagated to their corresponding attributes within the android namespace
for devices running Lollipop. Any exceptions to this will be noted by including the "android:" prefix.
All Clickable Views:
-----------
@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/)
@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 / 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 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);
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 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);
}
@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 / 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