2014-11-16 23:14:06 -08:00
|
|
|
/*
|
2020-08-17 16:17:20 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014 Ahmed I. Khalil <ahmedibrahimkhali@gmail.com>
|
2014-11-16 23:14:06 -08:00
|
|
|
*
|
2020-08-17 16:17:20 +02:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2018-10-29 15:07:43 +01:00
|
|
|
*/
|
2014-11-16 23:14:06 -08:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
package org.kde.kdeconnect.Plugins.MousePadPlugin;
|
|
|
|
|
2022-01-15 20:35:45 +00:00
|
|
|
import android.content.Intent;
|
2014-11-09 13:27:29 -08:00
|
|
|
import android.content.SharedPreferences;
|
2023-04-26 20:16:08 +00:00
|
|
|
import android.hardware.Sensor;
|
|
|
|
import android.hardware.SensorEvent;
|
|
|
|
import android.hardware.SensorEventListener;
|
|
|
|
import android.hardware.SensorManager;
|
2014-06-26 17:37:32 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.GestureDetector;
|
2014-12-10 23:39:28 -08:00
|
|
|
import android.view.HapticFeedbackConstants;
|
2014-06-29 18:36:23 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2014-06-26 17:37:32 +00:00
|
|
|
import android.view.MotionEvent;
|
2016-06-09 13:42:15 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2022-12-31 00:03:34 +01:00
|
|
|
import android.widget.Toast;
|
2023-05-24 19:26:54 +02:00
|
|
|
|
2020-07-07 16:45:02 +05:30
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.core.content.ContextCompat;
|
2023-04-08 22:05:25 +02:00
|
|
|
import androidx.preference.PreferenceManager;
|
2023-05-24 19:26:54 +02:00
|
|
|
|
|
|
|
import org.kde.kdeconnect.KdeConnect;
|
2023-04-08 22:05:25 +02:00
|
|
|
import org.kde.kdeconnect.UserInterface.PluginSettingsActivity;
|
2014-06-26 17:37:32 +00:00
|
|
|
import org.kde.kdeconnect_tp.R;
|
|
|
|
|
2021-03-07 10:55:47 +00:00
|
|
|
import java.util.Objects;
|
|
|
|
|
2023-04-23 22:50:05 +02:00
|
|
|
public class MousePadActivity
|
|
|
|
extends AppCompatActivity
|
|
|
|
implements GestureDetector.OnGestureListener,
|
|
|
|
GestureDetector.OnDoubleTapListener,
|
|
|
|
MousePadGestureDetector.OnGestureListener,
|
|
|
|
SensorEventListener,
|
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
2018-10-26 23:53:58 +02:00
|
|
|
private String deviceId;
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2016-06-14 18:42:21 +02:00
|
|
|
private final static float MinDistanceToSendScroll = 2.5f; // touch gesture scroll
|
|
|
|
private final static float MinDistanceToSendGenericScroll = 0.1f; // real mouse scroll wheel event
|
2018-07-07 22:27:42 +02:00
|
|
|
private final static float StandardDpi = 240.0f; // = hdpi
|
2014-06-29 17:58:21 +02:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
private float mPrevX;
|
|
|
|
private float mPrevY;
|
|
|
|
private float mCurrentX;
|
|
|
|
private float mCurrentY;
|
2016-01-21 01:00:21 +06:00
|
|
|
private float mCurrentSensitivity;
|
2018-07-07 22:27:42 +02:00
|
|
|
private float displayDpiMultiplier;
|
2015-12-01 03:40:05 -08:00
|
|
|
private int scrollDirection = 1;
|
2023-03-27 20:58:48 +00:00
|
|
|
private boolean allowGyro = false;
|
|
|
|
private boolean gyroEnabled = false;
|
2023-03-28 00:01:50 +02:00
|
|
|
private int gyroscopeSensitivity = 100;
|
2018-10-26 23:53:58 +02:00
|
|
|
private boolean isScrolling = false;
|
|
|
|
private float accumulatedDistanceY = 0;
|
2014-06-29 17:58:21 +02:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
private GestureDetector mDetector;
|
2023-03-27 20:58:48 +00:00
|
|
|
private SensorManager mSensorManager;
|
2014-07-01 18:28:39 +02:00
|
|
|
private MousePadGestureDetector mMousePadGestureDetector;
|
2018-08-13 23:47:32 +02:00
|
|
|
private PointerAccelerationProfile mPointerAccelerationProfile;
|
|
|
|
|
|
|
|
private PointerAccelerationProfile.MouseDelta mouseDelta; // to be reused on every touch move event
|
2014-07-01 18:28:39 +02:00
|
|
|
|
2018-10-26 23:53:58 +02:00
|
|
|
private KeyListenerView keyListenerView;
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2023-04-08 22:05:25 +02:00
|
|
|
private SharedPreferences prefs = null;
|
|
|
|
|
2023-04-23 22:50:05 +02:00
|
|
|
private boolean prefsApplied = false;
|
|
|
|
|
2015-08-10 00:26:58 -07:00
|
|
|
enum ClickType {
|
2021-07-16 05:47:33 +05:30
|
|
|
LEFT, RIGHT, MIDDLE, NONE;
|
2018-03-03 16:06:52 +01:00
|
|
|
|
2015-01-10 00:31:47 -08:00
|
|
|
static ClickType fromString(String s) {
|
2018-03-03 16:06:52 +01:00
|
|
|
switch (s) {
|
2021-07-16 05:47:33 +05:30
|
|
|
case "left":
|
|
|
|
return LEFT;
|
2018-03-03 16:06:52 +01:00
|
|
|
case "right":
|
|
|
|
return RIGHT;
|
|
|
|
case "middle":
|
|
|
|
return MIDDLE;
|
|
|
|
default:
|
|
|
|
return NONE;
|
2015-01-10 00:31:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-09 13:27:29 -08:00
|
|
|
|
2021-07-16 05:55:31 +05:30
|
|
|
private ClickType singleTapAction, doubleTapAction, tripleTapAction;
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2023-03-27 20:58:48 +00:00
|
|
|
@Override
|
|
|
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSensorChanged(SensorEvent event) {
|
|
|
|
float[] values = event.values;
|
|
|
|
|
2023-03-28 00:01:50 +02:00
|
|
|
float X = -values[2] * 70 * (gyroscopeSensitivity/100.0f);
|
|
|
|
float Y = -values[0] * 70 * (gyroscopeSensitivity/100.0f);
|
2023-03-27 20:58:48 +00:00
|
|
|
|
|
|
|
if (X < 0.25 && X > -0.25) {
|
|
|
|
X = 0;
|
|
|
|
} else {
|
2023-03-28 00:01:50 +02:00
|
|
|
X = X * (gyroscopeSensitivity/100.0f);
|
2023-03-27 20:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Y < 0.25 && Y > -0.25) {
|
|
|
|
Y = 0;
|
|
|
|
} else {
|
2023-03-28 00:01:50 +02:00
|
|
|
Y = Y * (gyroscopeSensitivity/100.0f);
|
2023-03-27 20:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final float nX = X;
|
|
|
|
final float nY = Y;
|
|
|
|
|
2023-05-24 19:26:54 +02:00
|
|
|
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
|
|
|
|
if (plugin == null) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
plugin.sendMouseDelta(nX, nY);
|
2023-03-27 20:58:48 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
setContentView(R.layout.activity_mousepad);
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2021-03-07 10:55:47 +00:00
|
|
|
setSupportActionBar(findViewById(R.id.toolbar));
|
|
|
|
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
|
|
|
|
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
|
|
|
|
2023-04-23 22:50:05 +02:00
|
|
|
findViewById(R.id.mouse_click_left).setOnClickListener(v -> sendLeftClick());
|
|
|
|
findViewById(R.id.mouse_click_middle).setOnClickListener(v -> sendMiddleClick());
|
|
|
|
findViewById(R.id.mouse_click_right).setOnClickListener(v -> sendRightClick());
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
deviceId = getIntent().getStringExtra("deviceId");
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2014-12-10 23:39:28 -08:00
|
|
|
getWindow().getDecorView().setHapticFeedbackEnabled(true);
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
mDetector = new GestureDetector(this, this);
|
2018-10-27 00:02:59 +02:00
|
|
|
mMousePadGestureDetector = new MousePadGestureDetector(this);
|
2014-06-26 17:37:32 +00:00
|
|
|
mDetector.setOnDoubleTapListener(this);
|
2023-03-27 20:58:48 +00:00
|
|
|
mSensorManager = ContextCompat.getSystemService(this, SensorManager.class);
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2018-10-26 23:49:38 +02:00
|
|
|
keyListenerView = findViewById(R.id.keyListener);
|
2014-08-14 21:40:04 +02:00
|
|
|
keyListenerView.setDeviceId(deviceId);
|
2014-11-09 13:27:29 -08:00
|
|
|
|
2023-04-08 22:05:25 +02:00
|
|
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2023-04-23 22:50:05 +02:00
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
2023-04-08 22:05:25 +02:00
|
|
|
|
2023-04-23 22:50:05 +02:00
|
|
|
applyPrefs();
|
2014-12-21 19:13:39 -08:00
|
|
|
|
2018-07-07 22:27:42 +02:00
|
|
|
//Technically xdpi and ydpi should be handled separately,
|
|
|
|
//but since ydpi is usually almost equal to xdpi, only xdpi is used for the multiplier.
|
|
|
|
displayDpiMultiplier = StandardDpi / getResources().getDisplayMetrics().xdpi;
|
2016-01-21 01:00:21 +06:00
|
|
|
|
2018-10-26 22:51:13 +02:00
|
|
|
final View decorView = getWindow().getDecorView();
|
|
|
|
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
|
|
|
|
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
2014-12-21 19:13:39 -08:00
|
|
|
|
2018-10-26 22:51:13 +02:00
|
|
|
int fullscreenType = 0;
|
2014-12-21 19:13:39 -08:00
|
|
|
|
2018-10-29 19:14:14 +01:00
|
|
|
fullscreenType |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
2023-03-05 16:14:01 +00:00
|
|
|
fullscreenType |= View.SYSTEM_UI_FLAG_FULLSCREEN;
|
|
|
|
fullscreenType |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
2018-10-26 22:51:13 +02:00
|
|
|
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(fullscreenType);
|
|
|
|
}
|
|
|
|
});
|
2023-03-27 20:58:48 +00:00
|
|
|
}
|
2014-12-21 19:13:39 -08:00
|
|
|
|
2023-03-27 20:58:48 +00:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
2023-04-23 22:50:05 +02:00
|
|
|
applyPrefs();
|
|
|
|
|
2023-04-07 02:17:37 +02:00
|
|
|
if (allowGyro && !gyroEnabled) {
|
2023-03-27 20:58:48 +00:00
|
|
|
mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
|
|
|
|
gyroEnabled = true;
|
|
|
|
}
|
2023-04-08 22:05:25 +02:00
|
|
|
|
|
|
|
invalidateMenu();
|
|
|
|
|
2023-03-27 20:58:48 +00:00
|
|
|
super.onResume();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
2023-04-07 02:17:37 +02:00
|
|
|
if (gyroEnabled) {
|
2023-03-27 20:58:48 +00:00
|
|
|
mSensorManager.unregisterListener(this);
|
|
|
|
gyroEnabled = false;
|
|
|
|
}
|
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
2023-04-23 22:50:05 +02:00
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
2023-04-07 02:17:37 +02:00
|
|
|
if (gyroEnabled) {
|
2023-03-27 20:58:48 +00:00
|
|
|
mSensorManager.unregisterListener(this);
|
|
|
|
gyroEnabled = false;
|
|
|
|
}
|
|
|
|
super.onStop();
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 22:50:05 +02:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
2014-06-29 18:36:23 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.menu_mousepad, menu);
|
2023-04-08 22:05:25 +02:00
|
|
|
|
|
|
|
boolean mouseButtonsEnabled = prefs
|
|
|
|
.getBoolean(getString(R.string.mousepad_mouse_buttons_enabled_pref), true);
|
|
|
|
menu.findItem(R.id.menu_right_click).setVisible(!mouseButtonsEnabled);
|
|
|
|
menu.findItem(R.id.menu_middle_click).setVisible(!mouseButtonsEnabled);
|
|
|
|
|
2014-06-29 18:36:23 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2022-01-22 12:03:53 +01:00
|
|
|
int id = item.getItemId();
|
2023-04-08 22:05:25 +02:00
|
|
|
if (id == R.id.menu_right_click) {
|
|
|
|
sendRightClick();
|
|
|
|
return true;
|
|
|
|
} else if (id == R.id.menu_middle_click) {
|
|
|
|
sendMiddleClick();
|
|
|
|
return true;
|
|
|
|
} else if (id == R.id.menu_open_mousepad_settings) {
|
|
|
|
Intent intent = new Intent(this, PluginSettingsActivity.class)
|
|
|
|
.putExtra(PluginSettingsActivity.EXTRA_DEVICE_ID, deviceId)
|
|
|
|
.putExtra(PluginSettingsActivity.EXTRA_PLUGIN_KEY, MousePadPlugin.class.getSimpleName());
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
|
|
|
} else if (id == R.id.menu_show_keyboard) {
|
2023-05-24 19:26:54 +02:00
|
|
|
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
|
|
|
|
if (plugin == null) {
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (plugin.isKeyboardEnabled()) {
|
|
|
|
showKeyboard();
|
|
|
|
} else {
|
|
|
|
Toast toast = Toast.makeText(this, R.string.mousepad_keyboard_input_not_supported, Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
2022-01-22 12:03:53 +01:00
|
|
|
return true;
|
|
|
|
} else if (id == R.id.menu_open_compose_send) {
|
2023-05-24 19:26:54 +02:00
|
|
|
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
|
|
|
|
if (plugin == null) {
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (plugin.isKeyboardEnabled()) {
|
|
|
|
showCompose();
|
|
|
|
} else {
|
|
|
|
Toast toast = Toast.makeText(this, R.string.mousepad_keyboard_input_not_supported, Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
2022-01-22 12:03:53 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return super.onOptionsItemSelected(item);
|
2014-06-29 18:36:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
2014-07-01 18:28:39 +02:00
|
|
|
if (mMousePadGestureDetector.onTouchEvent(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-03 16:06:52 +01:00
|
|
|
if (mDetector.onTouchEvent(event)) {
|
2014-06-29 17:15:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
int actionType = event.getAction();
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2014-06-29 17:15:58 +02:00
|
|
|
if (isScrolling) {
|
|
|
|
if (actionType == MotionEvent.ACTION_UP) {
|
|
|
|
isScrolling = false;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
switch (actionType) {
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
2014-08-14 21:40:04 +02:00
|
|
|
mPrevX = event.getX();
|
|
|
|
mPrevY = event.getY();
|
2014-06-26 17:37:32 +00:00
|
|
|
break;
|
|
|
|
case MotionEvent.ACTION_MOVE:
|
2014-08-14 21:40:04 +02:00
|
|
|
mCurrentX = event.getX();
|
|
|
|
mCurrentY = event.getY();
|
2018-08-13 23:47:32 +02:00
|
|
|
|
2023-05-24 19:26:54 +02:00
|
|
|
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
|
|
|
|
if (plugin == null) {
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-13 23:47:32 +02:00
|
|
|
|
2023-05-24 19:26:54 +02:00
|
|
|
float deltaX = (mCurrentX - mPrevX) * displayDpiMultiplier * mCurrentSensitivity;
|
|
|
|
float deltaY = (mCurrentY - mPrevY) * displayDpiMultiplier * mCurrentSensitivity;
|
2018-08-13 23:47:32 +02:00
|
|
|
|
2023-05-24 19:26:54 +02:00
|
|
|
// Run the mouse delta through the pointer acceleration profile
|
|
|
|
mPointerAccelerationProfile.touchMoved(deltaX, deltaY, event.getEventTime());
|
|
|
|
mouseDelta = mPointerAccelerationProfile.commitAcceleratedMouseDelta(mouseDelta);
|
2018-08-13 23:47:32 +02:00
|
|
|
|
2023-05-24 19:26:54 +02:00
|
|
|
plugin.sendMouseDelta(mouseDelta.x, mouseDelta.y);
|
2023-03-27 20:58:48 +00:00
|
|
|
|
2023-05-24 19:26:54 +02:00
|
|
|
mPrevX = mCurrentX;
|
|
|
|
mPrevY = mCurrentY;
|
2023-03-27 20:58:48 +00:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDown(MotionEvent e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onShowPress(MotionEvent e) {
|
2014-08-14 21:40:04 +02:00
|
|
|
//From GestureDetector, left empty
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSingleTapUp(MotionEvent e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-14 18:42:21 +02:00
|
|
|
@Override
|
2018-03-03 16:06:52 +01:00
|
|
|
public boolean onGenericMotionEvent(MotionEvent e) {
|
2018-10-26 22:51:13 +02:00
|
|
|
if (e.getAction() == MotionEvent.ACTION_SCROLL) {
|
|
|
|
final float distanceY = e.getAxisValue(MotionEvent.AXIS_VSCROLL);
|
2016-06-14 18:42:21 +02:00
|
|
|
|
2018-10-26 22:51:13 +02:00
|
|
|
accumulatedDistanceY += distanceY;
|
2016-06-14 18:42:21 +02:00
|
|
|
|
2018-10-26 22:51:13 +02:00
|
|
|
if (accumulatedDistanceY > MinDistanceToSendGenericScroll || accumulatedDistanceY < -MinDistanceToSendGenericScroll) {
|
|
|
|
sendScroll(accumulatedDistanceY);
|
|
|
|
accumulatedDistanceY = 0;
|
2016-06-14 18:42:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onGenericMotionEvent(e);
|
|
|
|
}
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
@Override
|
2014-06-29 17:15:00 +02:00
|
|
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, final float distanceX, final float distanceY) {
|
|
|
|
// If only one thumb is used then cancel the scroll gesture
|
|
|
|
if (e2.getPointerCount() <= 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-29 17:58:21 +02:00
|
|
|
|
2014-06-29 17:15:58 +02:00
|
|
|
isScrolling = true;
|
2014-06-29 17:58:21 +02:00
|
|
|
|
|
|
|
accumulatedDistanceY += distanceY;
|
2018-03-03 16:06:52 +01:00
|
|
|
if (accumulatedDistanceY > MinDistanceToSendScroll || accumulatedDistanceY < -MinDistanceToSendScroll) {
|
2016-06-14 18:42:21 +02:00
|
|
|
sendScroll(scrollDirection * accumulatedDistanceY);
|
2014-06-29 17:58:21 +02:00
|
|
|
|
|
|
|
accumulatedDistanceY = 0;
|
|
|
|
}
|
|
|
|
|
2014-06-29 17:15:00 +02:00
|
|
|
return true;
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLongPress(MotionEvent e) {
|
2014-12-10 23:39:28 -08:00
|
|
|
getWindow().getDecorView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
2023-05-24 19:26:54 +02:00
|
|
|
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
|
|
|
|
if (plugin == null) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
plugin.sendSingleHold();
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSingleTapConfirmed(MotionEvent e) {
|
2021-07-16 05:55:31 +05:30
|
|
|
switch (singleTapAction) {
|
|
|
|
case LEFT:
|
|
|
|
sendLeftClick();
|
|
|
|
break;
|
|
|
|
case RIGHT:
|
|
|
|
sendRightClick();
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
sendMiddleClick();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
2014-06-26 17:37:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDoubleTap(MotionEvent e) {
|
2023-05-24 19:26:54 +02:00
|
|
|
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
|
|
|
|
if (plugin == null) {
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
plugin.sendDoubleClick();
|
2014-06-26 17:37:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDoubleTapEvent(MotionEvent e) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-01 18:28:39 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTripleFingerTap(MotionEvent ev) {
|
2018-03-03 16:06:52 +01:00
|
|
|
switch (tripleTapAction) {
|
2021-07-16 05:47:33 +05:30
|
|
|
case LEFT:
|
|
|
|
sendLeftClick();
|
|
|
|
break;
|
2014-11-09 13:27:29 -08:00
|
|
|
case RIGHT:
|
|
|
|
sendRightClick();
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
sendMiddleClick();
|
|
|
|
break;
|
2015-01-10 00:31:47 -08:00
|
|
|
default:
|
2014-11-09 13:27:29 -08:00
|
|
|
}
|
2014-07-01 18:28:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDoubleFingerTap(MotionEvent ev) {
|
2018-03-03 16:06:52 +01:00
|
|
|
switch (doubleTapAction) {
|
2021-07-16 05:47:33 +05:30
|
|
|
case LEFT:
|
|
|
|
sendLeftClick();
|
|
|
|
break;
|
2014-11-09 13:27:29 -08:00
|
|
|
case RIGHT:
|
|
|
|
sendRightClick();
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
sendMiddleClick();
|
|
|
|
break;
|
2015-01-10 00:31:47 -08:00
|
|
|
default:
|
2014-11-09 13:27:29 -08:00
|
|
|
}
|
2014-07-01 18:28:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-04-23 22:50:05 +02:00
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
|
|
if (prefsApplied) prefsApplied = false;
|
|
|
|
}
|
|
|
|
|
2014-08-01 12:28:12 +02:00
|
|
|
|
2021-07-16 05:47:33 +05:30
|
|
|
private void sendLeftClick() {
|
2023-05-24 19:26:54 +02:00
|
|
|
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
|
|
|
|
if (plugin == null) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
plugin.sendLeftClick();
|
2021-07-16 05:47:33 +05:30
|
|
|
}
|
|
|
|
|
2014-07-01 18:28:39 +02:00
|
|
|
private void sendMiddleClick() {
|
2023-05-24 19:26:54 +02:00
|
|
|
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
|
|
|
|
if (plugin == null) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
plugin.sendMiddleClick();
|
2014-07-01 18:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void sendRightClick() {
|
2023-05-24 19:26:54 +02:00
|
|
|
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
|
|
|
|
if (plugin == null) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
plugin.sendRightClick();
|
2015-11-13 09:18:13 -08:00
|
|
|
}
|
2014-08-01 12:28:12 +02:00
|
|
|
|
2016-06-14 18:42:21 +02:00
|
|
|
private void sendScroll(final float y) {
|
2023-05-24 19:26:54 +02:00
|
|
|
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
|
|
|
|
if (plugin == null) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
plugin.sendScroll(0, y);
|
2016-06-14 18:42:21 +02:00
|
|
|
}
|
|
|
|
|
2014-08-01 12:28:12 +02:00
|
|
|
private void showKeyboard() {
|
2020-07-07 16:45:02 +05:30
|
|
|
InputMethodManager imm = ContextCompat.getSystemService(this, InputMethodManager.class);
|
2019-01-29 13:57:14 +01:00
|
|
|
keyListenerView.requestFocus();
|
2014-10-17 19:10:24 -07:00
|
|
|
imm.toggleSoftInputFromWindow(keyListenerView.getWindowToken(), 0, 0);
|
2014-08-01 12:28:12 +02:00
|
|
|
}
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2022-12-31 00:03:34 +01:00
|
|
|
private void showCompose() {
|
|
|
|
Intent intent = new Intent(this, ComposeSendActivity.class);
|
|
|
|
intent.putExtra("org.kde.kdeconnect.Plugins.MousePadPlugin.deviceId", deviceId);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2023-04-23 22:50:05 +02:00
|
|
|
private void applyPrefs() {
|
|
|
|
if (prefsApplied) return;
|
|
|
|
|
|
|
|
if (prefs.getBoolean(getString(R.string.mousepad_scroll_direction), false)) {
|
|
|
|
scrollDirection = -1;
|
|
|
|
} else {
|
|
|
|
scrollDirection = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
allowGyro = isGyroSensorAvailable() && prefs.getBoolean(getString(R.string.gyro_mouse_enabled), false);
|
2023-04-25 01:46:09 +02:00
|
|
|
if (allowGyro) gyroscopeSensitivity = prefs.getInt(getString(R.string.gyro_mouse_sensitivity), 100);
|
2023-04-23 22:50:05 +02:00
|
|
|
|
|
|
|
String singleTapSetting = prefs.getString(getString(R.string.mousepad_single_tap_key),
|
|
|
|
getString(R.string.mousepad_default_single));
|
|
|
|
String doubleTapSetting = prefs.getString(getString(R.string.mousepad_double_tap_key),
|
|
|
|
getString(R.string.mousepad_default_double));
|
|
|
|
String tripleTapSetting = prefs.getString(getString(R.string.mousepad_triple_tap_key),
|
|
|
|
getString(R.string.mousepad_default_triple));
|
|
|
|
String sensitivitySetting = prefs.getString(getString(R.string.mousepad_sensitivity_key),
|
|
|
|
getString(R.string.mousepad_default_sensitivity));
|
|
|
|
|
|
|
|
String accelerationProfileName = prefs.getString(getString(R.string.mousepad_acceleration_profile_key),
|
|
|
|
getString(R.string.mousepad_default_acceleration_profile));
|
|
|
|
|
|
|
|
mPointerAccelerationProfile = PointerAccelerationProfileFactory.getProfileWithName(accelerationProfileName);
|
|
|
|
|
|
|
|
singleTapAction = ClickType.fromString(singleTapSetting);
|
|
|
|
doubleTapAction = ClickType.fromString(doubleTapSetting);
|
|
|
|
tripleTapAction = ClickType.fromString(tripleTapSetting);
|
|
|
|
|
|
|
|
switch (sensitivitySetting) {
|
|
|
|
case "slowest":
|
|
|
|
mCurrentSensitivity = 0.2f;
|
|
|
|
break;
|
|
|
|
case "aboveSlowest":
|
|
|
|
mCurrentSensitivity = 0.5f;
|
|
|
|
break;
|
|
|
|
case "default":
|
|
|
|
mCurrentSensitivity = 1.0f;
|
|
|
|
break;
|
|
|
|
case "aboveDefault":
|
|
|
|
mCurrentSensitivity = 1.5f;
|
|
|
|
break;
|
|
|
|
case "fastest":
|
|
|
|
mCurrentSensitivity = 2.0f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mCurrentSensitivity = 1.0f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prefs.getBoolean(getString(R.string.mousepad_mouse_buttons_enabled_pref), true)) {
|
|
|
|
findViewById(R.id.mouse_buttons).setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.mouse_buttons).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
prefsApplied = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isGyroSensorAvailable() {
|
|
|
|
return mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null;
|
|
|
|
}
|
|
|
|
|
2021-10-17 11:32:41 +05:30
|
|
|
@Override
|
|
|
|
public boolean onSupportNavigateUp() {
|
|
|
|
super.onBackPressed();
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|
2014-08-14 21:40:04 +02:00
|
|
|
|