Skip to content

Instantly share code, notes, and snippets.

View billmote's full-sized avatar

Bill Mote billmote

  • Boca Raton, FL
  • 02:37 (UTC -05:00)
View GitHub Profile
@billmote
billmote / AndroidManifest.xml
Last active August 29, 2015 14:08
Simple GCM Implementation
<!-- GCM permissions -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission
android:name="com.example.android.app.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
@billmote
billmote / strip_play_services.gradle
Last active August 29, 2015 14:07 — forked from dmarcato/strip_play_services.gradle
Additions to build.gradle that will strip out parts of google play services
def toCamelCase(String string) {
String result = ""
string.findAll("[^\\W]+") { String word ->
result += word.capitalize()
}
return result
}
afterEvaluate { project ->
Configuration runtimeConfiguration = project.configurations.getByName('compile')
@billmote
billmote / SpannableStringBuilderActivity.java
Last active August 29, 2015 14:07
A SpannableStringBuilder used, in this case, to bold parts of a result while typing in a search field.
// ...
final String contactName = this.contact.getFullname();
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(contactName);
final StyleSpan boldSpan = new StyleSpan(android.graphics.Typeface.BOLD);
if (!TextUtils.isEmpty(searchTerm) && contactName.toLowerCase().contains(searchTerm.toLowerCase())) {
int startIndex = contactName.toLowerCase().indexOf(searchTerm.toLowerCase());
int endIndex = startIndex + searchTerm.length();
spannableStringBuilder.setSpan(boldSpan, startIndex, endIndex, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
this.fullname.setText(spannableStringBuilder);
@billmote
billmote / forkproject.sh
Last active August 29, 2015 14:06
A quick find-and-replace script in support of forking projects.
#!/bin/bash
# chmod +x ./forkproject.sh # make this file executable
# Search and replace {NewRepoName}, {newappname} and {NewAppName}
# NOTE: this will mess up 1 URL in res/values/build_properties.xml, but you'll want your own API endpoint anyway ;)
cd ~/git/{NewRepoName}/app
mv ~/git/{NewRepoName}/app/src/main/java/com/androidfu/foundation ~/git/{NewRepoName}/app/src/main/java/com/androidfu/{newappname}
@billmote
billmote / copyfiles.sh
Created September 8, 2014 14:42
A script to pull data from old HDDs
#!/bin/bash
echo Making Directories
mkdir -p ~/backup/docs
mkdir -p ~/backup/pictures
mkdir -p ~/backup/music
mkdir -p ~/backup/movies
echo Copying images ...
@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:

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 / 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() {
/**
* 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 {
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 {