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 / 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[] {
@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 / 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 / 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 / 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 / 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 / SlowAutoSwipeViewPager.java
Last active March 16, 2016 13:04
Slightly altered ViewPager that has a more natural speed when executing a programmatic swipe between pages
public class SlowAutoSwipeViewPager extends ViewPager {
public SlowAutoSwipeViewPager(Context context) {
super(context);
}
public SlowAutoSwipeViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@PPartisan
PPartisan / WhatsAbubbleSort.java
Created April 14, 2016 18:33
Someone asked me to make a "Bubble Sort" algorithm. So...
import java.util.*;
import java.lang.*;
import java.io.*;
class WhatsAbubbleSort {
public static void main (String[] args) throws java.lang.Exception {
final int[] unsorted = new int[] { 23, 25, 7, 13, 94, 11 };
public static char[] reverseCharArray(char[] input){
char[] output = new char[input.length];
char temp;
int index = 0;
for (int i = (output.length - 1); i >= (output.length/2); i--) {
temp = input[i];
output[i] = input[index];
output[index] = temp;
@PPartisan
PPartisan / SpannedStringUtils.java
Created July 21, 2016 09:32
Method for converting text to a SpannableString, depending on
private static SpannableString getSpannedString(String text, char... triggers) {
SpannableString spanString = new SpannableString(text);
for (int i = 0; i < spanString.length(); i++) {
for (char trigger : triggers) {
if (spanString.charAt(i) == trigger) {
spanString.setSpan(new ForegroundColorSpan(Color.CYAN), i, i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}