Skip to content

Instantly share code, notes, and snippets.

View dominicthomas's full-sized avatar

Dominic Thomas dominicthomas

View GitHub Profile
@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 / 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 / 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_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 / 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
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 / 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;
@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 / Android Touch Area Extender
Last active November 1, 2016 07:28
A lovely android view touch area extender builder class. Made to provide a larger touch area to views that aren't standard clickable android view widgets. Works well on things like a small bit of text or a little drop down arrow. The code here is from a project that uses retrolamda and google's guava library for preconditions and optionals.
import android.graphics.Rect;
import android.view.TouchDelegate;
import android.view.View;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
/**
* Utility used to extend the touchable area around a view in a viewgroup
* Usage: TouchAreaExtender.Builder.with(mReJamCaptionInput)
import com.android.build.OutputFile;
ext {
buildToolsVersion = System.env.CUSTOM_BUILDTOOLS != null ? System.env.CUSTOM_BUILDTOOLS : '20.0.0'
}
buildscript {
def gradleVersion = System.env.CUSTOM_GRADLE != null ? System.env.CUSTOM_GRADLE : '0.14.0'
repositories {
if (System.env.CUSTOM_REPO != null) {
maven { url System.env.CUSTOM_REPO }
} else {