Skip to content

Instantly share code, notes, and snippets.

View dominicthomas's full-sized avatar

Dominic Thomas dominicthomas

View GitHub Profile
@dominicthomas
dominicthomas / Check Unknown Sources Setting
Created December 17, 2013 18:26
Check if "Unknown sources" is enabled on this device..
boolean unknownSources = Settings.Secure.getInt(getContentResolver(),
Build.VERSION.SDK_INT < 17 ?
Settings.Secure.INSTALL_NON_MARKET_APPS :
Settings.Global.INSTALL_NON_MARKET_APPS, 0) == 1;
@dominicthomas
dominicthomas / Simple AlertDialog.Builder
Created December 18, 2013 10:21
Create a simple positive/negative dialog builder... can be extended by passing in message, yes & no text and callback interfaces....
// pass in values as arguements if required...
private AlertDialog.Builder getSimpleDialogBuilder() {
return new AlertDialog.Builder(this)
.setMessage(getString("Some message here"))
.setCancelable(true)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do something
@dominicthomas
dominicthomas / Proguard Settings - Gradle
Created December 23, 2013 13:18
Android Studio/Gradle proguard enabling for buildType release? Needs to be tested. Trying to use proguard with gradle in older projects never seemed to work.
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
@dominicthomas
dominicthomas / Android Screen Size
Created January 4, 2014 16:40
Android screen size with platform backwards compatibility.
private Point getScreenSize() {
Point size = new Point();
WindowManager w = getWindowManager();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
w.getDefaultDisplay().getSize(size);
}else{
Display d = w.getDefaultDisplay();
size.x = d.getWidth();
size.y = d.getHeight();
}
@dominicthomas
dominicthomas / Android Display Content Height
Created January 4, 2014 16:41
Get screen height excluding the action bar and notification bar.
public int getDisplayContentHeight() {
final WindowManager windowManager = getWindowManager();
final Point size = new Point();
int screenHeight = 0, actionBarHeight = 0;
if (getActionBar() != null) {
actionBarHeight = getActionBar().getHeight();
}
int contentTop = ((ViewGroup) findViewById(android.R.id.content)).getTop();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
windowManager.getDefaultDisplay().getSize(size);
@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 / 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