OSDN Git Service

Theta用にOpenGLのビューを用意したけど、無効のままにする。
authorMRSa <mrsa@myad.jp>
Thu, 4 Feb 2021 14:21:31 +0000 (23:21 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 4 Feb 2021 14:21:31 +0000 (23:21 +0900)
wear/src/main/java/jp/sfjp/gokigen/a01c/MainActivity.java
wear/src/main/java/jp/sfjp/gokigen/a01c/liveview/glview/GokigenGLUtilities.kt
wear/src/main/java/jp/sfjp/gokigen/a01c/liveview/glview/GokigenGLView.kt
wear/src/main/java/jp/sfjp/gokigen/a01c/liveview/glview/SphereDrawer.kt [moved from wear/src/main/java/jp/sfjp/gokigen/a01c/liveview/glview/EquirectangularDrawer.kt with 99% similarity]

index d8a9d39..6b1e439 100644 (file)
@@ -61,6 +61,8 @@ public class MainActivity extends AppCompatActivity implements  IChangeScene, IS
     private Vibrator vibrator = null;
     private boolean cameraDisconnectedHappened = false;
     private WifiConnection wifiConnection = null;
+    private CameraLiveViewListenerImpl liveViewListener =null;
+    private boolean enableGlView = false;
     //private boolean ambientMode = false;
 
     /**
@@ -372,21 +374,21 @@ public class MainActivity extends AppCompatActivity implements  IChangeScene, IS
                 liveView = findViewById(R.id.liveview);
                 liveView.setVisibility(View.VISIBLE);
             }
-            CameraLiveViewListenerImpl liveViewListener = new CameraLiveViewListenerImpl(liveView);
-            gestureParser = null;
-            glView = null;
-            boolean enableGlView = preferences.getBoolean(IPreferenceCameraPropertyAccessor.THETA_GL_VIEW, false);
-            if ((enableGlView)&&(connectionMethod.contains(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_THETA)))
+            liveViewListener = new CameraLiveViewListenerImpl(liveView);
+            if (glView == null)
             {
-                if (glView == null)
+                glView = findViewById(R.id.glview);
+            }
+            if (glView != null)
+            {
+                if (gestureParser == null)
                 {
-                    // GL VIEW に切り替える
-                    glView = findViewById(R.id.glview);
+                    gestureParser = new GestureParser(getApplicationContext(), glView);
                 }
-                if (glView != null)
+                enableGlView = preferences.getBoolean(IPreferenceCameraPropertyAccessor.THETA_GL_VIEW, false);
+                if ((enableGlView)&&(connectionMethod.contains(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_THETA)))
                 {
                     // GL VIEW に切り替える
-                    gestureParser = new GestureParser(getApplicationContext(), glView);
                     glView.setImageProvider(liveViewListener);
                     glView.setVisibility(View.VISIBLE);
                     liveView.setVisibility(View.GONE);
@@ -814,7 +816,7 @@ public class MainActivity extends AppCompatActivity implements  IChangeScene, IS
     public boolean dispatchTouchEvent(MotionEvent event)
     {
         //Log.v(TAG, " dispatchTouchEvent() ");
-        if (gestureParser != null)
+        if (enableGlView)
         {
             //Log.v(TAG, " onTouch() ");
             gestureParser.onTouch(event);
@@ -971,22 +973,12 @@ public class MainActivity extends AppCompatActivity implements  IChangeScene, IS
             String connectionMethod = preferences.getString(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD, IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
             int methodId = (connectionMethod.contains(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_THETA)) ? R.string.connection_method_theta : R.string.connection_method_opc;
             setMessage(IShowInformation.AREA_7, Color.MAGENTA, getString(methodId));
-            if (liveView == null)
+            if (liveView != null)
             {
-                liveView = findViewById(R.id.liveview);
-            }
-            liveView.setupInitialBackgroundImage(this);
-            liveView.setVisibility(View.VISIBLE);
-            liveView.invalidate();
-
-            if (glView != null)
-            {
-                glView.setVisibility(View.GONE);
-                glView = null;
+                liveView.setupInitialBackgroundImage(this);
+                liveView.setVisibility(View.VISIBLE);
+                liveView.invalidate();
             }
-
-
-
         }
         catch (Exception e)
         {
@@ -1001,6 +993,38 @@ public class MainActivity extends AppCompatActivity implements  IChangeScene, IS
             currentCoordinator = method;
             preferences.putString(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD, parameter);
             vibrate(IShowInformation.VIBRATE_PATTERN_SHORT_DOUBLE);
+            enableGlView = preferences.getBoolean(IPreferenceCameraPropertyAccessor.THETA_GL_VIEW, false);
+            if ((enableGlView)&&(parameter.contains(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_THETA)))
+            {
+                if (glView == null)
+                {
+                    // GL VIEW に切り替える
+                    glView = findViewById(R.id.glview);
+                }
+                if (glView != null)
+                {
+                    // GL VIEW に切り替える
+                    gestureParser = new GestureParser(getApplicationContext(), glView);
+                    glView.setImageProvider(liveViewListener);
+                    glView.setVisibility(View.VISIBLE);
+                    liveView.setVisibility(View.GONE);
+                }
+            }
+            else
+            {
+                if (liveView == null)
+                {
+                    liveView = findViewById(R.id.liveview);
+                }
+                if (liveView != null)
+                {
+                    if (glView != null)
+                    {
+                        glView.setVisibility(View.GONE);
+                    }
+                    liveView.setVisibility(View.VISIBLE);
+                }
+            }
         }
         catch (Exception e)
         {
index 432e3e0..d98cadd 100644 (file)
@@ -34,7 +34,7 @@ class GokigenGLUtilities(private val mContext: Context)
             gl?.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE.toFloat())
 
             /////////////////////////////////////////////////////////////////////
-            val inputStream: InputStream = mContext.getResources().openRawResource(resourceId)
+            val inputStream: InputStream = mContext.resources.openRawResource(resourceId)
             val bitmap: Bitmap
             bitmap = try
             {
@@ -48,7 +48,6 @@ class GokigenGLUtilities(private val mContext: Context)
                 }
                 catch (e: IOException)
                 {
-                    // Ignore.
                     e.printStackTrace()
                 }
             }
@@ -59,7 +58,6 @@ class GokigenGLUtilities(private val mContext: Context)
             }
             catch (ex: Exception)
             {
-                // ignore
                 ex.printStackTrace()
             }
             return textures[0]
@@ -70,61 +68,4 @@ class GokigenGLUtilities(private val mContext: Context)
             return -1
         }
     }
-
-    /**
-     * テクスチャの準備(ビットマップ指定)
-     *
-     *
-     */
-    fun prepareTextureBitmap(gl: GL10?, bitmap: Bitmap): Int
-    {
-        try
-        {
-           /*
-             * Create our texture. This has to be done each time the
-             * surface is created.
-             */
-            val textures = IntArray(1)
-            gl?.glGenTextures(1, textures, 0)
-            gl?.glBindTexture(GL10.GL_TEXTURE_2D, textures[0])
-            gl?.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST.toFloat())
-            gl?.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR.toFloat())
-            gl?.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE.toFloat())
-            gl?.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE.toFloat())
-            gl?.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE.toFloat())
-
-            try
-            {
-                GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0)
-                //bitmap.recycle()
-            }
-            catch (ex: Exception)
-            {
-                // ignore
-                ex.printStackTrace()
-            }
-            return textures[0]
-        }
-        catch (e : Exception)
-        {
-            e.printStackTrace()
-            return -1
-        }
-    }
-
-    fun updateTexture(gl: GL10?, bitmap: Bitmap)
-    {
-        try
-        {
-            GLUtils.texSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, bitmap)
-        }
-        catch (ex: Exception)
-        {
-            // ignore
-            ex.printStackTrace()
-        }
-
-
-
-    }
 }
