Skip to content

Instantly share code, notes, and snippets.

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class FadableLinearLayout extends LinearLayout {
@mr-archano
mr-archano / SerialAsyncTask
Created March 13, 2013 11:18
Quick & dirty copy of AsyncTask class using serial executor even on legacy Android versions. - Just get rid of all references to AsyncTask and replace them with SerialAsyncTask instead - Changed SerialExecutor.mTasks type from ArrayDeque to a simple LinkedList
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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
@mr-archano
mr-archano / root project build.gradle
Last active January 14, 2016 21:43
The idea is to create an android test module (eg: `tests`) with a dependency on the main android module (eg: `app`). With a little setup you can easily run unit tests (in your `tests/androidTest` folder) on the JVM and hava JaCoCo reports altogether.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
@mr-archano
mr-archano / AccountAuthenticator.java
Created January 16, 2016 11:40 — forked from burgalon/AccountAuthenticator.java
Implementing OAuth2 with AccountManager, Retrofit and Dagger
public class AccountAuthenticator extends AbstractAccountAuthenticator {
private final Context context;
@Inject @ClientId String clientId;
@Inject @ClientSecret String clientSecret;
@Inject ApiService apiService;
public AccountAuthenticator(Context context) {
super(context);
@mr-archano
mr-archano / howto.md
Created February 13, 2016 15:09 — forked from neworld/howto.md
How to make faster Android build without sacrificing new api lint check

Original solution sacrifices new api lint check.

Here my solution:

int minSdk = hasProperty('minSdk') ? minSdk.toInteger() : 16

apply plugin: 'com.android.application'

android {
 compileSdkVersion 23
@mr-archano
mr-archano / RxponetialBackoff
Created February 16, 2016 17:54 — forked from sddamico/LICENSE
Exponential Backoff Transformer
/**
* @param interval The base interval to start backing off from. The function is: attemptNum^2 * intervalTime
* @param units The units for interval
* @param retryAttempts The max number of attempts to retry this task or -1 to try MAX_INT times,
*/
public static <T> Observable.Transformer<T, T> backoff(final long interval, final TimeUnit units, final int retryAttempts) {
return new Observable.Transformer<T, T>() {
@Override
public Observable<T> call(final Observable<T> observable) {
return observable.retryWhen(
import rx.Observable;
import rx.functions.Action0;
import rx.functions.Func0;
import java.util.concurrent.atomic.AtomicReference;
class SubscribedObservableReplayer<T> implements Observable.Transformer<T, T> {
private final AtomicReference<Observable<T>> pendingObservable;
@mr-archano
mr-archano / Oauth1SigningInterceptor.java
Created September 11, 2016 10:19 — forked from serj-lotutovici/Oauth1SigningInterceptor.java
An OkHttp interceptor which does OAuth1 signing. Requires Java 7 (but can easily be ported to Java 6).
/*
* Copyright (C) 2015 Jake Wharton
*
* 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
import java.util.concurrent.atomic.AtomicReference;
import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func0;
class CachingObservableReplayer<T> implements Observable.Transformer<T, T> {
private final AtomicReference<Observable<T>> pendingObservable;
@mr-archano
mr-archano / EspressoTestRule.java
Created November 6, 2016 18:03 — forked from patrickhammond/EspressoTestRule.java
Hacking through Espresso issues...
import android.app.Activity;
import android.app.Instrumentation;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.support.test.InstrumentationRegistry;