Skip to content

Instantly share code, notes, and snippets.

View cnevinc's full-sized avatar

Nevin cnevinc

View GitHub Profile
@deepanshu42
deepanshu42 / RequestModuleWithCallback.java
Created September 2, 2018 20:43
Request an on demand module with callbacks
int mySessionId = 0;
// Creates a listener for request status updates.
SplitInstallStateUpdatedListener listener = state -> {
if (state.status() == SplitInstallSessionStatus.FAILED
&& state.errorCode() == SplitInstallErrorCode.SERVICE_DIES) {
// Retry the request.
return;
}
if (state.sessionId() == mySessionId) {
switch (state.status()) {
@JoseAlcerreca
JoseAlcerreca / EventObserver.kt
Created April 26, 2018 12:14
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
@ChrisXu
ChrisXu / .travis.yml
Last active January 16, 2019 22:14
Deploy an app automatically to Fabric Beta using Travis-CI.
language: objective-c
osx_image: xcode7.2
xcode_sdk: iphonesimulator9.2
env:
global:
- LANG=en_US.UTF-8
- WORKSPACE="YOUR_APP_WORKSPACE/YOUR_APP_PROJECT.xcworkspace"
- SCHEME="YOUR_BUILDSCHEME"
- APP_NAME="YOUR_APP_NAME"
@sargunv
sargunv / AnkoSupportLibrary.kt
Last active February 13, 2017 14:10 — forked from mgranberry/DesignSupport.kt
A set of Anko-compatible extensions for Google's support libraries
import android.app.Activity
import android.support.design.widget.*
import android.support.v4.app.Fragment
import android.support.v4.view.PagerTabStrip
import android.support.v4.view.PagerTitleStrip
import android.support.v4.view.ViewPager
import android.support.v4.widget.DrawerLayout
import android.support.v4.widget.SlidingPaneLayout
import android.support.v7.widget.CardView
import android.support.v7.widget.GridLayout
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/** Got flaky tests? Shampoo them away. */
public final class ShampooRule implements TestRule {
private final int iterations;
public ShampooRule(int iterations) {
if (iterations < 1) throw new IllegalArgumentException("iterations < 1: " + iterations);
@mgranberry
mgranberry / DesignSupport.kt
Created June 2, 2015 21:26
A set of Anko-compatible extensions for Google's Material Design Support Library
fun ViewManager.appBarLayout(init: AppBarLayout.() -> Unit = {}) =
__dslAddView({ AppBarLayout(it) }, init, this)
fun ViewManager.collapsingToolbarLayout(init: CollapsingToolbarLayout.() -> Unit = {}) =
__dslAddView({ CollapsingToolbarLayout(it) }, init, this)
fun ViewManager.coordinatorLayout(init: CoordinatorLayout.() -> Unit = {}) =
__dslAddView({ CoordinatorLayout(it) }, init, this)
fun ViewManager.floatingActionButton(init: FloatingActionButton.() -> Unit = {}) =
@jgilfelt
jgilfelt / ScalpelDrawer.java
Last active January 28, 2017 13:09
ScalpelDrawer - A simple wrapper for Scalpel (https://github.com/JakeWharton/scalpel) that includes toggle controls accessible from a right-side navigation drawer. Call ScalpelDrawer.wrapInside() in a base Activity onPostCreate() to easily wrap all content in your app.
package com.example.scalpeldrawer;
import android.app.Activity;
import android.content.Context;
import android.support.v4.widget.DrawerLayout;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
@dodyg
dodyg / gist:5823184
Last active March 29, 2024 03:59
Kotlin Programming Language Cheat Sheet Part 1

#Intro

Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3

Kotlin project website is at kotlin.jetbrains.org.

All the codes here can be copied and run on Kotlin online editor.

Let's get started.

@JakeWharton
JakeWharton / OkHttpStack.java
Created May 21, 2013 01:14
A `HttpStack` implementation for Volley that uses OkHttp as its transport.
import com.android.volley.toolbox.HurlStack;
import com.squareup.okhttp.OkHttpClient;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* An {@link com.android.volley.toolbox.HttpStack HttpStack} implementation which
* uses OkHttp as its transport.
*/