Kotlin - 未解决的常量参考

时间:2015-04-06 21:48:11

标签: android kotlin

我试图将新相机硬件API(android.hardware.camera2)的示例代码用于我的Android应用。首先,我通过Android Studio的Kotlin插件的自动转换功能将Java代码转换为Kotlin代码。下面是一段转换后的代码:

private val mCaptureCallback = object : CameraCaptureSession.CaptureCallback() {

    private fun process(result: CaptureResult) {
        when (mState) {
            STATE_PREVIEW -> {
            }// We have nothing to do when the camera preview is working normally.
            STATE_WAITING_LOCK -> {
                val afState = result.get(CaptureResult.CONTROL_AF_STATE)
                if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState || CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
                    // CONTROL_AE_STATE can be null on some devices
                    val aeState = result.get<Int>(CaptureResult.CONTROL_AE_STATE)
                    if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
                        mState = STATE_WAITING_NON_PRECAPTURE
                        captureStillPicture()
                    } else {
                        runPrecaptureSequence()
                    }
                }
            }
            STATE_WAITING_PRECAPTURE -> {
                // CONTROL_AE_STATE can be null on some devices
                val aeState = result.get<Int>(CaptureResult.CONTROL_AE_STATE)
                if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
                    mState = STATE_WAITING_NON_PRECAPTURE
                }
            }
            STATE_WAITING_NON_PRECAPTURE -> {
                // CONTROL_AE_STATE can be null on some devices
                val aeState = result.get<Int>(CaptureResult.CONTROL_AE_STATE)
                if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
                    mState = STATE_PICTURE_TAKEN
                    captureStillPicture()
                }
            }
        }
    }

我收到了未解决的参考错误:

CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED
CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED
CaptureResult.CONTROL_AE_STATE_CONVERGED
CaptureResult.CONTROL_AE_STATE_PRECAPTURE
CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED

但是这些常量在原始Java代码中得到了认可。有没有解决这些错误的方法?

1 个答案:

答案 0 :(得分:2)

这些变量在CameraMetadata中声明。在Kotlin中,不能在子类上调用静态变量和方法。