Skip to content

Instantly share code, notes, and snippets.

Avatar

Xi Zhang xizhang

View GitHub Profile
View ads2019-zoom-slider.kt
// Zoom slider: linear zoom effect
fun updateZoomSlider(percentage: Float) {
// percentage [0.0f .. 1.0f]
cameraControl.setLinearZoom(percentage)
}
View ads2019-pinch-to-zoom.kt
val scaleDetector = ScaleGestureDetector(context, listener)
override fun onTouchEvent(event: MotionEvent) : Boolean {
// Let the ScaleGestureDetector inspect all events
scaleDetector.onTouchEvent(event)
return true
}
val listener = object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
override fun onScale(detector: ScaleGestureDetector): Boolean {
View ads2019-tap-to-focus.kt
fun onTouch(x:Float, y:Float) {
val meteringPoint = new DisplayOrientedMeteringPointFactory(mSurfaceView.getDisplay(), cameraSelector, mSurfaceView.getWidth(), mSurfaceView.getHeight()).createPoint(x.y);
// Prepare focus action to be triggered.
val action = FocusMeteringAction.Builder(meteringPoint).build();
// Execute focus action
cameraControl.startFocusAndMetering(action);
}
View ads2019-usecase-setup.kt
// Set up use case
// Step 1. Config
val imageCapture = ImageCapture.Builder().setTargetResolution(Size(600, 800)).build()
// Step 2. Bind
CameraX.bindToLifecycle(lifecycleOwner, cameraSelector, imageCapture)
// Step 3. Act
imageCapture.takePicture(…)