Skip to content

Instantly share code, notes, and snippets.

@evant
evant / SnapTopLinearLayoutManager.java
Created July 16, 2015 19:33
Force item to top instead of just on screen when smooth scrolling with RecyclerView
public class SnapTopLinearLayoutManager extends LinearLayoutManager {
public SnapTopLinearLayoutManager(Context context) {
super(context);
}
public SnapTopLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
@evant
evant / ViewPagerRemoveHardwareLayer.java
Created June 25, 2015 18:00
Disable ViewPager hardware layer if you are animating the items within while paging
public class ViewPagerRemoveHardwareLayer implements ViewPager.OnPageChangeListener {
private ViewPager mPager;
public ViewPagerRemoveHardwareLayer(ViewPager pager) {
mPager = pager;
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
@evant
evant / Text.java
Created May 13, 2015 15:20
Helper for having a uniform resource text object.
import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.annotation.PluralsRes;
import android.support.annotation.StringRes;
import android.widget.TextView;
import java.util.Arrays;
@evant
evant / Wtf.java
Last active August 29, 2015 14:17
Why doesn't this compile?
public class Wtf {
public static abstract class Foo<V> { // Removing this type parameter allows it to compile
public <T> T bad(Class<T> fooClass) {
return null;
}
}
public static class Bar {
}
package me.tatarka.nofragment.view;
import android.support.v4.util.SparseArrayCompat;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
@evant
evant / ResizeTransformation.java
Last active August 29, 2015 14:05
Picasso Resize Transform
public class ResizeTransformation extends Transformation {
@Override public
Bitmap transform(Bitmap source) {
int targetWidth = getScreenWidth(); // Implementation left as an exercise for the reader.
if (targetWidth < source.getWidth()) {
double aspectRatio = (double) source.getHeight() / (double) source.getWidth();
int targetHeight = (int) (targetWidth * aspectRatio);
Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
if (result != source) {
// Same bitmap is returned if sizes are the same
@evant
evant / gist:6ccc8ae88dbe6e82d0c7
Created August 12, 2014 18:25
Delegate back button to child fragments.
public interface OnBackPressed {
boolean onBackPressed();
}
// ----------------------------------------------------------
public class DelegateBackPressActivity extends Acitivity {
@Override
public void onBackPressed() {
for (Fragment f : getFragmentManager().getFragments()) {
@evant
evant / gist:ab9a06194a5d910b7f13
Last active December 27, 2016 17:59
Proxy okhttp
OkHttpClient client = new OkHttpClient();
Proxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved("192.168.1.105", 8081);
client.setProxy(proxy);
/**
* Correctly sets the left padding between the drawable and text in a CheckBox. This is
* necessary because the behavior of setPadding() changed in 4.2
*
* @param checkBox the checkbox to pad
* @param buttonWidth the width in pixels of the button drawable used in the CheckBox
* @param paddingLeft the padding in pixels between the drawable and the text
*/
@SuppressLint("NewApi")
public static void setCheckboxPaddingLeft(CheckBox checkBox, int buttonWidth, int paddingLeft) {
#!/usr/bin/env ruby
require 'optparse'
require 'net/http'
require 'json'
OS = case RbConfig::CONFIG['host_os']
when /linux/
:linux
when /darwin/