Skip to content
This repository was archived by the owner on Nov 14, 2018. It is now read-only.
This repository was archived by the owner on Nov 14, 2018. It is now read-only.

Camera 1 Extensions? #373

Closed
Closed

Description

@minsik-ai

If Camera 1 extension methods are accepted, I'd like to propose some.

This for Camera parameter modification idiom :

fun Camera.setParameters(setAction: (Camera.Parameters) -> Unit) {
    val params = parameters
    setAction(params)
    parameters = params
}

This for opening Front / Back cameras :

enum class FACING {
    FRONT, BACK
}

fun openCamera(facing: FACING): Camera = Camera.open(getCameraId(facing))

private fun getCameraId(facing: CameraExtensions.FACING): Int {
    val info = Camera.CameraInfo()
    val numCameras = Camera.getNumberOfCameras()
    val direction =
            when (facing) {
                FACING.FRONT -> Camera.CameraInfo.CAMERA_FACING_FRONT
                FACING.BACK -> Camera.CameraInfo.CAMERA_FACING_BACK
            }
    for (i in 0 until numCameras) {
        Camera.getCameraInfo(i, info)
        if (info.facing == direction) {
            return i
        }
    }
    throw RuntimeException("No matching camera for $facing")
}

Opinions will be appreciated. Thanks.

Activity

  1. jaredsburrows commented on Mar 2, 2018

    @jaredsburrows
    Contributor
  2. minsik-ai commented on Mar 2, 2018

    @minsik-ai
    Author

    @jaredsburrows Thank you for the link. I'll look at it & file a PR soon.

  3. romainguy commented on Mar 2, 2018

    @romainguy
    Contributor

    These kind of APIs go beyond the scope of android-ktx extensions and belong to a dedicated library. Thank you for the suggestion though!

  4. jaredsburrows commented on Mar 2, 2018

    @jaredsburrows
    Contributor

    @romainguy Maybe androidx.core:camera-ktx?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions