Skip to content

Instantly share code, notes, and snippets.

View arriolac's full-sized avatar
🌍

Chris Arriola arriolac

🌍
View GitHub Profile
@arriolac
arriolac / TopCropImageView.java
Last active March 6, 2025 07:32
Custom Android ImageView for top-crop scaling of the contained drawable.
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
* Created by chris on 7/27/16.
// Copyright 2023 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
fun EpisodePlayerWithBackground(/* ... */) {
// Initialize a FocusRequester object
val focusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) {
// Copyright 2023 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
private fun HomeContentGrid(/* ... */) {
LazyVerticalGrid(
// Adapt number of columns wherein each column has at least 362.dp of space
columns = GridCells.Adaptive(362.dp),
modifier = modifier.fillMaxSize()
) {
@arriolac
arriolac / CustomView.java
Last active January 18, 2024 19:53
Saving state on configuration changes for a custom view.
package com.operator.android;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
/**
* A custom {@link View} that demonstrates how to save/restore instance state.
*/
// Copyright 2023 Google LLC.
// SPDX-License-Identifier: Apache-2.0
/**
* State holder for DropDownCheckBoxMenu
*/
class DropDownCheckboxMenuState(
var items: List<String>,
) {
// Internal set of selected items managed by wrapper
// Copyright 2023 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
fun DropDownCheckboxMenu(
items: List<String>,
selectedItems: Set<Int>,
onItemToggled: (Boolean, Int) -> Unit,
modifier: Modifier = Modifier
) {
// Copyright 2023 Google LLC.
// SPDX-License-Identifier: Apache-2.0
class DropDownCheckboxMenuView(context: Context) : View(context) {
/**
* The set of selected items in the menu
*/
fun setSelectedItems(items: Set<Int>) { /* ... */ }
@arriolac
arriolac / CheckBox.kt
Last active October 10, 2023 17:44
Refactoring CheckBox to not be stateful
// Copyright 2023 Google LLC.
// SPDX-License-Identifier: Apache-2.0
class CheckBox(context: Context) : View(context) {
override fun performClick(): Boolean {
// Refactor: prevent the checkbox from toggling when clicked
// toggleCheck()
return super.performClick()
}
// Copyright 2023 Google LLC.
// SPDX-License-Identifier: Apache-2.0
var checked by remember { mutableStateOf(false)}
Checkbox(checked = checked, onCheckedChange = {
checked = it
})
// Copyright 2023 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
fun DropDownCheckboxMenu(
items: List<String>,
onItemToggled: (Boolean, Int) -> Unit,
modifier: Modifier = Modifier
) {
AndroidView(