Skip to content

Instantly share code, notes, and snippets.

@alexfu
alexfu / AndroidAsync.java
Last active February 7, 2021 15:27
Helpful RxJava functions for daily use
/**
* Transforms an observable to run on a new thread
* and to be observed on Androids main thread.
*/
public static <T> Observable.Transformer<T, T> androidAsync() {
return new Observable.Transformer<T, T>() {
@Override
public Observable<T> call(Observable<T> observable) {
return observable
.subscribeOn(Schedulers.newThread())
@adavis
adavis / checkstyle
Created June 22, 2015 20:06
Checkstyle configuration for use in Android projects.
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<module name="FileLength"><property name="max" value="800"/></module>
<module name="TreeWalker">
<module name="MethodLength"><property name="max" value="60"/></module>
@nickbutcher
nickbutcher / 10: animator-morph_ridge_2_to_tick.xml
Last active September 4, 2024 05:58
Demonstrating an animation for scanning a fingerprint and showing success or failure. This uses a number of AnimatedVectorDrawables (https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html) to 'morph' parts of the fingerprint into the tick or cross to report success or failure. It also uses a moving clip-pat…
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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
@condesales
condesales / gist:d006639a4afa0e0b496b
Created March 2, 2015 17:22
RenderScript blur Android
public static Bitmap blur(View v) {
return blur(v.getContext(), getScreenshot(v));
}
public static void blur(Activity activity) {
Window window = activity.getWindow();
BlurredDiceActivity.sBlurredBackgroundImage = blur(activity, getScreenshot(window.getDecorView()));
}
public static Bitmap blur(Context ctx, Bitmap image) {
@JakeWharton
JakeWharton / gist:f50f3b4d87e57d8e96e9
Created February 7, 2015 01:59
Rise and Shine™, unlock and wake up your device automatically when you deploy from the IDE. Put this somewhere in your `src/debug/` code and run it when the application or main activity starts. Apache 2.
/**
* Show the activity over the lockscreen and wake up the device. If you launched the app manually
* both of these conditions are already true. If you deployed from the IDE, however, this will
* save you from hundreds of power button presses and pattern swiping per day!
*/
public static void riseAndShine(Activity activity) {
activity.getWindow().addFlags(FLAG_SHOW_WHEN_LOCKED);
PowerManager power = (PowerManager) activity.getSystemService(POWER_SERVICE);
PowerManager.WakeLock lock =
@JakeWharton
JakeWharton / README.md
Last active April 17, 2023 14:07
A JUnit @rule which launches an activity when your test starts. Stop extending gross ActivityInstrumentationBarfCase2!

Plugin Route

Trying this plugin: https://github.com/kageiit/gradle-robojava-plugin

I am starting from a Blank Activity wizard hello world project - nothing fancy. I stashed by attempts at the manual configuration route that I was pursuing yesterday.

Added tdd module

Used the drop down menu, selected Java at the very bottom.

/*
* Copyright 2014 Chris Banes
*
* 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
@jgilfelt
jgilfelt / gist:8105b5ca07776a4359c2
Created November 28, 2014 10:33
Notification whose content is partially redacted on API 21 secure lockscreens
private Notification buildNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setCategory(NotificationCompat.CATEGORY_EVENT)
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) // default
.setContentTitle(title)
.setContentText(shortText)
.setStyle(new NotificationCompat.BigTextStyle().bigText(fullText))
.setSmallIcon(R.drawable.ic_stat_notification)
.setColor(context.getResources().getColor(R.color.my_color))
.setContentIntent(intent);
@cpeppas
cpeppas / gist:b5ffe6bd29b67d96416a
Last active September 1, 2017 17:13
Espresso CustomMatcher to help test things like Actionbar title
import android.view.View;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import static org.hamcrest.Matchers.is;
public class CustomMatchers {
public static Matcher<View> withResourceName(String resourceName) {