Skip to content

Instantly share code, notes, and snippets.

View dominicthomas's full-sized avatar

Dominic Thomas dominicthomas

View GitHub Profile
@dominicthomas
dominicthomas / Android .gitignore
Created October 22, 2013 20:17
Android Studio / Gradle .gitignore, with exclusions for eclipse, maven and ant as well.
#==== Android Studio / Gradle
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
@dominicthomas
dominicthomas / Nodejs admin permissions
Created October 22, 2013 20:19
Use after a fresh node install to make sure root and admin have group ownership and write permissions to the said folders. This ensures you can run 'npm install -g' without have to use sudo.
cd /usr/local/lib/
sudo chown -R :admin node_modules/ node/ dtrace/
sudo chown -R root node_modules/ node/ dtrace/
sudo chmod g+x node_modules/ node/ dtrace/
@dominicthomas
dominicthomas / Android - Create Signing Key
Created October 22, 2013 20:24
Generates a 2,048 bit RSA key pair and self-signed certificate (SHA1withRSA) with a validity of 10,000 days
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
@dominicthomas
dominicthomas / Android - Verifiy Signed
Created October 22, 2013 21:21
Verify apk is signed
jarsigner -verify -verbose -certs my_application.apk
@dominicthomas
dominicthomas / Update gradlew
Created October 23, 2013 10:07
Update the gradle wrapper. To update the system gradle use the guide here http://devopsnet.com/2012/05/24/upgrading-gradle/. The graddlew wrapper is packaged in with your project so is independent of the gradle version on your system.
gradlew with --refresh-dependencies
@dominicthomas
dominicthomas / Android ViewTreeObserver
Created November 1, 2013 14:41
How to add and remove a viewtreeobserver to an android view. This lets you call stuff when the view is finished rendering.
final ViewTreeObserver vto = myview.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressLint("NewApi")
@Override
public void onGlobalLayout() {
// do stuff
// remove this layout listener - as it will run every time the view updates
if (myview.getViewTreeObserver().isAlive()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
@dominicthomas
dominicthomas / Dialog - Custom layout
Created November 22, 2013 15:25
Simple dialog using a custom layout displayed full screen over the content, with no title or border etc..
private Dialog getCustomDialog(String productSpecs) {
final Dialog dialog = new Dialog(this, R.style.Dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
dialog.setCancelable(true);
dialog.setContentView(R.layout.some_layout);
// dialog.findViewById stuff here...
return dialog;
}
@dominicthomas
dominicthomas / Android Apk Info Dump
Created November 28, 2013 12:41
See package name, version and permissions of an apk.
aapt dump badging your.apk
@dominicthomas
dominicthomas / Android - Launch another app
Created November 28, 2013 16:16
Launch another app using an intent with package name if app has a launcher activity or using package name and class name of main activity.
// only works if app has a launcher activity
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.yourapp");
startActivity(launchIntent);
// works if we know the name of the main activity, even if not a launcher
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.example.yourapp", "com.example.yourapp.MainActivity");
startActivity(intent);