リビジョン | 8b04cb0bcb03c95da779195bcef8575e2aef0c44 (tree) |
---|---|
日時 | 2021-02-04 00:05:40 |
作者 | MRSa <mrsa@myad...> |
コミッター | MRSa |
Theta用にOpenGLのビューを用意する(準備その2)。
@@ -10,6 +10,8 @@ import android.os.Vibrator; | ||
10 | 10 | import android.preference.PreferenceManager; |
11 | 11 | import android.provider.Settings; |
12 | 12 | import android.util.Log; |
13 | +import android.view.MotionEvent; | |
14 | +import android.view.View; | |
13 | 15 | import android.widget.ImageButton; |
14 | 16 | import android.widget.TextView; |
15 | 17 | import android.Manifest; |
@@ -29,11 +31,11 @@ import jp.sfjp.gokigen.a01c.liveview.ICameraStatusReceiver; | ||
29 | 31 | import jp.sfjp.gokigen.a01c.liveview.IMessageDrawer; |
30 | 32 | import jp.sfjp.gokigen.a01c.liveview.CameraLiveViewOnTouchListener; |
31 | 33 | import jp.sfjp.gokigen.a01c.liveview.glview.GokigenGLView; |
32 | -import jp.sfjp.gokigen.a01c.liveview.glview.ILiveViewRefresher; | |
33 | 34 | import jp.sfjp.gokigen.a01c.olycamerawrapper.OlyCameraCoordinator; |
34 | 35 | import jp.sfjp.gokigen.a01c.preference.IPreferenceCameraPropertyAccessor; |
35 | 36 | import jp.sfjp.gokigen.a01c.preference.PreferenceAccessWrapper; |
36 | 37 | import jp.sfjp.gokigen.a01c.thetacamerawrapper.ThetaCameraController; |
38 | +import jp.sfjp.gokigen.a01c.utils.GestureParser; | |
37 | 39 | |
38 | 40 | /** |
39 | 41 | * メインのActivity |
@@ -49,7 +51,7 @@ public class MainActivity extends AppCompatActivity implements IChangeScene, IS | ||
49 | 51 | private PowerManager powerManager = null; |
50 | 52 | private CameraLiveImageView liveView = null; |
51 | 53 | private GokigenGLView glView = null; |
52 | - private ILiveViewRefresher glViewRefresher = null; | |
54 | + private GestureParser gestureParser = null; | |
53 | 55 | private ICameraController currentCoordinator = null; |
54 | 56 | private ICameraController olyAirCoordinator = null; |
55 | 57 | private ICameraController thetaCoordinator = null; |
@@ -368,16 +370,28 @@ public class MainActivity extends AppCompatActivity implements IChangeScene, IS | ||
368 | 370 | if (liveView == null) |
369 | 371 | { |
370 | 372 | liveView = findViewById(R.id.liveview); |
373 | + liveView.setVisibility(View.VISIBLE); | |
371 | 374 | } |
372 | 375 | CameraLiveViewListenerImpl liveViewListener = new CameraLiveViewListenerImpl(liveView); |
373 | -/* | |
374 | - if (glView == null) | |
376 | + gestureParser = null; | |
377 | + glView = null; | |
378 | + boolean enableGlView = preferences.getBoolean(IPreferenceCameraPropertyAccessor.THETA_GL_VIEW, false); | |
379 | + if ((enableGlView)&&(connectionMethod.contains(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_THETA))) | |
375 | 380 | { |
376 | - glView = findViewById(R.id.glview); | |
377 | - glViewRefresher = glView; | |
378 | - glView.setImageProvider(liveViewListener); | |
381 | + if (glView == null) | |
382 | + { | |
383 | + // GL VIEW に切り替える | |
384 | + glView = findViewById(R.id.glview); | |
385 | + } | |
386 | + if (glView != null) | |
387 | + { | |
388 | + // GL VIEW に切り替える | |
389 | + gestureParser = new GestureParser(getApplicationContext(), glView); | |
390 | + glView.setImageProvider(liveViewListener); | |
391 | + glView.setVisibility(View.VISIBLE); | |
392 | + liveView.setVisibility(View.GONE); | |
393 | + } | |
379 | 394 | } |
380 | -*/ | |
381 | 395 | olyAirCoordinator = new OlyCameraCoordinator(this, liveView, this, this); |
382 | 396 | thetaCoordinator = new ThetaCameraController(this, this, this); |
383 | 397 | currentCoordinator = (connectionMethod.contains(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_THETA)) ? thetaCoordinator : olyAirCoordinator; |
@@ -792,6 +806,23 @@ public class MainActivity extends AppCompatActivity implements IChangeScene, IS | ||
792 | 806 | } |
793 | 807 | |
794 | 808 | /** |
809 | + * タッチイベントをフックする | |
810 | + * | |
811 | + * | |
812 | + */ | |
813 | + @Override | |
814 | + public boolean dispatchTouchEvent(MotionEvent event) | |
815 | + { | |
816 | + //Log.v(TAG, " dispatchTouchEvent() "); | |
817 | + if (gestureParser != null) | |
818 | + { | |
819 | + //Log.v(TAG, " onTouch() "); | |
820 | + gestureParser.onTouch(event); | |
821 | + } | |
822 | + return (super.dispatchTouchEvent(event)); | |
823 | + } | |
824 | + | |
825 | + /** | |
795 | 826 | * |
796 | 827 | * |
797 | 828 | */ |
@@ -945,7 +976,17 @@ public class MainActivity extends AppCompatActivity implements IChangeScene, IS | ||
945 | 976 | liveView = findViewById(R.id.liveview); |
946 | 977 | } |
947 | 978 | liveView.setupInitialBackgroundImage(this); |
979 | + liveView.setVisibility(View.VISIBLE); | |
948 | 980 | liveView.invalidate(); |
981 | + | |
982 | + if (glView != null) | |
983 | + { | |
984 | + glView.setVisibility(View.GONE); | |
985 | + glView = null; | |
986 | + } | |
987 | + | |
988 | + | |
989 | + | |
949 | 990 | } |
950 | 991 | catch (Exception e) |
951 | 992 | { |
@@ -15,6 +15,8 @@ public interface IPreferenceCameraPropertyAccessor | ||
15 | 15 | String FRAME_GRID = "frame_grid"; |
16 | 16 | String FRAME_GRID_DEFAULT_VALUE = "0"; |
17 | 17 | |
18 | + String THETA_GL_VIEW = "theta_gl_view"; | |
19 | + | |
18 | 20 | String IMAGE_CONVERTER = "image_converter"; |
19 | 21 | String IMAGE_CONVERTER_DEFAULT_VALUE = "0"; |
20 | 22 |
@@ -32,6 +32,10 @@ class PreferenceInitializer | ||
32 | 32 | IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE |
33 | 33 | ) |
34 | 34 | } |
35 | + if (!items.containsKey(IPreferenceCameraPropertyAccessor.THETA_GL_VIEW)) | |
36 | + { | |
37 | + editor.putBoolean(IPreferenceCameraPropertyAccessor.THETA_GL_VIEW, false) | |
38 | + } | |
35 | 39 | editor.apply() |
36 | 40 | } |
37 | 41 | catch (e : Exception) |
@@ -0,0 +1,93 @@ | ||
1 | +package jp.sfjp.gokigen.a01c.utils | |
2 | + | |
3 | +import android.content.Context | |
4 | +import android.view.GestureDetector | |
5 | +import android.view.MotionEvent | |
6 | +import android.view.ScaleGestureDetector | |
7 | +import jp.sfjp.gokigen.a01c.liveview.glview.ILiveViewRefresher | |
8 | + | |
9 | +class GestureParser(context : Context, private val imageView : ILiveViewRefresher) : GestureDetector.OnGestureListener, ScaleGestureDetector.OnScaleGestureListener | |
10 | +{ | |
11 | + private val gestureDetector = GestureDetector(context, this) | |
12 | + private val scaleGestureDetector = ScaleGestureDetector(context, this) | |
13 | + | |
14 | + // View.OnTouchListener | |
15 | + fun onTouch(event: MotionEvent?): Boolean | |
16 | + { | |
17 | + return (gestureDetector.onTouchEvent(event) || scaleGestureDetector.onTouchEvent(event)) | |
18 | + } | |
19 | + | |
20 | + // GestureDetector.OnGestureListener | |
21 | + override fun onDown(e: MotionEvent?): Boolean | |
22 | + { | |
23 | + //Log.v(TAG, " Gesture onDown") | |
24 | + return (false) | |
25 | + } | |
26 | + | |
27 | + // GestureDetector.OnGestureListener | |
28 | + override fun onShowPress(e: MotionEvent?) | |
29 | + { | |
30 | + //Log.v(TAG, " Gesture onShowPress") | |
31 | + } | |
32 | + | |
33 | + // GestureDetector.OnGestureListener | |
34 | + override fun onSingleTapUp(e: MotionEvent?): Boolean | |
35 | + { | |
36 | + //Log.v(TAG, " Gesture onSingleTapUp") | |
37 | + return (false) | |
38 | + } | |
39 | + | |
40 | + // GestureDetector.OnGestureListener | |
41 | + override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean | |
42 | + { | |
43 | + //Log.v(TAG, " Gesture onScroll") | |
44 | + imageView.moveView(distanceX, distanceY) | |
45 | + return (false) | |
46 | + } | |
47 | + | |
48 | + // GestureDetector.OnGestureListener | |
49 | + override fun onLongPress(e: MotionEvent?) | |
50 | + { | |
51 | + //Log.v(TAG, " Gesture onLongPress") | |
52 | + imageView.resetView() | |
53 | + } | |
54 | + | |
55 | + // GestureDetector.OnGestureListener | |
56 | + override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velocityX: Float, velocityY: Float): Boolean | |
57 | + { | |
58 | + //Log.v(TAG, " Gesture onFling") | |
59 | + return (false) | |
60 | + } | |
61 | + | |
62 | + // ScaleGestureDetector.OnScaleGestureListener | |
63 | + override fun onScale(detector: ScaleGestureDetector?): Boolean | |
64 | + { | |
65 | + //Log.v(TAG, " Gesture onScale") | |
66 | + try | |
67 | + { | |
68 | + if (detector != null) | |
69 | + { | |
70 | + imageView.setScaleFactor(detector.scaleFactor) | |
71 | + return (true) | |
72 | + } | |
73 | + } | |
74 | + catch (e : Exception) | |
75 | + { | |
76 | + e.printStackTrace() | |
77 | + } | |
78 | + return (false) | |
79 | + } | |
80 | + | |
81 | + // ScaleGestureDetector.OnScaleGestureListener | |
82 | + override fun onScaleBegin(detector: ScaleGestureDetector?): Boolean | |
83 | + { | |
84 | + //Log.v(TAG, " Gesture onScaleBegin") | |
85 | + return (true) | |
86 | + } | |
87 | + | |
88 | + // ScaleGestureDetector.OnScaleGestureListener | |
89 | + override fun onScaleEnd(detector: ScaleGestureDetector?) | |
90 | + { | |
91 | + //Log.v(TAG, " Gesture onScaleEnd") | |
92 | + } | |
93 | +} |
@@ -29,7 +29,7 @@ | ||
29 | 29 | android:layout_width="match_parent" |
30 | 30 | android:layout_height="match_parent" |
31 | 31 | android:gravity="center" |
32 | - /> | |
32 | + /> | |
33 | 33 | |
34 | 34 | <LinearLayout |
35 | 35 | android:layout_width="match_parent" |