Skip to content

Instantly share code, notes, and snippets.

View tunjos's full-sized avatar

Tunji Olu-Taiwo tunjos

View GitHub Profile
@tunjos
tunjos / build.gradle
Created July 7, 2015 12:25
versionName config
def versionMajor = 3
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
android {
defaultConfig {
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
}
@tunjos
tunjos / checkForPower.java
Created June 23, 2015 02:35
Checks if device is charging
private boolean checkForPower() {
// It is very easy to subscribe to changes to the battery state, but you can get the current
// state by simply passing null in as your receiver. Nifty, isn't that?
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = this.registerReceiver(null, filter);
// There are currently three ways a device can be plugged in. We should check them all.
int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = (chargePlug == BatteryManager.BATTERY_PLUGGED_USB);
@tunjos
tunjos / LogHelper.java
Last active August 29, 2015 14:19
LogHelper Class
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
public class LogHelper {
private static final String LOG_TAG = MyConstants.APP_NAME;
public static void log(String message) {
Log.d(LOG_TAG, message);
}
/**
* @author marco
* Workaround to be able to scroll text inside a TextView without it required
* to be focused. For some strange reason there isn't an easy way to do this
* natively.
*
* Original code written by Evan Cummings:
* http://androidbears.stellarpc.net/?p=185
*/
public class ScrollingTextView extends TextView {