commit cd83d0aa7ee1fc3a4d4b26c0d59fd3dfc33a0a8d
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Jun 18 11:39:12 2020 +0100

    Make the rotations and drag be independent of physical screen dimensions - take into account pixel density.

diff --git a/.gitignore b/.gitignore
index 59b3f7e1..b72757aa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,3 +43,4 @@ Thumbs.db
 
 # yes, ignore the .iml
 *.iml
+/google-services.json
diff --git a/src/main/java/org/distorted/main/RubikSurfaceView.java b/src/main/java/org/distorted/main/RubikSurfaceView.java
index c0fd8ab3..7ceb4d3b 100644
--- a/src/main/java/org/distorted/main/RubikSurfaceView.java
+++ b/src/main/java/org/distorted/main/RubikSurfaceView.java
@@ -24,6 +24,7 @@ import android.content.Context;
 import android.content.pm.ConfigurationInfo;
 import android.opengl.GLSurfaceView;
 import android.util.AttributeSet;
+import android.util.DisplayMetrics;
 import android.view.MotionEvent;
 
 import org.distorted.library.type.Static2D;
@@ -49,10 +50,10 @@ public class RubikSurfaceView extends GLSurfaceView
     // Moving the finger from the middle of the vertical screen to the right edge will rotate a
     // given face by SWIPING_SENSITIVITY/2 degrees.
     private final static int SWIPING_SENSITIVITY  = 240;
-    // Moving the finger by 1/15 the distance of min(scrWidth,scrHeight) will start a Rotation.
-    private final static int ROTATION_SENSITIVITY =  15;
-    // Every 1/12 the distance of min(scrWidth,scrHeight) the direction of cube rotation will reset.
-    private final static int DIRECTION_SENSITIVITY=  12;
+    // Moving the finger by 0.33 of an inch will start a Rotation.
+    private final static float ROTATION_SENSITIVITY =  0.33f;
+    // Every 0.33 of an inch the direction of cube drag will reset.
+    private final static float DIRECTION_SENSITIVITY=  0.33f;
 
     // Where did we get this sqrt(3)/2 ? From the (default, i.e. 60 degrees - see InternalOutputSurface!)
     // FOV of the projection matrix of the Node onto the Screen.
@@ -81,6 +82,7 @@ public class RubikSurfaceView extends GLSurfaceView
     private float[] mLastAngles;
     private long[] mLastTimestamps;
     private int mFirstIndex, mLastIndex;
+    private int mDensity;
 
     private static Static4D mQuatCurrent    = new Static4D(0,0,0,1);
     private static Static4D mQuatAccumulated= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
@@ -312,16 +314,13 @@ public class RubikSurfaceView extends GLSurfaceView
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    private boolean canBeginRotate(float x, float y)
+    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
       {
-      return (mX-x)*(mX-x) + (mY-y)*(mY-y) > 1.0f/(ROTATION_SENSITIVITY*ROTATION_SENSITIVITY);
-      }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
+      float xDist = mScreenWidth*(xFrom-xTo);
+      float yDist = mScreenHeight*(yFrom-yTo);
+      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
 
-    private boolean shouldChangeDirection(float x, float y)
-      {
-      return (mX-x)*(mX-x) + (mY-y)*(mY-y) > 1.0f/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY);
+      return distInPixels/mDensity;
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -392,7 +391,7 @@ public class RubikSurfaceView extends GLSurfaceView
       {
       if( mBeginningRotation )
         {
-        if( canBeginRotate(x,y) )
+        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
           {
           mStartRotX = x;
           mStartRotY = y;
@@ -447,7 +446,7 @@ public class RubikSurfaceView extends GLSurfaceView
         mTempCurrent.set(quatFromDrag(mX-x,y-mY));
         mPreRender.setQuatCurrentOnNextRender();
 
-        if( shouldChangeDirection(x,y) )
+        if( retFingerDragDistanceInInches(mX,mY,x,y) > DIRECTION_SENSITIVITY )
           {
           mX = x;
           mY = y;
@@ -515,10 +514,20 @@ public class RubikSurfaceView extends GLSurfaceView
         mRenderer  = new RubikRenderer(this);
         mPreRender = new RubikPreRender(this);
 
-        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
-        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
-        setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
-        setRenderer(mRenderer);
+        RubikActivity act = (RubikActivity)context;
+        DisplayMetrics dm = new DisplayMetrics();
+        act.getWindowManager().getDefaultDisplay().getMetrics(dm);
+
+        mDensity = dm.densityDpi;
+
+        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+
+        if( activityManager!=null )
+          {
+          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
+          setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
+          setRenderer(mRenderer);
+          }
         }
       }
 
