OSDN Git Service

Write pointercal as the same format as ts_calibrate kitkat-x86 lollipop-x86 marshmallow-x86 nougat-x86 oreo-x86 android-x86-6.0-r1 android-x86-6.0-r2 android-x86-6.0-r3 android-x86-7.1-r1 android-x86-7.1-r2 android-x86-7.1-r3 android-x86-7.1-r4 android-x86-7.1-r5 android-x86-8.1-r1 android-x86-8.1-r2 android-x86-8.1-r3 android-x86-8.1-r4 android-x86-8.1-r5 android-x86-8.1-r6
authorChih-Wei Huang <cwhuang@linux.org.tw>
Sat, 17 May 2014 17:52:45 +0000 (01:52 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Sat, 17 May 2014 18:05:13 +0000 (02:05 +0800)
The InputReader use the ts_calibrate format to do
5-point calibration.

Use the immersive mode of Kitkat to get the resolution
of full screen.

Android.mk
AndroidManifest.xml
src/org/zeroxlab/util/tscal/TSCalibration.java
src/org/zeroxlab/util/tscal/TSCalibrationStartup.java
src/org/zeroxlab/util/tscal/TSCalibrationView.java
src/org/zeroxlab/util/tscal/TargetView.java

index 9bbb552..2028e0f 100644 (file)
@@ -21,4 +21,5 @@ LOCAL_SRC_FILES := $(call all-subdir-java-files)
 LOCAL_PACKAGE_NAME := TSCalibration2
 LOCAL_OVERRIDES_PACKAGES := TSCalibration
 LOCAL_CERTIFICATE := platform
+LOCAL_PRIVILEGED_MODULE := true
 include $(BUILD_PACKAGE)
index 7ee6eb7..60969b7 100644 (file)
@@ -19,6 +19,8 @@ limitations under the License.
           package="org.zeroxlab.util.tscal"
           android:sharedUserId="android.uid.system">
   <uses-permission android:name="android.permission.SET_ALWAYS_FINISH" />
+  <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
+
   <application android:icon="@drawable/icon" android:label="@string/app_name">
     <activity android:name=".TSCalibration"
               android:label="Calibration"
index 1e67cd1..fa0681f 100644 (file)
@@ -22,10 +22,9 @@ import java.io.IOException;
 
 import android.app.Activity;
 import android.os.Bundle;
-import android.util.Log;
 import android.view.Display;
 import android.view.MotionEvent;
-
+import android.view.View;
 import android.util.Log;
 
 public class TSCalibration extends Activity {
@@ -33,7 +32,7 @@ public class TSCalibration extends Activity {
     final private static String TAG = "TSCalibration";
     final private static String POINTERCAL = "/data/misc/tscal/pointercal";
     final private static String defaultPointercalValues = "1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1\n";
-    final private static File FILE = new File(POINTERCAL);
+    final protected static File FILE = new File(POINTERCAL);
 
     private TSCalibrationView mTSCalibrationView;
 
@@ -41,10 +40,7 @@ public class TSCalibration extends Activity {
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        Display display = getWindowManager().getDefaultDisplay();
-        mTSCalibrationView = new TSCalibrationView(this,
-                                                   display.getHeight(),
-                                                   display.getWidth());
+        mTSCalibrationView = new TSCalibrationView(this);
         setContentView(R.layout.intro);
     }
 
@@ -71,7 +67,6 @@ public class TSCalibration extends Activity {
     private void reset() {
         try {
             FileOutputStream fos = new FileOutputStream(FILE);
-            fos.write(defaultPointercalValues.getBytes());
             fos.flush();
             fos.getFD().sync();
             fos.close();
@@ -86,4 +81,13 @@ public class TSCalibration extends Activity {
             setContentView(R.layout.done);
         }
     }
+
+    static protected void setImmersiveMode(View v) {
+        v.setSystemUiVisibility(v.SYSTEM_UI_FLAG_LAYOUT_STABLE
+            | v.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+            | v.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+            | v.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
+            | v.SYSTEM_UI_FLAG_FULLSCREEN      // hide status bar
+            | v.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
+    }
 }
index dfb220e..f5bfdae 100644 (file)
@@ -21,19 +21,21 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.os.Bundle;
+import android.provider.Settings;
+import android.util.Log;
 
 import java.io.File;
+//import org.zeroxlab.util.tscal.TSCalibration;
 
 public class TSCalibrationStartup extends Activity {
 
-    private static String cal_path = "/data/misc/tscal/pointercal";
-
-
     @Override
     public void onCreate(Bundle savedInstanceState) {
+        Settings.Secure.putString(getContentResolver(),
+                Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS,
+                getPackageName());
         super.onCreate(savedInstanceState);
-        File calFile = new File(cal_path);
-        if (!calFile.exists()) {
+        if (TSCalibration.FILE.exists() && TSCalibration.FILE.length() == 0) {
             Intent starterIntent = new Intent(this, TSCalibration.class);
             startActivityForResult(starterIntent, 0);
         } else {
index ad3e50f..9444934 100644 (file)
@@ -48,16 +48,11 @@ public class TSCalibrationView extends View {
     private TargetPoint mTargetPoints[];
     private TSCalibration mContext;
 
-    public TSCalibrationView(TSCalibration context, int h, int w) {
+    public TSCalibrationView(TSCalibration context) {
         super(context);
 
         mContext = context;
-        mTargetPoints = new TargetPoint[5];
-        mTargetPoints[0] = new TargetPoint(50, 50);
-        mTargetPoints[1] = new TargetPoint(w - 50, 50);
-        mTargetPoints[2] = new TargetPoint(w - 50, h - 50);
-        mTargetPoints[3] = new TargetPoint(50, h - 50);
-        mTargetPoints[4] = new TargetPoint(w/2, h/2);
+        context.setImmersiveMode(this);
     }
 
     public void reset() {
@@ -69,22 +64,10 @@ public class TSCalibrationView extends View {
     }
 
     public void dumpCalData(File file) {
-        StringBuilder sb = new StringBuilder();
-        for (TargetPoint point : mTargetPoints) {
-            sb.append(point.calx);
-            sb.append(" ");
-            sb.append(point.caly);
-            sb.append(" ");
-        }
-        for (TargetPoint point : mTargetPoints) {
-            sb.append(point.x);
-            sb.append(" ");
-            sb.append(point.y);
-            sb.append(" ");
-        }
+        String cal = performCalibration();
         try {
             FileOutputStream fos = new FileOutputStream(file);
-            fos.write(sb.toString().getBytes());
+            fos.write(cal.getBytes());
             fos.flush();
             fos.getFD().sync();
             fos.close();
@@ -110,6 +93,15 @@ public class TSCalibrationView extends View {
 
     @Override
     protected void onDraw(Canvas canvas) {
+        if (mTargetPoints == null) {
+            int w = getWidth(), h = getHeight();
+            mTargetPoints = new TargetPoint[5];
+            mTargetPoints[0] = new TargetPoint(50, 50);
+            mTargetPoints[1] = new TargetPoint(w - 50, 50);
+            mTargetPoints[2] = new TargetPoint(w - 50, h - 50);
+            mTargetPoints[3] = new TargetPoint(50, h - 50);
+            mTargetPoints[4] = new TargetPoint(w / 2, h / 2);
+        }
         if (isFinished())
             return;
         canvas.drawColor(Color.BLACK);
@@ -129,4 +121,79 @@ public class TSCalibrationView extends View {
         c.drawCircle(x, y, 5, white);
         c.drawCircle(x, y, 1, red);
     }
+
+    private String performCalibration() {
+        int cal[] = new int[7];
+        double n, x, y, x2, y2, xy, z, zx, zy;
+        double det, a, b, c, e, f, i;
+        double scaling = 65536.0;
+
+        // Get sums for matrix
+        n = x = y = x2 = y2 = xy = 0;
+        for (TargetPoint point : mTargetPoints) {
+            n += 1;
+            x += (double)point.calx;
+            y += (double)point.caly;
+            x2 += (double)(point.calx * point.calx);
+            y2 += (double)(point.caly * point.caly);
+            xy += (double)(point.calx * point.caly);
+            Log.v(TAG, n + "x=" + point.x + " y=" + point.y + " calx=" + point.calx + " caly=" + point.caly);
+        }
+
+        // Get determinant of matrix -- check if determinant is too small
+        det = n*(x2*y2 - xy*xy) + x*(xy*y - x*y2) + y*(x*xy - y*x2);
+        if (det > -0.1 && det < 0.1) {
+            Log.w(TAG, "determinant is too small -- " + det);
+        }
+
+        // Get elements of inverse matrix
+        a = (x2*y2 - xy*xy);
+        b = (xy*y - x*y2);
+        c = (x*xy - y*x2);
+        e = (n*y2 - y*y);
+        f = (x*y - n*xy);
+        i = (n*x2 - x*x);
+
+        // Get sums for x calibration
+        z = zx = zy = 0;
+        for (TargetPoint point : mTargetPoints) {
+            z += (double)point.x;
+            zx += (double)(point.x * point.calx);
+            zy += (double)(point.x * point.caly);
+        }
+
+        // Now multiply out to get the calibration for framebuffer x coord
+        cal[2] = (int)((a*z + b*zx + c*zy) * scaling / det);
+        cal[0] = (int)((b*z + e*zx + f*zy) * scaling / det);
+        cal[1] = (int)((c*z + f*zx + i*zy) * scaling / det);
+
+        // Get sums for y calibration
+        z = zx = zy = 0;
+        for (TargetPoint point : mTargetPoints) {
+            z += (double)point.y;
+            zx += (double)(point.y * point.calx);
+            zy += (double)(point.y * point.caly);
+        }
+
+        // Now multiply out to get the calibration for framebuffer y coord
+        cal[5] = (int)((a*z + b*zx + c*zy) * scaling / det);
+        cal[3] = (int)((b*z + e*zx + f*zy) * scaling / det);
+        cal[4] = (int)((c*z + f*zx + i*zy) * scaling / det);
+
+        // If we got here, we're OK, so assign scaling to a[6] and return
+        cal[6] = (int)scaling;
+
+        StringBuilder sb = new StringBuilder();
+        for (int s : cal) {
+            sb.append(s);
+            sb.append(" ");
+        }
+        sb.append(getWidth());
+        sb.append(" ");
+        sb.append(getHeight());
+        sb.append("\n");
+        String ret = sb.toString();
+        Log.i(TAG, "pointercal = " + ret);
+        return ret;
+    }
 }
index 8407ffa..3b6130b 100644 (file)
@@ -27,10 +27,11 @@ public class TargetView extends View {
     public TargetView(Context context, AttributeSet attrs)
     {
         super(context);
+        TSCalibration.setImmersiveMode(this);
     }
 
     @Override
-    protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
     {
         setMeasuredDimension(50, 50);
     }