Skip to content

Instantly share code, notes, and snippets.

Kiran Rao curioustechizen

Block or report user

Report or block curioustechizen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@curioustechizen
curioustechizen / LiveDataScanOperator.kt
Created Jan 23, 2019
Analog of RxJava's Observable.scan operator for Android Architecture Components LiveData
View LiveDataScanOperator.kt
/**
* Analog of RxJava's Observable.scan operator.
*
* Returns a LiveData that applies the [accumulator] function to the fist item in the source LiveData,
* and an initial value, then feeds the result of that function along with the second item emitted by
* the source LiveData into the same function, and so on until all items have been emitted by the source
* LiveData, emitting the result of each of these iterations.
*/
fun <T, R> LiveData<T>.scan(initialValue: R, accumulator: (R, T) -> R): LiveData<R> {
val returnLiveData = MediatorLiveData<R>()
@curioustechizen
curioustechizen / CascadingCustomLayout.java
Created Mar 19, 2018
Android: Cascade the value of a custom attribute from a parent view to a child view - solution to https://stackoverflow.com/q/15112522/570930
View CascadingCustomLayout.java
// 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
View EspressoTextInputLayoutUtils.java
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)));
}
@curioustechizen
curioustechizen / MainActivity.java
Last active Sep 16, 2015
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.
View MainActivity.java
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 Jul 10, 2015
Snippet for Visual Studio Code that created a revealing module pattern with constructor in Javascript
View js_revealing_module_snippet.js
"Revealing Module Pattern with constructor": {
"prefix": "reveal",
"body": [
"var ${1:ModuleName} = (function () {",
" var that,",
" constr = function (${2:constr_param}) {",
" that = this;",
" this.$2 = $2;",
" },",
"",
View markdown.css
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
@curioustechizen
curioustechizen / UseApiKey.java
Created Apr 6, 2015
Android: Loading API Keys and other secrets from properties file using gradle
View UseApiKey.java
String apiKey = BuildConfig.API_KEY
View build.gradle
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()
@curioustechizen
curioustechizen / EnhancedCheckBox.java
Last active May 29, 2019
Android programmatically checkable widgets, differentiate between user clicks & programmatic setChecked calls. Based on this answer on StackOverflow: http://stackoverflow.com/a/14307643/570930. There are times when setting a switch to ON results in some action (Save to DB/ perform an HTTP POST etc). However, you want this action to happen only o…
View EnhancedCheckBox.java
/**
* An enhanced {@code CheckBox} that differentiates between user clicks and
* programmatic clicks. In particular, the {@code OnCheckedChangeListener} is
* <strong>not</strong> triggered when the state of the checkbox is changed
* programmatically.
*
*/
public class EnhancedCheckBox extends CheckBox implements ProgrammaticallyCheckable{
private CompoundButton.OnCheckedChangeListener mListener = null;
public EnhancedCheckBox(Context context) {
@curioustechizen
curioustechizen / StateSavingArrayAdapter.java
Last active Jun 17, 2018
StateSavingArrayAdapter: An ArrayAdapter that knows how to save/restore its own state.
View StateSavingArrayAdapter.java
/**
* <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
You can’t perform that action at this time.