Skip to content

Instantly share code, notes, and snippets.

View dominicthomas's full-sized avatar

Dominic Thomas dominicthomas

View GitHub Profile
@dominicthomas
dominicthomas / adb_iso_country.txt
Created November 3, 2016 14:31
This enables you to change the sim country iso of the android emulator. This and more info here: http://stackoverflow.com/questions/2637606/how-do-i-change-the-mobile-country-code-mcc-in-the-android-emulator
adb shell setprop gsm.sim.operator.iso-country gb
@dominicthomas
dominicthomas / PhoneNumberFormatter.java
Last active October 7, 2016 12:45
Simple class to format and convert to E164, mobile phone numbers for the UK and the US. Probably better to just use google libphonenumber.
public class PhoneNumberFormatter {
private final String simCountryIso;
private final Map<String, String> countryCodeMap = Collections.unmodifiableMap(
new HashMap<String, String>() {{
put("GB", "44");
put("US", "1");
}});
@dominicthomas
dominicthomas / PhoneNumberFormatter.java
Created October 7, 2016 12:43
Simple class to format and convert to E164, mobile phone numbers for the UK and the US.
public class PhoneNumberFormatter {
private final String simCountryIso;
private final Map<String, String> countryCodeMap = Collections.unmodifiableMap(
new HashMap<String, String>() {{
put("GB", "44");
put("US", "1");
}});
@dominicthomas
dominicthomas / TextInputOnKeyChangedListener.java
Created September 23, 2016 14:49
Useful to listen to just key up and back key events for a text input or edittext. Turns out it doesn't work on some devices as some send hardware key events and some send soft keyboard events. This doesn't work with soft keyboard events.
public class TextInputOnKeyChangedListener implements EditText.OnKeyListener {
private EditText editText;
private OnKeyChangedListener onKeyChangedListener;
public interface OnKeyChangedListener {
void onKeyUp(String text);
void onBackPressed();
@dominicthomas
dominicthomas / jackson_guava_optional.txt
Created July 19, 2016 12:29
Jackson Guava Optional<T> Deserialization
Dependencies:
=============================================
compile "com.google.guava:guava:19.0"
compile 'com.fasterxml.jackson.datatype:jackson-datatype-guava:2.7.3'
Deserializer:
=============================================
@dominicthomas
dominicthomas / CompatGlobalLayoutListener.java
Created June 23, 2016 15:10
A useful abstract class that wraps in global layout listener functionality to support older android versions.
public abstract class CompatGlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {
private final View view;
public CompatGlobalLayoutListener(@NonNull final View view) {
this.view = view;
}
protected abstract void onGlobalLayoutReady();
@dominicthomas
dominicthomas / getdevelop.sh
Created March 23, 2016 17:52
Useful script to checkout and pull new changes on develop for a repo and all submodules... This will need to be adapted to the environment it is required in.
#/bin/bash
cd $1
if [ -d $1 ]; then
echo "Changing Directory too: " $1
else
echo "Directory does not exist"
exit 1
fi
@dominicthomas
dominicthomas / multiple_filters_ffmpeg
Created November 12, 2015 14:15
Small snippet of doing multiple filter calls on an ffmpeg command... using the android ffmpeg wrapper
cmd.add("movie=" + imagePath + " [overlay]; " +
"[in] transpose=1 [a]; " +
"[a] scale=360:-1 [b]; " +
"[b] crop=360:360:" + String.valueOf(cropX) + ":" + String.valueOf(cropY) + " [c]; " +
"[c] [overlay] overlay=" + overlayX + ":" + overlayY + " [out]");
@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<>();
@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 */