Skip to content

Instantly share code, notes, and snippets.

View billmote's full-sized avatar

Bill Mote billmote

  • Boca Raton, FL
  • 10:17 (UTC -04:00)
View GitHub Profile
import android.os.Parcel;
import android.os.Parcelable;
public class ParcelableHelper {
/**
* There is not always a guarantee that Parcelable values will be immediately written out and
* read back in. For data data that mutable (its own issue), this can be a problem. This is
* for the times when it would be great to have confidence that you will be working with a copy
* of that data.
@billmote
billmote / SomeClass.java
Last active May 2, 2016 20:10
Which do you prefer?
public class SomeClass {
someMethod(String className) {
// I see this more often
if (!TextUtils.isEmpty(className)) { // We have to ensure that className isn't null before calling equals()
if (className.equals(SomeClass.class.getName()) {
// do something
}
}
}
package com.example.helloworld.ui.adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.exacttarget.etpushsdk.adapter.CloudPageListAdapter;
@billmote
billmote / Foreground.java
Created January 21, 2016 19:30 — forked from steveliles/Foreground.java
Class for detecting and eventing whether an Android app is currently foreground or background (requires API level 14+)
package com.sjl.util;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import java.util.List;
class SoccerTeam {
private static int numWins;
private static int numLosses;
private static int numTies;
//these 2 variables are for the modified version
private static int numGames=0;
private static int numGoals=0;
@billmote
billmote / build.gradle
Created December 4, 2015 16:22 — forked from PhoenixIllusion/build.gradle
Using the local.properties file of an Android Studio project to select the latest BuildTools version
apply plugin: 'com.android.library'
android {
compileSdkVersion 'Google Inc.:Google APIs:22'
Properties localProps = new Properties()
localProps.load(new FileInputStream(file('../local.properties')))
def buildToolVer = file("${localProps['sdk.dir']}/build-tools/").listFiles().sort().reverse().first().name;
buildToolsVersion buildToolVer;
@billmote
billmote / DupeChecker.java
Last active November 10, 2015 13:25
"Write a method that determines whether all the characters in a string are the same, using only library string methods, but no loops or recursion." Tests ... assertEquals(true, allDuplicateChars("cccccc")); assertEquals(false, allDuplicateChars("abcdef"));
public class DupeChecker {
public boolean allDuplicateChars(final String input) {
if (input == null || input.length() == 0) {
return false;
}
String firstChar = input.substring(0,1);
String matchingChars[] = input.split(firstChar + "+");
return matchingChars.length == 0;
}
}
// annotation processor will generate DevicePhoneNumberSumType (see: 4_DevicePhoneNumberSumType.java)
@SumType
public interface DevicePhoneNumber {
String phoneNumber();
void phoneNumberNotAvailable();
String[] permissionsRequired();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
...
BarcodeLoggerActivityPermissionsDispatcher.startBarcodeCaptureWithCheck(this);
}
@NeedsPermission(Manifest.permission.CAMERA)
void startBarcodeCapture() {
int orientation = WindowManagerHelper.getCurrentAccurateOrientation(this);
Intent intent = CaptureActivity.buildIntent(this, orientation);
@billmote
billmote / ActivityPermissionDelegate.java
Created October 6, 2015 16:10 — forked from patrickhammond/ActivityPermissionDelegate.java
Pushing permission ugliness handling to one place.
import android.app.Activity;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import android.support.annotation.Size;
import android.support.v4.app.ActivityCompat;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
public class ActivityPermissionDelegate {
public interface PermissionRationaleRetryBehavior {