Skip to content

Instantly share code, notes, and snippets.

View ZacSweers's full-sized avatar

Zac Sweers ZacSweers

View GitHub Profile
@grantland
grantland / post.md
Last active February 9, 2023 05:09
RecyclerView item onClick

RecyclerView item onClick

RecyclerView does not have an OnItemClickListener like it's predecessor, ListView. However, detecting item clicks is pretty simple.

Set an OnClickListener in your ViewHolder creation:

private class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>  {

    public static class ViewHolder extends RecyclerView.ViewHolder
@JakeWharton
JakeWharton / ForegroundImageView.java
Created July 10, 2014 16:42
An ImageView which supports a foreground drawable.
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
public class ForegroundImageView extends ImageView {
private Drawable foreground;
@dmarcato
dmarcato / strip_play_services.gradle
Last active December 21, 2022 10:10
Gradle task to strip unused packages on Google Play Services library
def toCamelCase(String string) {
String result = ""
string.findAll("[^\\W]+") { String word ->
result += word.capitalize()
}
return result
}
afterEvaluate { project ->
Configuration runtimeConfiguration = project.configurations.getByName('compile')
fun main(args: Array<String>) {
println("a" to "b")
println("a" to "b" tre "c")
println("a" to "b" tre "c" fo "d")
println("a" to "b" tre "c" fo "d" fi "e")
println("a" to "b" tre "c" fo "d" fi "e" sik "f")
println("a" to "b" tre "c" fo "d" fi "e" sik "f" seva "g")
}
infix fun <A, B, C> Pair<A, B>.tre(c: C) = Triple(first, second, c)
@hanspeide
hanspeide / TimberFirebase.java
Last active October 29, 2022 23:30
Timber tree for use with Firebase Crash Reporting. Basically a copy/rewrite of Jake Wharton's CrashlyticsTree.
private static class FirebaseTree extends Timber.Tree {
@Override
protected void log(int priority, String tag, String message, Throwable t) {
if (priority == Log.VERBOSE || priority == Log.DEBUG) {
return;
}
FirebaseCrash.log(message);
if (t != null) {
@geekygecko
geekygecko / android.md
Last active October 14, 2022 19:32
Android Cheat Sheet

Android Cheat Sheet

Developer tips

Record a video of your app

Developer options -> Check show touches
adb shell screenrecord /sdcard/video.mp4
adb pull /sdcard/video.mp4
package com.cgollner.unclouded.preferences;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.preference.CheckBoxPreference;
import android.util.AttributeSet;
import com.cgollner.unclouded.R;
@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 =
public void readTwice()
{
Observable.fromCallable(() -> {
RedditData inflatedModel = null;
Response response = makeRequest();
String diskValue = null;
try {
File file = new File(getContext().getCacheDir(), "file");
BufferedSink cacheBody = Okio.buffer(Okio.sink(file));
@ShaishavGandhi
ShaishavGandhi / JavaPoetExt.kt
Last active May 2, 2022 21:14
Extensions to convert JavaPoet types to KotlinPoet and vice-versa
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.ParameterizedTypeName
import com.squareup.javapoet.TypeName
import com.squareup.javapoet.TypeVariableName
import com.squareup.javapoet.WildcardTypeName
import com.squareup.javapoet.ArrayTypeName
import com.squareup.kotlinpoet.ARRAY
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
fun ClassName.asKPClassName(): com.squareup.kotlinpoet.ClassName {