Kotlin extensions, BindingAdapters, Composable functions for Android CameraX

Overview

Setup

dependencies {
    implementation "com.github.skgmn:cameraxx:0.6.0"
}

Features

CameraXX provides extensions methods for CameraX to use functions with coroutines and flows.

suspend fun Context.getProcessCameraProvider(): ProcessCameraProvider
fun PreviewView.listenPreviewStreamState(): Flow<PreviewView.StreamState>
suspend fun ImageCapture.takePicture(): ImageProxy
suspend fun ImageCapture.takePicture(ImageCapture.OutputFileOptions): ImageCapture.OutputFileResults
fun ImageAnalysis.analyze(): Flow<ImageProxy>
You might also like...
🧮 Provides simple and advanced mathematical functions in a beautifully designed UI.
🧮 Provides simple and advanced mathematical functions in a beautifully designed UI.

Calculator 🧮 Android App 🔗 Download the App 🤔 What is this App ✍️ This will basically provide simple and advanced mathematical functions in a beaut

Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Kotlin_practice_problems Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP)

Mockative Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP). Installation Mockative uses KSP to generate

Kotlin-oop - Repositório criado para ser utilizado pelo projeto de Kotlin OOP desenvolvido em Kotlin nas aulas feitas através da plataforma Alura.

Projeto React OOP Repositório criado para ser utilizado pelo projeto de Kotlin OOP desenvolvido em Kotlin nas aulas feitas através da plataforma Alura

Kotlin-koans - Kotlin Koans are a series of exercises to get you familiar with the Kotlin Syntax

kotlin-koans-edu Kotlin Koans are a series of exercises to get you familiar with

Modular Android architecture which showcase Kotlin, MVVM, Navigation, Hilt, Coroutines, Jetpack compose, Retrofit, Unit test and Kotlin Gradle DSL.

SampleCompose Modular Android architecture which showcase Kotlin, MVVM, Navigation, Hilt, Coroutines, Jetpack compose, Retrofit, Unit test and Kotlin

🎲 Kotlin Symbol Processor to auto-generate extensive sealed classes and interfaces for Android and Kotlin.
🎲 Kotlin Symbol Processor to auto-generate extensive sealed classes and interfaces for Android and Kotlin.

SealedX 🎲 Kotlin Symbol Processor to auto-generate extensive sealed classes and interfaces for Android and Kotlin. Why SealedX? SealedX generates ext

Clean Android multi-module offline-first scalable app in 2022. Including Jetpack Compose, MVI, Kotlin coroutines/Flow, Kotlin serialization, Hilt and Room.

Android Kotlin starter project - 2022 edition Android starter project, described precisely in this article. Purpose To show good practices using Kotli

Kotlin TodoMVC – full-stack Kotlin application demo

Kotlin full stack TodoMVC This project is an example implementation of the TodoMVC app written in Kotlin. More specifically, it's the Kotlin port of t

