Skip to content

Instantly share code, notes, and snippets.

@kingargyle
kingargyle / AndroidManifest.xml
Created August 5, 2014 13:19
Android TV Recommendation Handlers.
<!-- Required for on Android TV to receive Boot Completed events -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- Need to Register the Recommendation Intent Service -->
<service android:name="us.nineworlds.serenity.core.services.OnDeckRecommendationIntentService"
android:enabled="true" android:exported="true"/>
<!-- The Receiver that actually responds to the Boot Completed event, needed
to start the recommendation service automatically when bootup has
@kingargyle
kingargyle / WebViewDialogSoftKeyboard
Last active August 29, 2015 14:04
Resize Dialog for Soft Keyboard input with Text Views
/**
* Make sure that the Dialog size adjusts when the softlkeyboard is displayed.
*/
alertDialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
/**
* Over ride onCheckIsTextEditor to always make sure the Webview
* brings up the softkeyboard when in an input field. There
* are situations like in a Dialog where the Softkeyboard will
@kingargyle
kingargyle / LeanbackUtil.java
Created August 10, 2014 19:14
Check to see if an Android device supports the Leanback system feature
public class LeanbackUtil {
/**
* Returns true if the Leanback System feature is available otherwise false
*
* Can be used to help determine if running on an android tv device with the leanback launcher.
*/
public static boolean isLeanbackSupported(Context context) {
final PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature("android.software.leanback");
}
@kingargyle
kingargyle / Gallery.java
Created August 19, 2014 14:29
Fix ItemLongClick and ItemClick both firing in Gallery widget
@kingargyle
kingargyle / VerifyRunOnUiThread
Created August 20, 2014 18:11
Verify that activity runOnUiThread is called using Robolectric and Mockito
/*
* Verifies that an activities runOnUiThread method is called and that
* appropriate class is called. In most cases we don't care about
* actually executing the runOnUiThread, just that it got called.
* By mocking out the Activity, we can use Mockito's verify method to
* make sure the method was called, with the expected Runnable class implementation
* passed into it.
*
* By doing this we avoid having to pause Robolectrics's UIScheduler and BackgroundSchedulers
* and then kick off the task. Since in this case it isn't actually necessary to run the code as it
@kingargyle
kingargyle / TransitionDrawableRunnable.java
Created August 21, 2014 13:25
A runable that handles only transitioning and crossfading when the bitmaps are different.
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.preference.PreferenceManager;
import android.view.View;
/**
* A runnable that transitions between a drawable and a bitmap.
@kingargyle
kingargyle / update-manifest.xml
Last active August 29, 2015 14:06
Update Version Number in AndroidManifest with POM version number.
<!--
Include the following snippet in a profile or as part of your standard build.
It will parse out the POM version number and then use it to update the
version number in your AndroidManfiest.xml. It will also increment the
versionCode based on the version number.
No more manually having to update the vesion number as part of a release!! Yipee!
-->
<plugin>
@kingargyle
kingargyle / SampleRecommendationContentProvider
Created November 15, 2014 21:39
RecomendationCardView ContentProvider Example
/**
* The MIT License (MIT)
* Copyright (c) 2014 David Carver
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
# Copyright (c) 2013 Embark Mobile
# Modified to work with Eclipse HIPP instance by David Carver
# Licensed under the MIT License.
# https://github.com/embarkmobile/android-sdk-installer
set +e
#detecting os
os=linux
if [[ `uname` == 'Darwin' ]]; then
@kingargyle
kingargyle / multifilepicker.java
Created October 19, 2015 18:15
Android 4.4+ Select Multiple Files with UI File Picker
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
// In code that handles the result returned to process the files:
ClipData clipData = intent.getClipData();