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 / jacoco.gradle.kts
Last active August 29, 2024 09:09
Kotlin DSL JaCoCo configuration for Android
import com.android.build.gradle.internal.tasks.factory.dependsOn
plugins {
id("com.android.application")
jacoco
}
// Register the main JaCoCo task to later depend on the per-variant tasks
val jacocoTestReport = tasks.register("jacocoTestReport")
@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 / RememberWindowSize.kt
Last active February 11, 2023 08:55
Composable method for observing the current window metrics as a Size
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
/**
* Remembers the [Size] in pixels of the window corresponding to the current window
* metrics.
*/
@Composable
fun Activity.rememberWindowSize(): Size {
val configuration = LocalConfiguration.current
// WindowMetricsCalculator implicitly depends on the configuration
@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
@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,