Skip to content

Instantly share code, notes, and snippets.

View dominicthomas's full-sized avatar

Dominic Thomas dominicthomas

View GitHub Profile
apply plugin: 'com.android.application'
import com.android.build.OutputFile;
dependencies {
compile project(':lib')
}
// map for the version code for ABIs.
// x86 is more important because x86 devices also support arm.
// Same for mips
ext.versionCodes = ["armeabi-v7a":1, "mips":2, "x86":3, "all":0]
android {
@dominicthomas
dominicthomas / apk_versioncode
Created February 25, 2015 09:33
Parse version code from apk
aapt dump badging MyAwesomeApplication.apk |grep version
@dominicthomas
dominicthomas / Resource to Uri
Created February 24, 2015 09:38
Get a uri to an android resource..
public static Uri resourceToUri(final Context context, final int resID) {
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
context.getResources().getResourcePackageName(resID) + '/' +
context.getResources().getResourceTypeName(resID) + '/' +
context.getResources().getResourceEntryName(resID));
}
@dominicthomas
dominicthomas / log_extending_activity_name
Created December 22, 2014 11:26
Display the name of any activity that extends the activity this code is in.
if(BuildConfig.DEBUG){
Log.d(TAG, this.getClass().getSimpleName() + " - onCreate!");
}
@dominicthomas
dominicthomas / check_for_newline_character
Created December 22, 2014 11:19
Check that the last key entered was enter... and replace with blank character. This can be used in an android TextWatcher, and called in afterTextChanged to stop a user pressing enter or handle the case that someone does. This was implemented in an attempt to limit the amount of enters someone could press when entering text in a multiline editex…
private void checkLastKeyWasEnter(final Editable pSequence) {
if (pSequence.length() > 0 && pSequence.charAt(pSequence.length() - 1) == '\n') {
pSequence.replace(pSequence.length() - 1, pSequence.length(), "");
}
}
@dominicthomas
dominicthomas / multiline_ime_snippets
Created December 22, 2014 11:03
One simple way of setting and firing an IME action on a multiline EditText. Google have stopped IME actions firing on multiline text input fields, has enter should be reserved in these cases to move the user to the next line. See: http://stackoverflow.com/questions/13239225/how-to-get-edittext-ime-action-textmultiline-to-work-for-jellybean && ht…
private class OnMyEditorActionListener implements OnEditorActionListener {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == R.id.your_new_ID || actionId = EditorInfo.IME_Null) {
doSomething();
return true;
}
return false;
}
}
@dominicthomas
dominicthomas / Android Path
Created December 15, 2014 11:48
Standard path stuff when setting up new android dev environment.
export JAVA_HOME='/usr/libexec/java_home -v 1.8'
export ANDROID_HOME='/Users/dominic.thomas/Library/Android/sdk'
export GRADLE_HOME='/Users/dominic.thomas/Build/gradle-2.2.1'
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$GRADLE_HOME/bin:$JAVA_HOME/bin
@dominicthomas
dominicthomas / CardView Attrs
Created November 18, 2014 00:35
Some interesting cardview attributes to remember
card_view:cardUseCompatPadding = "true"
card_view:cardCornerRadius="10dp"
card_view:contentPaddingLeft="20dp"
card_view:contentPaddingRight="@dimen/activity_horizontal_margin"
card_view:contentPaddingTop="20dp"
card_view:contentPaddingBottom="@dimen/activity_vertical_margin"
@dominicthomas
dominicthomas / ffmpeg wav -> mp3
Created October 7, 2014 09:30
Convert a wav to a 320k mp3 using ffmpeg.
ffmpeg -i inputfile.wav -ab 320k outputfile.mp3
@dominicthomas
dominicthomas / SquareImageButton
Created September 2, 2014 12:06
Creates an imagebutton that will always have a height that matches the width. Useful if displayed in a row in a horizontal linear layout.
public class SquareImageButton extends ImageButton {
public SquareImageButton(Context context) {
this(context, null);
}
public SquareImageButton(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}