Skip to content

Instantly share code, notes, and snippets.

Avatar

Nino Handler luckyhandler

View GitHub Profile
View DispatchersProvider.kt
package com.example.testingcoroutines
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
interface DispatchersProvider {
fun main(): CoroutineDispatcher = Dispatchers.Main
fun default(): CoroutineDispatcher = Dispatchers.Default
fun io(): CoroutineDispatcher = Dispatchers.IO
fun unconfined(): CoroutineDispatcher = Dispatchers.Unconfined
@luckyhandler
luckyhandler / collapsing_toolbar
Last active Sep 26, 2016
Android - Collapsing Toolbar Skeleton
View collapsing_toolbar
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
@luckyhandler
luckyhandler / convert_int_byte[]
Last active Sep 26, 2016
Java - int to byte[] / byte[] to int
View convert_int_byte[]
static byte[] mapPayload(int toConvert) {
byte[] ret = new byte[4];
ret[3] = (byte) (toConvert & 0xFF);
ret[2] = (byte) ((toConvert >> 8) & 0xFF);
ret[1] = (byte) ((toConvert >> 16) & 0xFF);
ret[0] = (byte) ((toConvert >> 24) & 0xFF);
return ret;
}
static int unmapPayload(byte[] payload) {
@luckyhandler
luckyhandler / snackbar_length_param
Created Sep 26, 2016
Android - Annotation Example
View snackbar_length_param
import android.support.annotation.IntDef;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static android.support.design.widget.Snackbar.LENGTH_INDEFINITE;
import static android.support.design.widget.Snackbar.LENGTH_LONG;
import static android.support.design.widget.Snackbar.LENGTH_SHORT;
@luckyhandler
luckyhandler / start_browser
Created Sep 25, 2016
Android - Start Browser
View start_browser
public static void startBrowser(@NonNull final Context context, @NonNull final String url, @Nullable final Bundle animationBundle) {
final String preparedUrl = trimUrl(url);
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(preparedUrl));
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(browserIntent, animationBundle);
}
private static String trimUrl(final String url) {
String toReturn = url;
if (!url.startsWith("http://") && !url.startsWith("https://")) {
@luckyhandler
luckyhandler / soft_restart.txt
Last active Sep 25, 2016
Android - Soft restart
View soft_restart.txt
/**
* Initiates a soft application restart.
* Clears the UI stack and opens the the entry class giving the impression of a new application start
* @param context the context the activity should be started from
* @param activity the activity which is declared as main entry point for the app
*/
public static void restartSoft(@Nonnull final Context context, @NonNull final Class<? extends Activity> activity) {
context.startActivity(new Intent(context, activity).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
}