Skip to content

Instantly share code, notes, and snippets.

View billmote's full-sized avatar

Bill Mote billmote

  • Boca Raton, FL
  • 04:22 (UTC -04:00)
View GitHub Profile
@billmote
billmote / LearningApplication.java
Created July 28, 2014 19:18
Force StrictMode for developer builds without requiring tweaking of the phone/emulator settings.
/**
* Created by Bill on 7/28/14.
*/
public class LearningApplication extends Application {
private static final String TAG = QuickeyLearningApplication.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
package com.atomicrobot.app;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
public class ActivityFirstRunHelper {
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import com.google.analytics.tracking.android.EasyTracker;
public class MainApplication extends Application {
int visibleActivities = 0;
@Override
@billmote
billmote / OnTouchSpinnerActivity.java
Last active August 27, 2016 08:55
A spinner that only updates when the user touches the screen
// A member variable
private boolean userIsInteracting;
/*
Beginning with API level 3 you can use onUserInteraction() on an Activity with a boolean to determine if the user is interacting with the device.
http://developer.android.com/reference/android/app/Activity.html#onUserInteraction()
*/
@Override
public void onUserInteraction() {
tag:^((?!CoreMetrics|InputEventConsistency|memalloc|Adreno200-EGLSUB|Resources|global|TaggingRequest|Facade[B|U]|dalvik|skia|KeyCharacterMap|BackStackEntry|FragmentManager|ServiceRunnable|ServiceLocator|BaseHttpRequest|szipinf|APACHE).)*$
// In Android Studio you do not include the leading "tag:" but you must "edit a filter configuration" in order to use this. It does not appear that the in-line search field supports RegEx.
// This line would remove any log line that included the words: StringMode, System.err or GAV4
^((?!StrictMode|System.err|GAV4).)*$
package com.atomicrobot.app;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
public class ActivityFirstRunHelper {
/**
* Log
* <p/>
* <pre>
* 20140623 -- Added wtf logging and a wrapper to protect against API versions prior to FROYO (8)
* 20130114 -- Code Review
* </pre>
*/
public class Log {
@billmote
billmote / HorsePowerApplication.java
Last active August 29, 2015 14:05
How much horsepower does my phone have?
public static Long CPU_MAX_FREQUENCY;
@Override
public void onCreate(){
// ...
CPU_MAX_FREQUENCY = getCpuMaxFrequency();
// ...
}
private Long getCpuMaxFrequency() {

Context

I was previously using https://gist.github.com/dmarcato/d7c91b94214acd936e42 to strip down Google Mobiele Services, but the build times for my project in Android Studio consistently exceeded 75 seconds; this solution is much less dynamic (and even a little ugly) but keeps my build times less than 15s.

Assumptions

  • Your app module has a directory named aars that will work as a project specific Maven repository; this directory should be placed under version control.
  • Maven (mvn) is installed and available on your path when running this script.

Disclaimer

I make absolutely NO claim the Python script follows typical Python code style, is clean, or is even safe. It is just a dumb, brute force script.

@billmote
billmote / ListViewByTypeActivity.java
Last active August 29, 2015 14:06
A ListView with 4 different row types built, originally, to populate a custom NavigationDrawer.
// ...
@DebugLog
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case android.R.id.home: