Skip to content

Instantly share code, notes, and snippets.

View alexvanyo's full-sized avatar

Alex Vanyo alexvanyo

View GitHub Profile
@alexvanyo
alexvanyo / hid.sh
Created October 11, 2018 23:02
HID Descriptor for use with HID Synergy
#!/bin/bash
# Snippet from https://github.com/girst/hardpass-sendHID/blob/master/README.md . In which, the following notice was left:
# this is a stripped down version of https://github.com/ckuethe/usbarmory/wiki/USB-Gadgets - I don't claim any rights
modprobe libcomposite
cd /sys/kernel/config/usb_gadget/
mkdir -p g1
cd g1
echo 0x1d6b > idVendor # Linux Foundation
@alexvanyo
alexvanyo / ImeProgressWindowInsetAnimation.kt
Last active November 15, 2020 19:49
WindowInsetsAnimation.Callback for IME animations that supplies a `progress` callback for use with MotionLayout
/**
* A [WindowInsetsAnimation.Callback] and [OnApplyWindowInsetsListener] for nicely handling IME animations.
*
* When the keyboard is opened and closed, [onProgress] will be called with a float value between 0 and 1 that
* corresponds to how far the IME has opened, where 0 means the IME is closed and 1 means the IME is fully open.
*
* [windowInsetsListener] will be forwarded on by the implementation of [OnApplyWindowInsetsListener].
*
* This approach is loosely based on the
* [WindowInsetsAnimation](https://github.com/android/user-interface-samples/tree/master/WindowInsetsAnimation) sample.
@alexvanyo
alexvanyo / SaveableSavedStateHandle.kt
Last active August 3, 2021 22:49
Prototype interoperability layer between `SavedStateHandle` and the Compose saveable API
/*
* Copyright 2021 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@alexvanyo
alexvanyo / SizeAwareModalDrawer.kt
Last active January 14, 2022 20:34
A modal drawer that is window size aware
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
val isExpandedScreen = windowSize == WindowSize.Expanded
ModalDrawer(
drawerContent = {
AppDrawer(/* ... */)
},
// Only enable opening the drawer via gestures if the screen is not expanded
@alexvanyo
alexvanyo / SizeAwareTabRow.kt
Last active January 14, 2022 20:35
A tab row that is window size aware
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
private fun InterestsTabRow(
selectedTabIndex: Int,
updateSection: (Sections) -> Unit,
tabContent: List<TabContent>,
isExpandedScreen: Boolean
) {
@alexvanyo
alexvanyo / CoreHomeRoute.kt
Last active January 14, 2022 20:35
The primary structure of the HomeRoute
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
fun HomeRoute(
isExpandedScreen: Boolean,
isArticleOpen: Boolean,
selectedArticleId: String,
onSelectArticle: (String) -> Unit,
onArticleBackPress: () -> Unit,
@alexvanyo
alexvanyo / HomeRouteScrollState.kt
Last active January 14, 2022 20:35
The scroll state hoisting for the HomeRoute
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
fun HomeRoute(
isExpandedScreen: Boolean,
isArticleOpen: Boolean,
selectedArticleId: String,
onSelectArticle: (String) -> Unit,
onArticleBackPress: () -> Unit,
@alexvanyo
alexvanyo / HomeListWithArticleDetailsScreen.kt
Last active January 14, 2022 20:36
Usage of notifyInput in HomeListWithArticleDetailScreen
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
fun HomeListWithArticleDetailsScreen(
onInteractWithList: () -> Unit,
onInteractWithDetail: (String) -> Unit,
// ...
) {
Row {
@alexvanyo
alexvanyo / NotifyInput.kt
Last active January 14, 2022 21:06
A Modifier to track all touch inputs on a Composable
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
/**
* A [Modifier] that tracks all input, and calls [block] every time input is received.
*/
private fun Modifier.notifyInput(block: () -> Unit): Modifier =
composed {
val currentBlock by rememberUpdatedState(block)
pointerInput(Unit) {
while (currentCoroutineContext().isActive) {
@alexvanyo
alexvanyo / WindowSizeClass.kt
Last active February 3, 2022 10:32
Composable method for observing the current window size class
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
enum class WindowSize { Compact, Medium, Expanded }
/**
* Remembers the [WindowSize] class for the window corresponding to the
* current window metrics.
*/
@Composable