Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'optparse'
require 'net/http'
require 'json'
OS = case RbConfig::CONFIG['host_os']
when /linux/
:linux
when /darwin/
/**
* 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) {
@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 / 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 / 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 {
}
@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 / 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) {
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
/**
* Abuse loaders to retain some state across rotations for a Fragment or Activity.
*/
public class RetainStateManager {

Suggestions for the new Transform Api

Possibly the biggest issue I see with the current api is that it is very hard to extend it in the future without breaking current implementations. For example, I asked to be provided the LoggingManager for the task so I can redirect stdout output inside the transform. This cannot be done without changing the api. I have a couple suggestions to fix this issue, it would be better to do it now while it's still in beta.

  1. Provide the gradle task that performs the transform to the transform method.
@evant
evant / gist:7796723
Created December 4, 2013 22:25
Android dp to pixels
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());