Skip to content

Instantly share code, notes, and snippets.

View luckyhandler's full-sized avatar
💭
👨‍💻

Nino Handler luckyhandler

💭
👨‍💻
View GitHub Profile
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 September 26, 2016 19:51
Android - Collapsing Toolbar Skeleton
<?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 September 26, 2016 19:42
Java - int to byte[] / byte[] to int
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 September 26, 2016 19:39
Android - Annotation Example
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 September 25, 2016 21:26
Android - 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 September 25, 2016 21:06
Android - Soft restart
/**
* 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));
}