Skip to content

Instantly share code, notes, and snippets.

🤓
Focusing

Tom Calver PPartisan

🤓
Focusing
Block or report user

Report or block PPartisan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@PPartisan
PPartisan / MainActivity.java
Created Nov 2, 2016
Quick sample layout for a login screen using support libraries
View MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
@PPartisan
PPartisan / SwitchCompatStateListUtils.java
Last active Sep 10, 2018
Utility methods that create a ColorStateList for use with SwitchCompat. Allows for dynamic colour changes.
View SwitchCompatStateListUtils.java
private static final int SWITCH_STATE_LIST_ALPHA = (int)(0.3f*255);
public static ColorStateList buildSwitchCompatColorStateListFromResId(
Context context, int activatedColorResId) {
return buildSwitchCompatColorStateList(
context, ContextCompat.getColor(context, activatedColorResId)
);
}
public static ColorStateList buildSwitchCompatColorStateList(Context context, int activatedColor) {
@PPartisan
PPartisan / DataModel.java
Created Oct 13, 2016
Supporting code for a Quora question regarding how to notify a caller that a method must be run off the UI thread.
View DataModel.java
%package com.github.ppartisan.watchface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.wearable.Asset;
import com.google.android.gms.wearable.DataItem;
@PPartisan
PPartisan / AndroidManifest.xml
Created Sep 19, 2016
Demo for an Android app that interacts with the browser and its bookmarks (API < 22)
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.ppartisan.bookmarklet">
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
@PPartisan
PPartisan / SpannedStringUtils.java
Created Jul 21, 2016
Method for converting text to a SpannableString, depending on
View SpannedStringUtils.java
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);
}
}
View ReverseCharArray.java
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 / WhatsAbubbleSort.java
Created Apr 14, 2016
Someone asked me to make a "Bubble Sort" algorithm. So...
View WhatsAbubbleSort.java
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 };
@PPartisan
PPartisan / SlowAutoSwipeViewPager.java
Last active Mar 16, 2016
Slightly altered ViewPager that has a more natural speed when executing a programmatic swipe between pages
View SlowAutoSwipeViewPager.java
public class SlowAutoSwipeViewPager extends ViewPager {
public SlowAutoSwipeViewPager(Context context) {
super(context);
}
public SlowAutoSwipeViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@PPartisan
PPartisan / TouchDelegatingRecyclerView.java
Created Feb 18, 2016
RecyclerView that passes touch interactions to child ScrollViews based on the ScrollView's content
View TouchDelegatingRecyclerView.java
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 Jan 17, 2016
Quick way of implementing a parallax effect for a ViewPager with two pages
View TwoPageParallaxViewPagerActivity.java
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);
You can’t perform that action at this time.