Skip to content

Instantly share code, notes, and snippets.

View TylerMcCraw's full-sized avatar

Tyler McCraw TylerMcCraw

View GitHub Profile
@arcadefire
arcadefire / bottomsheet.kt
Created September 12, 2021 12:50
Bottom sheet
enum class States {
EXPANDED,
COLLAPSED
}
@ExperimentalMaterialApi
@Composable
fun FullHeightBottomSheet(
header: @Composable () -> Unit,
body: @Composable () -> Unit
@surajsau
surajsau / ParallaxScreen.kt
Last active May 18, 2024 08:16
Parallax effect with Jetpack Compose
@Composable
fun ParallaxScreen(modifier: Modifier = Modifier) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var data by remember { mutableStateOf<SensorData?>(null) }
DisposableEffect(Unit) {
val dataManager = SensorDataManager(context)
dataManager.init()
@jamiesanson
jamiesanson / ViewLifecycleLazy.kt
Last active March 26, 2024 13:17
A Kotlin lazy implementation which automatically clears itself at appropriate times in the View Lifecycle, with a Fragment example
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
fun <T> Fragment.viewLifecycleLazy(initialise: () -> T): ReadOnlyProperty<Fragment, T> =
object : ReadOnlyProperty<Fragment, T>, DefaultLifecycleObserver {
@orwir
orwir / SharedPreferencesExtensions.kt
Last active March 12, 2024 09:27
Kotlin extensions for shared preferences
import android.content.Context
import android.content.SharedPreferences
import kotlin.reflect.KProperty
/**
* Creates delegate for property from [prefs] with the key presented as className+propertyName.
* @param T type of the property
* @param defaultValue is used if property not set
* @return wrapper for property accessors
*/
@Zhuinden
Zhuinden / FragmentViewBindingDelegate.kt
Last active February 24, 2024 20:13
Fragment view binding delegate
// https://github.com/Zhuinden/fragmentviewbindingdelegate-kt
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.viewbinding.ViewBinding
import kotlin.properties.ReadOnlyProperty
@Mariovc
Mariovc / ImagePicker.java
Last active February 7, 2024 23:33
Utility for picking an image from Gallery/Camera with Android Intents
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
/*
* Copyright (C) 2017 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
*
* Unless required by applicable law or agreed to in writing, software
@libinbensin
libinbensin / MainActivity.java
Last active December 9, 2023 14:44
Facebook Popup using PopupWindow
public class MainActivity extends
private PopupWindow popWindow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@ychescale9
ychescale9 / build.gradle.kts
Last active September 18, 2023 11:52
Customizing APK file name with new AGP variant APIs
android {
onVariantProperties {
val mainOutput = outputs.single { it.outputType == VariantOutputConfiguration.OutputType.SINGLE }
tasks.register<CreateRenamedApk>("createRenamedApkFor${name}") {
this.originalApkFolder.set(artifacts.get(ArtifactType.APK))
this.builtArtifactsLoader.set(artifacts.getBuiltArtifactsLoader())
this.newApkFolder.set(layout.buildDirectory.dir("outputs/renamed_apk/${this@onVariantProperties.name}"))
this.versionCode.set(mainOutput.versionCode)
this.versionName.set(mainOutput.versionName)
}