mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 05:07:40 +00:00
Simplify enabling the pointer
This commit is contained in:
parent
38caa1831f
commit
98c366ee6a
@ -59,17 +59,14 @@ public class PresenterActivity extends AppCompatActivity implements SensorEventL
|
||||
private float xPos, yPos;
|
||||
private float xOffset, yOffset;
|
||||
|
||||
// TODO: Decide if move to desktop
|
||||
static final float xMax = 800, yMax = 600;
|
||||
static final float sensitivity = 0.05f;
|
||||
static final float amplitude = 1.f;
|
||||
static final float SENSITIVITY = 0.05f; //TODO: Make configurable?
|
||||
|
||||
public void gyroscopeEvent(SensorEvent event) {
|
||||
xPos += -event.values[2];
|
||||
yPos += -event.values[0];
|
||||
|
||||
float percentX = clamp((xPos - xOffset) * sensitivity, -amplitude, amplitude)/amplitude;
|
||||
float percentY = clamp((yPos - yOffset) * sensitivity, -amplitude, amplitude)/amplitude;
|
||||
float percentX = clamp((xPos - xOffset) * SENSITIVITY, -1.f, 1.f);
|
||||
float percentY = clamp((yPos - yOffset) * SENSITIVITY, -1.f, 1.f);
|
||||
|
||||
plugin.sendPointer(percentX, percentY);
|
||||
}
|
||||
@ -118,12 +115,9 @@ public class PresenterActivity extends AppCompatActivity implements SensorEventL
|
||||
this.plugin = plugin;
|
||||
findViewById(R.id.next_button).setOnClickListener(v -> plugin.sendNext());
|
||||
findViewById(R.id.previous_button).setOnClickListener(v -> plugin.sendPrevious());
|
||||
plugin.setPointerEnabledCallback(new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
enablePointer();
|
||||
}
|
||||
});
|
||||
if (plugin.isPointerSupported()) {
|
||||
enablePointer();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@Override
|
||||
|
@ -41,11 +41,11 @@ import static org.kde.kdeconnect.Plugins.MousePadPlugin.KeyListenerView.SpecialK
|
||||
public class PresenterPlugin extends Plugin {
|
||||
|
||||
private final static String PACKET_TYPE_PRESENTER = "kdeconnect.presenter";
|
||||
private final static String PACKET_TYPE_PRESENTER_CONFIG = "kdeconnect.presenter.config";
|
||||
private final static String PACKET_TYPE_MOUSEPAD_REQUEST = "kdeconnect.mousepad.request";
|
||||
|
||||
private boolean pointerEnabled = false;
|
||||
private Handler pointerEnabledCallback = null;
|
||||
public boolean isPointerSupported() {
|
||||
return true; //TODO: Check capabilities
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
@ -80,21 +80,7 @@ public class PresenterPlugin extends Plugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPacketReceived(NetworkPacket np) {
|
||||
if (np.getBoolean("presenter_enabled", false)) {
|
||||
pointerEnabled = true;
|
||||
if (pointerEnabledCallback != null) {
|
||||
pointerEnabledCallback.dispatchMessage(new Message());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPacketTypes() {
|
||||
return new String[]{PACKET_TYPE_PRESENTER_CONFIG};
|
||||
}
|
||||
public String[] getSupportedPacketTypes() { return new String[0]; }
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPacketTypes() {
|
||||
@ -106,13 +92,6 @@ public class PresenterPlugin extends Plugin {
|
||||
return context.getString(R.string.pref_plugin_presenter);
|
||||
}
|
||||
|
||||
public void setPointerEnabledCallback(Handler handler) {
|
||||
this.pointerEnabledCallback = handler;
|
||||
if (pointerEnabled) {
|
||||
handler.dispatchMessage(new Message());
|
||||
}
|
||||
}
|
||||
|
||||
public void sendNext() {
|
||||
NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
|
||||
np.set("specialKey", SpecialKeysMap.get(KeyEvent.KEYCODE_PAGE_DOWN));
|
||||
|
Loading…
x
Reference in New Issue
Block a user