\ No newline at end of file
index 54e2a14..495d4e7 100644 (file)
@@ -8,7 +8,7 @@ import android.util.Log
 
 class GokigenGLView : GLSurfaceView, ILiveViewRefresher
 {
-    private var graphicsDrawer : IGraphicsDrawer = EquirectangularDrawer(context)
+    private var graphicsDrawer : IGraphicsDrawer = SphereDrawer(context)
     private lateinit var imageProvider : IImageProvider
 
     companion object
@@ -18,18 +18,18 @@ class GokigenGLView : GLSurfaceView, ILiveViewRefresher
 
     constructor(context: Context) : super(context)
     {
-        initializeSelf(context, null)
+        initializeSelf(context)
     }
     constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
     {
-        initializeSelf(context, attrs)
+        initializeSelf(context)
     }
 
     /**
      * クラスの初期化処理...レンダラを設定する
      *
      */
-    private fun initializeSelf(context: Context, attrs: AttributeSet?)
+    private fun initializeSelf(context: Context)
     {
         try
         {
@@ -12,7 +12,7 @@ import javax.microedition.khronos.opengles.GL10
 import kotlin.math.cos
 import kotlin.math.sin
 
-class EquirectangularDrawer(context: Context) : IGraphicsDrawer
+class SphereDrawer(context: Context) : IGraphicsDrawer
 {
     private lateinit var imageProvider : IImageProvider