Skip to content

Instantly share code, notes, and snippets.

@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());
@evant
evant / code-review
Last active August 2, 2017 11:51
A ruby script to automatically create crucible reviews based on your current branch and youtrack ticket.
#!/usr/bin/env ruby
# A script to create a review on crucible based on the current git branch and
# youtrack ticket.
#
# To configure settings, create a file named .code-review in your home directory
# The format should be:
# ------------------------------------------------------------------------------
# crucible:
# url: <crucible url>
# username: <username>
#!/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: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);
@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
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 / 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;