mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-14 15:17:02 -04:00
Added double tap to swap second hand item
This commit is contained in:
parent
094bd32f2b
commit
54e9b421a3
@ -8,19 +8,16 @@ import static org.lwjgl.glfw.CallbackBridge.windowWidth;
|
|||||||
import android.app.*;
|
import android.app.*;
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.view.View.*;
|
import android.view.View.*;
|
||||||
import android.view.inputmethod.*;
|
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
import androidx.drawerlayout.widget.*;
|
import androidx.drawerlayout.widget.*;
|
||||||
import com.google.android.material.navigation.*;
|
import com.google.android.material.navigation.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import net.kdt.pojavlaunch.customcontrols.*;
|
import net.kdt.pojavlaunch.customcontrols.*;
|
||||||
|
|
||||||
@ -100,6 +97,7 @@ public class BaseMainActivity extends LoggableActivity {
|
|||||||
private ScrollView contentScroll;
|
private ScrollView contentScroll;
|
||||||
private ToggleButton toggleLog;
|
private ToggleButton toggleLog;
|
||||||
private GestureDetector gestureDetector;
|
private GestureDetector gestureDetector;
|
||||||
|
private GestureDetector doubleTapDetector;
|
||||||
|
|
||||||
private TextView debugText;
|
private TextView debugText;
|
||||||
private NavigationView.OnNavigationItemSelectedListener gameActionListener;
|
private NavigationView.OnNavigationItemSelectedListener gameActionListener;
|
||||||
@ -167,6 +165,8 @@ public class BaseMainActivity extends LoggableActivity {
|
|||||||
|
|
||||||
|
|
||||||
gestureDetector = new GestureDetector(this, new SingleTapConfirm());
|
gestureDetector = new GestureDetector(this, new SingleTapConfirm());
|
||||||
|
doubleTapDetector = new GestureDetector(this, new DoubleTapConfirm());
|
||||||
|
|
||||||
|
|
||||||
// Menu
|
// Menu
|
||||||
drawerLayout = findViewById(R.id.main_drawer_options);
|
drawerLayout = findViewById(R.id.main_drawer_options);
|
||||||
@ -316,6 +316,8 @@ public class BaseMainActivity extends LoggableActivity {
|
|||||||
|
|
||||||
glTouchListener = new OnTouchListener(){
|
glTouchListener = new OnTouchListener(){
|
||||||
private boolean isTouchInHotbar = false;
|
private boolean isTouchInHotbar = false;
|
||||||
|
private int lastHotbarKey = -1;
|
||||||
|
private boolean hasDoubleTapped = false;
|
||||||
/*
|
/*
|
||||||
* Events can start with only a move instead of an pointerDown
|
* Events can start with only a move instead of an pointerDown
|
||||||
* It is due to the mouse passthrough option bundled with the control button.
|
* It is due to the mouse passthrough option bundled with the control button.
|
||||||
@ -345,14 +347,16 @@ public class BaseMainActivity extends LoggableActivity {
|
|||||||
|
|
||||||
//Getting scaled position from the event
|
//Getting scaled position from the event
|
||||||
if(!CallbackBridge.isGrabbing()) {
|
if(!CallbackBridge.isGrabbing()) {
|
||||||
|
hasDoubleTapped = false;
|
||||||
mouse_x = (e.getX() * scaleFactor);
|
mouse_x = (e.getX() * scaleFactor);
|
||||||
mouse_y = (e.getY() * scaleFactor);
|
mouse_y = (e.getY() * scaleFactor);
|
||||||
}
|
//One android click = one MC click
|
||||||
|
if(gestureDetector.onTouchEvent(e)){
|
||||||
int hudKeyHandled;
|
CallbackBridge.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (int)mouse_x, (int)mouse_y);
|
||||||
if (!CallbackBridge.isGrabbing() && gestureDetector.onTouchEvent(e)){
|
return true;
|
||||||
CallbackBridge.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (int)mouse_x, (int)mouse_y);
|
}
|
||||||
return true;
|
}else{
|
||||||
|
hasDoubleTapped = doubleTapDetector.onTouchEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (e.getActionMasked()) {
|
switch (e.getActionMasked()) {
|
||||||
@ -365,14 +369,19 @@ public class BaseMainActivity extends LoggableActivity {
|
|||||||
prevX = e.getX();
|
prevX = e.getX();
|
||||||
prevY = e.getY();
|
prevY = e.getY();
|
||||||
|
|
||||||
|
int hudKeyHandled;
|
||||||
hudKeyHandled = handleGuiBar((int)e.getX(), (int) e.getY());
|
hudKeyHandled = handleGuiBar((int)e.getX(), (int) e.getY());
|
||||||
isTouchInHotbar = hudKeyHandled != -1;
|
isTouchInHotbar = hudKeyHandled != -1;
|
||||||
if (isTouchInHotbar) {
|
if (isTouchInHotbar) {
|
||||||
sendKeyPress(hudKeyHandled);
|
sendKeyPress(hudKeyHandled);
|
||||||
|
if(hasDoubleTapped && hudKeyHandled == lastHotbarKey){
|
||||||
|
//Prevent double tapping Event on two different slots
|
||||||
|
sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_F);
|
||||||
|
}
|
||||||
|
|
||||||
theHandler.sendEmptyMessageDelayed(BaseMainActivity.MSG_DROP_ITEM_BUTTON_CHECK, 350);
|
theHandler.sendEmptyMessageDelayed(BaseMainActivity.MSG_DROP_ITEM_BUTTON_CHECK, 350);
|
||||||
CallbackBridge.sendCursorPos(mouse_x, mouse_y);
|
CallbackBridge.sendCursorPos(mouse_x, mouse_y);
|
||||||
|
lastHotbarKey = hudKeyHandled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,6 +392,7 @@ public class BaseMainActivity extends LoggableActivity {
|
|||||||
initialY = mouse_y;
|
initialY = mouse_y;
|
||||||
if(!isTouchInHotbar) theHandler.sendEmptyMessageDelayed(BaseMainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, LauncherPreferences.PREF_LONGPRESS_TRIGGER);
|
if(!isTouchInHotbar) theHandler.sendEmptyMessageDelayed(BaseMainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, LauncherPreferences.PREF_LONGPRESS_TRIGGER);
|
||||||
}
|
}
|
||||||
|
lastHotbarKey = hudKeyHandled;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_UP: // 1
|
case MotionEvent.ACTION_UP: // 1
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package net.kdt.pojavlaunch;
|
||||||
|
|
||||||
|
import android.view.GestureDetector;
|
||||||
|
import android.view.GestureDetector.*;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
public class DoubleTapConfirm extends SimpleOnGestureListener {
|
||||||
|
@Override
|
||||||
|
public boolean onDoubleTap(MotionEvent e) {return true;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onDoubleTapEvent(MotionEvent e) {return false;}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user