OSDN Git Service

内蔵カメラの向きを適切に表示できるようにした。
authorMRSa <mrsa@myad.jp>
Sun, 20 Feb 2022 15:13:39 +0000 (00:13 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 20 Feb 2022 15:13:39 +0000 (00:13 +0900)
.idea/deploymentTargetDropDown.xml [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/gokigenassets/liveview/CameraOrientationEventReceiver.kt [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/gokigenassets/liveview/IImageRotation.kt [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/gokigenassets/liveview/ILiveView.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/liveview/LiveImageView.kt

diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
new file mode 100644 (file)
index 0000000..409bb86
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="deploymentTargetDropDown">
+    <runningDeviceTargetSelectedWithDropDown>
+      <Target>
+        <type value="RUNNING_DEVICE_TARGET" />
+        <deviceKey>
+          <Key>
+            <type value="SERIAL_NUMBER" />
+            <value value="3e50111c1220" />
+          </Key>
+        </deviceKey>
+      </Target>
+    </runningDeviceTargetSelectedWithDropDown>
+    <timeTargetWasSelectedWithDropDown value="2022-02-20T14:51:00.404275800Z" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/liveview/CameraOrientationEventReceiver.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/liveview/CameraOrientationEventReceiver.kt
new file mode 100644 (file)
index 0000000..642c4e8
--- /dev/null
@@ -0,0 +1,19 @@
+package jp.osdn.gokigen.gokigenassets.liveview
+
+import android.content.Context
+import android.view.OrientationEventListener
+
+class CameraOrientationEventReceiver(context: Context): OrientationEventListener(context)
+{
+    private var orientation : Int = -1
+
+    override fun onOrientationChanged(p0: Int)
+    {
+        orientation = p0
+    }
+
+    fun isPositionIsClockWise() : Boolean
+    {
+        return (orientation <= 180)
+    }
+}
diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/liveview/IImageRotation.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/liveview/IImageRotation.kt
new file mode 100644 (file)
index 0000000..f63df93
--- /dev/null
@@ -0,0 +1,6 @@
+package jp.osdn.gokigen.gokigenassets.liveview
+
+interface IImageRotation
+{
+    fun updateImageRotation(degrees : Int)
+}
\ No newline at end of file
index 6ea3b73..1357dfe 100644 (file)
@@ -7,7 +7,6 @@ interface ILiveView
 {
     fun setImageProvider(provider : IImageProvider)
     fun setAnotherDrawer(drawer : IAnotherDrawer?, drawer2 : IAnotherDrawer?)
-    fun updateImageRotation(degrees : Int)
     fun getMessageDrawer() : IMessageDrawer
     fun invalidate()
 }
index 2f1db2e..ed71583 100644 (file)
@@ -28,13 +28,14 @@ import jp.osdn.gokigen.gokigenassets.liveview.message.InformationDrawer
 import java.util.*
 import kotlin.math.min
 
-class LiveImageView : View, ILiveView, ILiveViewRefresher, IShowGridFrame, OnSeekBarChangeListener, IFocusingModeNotify, IFocusFrameDrawer, IAutoFocusFrameDisplay, ICachePositionProvider
+class LiveImageView : View, ILiveView, ILiveViewRefresher, IShowGridFrame, OnSeekBarChangeListener, IFocusingModeNotify, IFocusFrameDrawer, IAutoFocusFrameDisplay, ICachePositionProvider, IImageRotation
 {
     companion object
     {
         private val TAG = LiveImageView::class.java.simpleName
     }
 
+    private lateinit var orientationEventListener : CameraOrientationEventReceiver
     private var sliderPosition : Float = 0.0f
     private var imageRotationDegrees : Int = 0
     private var showGrid : Boolean = false
@@ -80,6 +81,8 @@ class LiveImageView : View, ILiveView, ILiveViewRefresher, IShowGridFrame, OnSee
         informationDrawer = InformationDrawer(this)
         indicatorControl = IndicatorControl()
         imageBitmap = BitmapFactory.decodeResource(context.resources, ID_DRAWABLE_BACKGROUND_IMAGE)
+        orientationEventListener = CameraOrientationEventReceiver(context)
+        orientationEventListener.enable()
     }
 
     fun injectDisplay(cameraControl: ICameraControl)
@@ -144,7 +147,7 @@ class LiveImageView : View, ILiveView, ILiveViewRefresher, IShowGridFrame, OnSee
                 val config = context.resources.configuration
                 if (config.orientation == Configuration.ORIENTATION_LANDSCAPE)
                 {
-                    addDegrees = 90
+                    addDegrees = if (orientationEventListener.isPositionIsClockWise()) { 90 } else { 270 }
                 }
             }
             catch (e: Exception)
@@ -603,5 +606,4 @@ class LiveImageView : View, ILiveView, ILiveViewRefresher, IShowGridFrame, OnSee
         }
         return PointF(imagePointX, imagePointY)
     }
-
 }