Code[mouse]: change internal function names and use default in AbstractTouchpad

This commit is contained in:
artdeell 2024-04-29 13:07:31 +03:00 committed by Maksim Belov
parent aab37d1fef
commit e302a467a2
2 changed files with 12 additions and 17 deletions

View File

@ -13,7 +13,9 @@ public interface AbstractTouchpad {
* on the screen and send the new cursor position to the game. * on the screen and send the new cursor position to the game.
* @param vector the array that contains the vector * @param vector the array that contains the vector
*/ */
void applyMotionVector(float[] vector); default void applyMotionVector(float[] vector) {
applyMotionVector(vector[0], vector[1]);
}
/** /**
* Apply a motion vector to the mouse in form of the separate X/Y coordinates. This will move the mouse * Apply a motion vector to the mouse in form of the separate X/Y coordinates. This will move the mouse

View File

@ -41,13 +41,13 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
} }
/** Enable the touchpad */ /** Enable the touchpad */
private void privateEnable(){ private void _enable(){
setVisibility(VISIBLE); setVisibility(VISIBLE);
placeMouseAt(currentDisplayMetrics.widthPixels / 2f, currentDisplayMetrics.heightPixels / 2f); placeMouseAt(currentDisplayMetrics.widthPixels / 2f, currentDisplayMetrics.heightPixels / 2f);
} }
/** Disable the touchpad and hides the mouse */ /** Disable the touchpad and hides the mouse */
private void privateDisable(){ private void _disable(){
setVisibility(GONE); setVisibility(GONE);
} }
@ -55,8 +55,8 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
public boolean switchState(){ public boolean switchState(){
mDisplayState = !mDisplayState; mDisplayState = !mDisplayState;
if(!CallbackBridge.isGrabbing()) { if(!CallbackBridge.isGrabbing()) {
if(mDisplayState) privateEnable(); if(mDisplayState) _enable();
else privateDisable(); else _disable();
} }
return mDisplayState; return mDisplayState;
} }
@ -112,10 +112,10 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
} }
private void updateGrabState(boolean isGrabbing) { private void updateGrabState(boolean isGrabbing) {
if(!isGrabbing) { if(!isGrabbing) {
if(mDisplayState && getVisibility() != VISIBLE) privateEnable(); if(mDisplayState && getVisibility() != VISIBLE) _enable();
if(!mDisplayState && getVisibility() == VISIBLE) privateDisable(); if(!mDisplayState && getVisibility() == VISIBLE) _disable();
}else{ }else{
if(getVisibility() != View.GONE) privateDisable(); if(getVisibility() != View.GONE) _disable();
} }
} }
@ -124,11 +124,6 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
return mDisplayState; return mDisplayState;
} }
@Override
public void applyMotionVector(float[] vector) {
applyMotionVector(vector[0], vector[1]);
}
@Override @Override
public void applyMotionVector(float x, float y) { public void applyMotionVector(float x, float y) {
mMouseX = Math.max(0, Math.min(currentDisplayMetrics.widthPixels, mMouseX + x * LauncherPreferences.PREF_MOUSESPEED)); mMouseX = Math.max(0, Math.min(currentDisplayMetrics.widthPixels, mMouseX + x * LauncherPreferences.PREF_MOUSESPEED));
@ -141,15 +136,13 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
if(mDisplayState) return; if(mDisplayState) return;
mDisplayState = true; mDisplayState = true;
if(supposed && CallbackBridge.isGrabbing()) return; if(supposed && CallbackBridge.isGrabbing()) return;
privateEnable(); _enable();
} }
@Override @Override
public void disable() { public void disable() {
if(!mDisplayState) return; if(!mDisplayState) return;
mDisplayState = false; mDisplayState = false;
privateDisable(); _disable();
} }
} }