Skip to content

Instantly share code, notes, and snippets.

View sonique6784's full-sized avatar

sonique6784

View GitHub Profile
@sonique6784
sonique6784 / RobolectricFlavourTestRunner.java
Last active March 10, 2017 01:21
Robolectric Flavour Test Runner (fix paths when you have an app with flavouring)
package au.com.myapp;
import org.junit.runners.model.InitializationError;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.manifest.AndroidManifest;
import org.robolectric.res.FileFsFile;
import org.robolectric.util.ReflectionHelpers;
@sonique6784
sonique6784 / CustomView.kt
Created June 15, 2021 13:13
Jetpack Compose: Custom View
import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
data class DataCustomView(
val title: String,
val description: String
@sonique6784
sonique6784 / CustomViewTest.kt
Created June 15, 2021 13:15
Jetpack Compose: CustomViewTest
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.test.assertTrue
@sonique6784
sonique6784 / GLFrontBufferedRenderer.kt
Last active December 16, 2022 20:55
GLFrontBufferedRenderer setup
/* Copyright 2022 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
val callbacks = object : GLFrontBufferedRenderer.Callback<DATA_TYPE> {
override fun onDrawFrontBufferedLayer(
eglManager: EGLManager,
bufferWidth: Int,
bufferHeight: Int,
transform: FloatArray,
param: DATA_TYPE
@sonique6784
sonique6784 / InputViewWithMotionEventPredicor.kt
Last active December 16, 2022 21:00
MotionEventPredicor setup
/* Copyright 2022 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class InputView : View {
// init motion predictor
val motionEventPredicor: MotionEventPredicor = MotionEventPredictor.newInstance(this)
setOnTouchListener
{
@sonique6784
sonique6784 / AutoNavMaterial3.kt
Last active December 19, 2022 20:37
A proposition of handling BottomBar, NavRail and NavDrawer in a single-composable.
/* Copyright 2022 Cedric Ferry.
SPDX-License-Identifier: Apache-2.0 */
import android.content.res.Configuration.ORIENTATION_LANDSCAPE
import android.content.res.Configuration.ORIENTATION_PORTRAIT
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable
@sonique6784
sonique6784 / ComposeIndicationAndHoverable.kt
Last active June 22, 2023 21:28
This show how to implements Indication and Hoverable on Compose. This is great to add Mouse and Stylus support in apps, such as hover state, focus state...
/* Copyright 2023 Google.
SPDX-License-Identifier: Apache-2.0 */
@Composable
fun hoverableHighlightAndPointer() {
val highlightIndication: Indication = remember {
HighlightIndication()
}
val interactionSource = MutableInteractionSource()
@sonique6784
sonique6784 / Collections.kt
Last active February 16, 2023 21:37
kotlin findLastIndex() extension function
// https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/collections/Collections.kt
/**
* Returns the index of the last item in the list that match predicate
* @param predicate function returning boolean for matching element.
*
* @return the index of the last element found
* otherwise returns -1
*/
public inline fun <T> List<T>.findLastIndex(predicate: (T) -> Boolean): Int {
@sonique6784
sonique6784 / vimrc.vim
Created February 21, 2023 23:06
vimrc
set backspace=2 " allow backspacing over everything in insert mode
set history=50 " keep 50 lines of command line history
set ignorecase " search commands are case-insensitive
set incsearch " while typing a search command, show matches incrementally
" instead of waiting for you to press enter
set ruler " show the cursor position all the time
set viminfo='20,\"50 " read/write a .viminfo file, don't store more than 50 lines of registers
set encoding=utf8 " non-ascii characters are encoded with UTF-8 by default
set formatoptions=croq " c=autowrap comments, r=continue comment on <enter>,
/* Copyright 2023 Cedric Ferry.
SPDX-License-Identifier: Apache-2.0 */
import android.view.Window
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat