Skip to content

Instantly share code, notes, and snippets.

@jkreiser
jkreiser / Interceptor.java
Created May 20, 2019 — forked from alex-shpak/Interceptor.java
Refreshing OAuth token with okhttp interceptors. All requests will wait until token refresh finished, and then will continue with the new token.
View Interceptor.java
private class HttpInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
//Build new request
Request.Builder builder = request.newBuilder();
builder.header("Accept", "application/json"); //if necessary, say to consume JSON
View android_material_design_colours.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- google's material design colours from
http://www.google.com/design/spec/style/color.html#color-ui-color-palette -->
<!--reds-->
<color name="md_red_50">#FFEBEE</color>
<color name="md_red_100">#FFCDD2</color>
<color name="md_red_200">#EF9A9A</color>
@jkreiser
jkreiser / account-manager-remove-account-helper.kt
Last active Jan 25, 2018
Utility method for calling the correct AccountManager.removeAccount() - Kotlin
View account-manager-remove-account-helper.kt
/*
Copyright 2018 Michigan Software Labs, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@jkreiser
jkreiser / account-manager-remove-account-helper.java
Last active Jan 25, 2018
Utility method for calling the correct AccountManager.removeAccount() - Java
View account-manager-remove-account-helper.java
/*
Copyright 2018 Michigan Software Labs, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
View Android Color Control Cheat Sheet
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:
-----------
@jkreiser
jkreiser / android_lifecycle_recommendations.md
Created Jun 2, 2017 — forked from kaushikgopal/android_lifecycle_recommendations.md
Notes on opportune moments to do "stuff" in the Android Lifecycle
View android_lifecycle_recommendations.md
  • In general you want to try and put things in onStart and onStop for logical start and stops.

Activity

onCreate

  • Dagger inject self into graph
  • setContentView(R.layout.xxx)
  • Butterknife.bind(this)
  • RxJava CompositeSubscription.add (if NON UI related work being done)
  • realm = Realm.getDefaultInstance();
@jkreiser
jkreiser / LocationExampleActivity.java
Created Aug 14, 2014
Android - LocationClient example
View LocationExampleActivity.java
import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
View MyActivity.java
package com.example.SlidingGestureExample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
@jkreiser
jkreiser / CaptionButton.java
Created Feb 25, 2014
Android - Custom Component - Caption Button
View CaptionButton.java
package com.yourpackagename;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;