Skip to content

Commit

Permalink
[Android] Add a way to disable interactions on the SurfaceView (axmol…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreK38 authored Feb 21, 2025
1 parent f8fa5a8 commit 3e7873e
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class AxmolGLSurfaceView extends GLSurfaceView {

private boolean mSoftKeyboardShown = false;
private boolean mMultipleTouchEnabled = true;
private boolean mInteractive = true;

private CountDownLatch mNativePauseComplete;

Expand All @@ -83,6 +84,14 @@ public void setMultipleTouchEnabled(boolean multipleTouchEnabled) {
this.mMultipleTouchEnabled = multipleTouchEnabled;
}

public boolean isInteractive() {
return mInteractive;
}

public void setInteractive(boolean interactive) {
this.mInteractive = interactive;
}

// ===========================================================
// Constructors
// ===========================================================
Expand Down Expand Up @@ -214,6 +223,10 @@ public boolean onTouchEvent(final MotionEvent pMotionEvent) {

switch (pMotionEvent.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_DOWN:
if (!mInteractive) {
break;
}

final int indexPointerDown = pMotionEvent.getAction() >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
if (!mMultipleTouchEnabled && indexPointerDown != 0) {
break;
Expand All @@ -231,6 +244,10 @@ public void run() {
break;

case MotionEvent.ACTION_DOWN:
if (!mInteractive) {
break;
}

// there are only one finger on the screen
final int idDown = pMotionEvent.getPointerId(0);
final float xDown = xs[0];
Expand Down Expand Up @@ -351,6 +368,10 @@ protected void onSizeChanged(final int pNewSurfaceWidth, final int pNewSurfaceHe

@Override
public boolean onKeyDown(final int pKeyCode, final KeyEvent pKeyEvent) {
if (!mInteractive) {
return false;
}

switch (pKeyCode) {
case KeyEvent.KEYCODE_BACK:
case KeyEvent.KEYCODE_MENU:
Expand All @@ -375,6 +396,10 @@ public void run() {

@Override
public boolean onKeyUp(final int keyCode, KeyEvent event) {
if (!mInteractive) {
return false;
}

switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
case KeyEvent.KEYCODE_MENU:
Expand Down

0 comments on commit 3e7873e

Please sign in to comment.