This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun onKeyUp(code: Int, ev: KeyEvent?): Boolean { | |
| return when (code) { | |
| KeyEvent.KEYCODE_J -> { | |
| // Do something here | |
| true | |
| } | |
| else -> super.onKeyUp(code, ev) // Important | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module GroupBy where | |
| import Data.Map (Map) | |
| import qualified Data.Map as Map | |
| groupBy :: Ord b => (a -> b) -> [a] -> Map b [a] | |
| groupBy f = foldr (\ v -> Map.insertWith (++) (f v) [v]) Map.empty | |
| groupBy' :: Ord b => (a -> b) -> [a] -> Map b [a] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.content.ActivityNotFoundException; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.pm.PackageManager; | |
| import android.net.Uri; | |
| import android.os.Bundle; | |
| import android.support.v4.app.Fragment; | |
| import android.support.v7.widget.CardView; | |
| import android.view.LayoutInflater; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final int defaultFlag = PackageManager.MATCH_DEFAULT_ONLY; | |
| Intent[] explicitIntents; | |
| //see an example here http://stackoverflow.com/questions/2662531/launching-google-maps-directions-via-an-intent-on-android | |
| private Intent[] getExplicitIntents() { | |
| if(explicitIntents == null) { | |
| PackageManager currentPM = getPackageManager(); | |
| explicitIntents = new Intent[]{ | |
| new Intent("android.intent.action.navigon.START_PUBLIC"), //navigon with public intent | |
| currentPM.getLaunchIntentForPackage("com.navigon.navigator"), //navigon without public intent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Code by @vmironov on Kotlinlang slack. | |
| * | |
| * This code uses dynamic proxies in Java to make it easier to access inaccessible classes via an accessible representation. | |
| */ | |
| inline fun <reified T : Any> createMirror(value: Any) = createMirror(value, T::class.java) | |
| fun <T> createMirror(value: Any, clazz: Class<T>): T { | |
| val loader = clazz.classLoader |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import androidx.annotation.StringRes | |
| import androidx.test.espresso.Espresso.onView | |
| import androidx.test.espresso.ViewInteraction | |
| import androidx.test.espresso.matcher.ViewMatchers | |
| import org.hamcrest.CoreMatchers | |
| import org.hamcrest.CoreMatchers.allOf | |
| fun onSnackbar(@StringRes withText: Int): ViewInteraction { | |
| return onView( | |
| CoreMatchers.allOf( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import androidx.compose.foundation.BorderStroke | |
| /* | |
| * Copyright 2020 The Android Open Source Project | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| Greeting message = Hi(); | |
| final result = match(message, { | |
| on((Hi hi) => "hello, ${hi.name}"), | |
| on((Bye bye) => "bye, see you at ${bye.seeYouAgain}"), | |
| otherwise(() => throw Error()), | |
| }); | |
| print(result); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| main() { | |
| // Either<dynamic, int> result | |
| final result = Either.Do(() { | |
| final num1 = perform(Right(5)); | |
| final num2 = perform(Right(2)); | |
| return num1 * num2; | |
| }); | |
| print(result.value); // 10 | |
| // Option<int> result2 | |
| final result2 = Option.Do(() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| main() { | |
| final value = async(() { | |
| final num1 = await(Future.value(5)); | |
| final num2 = await(Future.value(2)); | |
| return num1 * num2; | |
| }); | |
| value.then(print).catchError(print); | |
| async(() { | |
| [1,2,3,4,5].forEach((i) { |
OlderNewer