Comments
  • Failed to call observer method

    Failed to call observer method

    Hello,

    I encountered the following bug. When I use your project in my composable it launches fine for the first time, but when I navigate somewhere (at least 2 views deep) and then come back to view using CameraPreview my app crashes with this:

    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: pl.noolstudio.<redactedAppName>, PID: 21901
        java.lang.RuntimeException: Failed to call observer method
            at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:226)
            at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:194)
            at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:185)
            at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:37)
            at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
            at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:284)
            at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:302)
            at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:148)
            at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.java:121)
            at androidx.navigation.NavBackStackEntry.updateState(NavBackStackEntry.kt:169)
            at androidx.navigation.NavBackStackEntry.setMaxLifecycle(NavBackStackEntry.kt:150)
            at androidx.navigation.NavController$NavControllerNavigatorState.markTransitionComplete(NavController.kt:312)
            at androidx.navigation.compose.ComposeNavigator.onTransitionComplete$navigation_compose_release(ComposeNavigator.kt:71)
            at androidx.navigation.compose.NavHostKt$NavHost$3$2$1$invoke$$inlined$onDispose$1.dispose(Effects.kt:486)
            at androidx.compose.runtime.DisposableEffectImpl.onForgotten(Effects.kt:85)
            at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers(Composition.kt:772)
            at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:639)
            at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invoke(Recomposer.kt:479)
            at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invoke(Recomposer.kt:416)
            at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame(AndroidUiFrameClock.android.kt:34)
            at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch(AndroidUiDispatcher.android.kt:109)
            at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch(AndroidUiDispatcher.android.kt:41)
            at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:69)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:970)
            at android.view.Choreographer.doCallbacks(Choreographer.java:796)
            at android.view.Choreographer.doFrame(Choreographer.java:727)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
            at android.os.Handler.handleCallback(Handler.java:938)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:223)
            at android.app.ActivityThread.main(ActivityThread.java:7656)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
         Caused by: java.lang.NullPointerException
            at androidx.core.util.Preconditions.checkNotNull(Preconditions.java:119)
            at androidx.camera.lifecycle.LifecycleCameraRepository.suspendUseCases(LifecycleCameraRepository.java:433)
            at androidx.camera.lifecycle.LifecycleCameraRepository.setInactive(LifecycleCameraRepository.java:387)
            at androidx.camera.lifecycle.LifecycleCameraRepository.unregisterLifecycle(LifecycleCameraRepository.java:214)
            at androidx.camera.lifecycle.LifecycleCameraRepository$LifecycleCameraRepositoryObserver.onDestroy(LifecycleCameraRepository.java:514)
            at java.lang.reflect.Method.invoke(Native Method)
            at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:219)
            at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:194) 
            at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:185) 
            at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:37) 
            at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354) 
            at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:284) 
            at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:302) 
            at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:148) 
            at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.java:121) 
            at androidx.navigation.NavBackStackEntry.updateState(NavBackStackEntry.kt:169) 
            at androidx.navigation.NavBackStackEntry.setMaxLifecycle(NavBackStackEntry.kt:150) 
            at androidx.navigation.NavController$NavControllerNavigatorState.markTransitionComplete(NavController.kt:312) 
            at androidx.navigation.compose.ComposeNavigator.onTransitionComplete$navigation_compose_release(ComposeNavigator.kt:71) 
            at androidx.navigation.compose.NavHostKt$NavHost$3$2$1$invoke$$inlined$onDispose$1.dispose(Effects.kt:486) 
            at androidx.compose.runtime.DisposableEffectImpl.onForgotten(Effects.kt:85) 
            at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers(Composition.kt:772) 
            at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:639) 
            at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invoke(Recomposer.kt:479) 
            at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invoke(Recomposer.kt:416) 
            at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame(AndroidUiFrameClock.android.kt:34) 
            at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch(AndroidUiDispatcher.android.kt:109) 
            at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch(AndroidUiDispatcher.android.kt:41) 
            at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:69) 
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:970) 
            at android.view.Choreographer.doCallbacks(Choreographer.java:796) 
            at android.view.Choreographer.doFrame(Choreographer.java:727) 
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957) 
            at android.os.Handler.handleCallback(Handler.java:938) 
            at android.os.Handler.dispatchMessage(Handler.java:99) 
            at android.os.Looper.loop(Looper.java:223) 
            at android.app.ActivityThread.main(ActivityThread.java:7656) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
    

    I will try to make minimal reproduction, but can't do it right now as I have no time.

    opened by maxtomczyk 6
  • syntax in readMe example

    syntax in readMe example

    In the usage example in the readMe, you use:

    val zoomState by remember { ZoomState(pinchZoomEnabled = true) }
    

    I think the intent is:

    val zoomState:ZoomState = remember{ ZoomState(true) }
    

    edit: Since a lot of these things, like preview in particular, are nullable and it's useful to change their value later, I'm thinking the original intent was probably:

    var zoomState by remember { mutableStateOf(ZoomState(pinchZoomEnabled = true)) }
    

    My only real purpose here is to say that there looks like a versioning issue where either an "=" got switched with a "by" or the mutableStateOf() got dropped.

    opened by randyheaton 0
