2014-11-16 23:14:06 -08:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Ahmed I. Khalil <ahmedibrahimkhali@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License or (at your option) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
package org.kde.kdeconnect.Plugins.MousePadPlugin;
|
|
|
|
|
2014-08-01 12:28:12 +02:00
|
|
|
import android.content.Context;
|
2014-11-09 13:27:29 -08:00
|
|
|
import android.content.SharedPreferences;
|
2014-12-21 19:13:39 -08:00
|
|
|
import android.os.Build;
|
2014-06-26 17:37:32 +00:00
|
|
|
import android.os.Bundle;
|
2014-11-09 13:27:29 -08:00
|
|
|
import android.preference.PreferenceManager;
|
2017-07-25 18:12:18 +02:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2014-06-26 17:37:32 +00:00
|
|
|
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;
|
2014-06-26 17:37:32 +00:00
|
|
|
|
|
|
|
import org.kde.kdeconnect.BackgroundService;
|
|
|
|
import org.kde.kdeconnect.Device;
|
Add a dark theme
Summary:
BUG: 375376
This revision adds dark mode support to the app ( T7044 ). It does so by injecting
theme information into each activity, and making sure that all Views
define their colors by reference to theme attributes.
In order to make this work, all of the buttons with images (like the list
of available devices) now are tinted according to the theme.
While all versions of android support the theme, only devices running
Android ICS or higher will have a toggle button in the drawer.
Test Plan: Open all the screens, both with and without the dark theme on.
Reviewers: #kde_connect, mtijink, #vdg, nicolasfella
Reviewed By: #kde_connect, mtijink, nicolasfella
Subscribers: apol, ngraham, nicolasfella, mtijink
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D11694
2018-04-23 18:31:44 +02:00
|
|
|
import org.kde.kdeconnect.UserInterface.ThemeUtil;
|
2014-06-26 17:37:32 +00:00
|
|
|
import org.kde.kdeconnect_tp.R;
|
|
|
|
|
2017-07-25 18:12:18 +02:00
|
|
|
public class MousePadActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener, MousePadGestureDetector.OnGestureListener {
|
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;
|
2014-06-26 17:37:32 +00:00
|
|
|
|
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;
|
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
|
|
|
|
2015-08-10 00:26:58 -07:00
|
|
|
enum ClickType {
|
2015-01-10 00:31:47 -08:00
|
|
|
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) {
|
|
|
|
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
|
|
|
|
|
|
|
private ClickType doubleTapAction, tripleTapAction;
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
Add a dark theme
Summary:
BUG: 375376
This revision adds dark mode support to the app ( T7044 ). It does so by injecting
theme information into each activity, and making sure that all Views
define their colors by reference to theme attributes.
In order to make this work, all of the buttons with images (like the list
of available devices) now are tinted according to the theme.
While all versions of android support the theme, only devices running
Android ICS or higher will have a toggle button in the drawer.
Test Plan: Open all the screens, both with and without the dark theme on.
Reviewers: #kde_connect, mtijink, #vdg, nicolasfella
Reviewed By: #kde_connect, mtijink, nicolasfella
Subscribers: apol, ngraham, nicolasfella, mtijink
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D11694
2018-04-23 18:31:44 +02:00
|
|
|
ThemeUtil.setUserPreferredTheme(this);
|
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
|
|
|
|
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);
|
2014-07-01 18:28:39 +02:00
|
|
|
mMousePadGestureDetector = new MousePadGestureDetector(this, this);
|
2014-06-26 17:37:32 +00:00
|
|
|
mDetector.setOnDoubleTapListener(this);
|
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
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2018-03-03 16:06:52 +01:00
|
|
|
if (prefs.getBoolean(getString(R.string.mousepad_scroll_direction), false)) {
|
2015-12-01 03:40:05 -08:00
|
|
|
scrollDirection = -1;
|
|
|
|
} else {
|
|
|
|
scrollDirection = 1;
|
|
|
|
}
|
2014-11-09 13:27:29 -08:00
|
|
|
String doubleTapSetting = prefs.getString(getString(R.string.mousepad_double_tap_key),
|
2017-06-05 00:26:22 +02:00
|
|
|
getString(R.string.mousepad_default_double));
|
2014-11-09 13:27:29 -08:00
|
|
|
String tripleTapSetting = prefs.getString(getString(R.string.mousepad_triple_tap_key),
|
2017-06-05 00:26:22 +02:00
|
|
|
getString(R.string.mousepad_default_triple));
|
2016-01-21 01:00:21 +06:00
|
|
|
String sensitivitySetting = prefs.getString(getString(R.string.mousepad_sensitivity_key),
|
2017-06-05 00:26:22 +02:00
|
|
|
getString(R.string.mousepad_default_sensitivity));
|
2014-11-09 13:27:29 -08:00
|
|
|
|
2018-08-13 23:47:32 +02:00
|
|
|
String accelerationProfileName=prefs.getString(getString(R.string.mousepad_acceleration_profile_key),
|
|
|
|
getString(R.string.mousepad_default_acceleration_profile));
|
|
|
|
|
|
|
|
mPointerAccelerationProfile = PointerAccelerationProfileFactory.getProfileWithName(accelerationProfileName);
|
|
|
|
|
2015-01-10 00:31:47 -08:00
|
|
|
doubleTapAction = ClickType.fromString(doubleTapSetting);
|
|
|
|
tripleTapAction = ClickType.fromString(tripleTapSetting);
|
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;
|
|
|
|
|
2018-03-03 16:06:52 +01:00
|
|
|
switch (sensitivitySetting) {
|
2016-01-21 01:00:21 +06:00
|
|
|
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:
|
2016-06-03 15:33:43 +02:00
|
|
|
mCurrentSensitivity = 1.0f;
|
2016-01-21 01:00:21 +06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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-26 22:51:13 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
fullscreenType |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
|
|
|
}
|
2014-12-21 19:13:39 -08:00
|
|
|
|
2018-10-26 22:51:13 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
|
|
fullscreenType |= View.SYSTEM_UI_FLAG_FULLSCREEN;
|
|
|
|
}
|
2018-05-09 14:02:56 +02:00
|
|
|
|
2018-10-26 22:51:13 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
|
fullscreenType |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
2014-12-21 19:13:39 -08:00
|
|
|
}
|
2018-10-26 22:51:13 +02:00
|
|
|
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(fullscreenType);
|
|
|
|
}
|
|
|
|
});
|
2014-12-21 19:13:39 -08:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|
|
|
|
|
2014-06-29 18:36:23 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.menu_mousepad, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_right_click:
|
2014-07-01 18:28:39 +02:00
|
|
|
sendRightClick();
|
|
|
|
return true;
|
2014-06-29 18:36:23 +02:00
|
|
|
case R.id.menu_middle_click:
|
2014-07-01 18:28:39 +02:00
|
|
|
sendMiddleClick();
|
|
|
|
return true;
|
2014-08-01 12:28:12 +02:00
|
|
|
case R.id.menu_show_keyboard:
|
|
|
|
showKeyboard();
|
|
|
|
return true;
|
2014-07-01 18:28:39 +02:00
|
|
|
default:
|
|
|
|
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-05-09 14:02:56 +02:00
|
|
|
BackgroundService.RunCommand(this, service -> {
|
|
|
|
Device device = service.getDevice(deviceId);
|
|
|
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
|
|
|
if (mousePadPlugin == null) return;
|
2018-08-13 23:47:32 +02:00
|
|
|
|
|
|
|
float deltaX = (mCurrentX - mPrevX) * displayDpiMultiplier * mCurrentSensitivity;
|
|
|
|
float deltaY = (mCurrentY - mPrevY) * displayDpiMultiplier * mCurrentSensitivity;
|
|
|
|
|
|
|
|
// Run the mouse delta through the pointer acceleration profile
|
|
|
|
mPointerAccelerationProfile.touchMoved(deltaX, deltaY, event.getEventTime());
|
|
|
|
mouseDelta = mPointerAccelerationProfile.commitAcceleratedMouseDelta(mouseDelta);
|
|
|
|
|
|
|
|
mousePadPlugin.sendMouseDelta(mouseDelta.x,mouseDelta.y);
|
|
|
|
|
2018-05-09 14:02:56 +02:00
|
|
|
mPrevX = mCurrentX;
|
|
|
|
mPrevY = mCurrentY;
|
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);
|
|
|
|
|
2018-05-09 14:02:56 +02:00
|
|
|
BackgroundService.RunCommand(this, service -> {
|
|
|
|
Device device = service.getDevice(deviceId);
|
|
|
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
|
|
|
if (mousePadPlugin == null) return;
|
|
|
|
mousePadPlugin.sendSingleHold();
|
2014-12-10 23:33:13 -08:00
|
|
|
});
|
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) {
|
2018-05-09 14:02:56 +02:00
|
|
|
BackgroundService.RunCommand(this, service -> {
|
|
|
|
Device device = service.getDevice(deviceId);
|
|
|
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
|
|
|
if (mousePadPlugin == null) return;
|
|
|
|
mousePadPlugin.sendSingleClick();
|
2014-06-26 17:37:32 +00:00
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDoubleTap(MotionEvent e) {
|
2018-05-09 14:02:56 +02:00
|
|
|
BackgroundService.RunCommand(this, service -> {
|
|
|
|
Device device = service.getDevice(deviceId);
|
|
|
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
|
|
|
if (mousePadPlugin == null) return;
|
|
|
|
mousePadPlugin.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) {
|
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) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-08-01 12:28:12 +02:00
|
|
|
|
2014-07-01 18:28:39 +02:00
|
|
|
private void sendMiddleClick() {
|
2018-05-09 14:02:56 +02:00
|
|
|
BackgroundService.RunCommand(this, service -> {
|
|
|
|
Device device = service.getDevice(deviceId);
|
|
|
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
|
|
|
if (mousePadPlugin == null) return;
|
|
|
|
mousePadPlugin.sendMiddleClick();
|
2014-07-01 18:28:39 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendRightClick() {
|
2018-05-09 14:02:56 +02:00
|
|
|
BackgroundService.RunCommand(this, service -> {
|
|
|
|
Device device = service.getDevice(deviceId);
|
|
|
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
|
|
|
if (mousePadPlugin == null) return;
|
|
|
|
mousePadPlugin.sendRightClick();
|
2014-07-01 18:28:39 +02:00
|
|
|
});
|
|
|
|
}
|
2015-11-13 09:18:13 -08:00
|
|
|
|
|
|
|
private void sendSingleHold() {
|
2018-05-09 14:02:56 +02:00
|
|
|
BackgroundService.RunCommand(this, service -> {
|
|
|
|
Device device = service.getDevice(deviceId);
|
|
|
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
|
|
|
if (mousePadPlugin == null) return;
|
|
|
|
mousePadPlugin.sendSingleHold();
|
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) {
|
2018-05-09 14:02:56 +02:00
|
|
|
BackgroundService.RunCommand(this, service -> {
|
|
|
|
Device device = service.getDevice(deviceId);
|
|
|
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
|
|
|
if (mousePadPlugin == null) return;
|
|
|
|
mousePadPlugin.sendScroll(0, y);
|
2016-06-14 18:42:21 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-01 12:28:12 +02:00
|
|
|
private void showKeyboard() {
|
|
|
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
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
|
|
|
|
2015-09-09 12:34:42 -07:00
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
BackgroundService.addGuiInUseCounter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
BackgroundService.removeGuiInUseCounter(this);
|
|
|
|
}
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|
2014-08-14 21:40:04 +02:00
|
|
|
|