Skip to content

Instantly share code, notes, and snippets.

@curioustechizen
curioustechizen / LocalBroadcastReceiver.java
Created May 24, 2012 10:54
Adding ordered broadcast capability to LocalBroadcastManager from Android support library.
package in.curtech.android.common;
import android.content.BroadcastReceiver;
/**
* Extension of {@code BroadcastReceiver} meant to be used in conjunction with
* {@link OrderEnabledLocalBroadcastManager}
*
* @author Kiran Rao
*/
@curioustechizen
curioustechizen / NsdReflectionUtils.java
Created April 26, 2013 08:37
Using reflection to try and get the DnsSdTxtRecord object from NdsServiceInfo while using [android.net.nsd](http://developer.android.com/reference/android/net/nsd/NsdManager.html) for performing mDNS discovery. This sample uses [fest-reflect](https://github.com/alexruiz/fest-reflect) for reflection.
import static org.fest.reflect.core.Reflection.*;
import android.net.nsd.NsdServiceInfo;
public class ReflectionUtils {
public static int extractTxtRecordFromServiceInfo(NsdServiceInfo serviceInfo) {
Class<?> dnsSdTxtRecordType = type("android.net.nsd.DnsSdTxtRecord")
.load();
Object txtRecord =
method("getTxtRecord")
.withReturnType(dnsSdTxtRecordType)
@curioustechizen
curioustechizen / AsyncTaskUtils.java
Created March 11, 2013 06:57
Snippet demonstrating how to ensure AsyncTasks are always executed in parallel (the default pre-HC behavior)
import android.annotation.TargetApi;
import android.os.AsyncTask;
import android.os.Build;
public class AsyncTaskUtils {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static <P> void executeAsyncTaskInParallel(
AsyncTask<P, ?, ?> asyncTask, P... params) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
@curioustechizen
curioustechizen / MainActivity.java
Last active September 16, 2015 13:10
Android Visibility save/restore: Quick gist to demonstrate the fact that the visibility of views is not preserved across screen rotation or other save/restore cycles.
public class MainActivity extends Activity {
private TextView tvHello;
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.layout);
tvHello = (TextView) findViewById(R.id.tv_hello);
}
@curioustechizen
curioustechizen / js_revealing_module_snippet.js
Created July 10, 2015 13:52
Snippet for Visual Studio Code that created a revealing module pattern with constructor in Javascript
"Revealing Module Pattern with constructor": {
"prefix": "reveal",
"body": [
"var ${1:ModuleName} = (function () {",
" var that,",
" constr = function (${2:constr_param}) {",
" that = this;",
" this.$2 = $2;",
" },",
"",
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
def logger = new com.android.build.gradle.internal.LoggerWrapper(project.logger)
def sdkHandler = new com.android.build.gradle.internal.SdkHandler(project, logger)
for (File file : sdkHandler.sdkLoader.repositories) {
project.repositories.maven {
url = file.toURI()