Skip to content

Instantly share code, notes, and snippets.

View dominicthomas's full-sized avatar

Dominic Thomas dominicthomas

View GitHub Profile
@dominicthomas
dominicthomas / VirtualBox Restart (Mavericks)
Created May 20, 2014 14:18
Genny Motion - Restart VirtualBox (Mavericks)
sudo /Library/Application\ Support/VirtualBox/LaunchDaemons/VirtualBoxStartup.sh restart
@dominicthomas
dominicthomas / VirtualBox Nexus5 Poweroff
Created June 11, 2014 13:56
Poweroff VirtualBox Vm
VBoxManage controlvm Google\ Nexus\ 5\ -\ 4.4.2\ -\ API\ 19\ -\ 1080x1920 poweroff
@dominicthomas
dominicthomas / Enum - Value From String
Created September 2, 2014 10:14
Use an enum to get a value from a string
private enum GravityExpandableText {
LEFT(Gravity.LEFT), RIGHT(Gravity.RIGHT), CENTER(Gravity.CENTER);
private final int mValue;
GravityExpandableText(int value) {
mValue = value;
}
@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);
}
@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 / 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 / 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 / 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 / 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 / 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));
}