OSDN Git Service

ロータリー入力に対応。
authorMRSa <mrsa@myad.jp>
Thu, 6 Apr 2023 15:29:12 +0000 (00:29 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 6 Apr 2023 15:29:12 +0000 (00:29 +0900)
wear/src/main/java/jp/sfjp/gokigen/a01c/ManinActivity.kt
wear/src/main/res/layout/activity_main.xml

index 1dfda39..5dec0d9 100644 (file)
@@ -10,6 +10,7 @@ import android.provider.Settings
 import android.util.Log
 import android.view.MotionEvent
 import android.view.View
+import android.view.ViewConfiguration
 import android.view.WindowManager
 import android.widget.ImageButton
 import android.widget.TextView
@@ -18,6 +19,10 @@ import androidx.appcompat.app.AppCompatActivity
 import androidx.core.app.ActivityCompat
 import androidx.core.content.ContextCompat
 import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
+import androidx.core.view.InputDeviceCompat
+import androidx.core.view.MotionEventCompat
+import androidx.core.view.ViewConfigurationCompat
+import androidx.core.widget.NestedScrollView
 import androidx.preference.PreferenceManager
 import jp.sfjp.gokigen.a01c.IShowInformation.operation
 import jp.sfjp.gokigen.a01c.liveview.*
@@ -29,6 +34,7 @@ import jp.sfjp.gokigen.a01c.preference.IPreferenceCameraPropertyAccessor
 import jp.sfjp.gokigen.a01c.preference.PreferenceAccessWrapper
 import jp.sfjp.gokigen.a01c.thetacamerawrapper.ThetaCameraController
 import jp.sfjp.gokigen.a01c.utils.GestureParser
+import kotlin.math.roundToInt
 
 /**
  * メインのActivity
@@ -255,6 +261,28 @@ class MainActivity : AppCompatActivity(), IChangeScene, IShowInformation, ICamer
         }
     }
 
+    override fun onGenericMotionEvent(ev: MotionEvent?): Boolean
+    {
+        try
+        {
+            if ((ev?.action == MotionEvent.ACTION_SCROLL)&& (ev.isFromSource(InputDeviceCompat.SOURCE_ROTARY_ENCODER)))
+            {
+                // ロータリー入力でスクロールする
+                // Log.v(TAG, "Rotary Encoder Input")
+                val view = findViewById<NestedScrollView>(R.id.main_screen)
+                val delta = -ev.getAxisValue(MotionEventCompat.AXIS_SCROLL) *
+                        ViewConfigurationCompat.getScaledVerticalScrollFactor(ViewConfiguration.get(this), this)
+                view.scrollBy(0, delta.roundToInt())
+                return (true)
+            }
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+        return (super.onGenericMotionEvent(ev))
+    }
+
     /**
      * Intentを使ってWiFi設定画面を開く
      *
@@ -781,6 +809,7 @@ class MainActivity : AppCompatActivity(), IChangeScene, IShowInformation, ICamer
         return (packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS))
     }
 
+
     /**
      * タッチイベントをフックする
      *
index 2d11b24..3f88ed2 100644 (file)
@@ -5,13 +5,13 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:id="@+id/main_screen"
     android:padding="@dimen/box_inset_layout_padding"
     android:background="@color/black"
     android:focusable="true"
     android:scrollbars="vertical"
     tools:context=".MainActivity"
     tools:deviceIds="wear">
-
     <androidx.constraintlayout.widget.ConstraintLayout
         android:layout_height="match_parent"
         android:layout_width="match_parent"