Skip to content

Instantly share code, notes, and snippets.

View rocboronat's full-sized avatar

Roc Boronat rocboronat

View GitHub Profile
@rocboronat
rocboronat / ConcatStringComparison.java
Last active April 1, 2016 11:11
Comparison of 4 ways to concat Strings
package com.fewlaps;
public class ConcatStringComparison {
static long timeAdding;
static long timeConcat;
static long timeStringBuffer;
static long timeStringBuilder;
public static final int ITERATIONS = 1000000;
@rocboronat
rocboronat / DebugClient.java
Last active December 2, 2015 11:08
A Retrofit Client that ignores autosigned certificate issues
public class DebugClient extends DefaultHttpClient {
@Override
protected ClientConnectionManager createClientConnectionManager() {
KeyStore trustStore = null;
try {
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
@rocboronat
rocboronat / MaterialErrorTextView.java
Last active August 29, 2015 14:23
A custom View to mimic the Material behavior for the error labels
package at.rocboron.android.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.animation.ValueAnimator;
/**
@rocboronat
rocboronat / AndroidTVUtils.java
Created June 27, 2015 15:43
A Util to useful and common Android TV things
package com.fewlaps.electroswingrevolution.util;
import android.app.UiModeManager;
import android.content.Context;
import android.content.res.Configuration;
import android.util.Log;
/**
* @author Roc Boronat ([email protected])
* @date 27/06/2015
@rocboronat
rocboronat / KeyboardUtil.java
Created June 3, 2015 09:24
The common util with common methods to work with Android SoftKeyboard (the common one)
package at.rocboron.android.utils;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
public class SoftKeyboardUtil {
@rocboronat
rocboronat / DarkOrLightColour.java
Last active June 30, 2018 19:04
Know if a text on a dynamic background colour must be black or white to be easy to read
int color = palette.getVibrantColor(defaultColor);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 0) & 0xFF;
row.setBackgroundColor(color);
//@see http://stackoverflow.com/questions/12043187/how-to-check-if-hex-color-is-too-black
double luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
@rocboronat
rocboronat / ConfirmCancelDialogFragment.java
Last active August 29, 2015 14:20
A common DialogFragment with a confirm and a cancel button
package com.infojobs.app.base.view.fragment;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
@rocboronat
rocboronat / GetMonthName.java
Last active June 30, 2018 19:04
Get the names of the months, from strings.xml or the SimpleDateFormat class
public String getDateMonthFromStrings(Context context, DateTime date) {
String result;
if (date.getMonthOfYear() == 1) {
result = context.getString(R.string.month_january);
} else if (date.getMonthOfYear() == 2) {
result = context.getString(R.string.month_february);
} else if (date.getMonthOfYear() == 3) {
result = context.getString(R.string.month_march);
} else if (date.getMonthOfYear() == 4) {
result = context.getString(R.string.month_april);
@rocboronat
rocboronat / CubicBezierInterpolator.java
Created March 17, 2015 11:22
Cubic Bezier Android interpolator
package com.infojobs.app.base.utils.animation;
import android.graphics.PointF;
import android.view.animation.Interpolator;
/**
* Derived from: https://github.com/rdallasgray/bez
*/
public class CubicBezierInterpolator implements Interpolator {
@rocboronat
rocboronat / RippleDelayedRunner.java
Last active November 29, 2020 12:42
A simple way to call the common new Handler().postDelayed(..., time);
package com.fewlaps.android.quitnow.base.customview;
import android.os.Handler;
import android.view.View;
/**A simple way to call the common new Handler().postDelayed(..., time);
*
* Created by Roc Boronat on 12/12/2014.
*/
public class RippleDelayedRunner implements View.OnClickListener {