Skip to content

Instantly share code, notes, and snippets.

View curioustechizen's full-sized avatar

Kiran Rao curioustechizen

View GitHub Profile
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()
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
@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;",
" },",
"",
@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 / 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 / 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 / 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 / CascadingCustomLayout.java
Created March 19, 2018 08:33
Android: Cascade the value of a custom attribute from a parent view to a child view - solution to https://stackoverflow.com/q/15112522/570930
// See https://stackoverflow.com/q/15112522/570930
class CustomLayout extends WhateverLayout {
private float percent;
private CustomView customView;
//View constructors go here
private void init(){
//Inflation goes here if needed
@curioustechizen
curioustechizen / StateSavingArrayAdapter.java
Last active June 17, 2018 09:56
StateSavingArrayAdapter: An ArrayAdapter that knows how to save/restore its own state.
/**
* <p>
* An {@code ArrayAdapter} that also knows how to save and restore its state.
* Basically all it does is save/restore the array of objects being managed by
* the Adapter.
* </p>
*
* <p>
* Note that this only saves the items and not things like checked item
* positions. Those belong to the {@link ListView} itself. Consider using
class EspressoTextInputLayoutUtils{
/*
* Use this method to find the EditText within the TextInputLayout. Useful for typing into the TextInputLayout
*/
public static ViewInteraction onEditTextWithinTilWithId(@IdRes int textInputLayoutId) {
//Note, if you have specified an ID for the EditText that you place inside
//the TextInputLayout, use that instead - i.e, onView(withId(R.id.my_edit_text));
return onView(allOf(isDescendantOfA(withId(textInputLayoutId)), isAssignableFrom(EditText.class)));
}