Skip to content

Instantly share code, notes, and snippets.

@mrhether
mrhether / DynamicHeightViewPager
Created May 27, 2015 17:52
DynamicHeightViewPager
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for(int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if(h > height) height = h;
}
@mrhether
mrhether / printInside.java
Created August 6, 2015 15:47
Reflection Method to print the insides of an object
public static String printInsides(Object object) {
StringBuilder result = new StringBuilder();
String newLine = "\n";
result.append( object.getClass().getName() );
result.append( " Object { " );
result.append(newLine);
//determine fields declared in this class only (no fields of superclass)
Field[] fields = object.getClass().getDeclaredFields();
@mrhether
mrhether / SpacesItemDecoration.java
Created August 24, 2015 22:01
The following code will handle padding on StaggeredGridLayoutManager, GridLayoutManager, and LinearLayoutManager.
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
/**
* Created by markhetherington on 15-08-17.
*/
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
private int halfSpace;
public static Bitmap addGradient(Bitmap src, @ColorInt int start, @ColorInt int end, int alpha) {
int w = src.getWidth();
int h = src.getHeight();
Bitmap overlay = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.drawBitmap(src, 0, 0, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, 0, 0, h, start, end, Shader.TileMode.CLAMP);
@mrhether
mrhether / NeedGithubUsername.java
Last active November 10, 2015 20:22
Github names are vital and the smaller they are the better! This tool finds you the smallest github name available.
private final Log logger = LogFactory.getLog(getClass());
public void given_i_need_a_github_name() {
List<String> names = getNamePerms(6);
for (String name : names) {
System.out.print('.');
RestTemplate restTemplate = new RestTemplate();
String url = "http://github.com/" + name;
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
if (response.hasBody() && response.getBody().contains("This is not the web page you are looking for")) {
@mrhether
mrhether / UILabel+HTML.m
Created February 24, 2016 19:38
UILabel + HTML
#import "UILabel+HTML.h"
@implementation UILabel (HTML)
- (void) setHtml: (NSString*) html
{
// Add font from label
NSString* finalHtml = [html stringByAppendingString:[NSString stringWithFormat:@"<style>body{font-family: '%@'; font-size:%fpx;}</style>",
self.font.fontName,
self.font.pointSize]];
@mrhether
mrhether / WindowUtils.java
Created April 6, 2016 18:12
Window Utils Android
public class WindowUtils {
public static int getActionBarHeight(Context context) {
final TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(
new int[]{R.attr.actionBarSize});
int actionBarHeight = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
return actionBarHeight;
}
@mrhether
mrhether / OnSingleClickListener.java
Created May 9, 2016 19:46
OnSingleClickListener
/**
* Implementation of {@link OnClickListener} that ignores subsequent clicks that happen too quickly after the first one.<br/>
* To use this class, implement {@link #onSingleClick(View)} instead of {@link OnClickListener#onClick(View)}.
*/
public abstract class OnSingleClickListener implements OnClickListener {
private static final String TAG = OnSingleClickListener.class.getSimpleName();
private static final long MIN_DELAY_MS = 500;
private long mLastClickTime;
@mrhether
mrhether / moveRes.py
Last active January 10, 2017 15:58
Allows you to move resources from one android app/lib to another
import os, sys
if len(sys.argv) < 4:
print "Family you need 3 params, originalFolder, newResFolder, fileName"
else:
orginalResFolder = sys.argv[1]
newResFolder = sys.argv[2]
fileNames = sys.argv[3:]
print "files to move " + str(fileNames)
TwitterServiceBuilder.getTwitterService().search("test").enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Toast.makeText(TwitterActivity.this, response.toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(TwitterActivity.this, t.toString(), Toast.LENGTH_LONG).show();
}