Skip to content

Instantly share code, notes, and snippets.

View mustafa01ali's full-sized avatar

Mustafa Ali mustafa01ali

View GitHub Profile
@mustafa01ali
mustafa01ali / gist:042fcab6c3ed40809a77
Created September 5, 2015 13:42
Gradle task to install and launch an app on a device/emulator
// Task to compile, install and run the debug build on a device/emulator
task run(type: Exec, dependsOn: 'installDebug') {
commandLine 'adb', 'shell', 'am', 'start', '-n', 'com.myapp/.MyFirstActivity'
}
@mustafa01ali
mustafa01ali / internet-monitor.sh
Last active August 29, 2015 14:28
Simple bash script to detect network outage and troll network admins
#!/bin/bash
while true
do
ping -c 1 www.example.com &> /dev/null
if [ $? -ne 0 ]; then
echo `date`: ping failed!
say "Hey network admin - internet is down" -v bruce
fi
sleep 10
@mustafa01ali
mustafa01ali / Hide soft keyboard
Created May 17, 2015 10:02
Hide soft keyboard
public static void hideKeyboard(Context context) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
@mustafa01ali
mustafa01ali / .gitignore
Created February 18, 2015 06:43
.gitignore for Android Studio projects
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
@mustafa01ali
mustafa01ali / gist:efab1f10b482a63c4bc5
Created December 6, 2014 01:23
Preventing fast clicks
private long mLastClickTime = 0;
protected boolean isNotAFastClick() {
boolean result = true;
if (SystemClock.elapsedRealtime() - mLastClickTime < FAST_CLICK_THRESHOLD) {
result = false;
}
mLastClickTime = SystemClock.elapsedRealtime();
return result;
}
@mustafa01ali
mustafa01ali / gist:027c79dcd6c917816e08
Created December 4, 2014 21:47
Simple logging util for Android
import android.util.Log;
/**
* @author Mustafa Ali
*/
public class L {
private static final String LOG_TAG = "MyAwesomeApp";
private static final boolean IS_LOGGING_ENABLED = true;
public static void d(String msg) {
import android.os.Handler;
import android.os.Looper;
import com.squareup.otto.Bus;
/**
* @author Mustafa Ali
*/
public class AppBus {
private Bus mBus = new Bus();