Android: Possible fix for white overlay with controller
This commit is contained in:
parent
295f369519
commit
d130fc9465
|
@ -7,9 +7,12 @@ import android.content.pm.ActivityInfo;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.hardware.input.InputManager;
|
import android.hardware.input.InputManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
@ -209,7 +212,11 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
|
|
||||||
mContentView = findViewById(R.id.fullscreen_content);
|
mContentView = findViewById(R.id.fullscreen_content);
|
||||||
mContentView.getHolder().addCallback(this);
|
mContentView.getHolder().addCallback(this);
|
||||||
|
mContentView.setFocusableInTouchMode(true);
|
||||||
mContentView.setFocusable(true);
|
mContentView.setFocusable(true);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
mContentView.setFocusedByDefault(true);
|
||||||
|
}
|
||||||
mContentView.requestFocus();
|
mContentView.requestFocus();
|
||||||
|
|
||||||
// Hook up controller input.
|
// Hook up controller input.
|
||||||
|
@ -265,6 +272,27 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
showMenu();
|
showMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
|
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||||
|
if (mContentView.onKeyDown(event.getKeyCode(), event))
|
||||||
|
return true;
|
||||||
|
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||||
|
if (mContentView.onKeyUp(event.getKeyCode(), event))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.dispatchKeyEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dispatchGenericMotionEvent(MotionEvent ev) {
|
||||||
|
if (mContentView.onGenericMotionEvent(ev))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return super.dispatchGenericMotionEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
|
|
|
@ -31,31 +31,53 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
(source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK;
|
(source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isExternalKeyCode(int keyCode) {
|
||||||
|
switch (keyCode) {
|
||||||
|
case KeyEvent.KEYCODE_BACK:
|
||||||
|
case KeyEvent.KEYCODE_HOME:
|
||||||
|
case KeyEvent.KEYCODE_MENU:
|
||||||
|
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||||
|
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||||
|
case KeyEvent.KEYCODE_VOLUME_MUTE:
|
||||||
|
case KeyEvent.KEYCODE_POWER:
|
||||||
|
case KeyEvent.KEYCODE_CAMERA:
|
||||||
|
case KeyEvent.KEYCODE_CALL:
|
||||||
|
case KeyEvent.KEYCODE_ENDCALL:
|
||||||
|
case KeyEvent.KEYCODE_VOICE_ASSIST:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (isDPadOrButtonEvent(event) && event.getRepeatCount() == 0 &&
|
if (!isDPadOrButtonEvent(event) || isExternalKeyCode(keyCode))
|
||||||
handleControllerKey(event.getDeviceId(), keyCode, true)) {
|
return false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onKeyDown(keyCode, event);
|
if (event.getRepeatCount() == 0)
|
||||||
|
handleControllerKey(event.getDeviceId(), keyCode, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
if (isDPadOrButtonEvent(event) && event.getRepeatCount() == 0 &&
|
if (!isDPadOrButtonEvent(event) || isExternalKeyCode(keyCode))
|
||||||
handleControllerKey(event.getDeviceId(), keyCode, false)) {
|
return false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onKeyDown(keyCode, event);
|
if (event.getRepeatCount() == 0)
|
||||||
|
handleControllerKey(event.getDeviceId(), keyCode, false);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||||
final int source = event.getSource();
|
final int source = event.getSource();
|
||||||
if ((source & InputDevice.SOURCE_JOYSTICK) == 0)
|
if ((source & (InputDevice.SOURCE_JOYSTICK | InputDevice.SOURCE_GAMEPAD | InputDevice.SOURCE_DPAD)) == 0)
|
||||||
return super.onGenericMotionEvent(event);
|
return false;
|
||||||
|
|
||||||
final int deviceId = event.getDeviceId();
|
final int deviceId = event.getDeviceId();
|
||||||
for (AxisMapping mapping : mControllerAxisMapping) {
|
for (AxisMapping mapping : mControllerAxisMapping) {
|
||||||
|
|
|
@ -41,6 +41,8 @@ public class TouchscreenControllerView extends FrameLayout {
|
||||||
|
|
||||||
public TouchscreenControllerView(Context context) {
|
public TouchscreenControllerView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
setFocusable(false);
|
||||||
|
setFocusableInTouchMode(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TouchscreenControllerView(Context context, AttributeSet attrs) {
|
public TouchscreenControllerView(Context context, AttributeSet attrs) {
|
||||||
|
|
Loading…
Reference in New Issue