Skip to content

Instantly share code, notes, and snippets.

View billmote's full-sized avatar

Bill Mote billmote

  • Boca Raton, FL
  • 04:23 (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 / 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;
@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;
// 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 {
<receiver
android:name=".DownloadBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:enabled="true" android:name="android.intent.action.DOWNLOAD_COMPLETE" />
</intent-filter>
</receiver>
package com.androidfu.nowplaying.app.api;
import android.content.Context;
import com.androidfu.nowplaying.app.util.Log;
import com.androidfu.nowplaying.app.util.Preconditions;
import com.jakewharton.byteunits.DecimalByteUnit;
import com.squareup.okhttp.Cache;
import com.squareup.okhttp.OkHttpClient;
@billmote
billmote / AndroidManifest.xml
Last active October 15, 2023 10:48 — forked from JakeWharton/gist:f50f3b4d87e57d8e96e9
When pushing code from your IDE, wake the device and show the activity.
<?xml version="1.0" encoding="utf-8"?>
<!-- Add this as a debug manifest so the permissions won't be required by your production app -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
</manifest>
import android.app.Activity;
import android.content.Context;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.test.ActivityInstrumentationTestCase2;
/**
* This requires to be declared in the effective manifest:
* <uses-permission android:name="android.permission.WAKE_LOCK"/>
*