Skip to content

Instantly share code, notes, and snippets.

View AfzalivE's full-sized avatar

Afzal Najam AfzalivE

View GitHub Profile
@AfzalivE
AfzalivE / ComposeLayoutPreviewHelper.kt
Last active February 9, 2023 14:37
AbstractComposeView layout preview helper
package com.yourpackage
import android.os.Bundle
import android.view.View
import androidx.compose.runtime.MonotonicFrameClock
import androidx.compose.runtime.PausableMonotonicFrameClock
import androidx.compose.runtime.Recomposer
import androidx.compose.ui.InternalComposeUiApi
import androidx.compose.ui.platform.AbstractComposeView
import androidx.compose.ui.platform.AndroidUiDispatcher
@AfzalivE
AfzalivE / androidx-M1.patch
Last active February 12, 2022 03:42
androidx-on-M1-Mac
This patch allows building androidx-main on a Mac with M1 Apple Silicon.
After following the instructions in the repository (https://github.com/androidx/androidx/blob/androidx-main/README.md)
to sync the repo, edit the patch below to replace YOUR_JDK_FOLDER_HERE with an arm64 JDK path, then apply this patch.
In prebuilts/androidx/external/com/google/protobuf folder, for the dependencies that
needs to be updated to version 3.19.4 because it supports aarch64,
create a 3.19.4 folder inside their folders. Here are the ones that need updating:
. protobuf-bom
. protobuf-java
. protobuf-java-util
@AfzalivE
AfzalivE / ands
Created July 6, 2021 18:35
Android Studio terminal launcher
#!/bin/bash
# check for where the latest version of IDEA is installed
STUDIOS=()
STUDIO_NAMES=()
while read line
do
studio=`echo $line`
STUDIOS+=("${studio}")
@AfzalivE
AfzalivE / BottomSheetScrollView.kt
Last active November 12, 2025 06:49
BottomSheetScrollView for when you have a ViewPager with RecyclerViews in your BottomSheet
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.NestedScrollingChildHelper
import androidx.core.view.NestedScrollingParent2
import androidx.core.view.ViewCompat
import androidx.recyclerview.widget.LinearLayoutManager
@AfzalivE
AfzalivE / LaunchCoroutines.kt
Last active February 4, 2021 17:58
Coroutines cancellation
fun main(args: Array<String>) {
val handler = CoroutineExceptionHandler { context, exception ->
println("CoroutineExceptionHandler got $exception with suppressed ${exception.suppressed.contentToString()}")
}
val parentScope = CoroutineScope(Dispatchers.Default + Job() + handler)
// val parentScope = MyScope()
parentScope.launch {
println("one job: " + this.coroutineContext[Job].toString())
println("Hello")
@AfzalivE
AfzalivE / ExplodingFab1.kt
Last active September 2, 2022 14:10
ExplodingFab Jetpack Compose
// Using Jetpack Compose Transition v1
enum class FabState {
Initial,
Normal,
Exploded,
}
val fabSizeKey = DpPropKey()
val fabColorKey = ColorPropKey()
class ForegroundServiceLauncher(private val serviceClass: Class<out Service>) {
private var isStarting = false
private var shouldStop = false
private var isCreated = false
@Synchronized
fun startService(context: Context, block: Intent.() -> Unit = {}) {
if (!isCreated) {
isStarting = true
@AfzalivE
AfzalivE / debug_from_qr.py
Created October 29, 2020 23:02 — forked from benigumocom/debug_from_qr.py
Connect Wireless Debug from Terminal on Android11
#!/usr/bin/env python3
"""
Android11
Pair and connect devices for wireless debug on terminal
python-zeroconf: A pure python implementation of multicast DNS service discovery
https://github.com/jstasiak/python-zeroconf
"""
@AfzalivE
AfzalivE / Fake.kt
Created October 14, 2020 22:47
fake() for all the unit tests
val ALL_FAKES = listOf(
FakePostLoginUseCase::class,
// all fake classes go here
)
/**
* Finds and initializes an instance of
* class [T] if it exists in [ALL_FAKES].
*
* If it doesn't, a [FakeNotFoundException] is thrown
@AfzalivE
AfzalivE / BasicNav.kt
Last active September 7, 2021 17:33
jetpack compose navigation
@Composable
fun VeryBasicNav() {
NavHost(startDestination = "Profile") { // this: NavGraphBuilder
composable("Profile") {
Profile()
}
composable("Dashboard") {
Dashboard()
}
composable("Scrollable") {