Skip to content

Instantly share code, notes, and snippets.

View dominicthomas's full-sized avatar

Dominic Thomas dominicthomas

View GitHub Profile
@dominicthomas
dominicthomas / CollectionUtil
Created April 15, 2015 14:09
Stuff Guava is Missing
import static com.google.common.base.Optional.of;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.isEmpty;
import static com.google.common.collect.Iterables.transform;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import com.google.common.base.Function;
import com.google.common.base.Optional;
@dominicthomas
dominicthomas / Rainbow_Brush_Demo
Last active March 26, 2018 09:22
A simple activity with a drawing view and a rainbow brush. Proof of concept. Potential to be improved.
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.MotionEvent;
import android.view.View;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName();
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more.
int firstVisibleItem, visibleItemCount, totalItemCount;
@dominicthomas
dominicthomas / json_from_raw
Created June 16, 2015 10:46
Open a json file from the android raw directory and construct using GSON.
public class JSONUtils {
/**
* Open a json file from raw and construct as class using Gson.
*
* @param resources
* @param resId
* @param classType
* @param <T>
* @return
@dominicthomas
dominicthomas / android_dockerfile
Created July 10, 2015 08:45
Dockerfile script used to install the android sdk, required api levels and any extras..
FROM default-java8
MAINTAINER [email protected]
# Installs i386 architecture required for running 32 bit Android tools
RUN dpkg --add-architecture i386 && \
apt-get update -y && \
apt-get install -y libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 && \
rm -rf /var/lib/apt/lists/* && \
apt-get autoremove -y && \
apt-get clean
@dominicthomas
dominicthomas / imageview_pager_adapter_currentview
Created August 10, 2015 15:57
An example of a viewpager adapter that supports getting a reference to the current view. This is required as the viewpager only keeps 3 items in memory so trying to get the item using the current item index does not work.
/**
* Pager adapter to display a feed item image in a square image view
*/
public class MultipleFeedPostItemAdapter extends PagerAdapter {
private final Context mContext;
private List<FeedItem> mFeedPosts = new ArrayList<>();
private ImageView mCurrentView;
public MultipleFeedPostItemAdapter(final Context pContext, final List<FeedItem> pFeedPosts) {
@dominicthomas
dominicthomas / Android_increment_versionCode
Created September 30, 2015 09:43
Simple way of incrementing the app versionCode when a particular task is run. Useful to increment versionCode when doing a production release build.
// Increment version code when running a production release
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def value = 0
def runTasks = gradle.startParameter.taskNames
if ('assembleProductionRelease' in runTasks) {
value = 1;
}
@dominicthomas
dominicthomas / Android_play_video_intent
Created October 2, 2015 09:21
Used to play a video file from the file system.
private void playVideo(final File file) {
Uri intentUri = Uri.fromFile(file);
file.setReadable(true, false); // security?
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(intentUri, "video/*");
startActivity(intent);
}
@dominicthomas
dominicthomas / SoundManager.java
Created October 23, 2015 00:28
android soundpool wrapper
import java.util.HashMap;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.Log;
public class SoundManager implements SoundPool.OnLoadCompleteListener {
/** SoundPool left volume */
@dominicthomas
dominicthomas / mp4parser_append_example
Last active November 5, 2015 13:22
Code used to append 4 mp4 files using mp4parser - Code uses example path to file strings.
try {
final Movie intro = MovieCreator.build(new FileDataSourceImpl(file1));
final Movie main = MovieCreator.build(new FileDataSourceImpl(file2));
final Movie resultClip = MovieCreator.build(new FileDataSourceImpl(file3));
final Movie end = MovieCreator.build(new FileDataSourceImpl(file4));
final Movie[] movies = new Movie[]{intro, main, resultClip, end};
final List<Track> videoTracks = new LinkedList<>();