Skip to content

Instantly share code, notes, and snippets.

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.Build;
import com.squareup.picasso.Transformation;
@voghDev
voghDev / DBUtil.java
Last active August 29, 2015 14:27
Helper method to copy your SQLite database to SD Card, in order to access it in non-rooted phones.
public class DBUtil {
public static void copyDatabaseToSDCard(String dbName) {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//"+ BuildConfig.APPLICATION_ID+"//databases//"+ dbName+".db";
String backupDBPath = dbName+"-backup.db";
File currentDB = new File(data, currentDBPath);
@voghDev
voghDev / CustomImageCache.java
Created August 21, 2015 07:10
square/picasso Image Cache example implementation
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.squareup.picasso.Cache;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@voghDev
voghDev / NDRendererBuilder.java
Last active May 4, 2017 07:17
Generic RendererBuilder implementation that supports "multi-renderer" mode (a single RendererBuilder for all Renderer classes)
package x.y.z;
import android.content.Context;
import com.pedrogomez.renderers.Renderer;
import com.pedrogomez.renderers.RendererBuilder;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
@voghDev
voghDev / LogJsonInterceptor.java
Created October 29, 2015 12:51
retrofit2 interceptor that logs the raw JSON response from API. After that it clones it and returns a sane copy that other classes can consume.
import android.util.Log;
import com.appandweb.prjtestdrivendev.BuildConfig;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
import java.io.IOException;
@voghDev
voghDev / ColoredTitleDialog.java
Last active November 6, 2015 06:45
custom Dialog class that colors the title
package es.voghdev.examples;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
@voghDev
voghDev / SSnackbar.java
Last active November 18, 2017 00:15
Example class with Builder pattern that generates custom colored snackbars (android.support.design 22.2.0)
package es.voghdev.examples;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class SSnackbar {
@voghDev
voghDev / ExtRecyclerView.java
Created January 26, 2016 11:03
Simple RecyclerView customization that implements "OnLastItemVisible" feature, where the number of "items left to load more" can be set
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
public class ExtRecyclerView extends RecyclerView {
private static final int DEFAULT_ITEMS_LEFT_TO_LOAD_MORE = 5;
Context context;
@voghDev
voghDev / PreferenceHelper.java
Last active June 29, 2020 20:16
Generic Preference Helper to save some lines of code managing shared preferences
/*
* Copyright (C) 2016 Olmo Gallegos Hernández.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@voghDev
voghDev / AddHeaderInterceptor.java
Last active August 22, 2018 08:44
Retrofit2 interceptor to add headers to HTTP requests
public class AddHeaderInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request.Builder builder = chain.request().newBuilder();
builder.addHeader("Authorization", "headerContent");
return chain.proceed(builder.build());
}
}