Skip to content

Commit 3e7873e

Browse files
authored
[Android] Add a way to disable interactions on the SurfaceView (#2410)
1 parent f8fa5a8 commit 3e7873e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

core/platform/android/java/src/dev/axmol/lib/AxmolGLSurfaceView.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class AxmolGLSurfaceView extends GLSurfaceView {
6464

6565
private boolean mSoftKeyboardShown = false;
6666
private boolean mMultipleTouchEnabled = true;
67+
private boolean mInteractive = true;
6768

6869
private CountDownLatch mNativePauseComplete;
6970

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

87+
public boolean isInteractive() {
88+
return mInteractive;
89+
}
90+
91+
public void setInteractive(boolean interactive) {
92+
this.mInteractive = interactive;
93+
}
94+
8695
// ===========================================================
8796
// Constructors
8897
// ===========================================================
@@ -214,6 +223,10 @@ public boolean onTouchEvent(final MotionEvent pMotionEvent) {
214223

215224
switch (pMotionEvent.getAction() & MotionEvent.ACTION_MASK) {
216225
case MotionEvent.ACTION_POINTER_DOWN:
226+
if (!mInteractive) {
227+
break;
228+
}
229+
217230
final int indexPointerDown = pMotionEvent.getAction() >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
218231
if (!mMultipleTouchEnabled && indexPointerDown != 0) {
219232
break;
@@ -231,6 +244,10 @@ public void run() {
231244
break;
232245

233246
case MotionEvent.ACTION_DOWN:
247+
if (!mInteractive) {
248+
break;
249+
}
250+
234251
// there are only one finger on the screen
235252
final int idDown = pMotionEvent.getPointerId(0);
236253
final float xDown = xs[0];
@@ -351,6 +368,10 @@ protected void onSizeChanged(final int pNewSurfaceWidth, final int pNewSurfaceHe
351368

352369
@Override
353370
public boolean onKeyDown(final int pKeyCode, final KeyEvent pKeyEvent) {
371+
if (!mInteractive) {
372+
return false;
373+
}
374+
354375
switch (pKeyCode) {
355376
case KeyEvent.KEYCODE_BACK:
356377
case KeyEvent.KEYCODE_MENU:
@@ -375,6 +396,10 @@ public void run() {
375396

376397
@Override
377398
public boolean onKeyUp(final int keyCode, KeyEvent event) {
399+
if (!mInteractive) {
400+
return false;
401+
}
402+
378403
switch (keyCode) {
379404
case KeyEvent.KEYCODE_BACK:
380405
case KeyEvent.KEYCODE_MENU:

0 commit comments

Comments
 (0)