Releases(v0.7.1)
  • v0.7.1(Oct 1, 2021)

  • v0.7.0(Sep 29, 2021)

    cameraxx

    • Added ImageAnalysis.analyze<T>(suspend (ImageProxy) -> T): Flow<T> to manage the lifecycle of ImageProxy better.
    • Added some utility functions: ImageProxy.toByteArray(), ImageProxy.toBitmap()
    • Changed some return types
      • Changed the return type of CameraInfo.getTorchState() from Flow<Int> to StateFlow<Int?>
      • Changed the return type of CameraInfo.getZoomState() from Flow<ZoomState> to StateFlow<ZoomState?>
      • Changed the return type of PreviewView.listenPreviewStreamState() from Flow<PreviewView.StreamState> to StateFlow<PreviewView.StreamState?>
    • Fixed ConcurrentModificationException for ImageAnalysis.analyze() (but now it's deprecated)
    Source code(tar.gz)
    Source code(zip)
  • v0.6.1(Sep 15, 2021)

  • v0.6.0(Sep 15, 2021)

    cameraxx

    • Published to Maven Central
    • Behavior changes of ImageAnalysis.analyze()
      • Previously it used shareIn inside the method to provide a convenient way to be collected from many collectors, but it's now caller's responsibility. I misunderstood the behavior of shareIn.
      • Now it automatically closes undelivered ImageProxy instances.
    • Add some kdocs
    • Now provides sources artifact

    cameraxx-bindingadapter

    • Published to Maven Central
    • Add some kdocs
    • Now provides sources artifact
    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Sep 2, 2021)

    cameraxx

    • Added PreviewView.listenPreviewStreamState()
    • Changed to use org.jetbrains.kotlinx:kotlinx-coroutines-guava instead of implementing myself

    cameraxx-composable

    • Added focus metering feature
    • Added PreviewStreamState
    • Migrated from Flow to State for all state classes
    • Optimizations to reduce recompositions
    • Moved the pinchZoomEnabled parameter into ZoomState

    cameraxx-bindingadapter

    • Removed app:zoomRatio, app:torchOn binding adapter attributes
    • Now Camera can be retrieved through app:onCameraRetrieved
    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Aug 29, 2021)

    cameraxx

    • changed Context.getProcessCameraProvider() not to cancel ListenableFuture even though coroutine is cancelled

    cameraxx-compose

    • add parameter scaleType
    • add parameter implementationMode
    • support pinch zoom
    • add ZoomState for zoom
    • add TorchState for torch

    cameraxx-bindingadapter

    • add app:zoomRatio as two-way binding attribute
    • add app:torchOn as two-way binding attribute
    • add app:onCameraInfoRetrieved to get camera info
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Aug 23, 2021)

  • v0.1.0(Aug 7, 2021)

Owner
null
Plugin and Desktop app for parsing layout xml into Composable code

composed-xml Inspired by - Recompose composed-xml is a tool for parsing Android layouts into Jetpack Compose code. It can work as both Desktop app or

Bacho Kurtanidze 9 Dec 26, 2022
CodeLab for the workshop: A Composable New World

A Composable New World! Compose is here! ?? I've created a codelab where you can follow step by step the development of android application using Comp

Carlos Mota 9 Nov 25, 2022
FlowExt is a Kotlin Multiplatform library, that provides many operators and extensions to Kotlin Coroutines Flow

FlowExt | Kotlinx Coroutines Flow Extensions | Kotlinx Coroutines Flow Extensions. Extensions to the Kotlin Flow library | kotlin-flow-extensions | Coroutines Flow Extensions | Kotlin Flow extensions | kotlin flow extensions | Flow extensions

Petrus Nguyễn Thái Học 151 Jan 1, 2023
Set of extensions for Kotlin that provides Discrete math functionalities

DiscreteMathToolkit Set of extensions for Kotlin that provides Discrete Math functionalities as an Kotlin extension functions. To stay current with ne

Marcin Moskała 177 Dec 15, 2022
Flowbius provides interoperability extensions for using Kotlin Flows with Mobius

Flowbius Flowbius provides interoperability extensions for using Kotlin Flows with Mobius. They allow conversion from Flows to Mobius types and vice v

Atlassian Labs 54 Jul 19, 2022
Helper functions for making Approvals-Java more Kotlin friendly

Approvals-Kt Helper functions for making Approvals-Java more Kotlin-friendly Usage Verify using Approvals-Kt import com.github.greghynds.approvals.Kot

Greg Hynds 2 Oct 18, 2021
Various Ktor extensions and plugins.

Ktor Plugins Collection of useful Ktor plugins. All plugins are hosted on Maven central and have same version that should be similar to the latest ver

Lukas Forst 25 Nov 24, 2022
Esito ambition is to be your return type for suspending functions.

Esito ambition is to be your return type for suspending functions.

null 58 Oct 21, 2022
An annotation processor library that automatically creates Hilt's `@Binds` functions and modules.

HiltBinder An annotation processor library that automatically creates Hilt's @Binds functions and modules. If you think this library is useful, please

SangMin Park 5 Sep 19, 2022
A ksp library to automatically generate navigation functions for jetpack compose.

Compose/Navigation/Generator ⚠️ This library is still under development and not considered stable! Content Introduction Usage Example: Single destinat

Steffen Eckardt 4 Sep 13, 2022