Skip to content

Instantly share code, notes, and snippets.

View PPartisan's full-sized avatar
:octocat:
Focusing

Tom Calver PPartisan

:octocat:
Focusing
View GitHub Profile
@PPartisan
PPartisan / TouchDelegatingRecyclerView.java
Created February 18, 2016 16:25
RecyclerView that passes touch interactions to child ScrollViews based on the ScrollView's content
public class TouchDelegatingRecyclerView extends RecyclerView {
private static final String TAG = TouchDelegatingRecyclerView.class.getSimpleName();
private static final int UP_SWIPE = 803;
private static final int DOWN_SWIPE = UP_SWIPE + 1;
private float originalY = 0;
private int swipeDirection = 0;
@PPartisan
PPartisan / TwoPageParallaxViewPagerActivity.java
Created January 17, 2016 09:06
Quick way of implementing a parallax effect for a ViewPager with two pages
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
MyViewPagerAdapter adapter = new MyViewPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
@PPartisan
PPartisan / ParcelableSpareBooleanArray.java
Created January 9, 2016 14:48
SparseBooleanArray that is also Parcelable
/**
* SparseBooleanArray that is also Parcelable. Had to put this together so I could pass this to a
* {@code Fragment} bundle.
*/
public class ParcelableSparseBooleanArray extends SparseBooleanArray implements Parcelable {
public ParcelableSparseBooleanArray(){
super();
}
@PPartisan
PPartisan / MathUtils.java
Created December 28, 2015 22:13
Short method for determining whether input is a triangular number
public static boolean isTriangularNumber(int number) {
return (((Math.sqrt((8*number)+1)) % 1) == 0)
}
@PPartisan
PPartisan / FloatingActionButtonBehavior.java
Created October 26, 2015 13:22
Auto-Hide Behaviour for the Design Support Library FloatingActionButton
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
public class FloatingActionButtonBehavior {
@PPartisan
PPartisan / PaintUtils.java
Created September 30, 2015 08:29
Utility methods for creating fade animations between two colours
import android.graphics.Color;
public final class PaintUtils {
private PaintUtils() { throw new AssertionError(); }
public static int createInterimColor(int colorFrom, int colorTo, float percentage) {
int[] colorFromArray, colorToArray;
colorFromArray = new int[] {