import androidx.camera.core.CameraSelector
import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraControl
import jp.osdn.gokigen.gokigenassets.camera.interfaces.IDisplayInjector
+import jp.osdn.gokigen.gokigenassets.camera.interfaces.IFocusingControl
import jp.osdn.gokigen.gokigenassets.camera.interfaces.IKeyDown
import jp.osdn.gokigen.gokigenassets.liveview.ILiveView
import jp.osdn.gokigen.gokigenassets.liveview.ILiveViewRefresher
override fun setRefresher(refresher: ILiveViewRefresher, imageView: ILiveView) { }
override fun captureButtonReceiver(id: Int): View.OnClickListener { return (this) }
override fun keyDownReceiver(id: Int): IKeyDown { return (this) }
+ override fun getFocusingControl(id: Int): IFocusingControl? { return (null) }
override fun getDisplayInjector(): IDisplayInjector? { return (null) }
override fun onClick(v: View?) { }
override fun handleKeyDown(keyCode: Int, event: KeyEvent): Boolean { return (false) }
import jp.osdn.gokigen.gokigenassets.utils.imagefile.FileControl
import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraControl
import jp.osdn.gokigen.gokigenassets.camera.interfaces.IDisplayInjector
+import jp.osdn.gokigen.gokigenassets.camera.interfaces.IFocusingControl
import jp.osdn.gokigen.gokigenassets.camera.interfaces.IKeyDown
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
return (fileControl)
}
+ override fun getFocusingControl(id: Int): IFocusingControl?
+ {
+ return (null)
+ }
override fun getDisplayInjector(): IDisplayInjector?
{
fun captureButtonReceiver(id : Int = 0) : View.OnClickListener
fun keyDownReceiver(id : Int = 0) : IKeyDown
+ fun getFocusingControl(id : Int = 0) : IFocusingControl?
+
fun getDisplayInjector() : IDisplayInjector?
}
return (this)
}
+ override fun getFocusingControl(id: Int): IFocusingControl?
+ {
+ cameraPositionId = id
+ return (focusControl)
+ }
+
override fun getDisplayInjector(): IDisplayInjector
{
return (this)
if ((captureBothCamera)&&(liveViewListener.isImageReceived()))
{
// ライブビュー画像を保管する場合...
- val thread = Thread { storeImage.doStore(cameraPositionId, true) }
+ val thread = Thread { storeImage.doStore(cameraPositionId, false) }
try
{
thread.start()
*
*/
override fun driveAutoFocus(motionEvent: MotionEvent?): Boolean {
- Log.v(TAG, "driveAutoFocus()")
+ //Log.v(TAG, "driveAutoFocus()")
if ((motionEvent == null)||(motionEvent.action != MotionEvent.ACTION_DOWN))
{
return false
val point: PointF? = frameDisplay.getPointWithEvent(motionEvent)
if ((point != null)&&(frameDisplay.isContainsPoint(point)))
{
+ //Log.v(TAG, "driveAutoFocus() : [$point.x, $point.y]")
afControl.lockAutoFocus(point)
}
}
import jp.osdn.gokigen.gokigenassets.liveview.IIndicatorControl
import jp.osdn.gokigen.gokigenassets.utils.communication.SimpleHttpClient
import org.json.JSONObject
+import kotlin.math.roundToInt
/**
*
val preFocusFrameRect = getPreFocusFrameRect(point)
try
{
- showFocusFrame(
- preFocusFrameRect,
- IAutoFocusFrameDisplay.FocusFrameStatus.Running,
- 0.0f
- )
+ showFocusFrame(preFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Running, 0.0f)
//int posX = (int) (Math.round(point.x * 100.0));
//int posY = (int) (Math.round(point.y * 100.0));
val focusUrl = if (useGR2command) lockAutoFocusUrl else autoFocusUrl
val postData =
- "pos=" + Math.round(point.x * 100.0).toInt() + "," + Math.round(
- point.y * 100.0
- ).toInt()
+ "pos=" + (point.x * 100.0).roundToInt() + "," + (point.y * 100.0).roundToInt()
Log.v(TAG, "AF ($postData)")
- val result: String? =
- httpClient.httpPost(focusUrl, postData, timeoutMs)
- if (result == null || result.isEmpty()) {
- Log.v(
- TAG,
- "setTouchAFPosition() reply is null."
- )
- } else if (findTouchAFPositionResult(result)) {
+ val result: String? = httpClient.httpPost(focusUrl, postData, timeoutMs)
+ if (result == null || result.isEmpty())
+ {
+ Log.v(TAG, "setTouchAFPosition() reply is null.")
+ }
+ else if (findTouchAFPositionResult(result))
+ {
// AF FOCUSED
- Log.v(
- TAG,
- "lockAutoFocus() : FOCUSED"
- )
- showFocusFrame(
- preFocusFrameRect,
- IAutoFocusFrameDisplay.FocusFrameStatus.Focused,
- 1.0f
- ) // いったん1秒だけ表示
+ Log.v(TAG, "lockAutoFocus() : FOCUSED")
+ showFocusFrame(preFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Focused, 1.0f) // いったん1秒だけ表示
} else {
// AF ERROR
Log.v(
// Display a provisional focus frame at the touched point.
val focusWidth = 0.125f // 0.125 is rough estimate.
var focusHeight = 0.125f
- focusHeight *= if (imageWidth > imageHeight) {
+ focusHeight *= if (imageWidth > imageHeight)
+ {
imageWidth / imageHeight
- } else {
+ }
+ else
+ {
imageHeight / imageWidth
}
+ //Log.v(TAG, " getPreFocusFrameRect ($point) --> [$focusWidth | $focusHeight] ($imageWidth,$imageHeight)")
return RectF(
point.x - focusWidth / 2.0f, point.y - focusHeight / 2.0f,
point.x + focusWidth / 2.0f, point.y + focusHeight / 2.0f
var afResult = false
try
{
+ Log.v(TAG, " findTouchAFPositionResult() : $replyString")
val resultObject = JSONObject(replyString)
val result = resultObject.getString("errMsg")
val focused = resultObject.getBoolean("focused")
return (null)
}
+ override fun getFocusingControl(id: Int): IFocusingControl?
+ {
+ return (null)
+ }
+
override fun handleKeyDown(keyCode: Int, event: KeyEvent): Boolean
{
if ((event.action == KeyEvent.ACTION_DOWN)&&((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
override fun drawFocusFrame(canvas: Canvas, imageWidth : Float, imageHeight : Float)
{
- val focusRectOnImage: RectF = convertRectOnViewfinderIntoLiveImage(
- focusFrameRect,
- imageWidth,
- imageHeight,
- imageRotationDegrees
- )
+ val focusRectOnImage: RectF = convertRectOnViewfinderIntoLiveImage(focusFrameRect, imageWidth, imageHeight, imageRotationDegrees)
val focusRectOnView: RectF = convertRectFromImageArea(focusRectOnImage)
+
// Draw a rectangle to the canvas.
// Draw a rectangle to the canvas.
val focusFramePaint = Paint()
focusFramePaint.style = Paint.Style.STROKE
- when (focusFrameStatus) {
+ when (focusFrameStatus)
+ {
IAutoFocusFrameDisplay.FocusFrameStatus.Running -> focusFramePaint.color = Color.WHITE
IAutoFocusFrameDisplay.FocusFrameStatus.Focused -> focusFramePaint.color = Color.GREEN
IAutoFocusFrameDisplay.FocusFrameStatus.Failed -> focusFramePaint.color = Color.RED
}
val focusFrameStrokeWidth = 2.0f
val dm: DisplayMetrics = context.resources.displayMetrics
- val strokeWidth =
- TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, focusFrameStrokeWidth, dm)
+ val strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, focusFrameStrokeWidth, dm)
focusFramePaint.strokeWidth = strokeWidth
+
canvas.drawRect(focusRectOnView, focusFramePaint)
}
{
e.printStackTrace()
}
+ //Log.v(TAG, " [$left,$top]-[$right,$bottom]")
return RectF(left, top, right, bottom)
}
}
ImageView.ScaleType.FIT_CENTER, ImageView.ScaleType.CENTER_INSIDE -> {
scale = ratioX.coerceAtMost(ratioY)
- viewPointX *= scale
- viewPointY *= scale
- viewPointX += (viewSizeWidth - imageSizeWidth * scale) / 2.0f
+ //viewPointX *= scale
+ //viewPointY *= scale
+ viewPointX += (viewSizeWidth - imageSizeWidth * scale) / 2.0f
viewPointY += (viewSizeHeight - imageSizeHeight * scale) / 2.0f
}
ImageView.ScaleType.CENTER_CROP -> {
else -> {
}
}
+ // Log.v(TAG, "(viewPointX : $viewPointX, viewPointY : $viewPointY) : $imageSizeWidth x $imageSizeHeight")
return PointF(viewPointX, viewPointY)
}
}
return PointF(imagePointX, imagePointY)
}
-
-
}
package jp.osdn.gokigen.gokigenassets.liveview
+import android.annotation.SuppressLint
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Log
updateCameraLayout()
}
+ @SuppressLint("ClickableViewAccessibility")
private fun updateCameraLayout()
{
if (!::liveviewView.isInitialized)
{
cameraControl0.setRefresher(imageView0, imageView0)
imageView0.injectDisplay(cameraControl0)
+ imageView0.setOnTouchListener(LiveViewOnTouchListener(cameraControl0, 0))
if (isCacheImage)
{
imageCache0.visibility = View.VISIBLE
{
cameraControl1.setRefresher(imageView1, imageView1)
imageView1.injectDisplay(cameraControl1)
+ imageView1.setOnTouchListener(LiveViewOnTouchListener(cameraControl1, 1))
if (isCacheImage)
{
imageCache1.visibility = View.VISIBLE
{
cameraControl2.setRefresher(imageView2, imageView2)
imageView2.injectDisplay(cameraControl2)
+ imageView2.setOnTouchListener(LiveViewOnTouchListener(cameraControl2, 2))
if (isCacheImage)
{
imageCache2.visibility = View.VISIBLE
{
cameraControl3.setRefresher(imageView3, imageView3)
imageView3.injectDisplay(cameraControl3)
+ imageView3.setOnTouchListener(LiveViewOnTouchListener(cameraControl3, 3))
if (isCacheImage)
{
imageCache3.visibility = View.VISIBLE
--- /dev/null
+package jp.osdn.gokigen.gokigenassets.liveview
+
+import android.annotation.SuppressLint
+import android.util.Log
+import android.view.MotionEvent
+import android.view.View
+import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraControl
+
+class LiveViewOnTouchListener(private val cameraControl : ICameraControl, private val id : Int = 0) : View.OnTouchListener
+{
+ companion object
+ {
+ private val TAG = LiveViewOnTouchListener::class.java.simpleName
+ }
+
+ @SuppressLint("ClickableViewAccessibility")
+ override fun onTouch(v: View?, event: MotionEvent?): Boolean
+ {
+ try
+ {
+ val focusControl = cameraControl.getFocusingControl(id)
+ if (focusControl != null)
+ {
+ return (focusControl.driveAutoFocus(event))
+ }
+ Log.v(TAG, " onTouch() : focusControl is NULL...")
+ }
+ catch (e : Exception)
+ {
+ e.printStackTrace()
+ }
+ return (false)
+ }
+}