Add "Touchscreen" app to properly setup touchscreen calibration
This commit is contained in:
parent
1fd501fdc4
commit
19f71681a4
14
Touchscreen/Android.mk
Normal file
14
Touchscreen/Android.mk
Normal file
|
@ -0,0 +1,14 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
||||
|
||||
LOCAL_CERTIFICATE := platform
|
||||
LOCAL_PRIVILEGED_MODULE := true
|
||||
LOCAL_PACKAGE_NAME := Touchscreen
|
||||
LOCAL_PROGUARD_ENABLED := disabled
|
||||
|
||||
LOCAL_DEX_PREOPT := false
|
||||
|
||||
include $(BUILD_PACKAGE)
|
16
Touchscreen/AndroidManifest.xml
Normal file
16
Touchscreen/AndroidManifest.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="me.phh.treble.touchscreen"
|
||||
android:sharedUserId="android.uid.system">
|
||||
|
||||
<uses-permission android:name="android.permission.SET_INPUT_CALIBRATION" />
|
||||
<application
|
||||
android:label="@string/app_label">
|
||||
|
||||
<receiver android:name=".Starter">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
4
Touchscreen/res/values/strings.xml
Normal file
4
Touchscreen/res/values/strings.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_label">Hardware Overlay Picker</string>
|
||||
</resources>
|
91
Touchscreen/src/me/phh/treble/touchscreen/Starter.java
Normal file
91
Touchscreen/src/me/phh/treble/touchscreen/Starter.java
Normal file
|
@ -0,0 +1,91 @@
|
|||
package me.phh.treble.touchscreen;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.om.IOverlayManager;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
import android.hardware.input.TouchCalibration;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemProperties;
|
||||
import android.util.Log;
|
||||
|
||||
public class Starter extends BroadcastReceiver {
|
||||
private final static String TAG = "TouchScreen";
|
||||
|
||||
private int getRotation(Context ctxt, Intent intent) {
|
||||
int rotation = -1;
|
||||
String vndFingerprint = SystemProperties.get("ro.vendor.build.fingerprint", "");
|
||||
int hwrotation = SystemProperties.getInt("ro.sf.hwrotation", -1);
|
||||
if(vndFingerprint.contains("full_x970_t10") && hwrotation == 270) {
|
||||
rotation = 271;
|
||||
}
|
||||
if(intent.hasExtra("rotation")) {
|
||||
rotation = intent.getIntExtra("rotation", rotation);
|
||||
}
|
||||
return rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context ctxt, Intent intent) {
|
||||
int rotation = getRotation(ctxt, intent);
|
||||
if(rotation == -1) return;
|
||||
android.util.Log.d("PHH", "Applying rotation " + rotation);
|
||||
InputManager im = ctxt.getSystemService(InputManager.class);
|
||||
int[] ids = im.getInputDeviceIds();
|
||||
for(int id: ids) {
|
||||
InputDevice dev = im.getInputDevice(id);
|
||||
String descriptor = dev.getDescriptor();
|
||||
android.util.Log.d("PHH", "Checking device " + descriptor + ":" + dev.getSources());
|
||||
if( (dev.getSources() & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN ) {
|
||||
InputDevice.MotionRange rangeX = dev.getMotionRange(MotionEvent.AXIS_X);
|
||||
InputDevice.MotionRange rangeY = dev.getMotionRange(MotionEvent.AXIS_Y);
|
||||
|
||||
float dX = rangeX.getMax();
|
||||
float dY = rangeY.getMax();
|
||||
//TouchCalibration cal = new TouchCalibration(
|
||||
// 0.0f, dX/dY, 0.0f,
|
||||
// dY/dX, 0.0f, 0.0f);
|
||||
TouchCalibration cal;
|
||||
if(rotation == 0) {
|
||||
cal = new TouchCalibration(
|
||||
1.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f);
|
||||
} else if(rotation == 90) {
|
||||
cal = new TouchCalibration(
|
||||
0.0f, dX/dY, 0.0f,
|
||||
dY/dX, 0.0f, 0.0f);
|
||||
} else if(rotation == 91) {
|
||||
cal = new TouchCalibration(
|
||||
0.0f, -dX/dY, dX,
|
||||
dY/dX, 0.0f, 0.0f);
|
||||
} else if(rotation == 180) {
|
||||
cal = new TouchCalibration(
|
||||
-1.0f, 0.0f, dX,
|
||||
0.0f, -1.0f, dY);
|
||||
} else if(rotation == 270) {
|
||||
cal = new TouchCalibration(
|
||||
0.0f, -dX/dY, dX,
|
||||
-dY/dX, 0.0f, dY);
|
||||
} else if(rotation == 271) {
|
||||
cal = new TouchCalibration(
|
||||
0.0f, dX/dY, 0.0f,
|
||||
-dY/dX, 0.0f, dY);
|
||||
} else {
|
||||
cal = new TouchCalibration(
|
||||
1.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
android.util.Log.d("PHH", "Setting touch calibration " + dY/dX + ":" + dX/dY);
|
||||
im.setTouchCalibration(descriptor, 0, cal);
|
||||
im.setTouchCalibration(descriptor, 1, cal);
|
||||
im.setTouchCalibration(descriptor, 2, cal);
|
||||
im.setTouchCalibration(descriptor, 3, cal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,8 @@ PRODUCT_PACKAGES += \
|
|||
treble-overlay-Telephony-LTE \
|
||||
treble-overlay-SystemUI-FalseLocks \
|
||||
HardwareOverlayPicker \
|
||||
QtiAudio
|
||||
QtiAudio \
|
||||
Touchscreen
|
||||
|
||||
|
||||
PRODUCT_PACKAGES += \
|
||||
|
|
Loading…
Reference in a new issue