Skip to content

Instantly share code, notes, and snippets.

View eoinfogarty's full-sized avatar
😃
Ceart go leor

Eoin Fogarty eoinfogarty

😃
Ceart go leor
View GitHub Profile
@eoinfogarty
eoinfogarty / Recycler.kt
Created July 21, 2017 07:11
Kotlin extension methods to simplify saving and restoring a recyclerviews scroll postion
import android.os.Bundle
import android.os.Parcelable
import android.support.v7.widget.RecyclerView
/**
* We have to handle restoring a recyclerviews scroll position oneself.
* Add a extension field so we don't have to handle the key ourselves anymore
* Add a post to avoid some bug where recyclerview does not restore scroll position
*
@eoinfogarty
eoinfogarty / Intent.kt
Created July 19, 2017 08:15
Kotlin extension to add extras as pairs
import android.content.Intent
import android.os.Bundle
import android.os.Parcelable
import java.io.Serializable
/**
* Intent(context, MyActivity::class.java).withExtras(
* KEY_HOGE to "hoge",
* KEY_FOO to "foo"
* )
@eoinfogarty
eoinfogarty / SelectorTouchListener.java
Created June 3, 2016 04:08
Touch listener to use with a selector
package com.example.app;
import android.view.MotionEvent;
import android.view.View;
public final class SelectorTouchListener implements View.OnTouchListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
@eoinfogarty
eoinfogarty / RatioImageView.java
Created November 9, 2015 02:50
imageview with ratio that can be set based on width
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
* Created by Eoin Fogarty on 2015/11/06.
*
* Clamps an image ratio