Skip to content

Instantly share code, notes, and snippets.

View jerrellmardis's full-sized avatar

Jerrell Mardis jerrellmardis

View GitHub Profile
@jerrellmardis
jerrellmardis / DisplayTimeoutTileService.java
Created June 3, 2016 22:10
A quick example demonstrating how to create a Quick Settings Tile using the new Quick Settings Tile API introduced in Android N.
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.widget.Toast;
import java.util.concurrent.TimeUnit;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
/**
@jerrellmardis
jerrellmardis / ExponentialBackoff
Last active June 3, 2019 13:10
Exponential Backoff using Rx.retryWhen()
// retries up to 3 times while exponentially backing off with each retry
.retryWhen(errors ->
errors
.zipWith(
Observable.range(1, MAX_RETRIES), (n, i) -> i
)
.flatMap(
retryCount -> Observable.timer((long) Math.pow(4, retryCount), TimeUnit.SECONDS)
)
)
@jerrellmardis
jerrellmardis / ColorUtils.java
Created January 6, 2016 23:01
Lightens or darkens a color
package com.desk.android.util;
import android.graphics.Color;
/**
* Lightens or darkens a color
*/
public final class ColorUtils {
private ColorUtils() {
@jerrellmardis
jerrellmardis / dex_counter.sh
Created March 27, 2014 14:13
Counts the number of methods in a list of jars
for file in jars/*.jar; do
echo $file; /Applications/Android\ Studio.app/sdk/build-tools/19.0.3/dx --dex --output=temp.dex $file 2> /dev/null
cat temp.dex| head -c 92 | tail -c 4 | hexdump -e '1/4 "%d\n"'
done
@jerrellmardis
jerrellmardis / RoundedRelativeLayout.java
Last active May 11, 2018 06:22
A {@link android.widget.RelativeLayout} that supports rounded corners and proper child view clipping. Perfect for situations where you have full bleed images that you want clipped to the bounds of this layout.
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
/**
* A {@link android.widget.RelativeLayout} that supports rounded corners.
#!/bin/bash
f=$(pwd)
mkdir drawable-mdpi drawable-hdpi drawable-xhdpi drawable-xxhdpi
# fake argv and argc in bash
argc=$#; argv[0]=$0 # argv[0] is a prog name
for foo in $( seq $argc )
do
function dex-method-count() {
cat $1 | head -c 92 | tail -c 4 | hexdump -e '1/4 "%d\n"'
}
function dex-method-count-by-package() {
dir=$(mktemp -d -t dex)
java -jar baksmali.jar $1 -o $dir
for pkg in `find $dir/* -type d`; do
java -jar smali.jar $pkg -o $pkg/classes.dex
count=$(dex-method-count $pkg/classes.dex)
@jerrellmardis
jerrellmardis / gist:5687856
Last active May 20, 2019 10:19
A simple example illustrating how to use Picasso to load a bitmap into a Target. https://github.com/square/picasso
Picasso.with(context).load(url).into(new Target() {
@Override
public void onSuccess(Bitmap bitmap) {
holder.image.setImageBitmap(bitmap);
}
@Override
public void onError() {
// handle
@jerrellmardis
jerrellmardis / ZoomFragment.java
Created April 10, 2013 22:37
This demonstrates how to implement the onTouch(...) callback method within a Fragment in order to scale/zoom out the Fragment's root view when a user drags their finger up or down. Note: You can use the nineoldandroids lib to get this to work on pre-Honeycomb devices.
public class ZoomFragment implements OnTouchListener {
private static final float MIN_SCALE = 0.95f;
private float mLastScaleFactor = 0;
private float mTouchY;
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_layout, container, false);
@jerrellmardis
jerrellmardis / BaseAsyncTaskLoader
Created March 22, 2013 16:14
Generic {@link AsyncTaskLoader} which also registers and handles data changes via a {@link BroadcastReceiver}.
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.AsyncTaskLoader;
/**
* Generic {@link AsyncTaskLoader} which also registers and handles data changes via a {@link BroadcastReceiver}.
*
* @author jmardis