Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jgilfelt's full-sized avatar

Jeff Gilfelt jgilfelt

  • readyState Software Ltd
  • London, United Kingdom
View GitHub Profile
@MikolajKakol
MikolajKakol / OkHttp provider
Created October 9, 2014 13:46
Proxy+gradle+OkHttp config
@Provides
@Singleton
OkHttpClient okHttpClient() {
OkHttpClient client = new OkHttpClient();
if (BuildConfig.OMIT_HTTPS_SECURITY) {
ignoreHttpsSecurity(client);
}
//noinspection ConstantConditions
if (BuildConfig.HTTP_PROXY_INET != null) {
client.setProxy(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(BuildConfig.HTTP_PROXY_INET, BuildConfig.HTTP_PROXY_PORT)));
@amlcurran
amlcurran / MultiContentAdapter.java
Last active December 11, 2015 03:38
Simple Adapter which can handle multiple input cursors asynchronously (ideal for usage with CursorLoaders)
/* Copyright 2013 Alex Curran
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
distributed under the License is distributed on an "AS IS" BASIS,
@amlcurran
amlcurran / PreferenceMenuItemHelper
Last active December 15, 2015 11:29
Helper class which can associate a checkable MenuItem with a boolean preference
/**
* Copyright 2013 Alex Curran
*
* 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
@amlcurran
amlcurran / LoadHideHelper.java
Last active December 19, 2015 20:09
Utility class which makes it easy to hide and show areas of the UI until the data they represent is loaded. Simply initialise with a Fragment or view(s), and call show() to show, and hide() to hide the UI. You can automatically add a ProgressBar* which will show and hide exactly when you need it to, and even supply your own custom animations by …
/*
* Copyright (c) 2013 Alex Curran
*
* 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
@robUx4
robUx4 / gist:7543300
Last active December 28, 2015 18:29
OrientationDrawable: a Drawable that handles orientation changes without allocating anything updated with a fix when a Matrix is already applied in the canvas
/*
* Copyright (C) 2013 LevelUp Studio
*
* 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
// Underhanded skullduggery to access the keystore daemon.
//
// This is merely a slightly cleaned up implementation of
// http://nelenkov.blogspot.com/2012/05/storing-application-secrets-in-androids.html
// and all credit to Nikolay for digging into this.
package org.kbsriram.android.util;
import android.content.Context;
import android.content.Intent;
/**
* A base class that provides a consistent interface for FormModel-like objects
*/
public abstract class BaseFormModel extends LinearLayout implements FormModel {
protected Context mContext;
public BaseFormModel(Context context) {
super(context);
setup(context);
/**
* Execute an {@link AsyncTask} on a thread pool.
*
* @param task Task to execute.
* @param args Optional arguments to pass to {@link AsyncTask#execute(Object[])}.
* @param <T> Task argument type.
*/
public static <T> void execute(AsyncTask<T, ?, ?> task, T... args) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) {
throw new UnsupportedOperationException("This class can only be used on API 4 and newer.");
@JakeWharton
JakeWharton / ContractFragment.java
Created May 6, 2012 09:12
Base fragment to ensure the parent activity implements a contract interface.
/* Base fragment to ensure the parent activity implements a contract interface. */
public abstract class ContractFragment<T> extends Fragment {
private T mContract;
@Override
public void onAttach(Activity activity) {
try {
mContract = (T)activity;
} catch (ClassCastException e) {
throw new IllegalStateException(activity.getClass().getSimpleName()
@dzolnai
dzolnai / OAuthClient.java
Last active August 18, 2021 07:23
Retrofit OAuth2 refreshing tokens without modifying all requests.
package com.example.yourapp;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.example.yourapp.AuthenticationModel;
import retrofit.client.Header;
import retrofit.client.OkClient;