mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-01 06:35:09 +00:00
Merge branch 'pointer-delta'
This commit is contained in:
@@ -56,16 +56,12 @@ public class PresenterActivity extends AppCompatActivity implements SensorEventL
|
|||||||
private PresenterPlugin plugin;
|
private PresenterPlugin plugin;
|
||||||
|
|
||||||
private SensorManager sensorManager;
|
private SensorManager sensorManager;
|
||||||
private float xPos, yPos;
|
|
||||||
|
|
||||||
static final float SENSITIVITY = 0.05f; //TODO: Make configurable?
|
static final float SENSITIVITY = 0.03f; //TODO: Make configurable?
|
||||||
|
|
||||||
public void gyroscopeEvent(SensorEvent event) {
|
public void gyroscopeEvent(SensorEvent event) {
|
||||||
xPos += -event.values[2] * SENSITIVITY;
|
float xPos = -event.values[2] * SENSITIVITY;
|
||||||
yPos += -event.values[0] * SENSITIVITY;
|
float yPos = -event.values[0] * SENSITIVITY;
|
||||||
|
|
||||||
xPos = clamp(xPos, -1.f, 1.f);
|
|
||||||
yPos = clamp(yPos, -1.f, 1.f);
|
|
||||||
|
|
||||||
plugin.sendPointer(xPos, yPos);
|
plugin.sendPointer(xPos, yPos);
|
||||||
}
|
}
|
||||||
@@ -89,13 +85,12 @@ public class PresenterActivity extends AppCompatActivity implements SensorEventL
|
|||||||
findViewById(R.id.pointer_button).setVisibility(View.VISIBLE);
|
findViewById(R.id.pointer_button).setVisibility(View.VISIBLE);
|
||||||
findViewById(R.id.pointer_button).setOnTouchListener((v, event) -> {
|
findViewById(R.id.pointer_button).setOnTouchListener((v, event) -> {
|
||||||
if(event.getAction() == MotionEvent.ACTION_DOWN){
|
if(event.getAction() == MotionEvent.ACTION_DOWN){
|
||||||
yPos = 0;
|
|
||||||
xPos = 0;
|
|
||||||
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
|
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
|
||||||
v.performClick(); // The linter complains if this is not called
|
v.performClick(); // The linter complains if this is not called
|
||||||
}
|
}
|
||||||
else if (event.getAction() == MotionEvent.ACTION_UP) {
|
else if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
sensorManager.unregisterListener(this);
|
sensorManager.unregisterListener(this);
|
||||||
|
plugin.stopPointer();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@@ -24,6 +24,7 @@ package org.kde.kdeconnect.Plugins.PresenterPlugin;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.net.Network;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
@@ -116,11 +117,23 @@ public class PresenterPlugin extends Plugin {
|
|||||||
device.sendPacket(np);
|
device.sendPacket(np);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPointer(float percentX, float percentY) {
|
public void sendPointer(float xDelta, float yDelta) {
|
||||||
NetworkPacket np = new NetworkPacket(PACKET_TYPE_PRESENTER);
|
NetworkPacket np = device.getAndRemoveUnsentPacket(NetworkPacket.PACKET_REPLACEID_PRESENTERPOINTER);
|
||||||
np.set("px", percentX);
|
if (np == null) {
|
||||||
np.set("py", percentY);
|
np = new NetworkPacket(PACKET_TYPE_PRESENTER);
|
||||||
|
} else {
|
||||||
|
xDelta += np.getInt("dx");
|
||||||
|
yDelta += np.getInt("dy");
|
||||||
|
}
|
||||||
|
np.set("dx", xDelta);
|
||||||
|
np.set("dy", yDelta);
|
||||||
device.sendPacket(np, NetworkPacket.PACKET_REPLACEID_PRESENTERPOINTER);
|
device.sendPacket(np, NetworkPacket.PACKET_REPLACEID_PRESENTERPOINTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void stopPointer() {
|
||||||
|
device.getAndRemoveUnsentPacket(NetworkPacket.PACKET_REPLACEID_PRESENTERPOINTER);
|
||||||
|
NetworkPacket np = new NetworkPacket(PACKET_TYPE_PRESENTER);
|
||||||
|
np.set("stop", true);
|
||||||
|
device.sendPacket(np);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user