Skip to content

Instantly share code, notes, and snippets.

@rabidaudio
Last active August 29, 2015 14:02
Show Gist options
  • Save rabidaudio/9c1589023a8616df92a0 to your computer and use it in GitHub Desktop.
Save rabidaudio/9c1589023a8616df92a0 to your computer and use it in GitHub Desktop.
Useful methods for Android
package com.rabidaudio;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import java.util.Iterator;
import java.util.Set;
/**
* Created by charles on 6/14/14.
* <p/>
* A set of useful methods across many apps.
*/
public class Common {
public static void dumpIntent(Intent i) {
dumpIntent(i, "Intent Dumper");
}
//Source: http://stackoverflow.com/a/16782044
public static void dumpIntent(Intent i, String LOG_TAG) {
Bundle bundle = i.getExtras();
if (bundle != null) {
Set<String> keys = bundle.keySet();
Iterator<String> it = keys.iterator();
Log.e(LOG_TAG, "Dumping Intent start");
while (it.hasNext()) {
String key = it.next();
Log.e(LOG_TAG, "[" + key + "=" + bundle.get(key) + "]");
}
Log.e(LOG_TAG, "Dumping Intent end");
}
}
public static void Toaster(Activity a, String message) {
Toast.makeText(a, message, Toast.LENGTH_SHORT).show();
}
public static int rand_int(int min, int max) {
return min + (int) (Math.random() * ((max - min) + 1));
}
public static int rand_int(int max) {
return rand_int(0, max);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment