Merge pull request #50108 from madmiraal/android-use-lambdas-3.x
[3.x] Replace single method anonymous classes with lambdas in Godot Java code
This commit is contained in:
commit
009aa63a57
5 changed files with 120 additions and 244 deletions
|
@ -366,36 +366,27 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
edittext.setView(mView);
|
||||
io.setEdit(edittext);
|
||||
|
||||
mView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
mView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
|
||||
Point fullSize = new Point();
|
||||
activity.getWindowManager().getDefaultDisplay().getSize(fullSize);
|
||||
Rect gameSize = new Rect();
|
||||
mView.getWindowVisibleDisplayFrame(gameSize);
|
||||
|
||||
final int keyboardHeight = fullSize.y - gameSize.bottom;
|
||||
GodotLib.setVirtualKeyboardHeight(keyboardHeight);
|
||||
}
|
||||
});
|
||||
|
||||
final String[] current_command_line = command_line;
|
||||
mView.queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mView.queueEvent(() -> {
|
||||
GodotLib.setup(current_command_line);
|
||||
|
||||
// Must occur after GodotLib.setup has completed.
|
||||
for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
|
||||
plugin.onRegisterPluginWithGodotNative();
|
||||
}
|
||||
|
||||
setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on")));
|
||||
|
||||
// The Godot Android plugins are setup on completion of GodotLib.setup
|
||||
mainThreadHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mainThreadHandler.post(() -> {
|
||||
// Include the non-null views returned in the Godot view hierarchy.
|
||||
for (int i = 0; i < singleton_count; i++) {
|
||||
View view = singletons[i].onMainCreateView(activity);
|
||||
|
@ -403,9 +394,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
containerLayout.addView(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Include the returned non-null views in the Godot view hierarchy.
|
||||
|
@ -418,15 +407,12 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
}
|
||||
|
||||
public void setKeepScreenOn(final boolean p_enabled) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runOnUiThread(() -> {
|
||||
if (p_enabled) {
|
||||
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
} else {
|
||||
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -472,21 +458,14 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
|
||||
public void alert(final String message, final String title) {
|
||||
final Activity activity = getActivity();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runOnUiThread(() -> {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setMessage(message).setTitle(title);
|
||||
builder.setPositiveButton(
|
||||
"OK",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
(dialog, id) -> dialog.cancel());
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -866,9 +845,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
|
||||
public void UiChangeListener() {
|
||||
final View decorView = getActivity().getWindow().getDecorView();
|
||||
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
|
||||
@Override
|
||||
public void onSystemUiVisibilityChange(int visibility) {
|
||||
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
|
||||
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
decorView.setSystemUiVisibility(
|
||||
|
@ -880,7 +857,6 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -909,9 +885,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
|
||||
final int typeOfSensor = event.sensor.getType();
|
||||
if (mView != null) {
|
||||
mView.queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mView.queueEvent(() -> {
|
||||
if (typeOfSensor == Sensor.TYPE_ACCELEROMETER) {
|
||||
GodotLib.accelerometer(-x, y, -z);
|
||||
}
|
||||
|
@ -924,7 +898,6 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
if (typeOfSensor == Sensor.TYPE_GYROSCOPE) {
|
||||
GodotLib.gyroscope(x, -y, z);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -965,12 +938,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
}
|
||||
|
||||
if (shouldQuit && mView != null) {
|
||||
mView.queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.back();
|
||||
}
|
||||
});
|
||||
mView.queueEvent(GodotLib::back);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1047,9 +1015,8 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
;
|
||||
if (cnt == 0)
|
||||
return false;
|
||||
mView.queueEvent(new Runnable() {
|
||||
// This method will be called on the rendering thread:
|
||||
public void run() {
|
||||
mView.queueEvent(() -> {
|
||||
for (int i = 0, n = cc.length; i < n; i++) {
|
||||
int keyCode;
|
||||
if ((keyCode = cc[i]) != 0) {
|
||||
|
@ -1058,7 +1025,6 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
|
|||
GodotLib.key(0, 0, keyCode, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -184,13 +184,10 @@ public class GodotView extends GLSurfaceView {
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
queueEvent(() -> {
|
||||
// Resume the renderer
|
||||
godotRenderer.onActivityResumed();
|
||||
GodotLib.focusin();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -198,13 +195,10 @@ public class GodotView extends GLSurfaceView {
|
|||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
queueEvent(() -> {
|
||||
GodotLib.focusout();
|
||||
// Pause the renderer
|
||||
godotRenderer.onActivityPaused();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,12 +75,7 @@ public class GodotGestureHandler extends GestureDetector.SimpleOnGestureListener
|
|||
final int x = Math.round(event.getX());
|
||||
final int y = Math.round(event.getY());
|
||||
final int buttonMask = event.getButtonState();
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.doubleTap(buttonMask, x, y);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.doubleTap(buttonMask, x, y));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -89,12 +84,7 @@ public class GodotGestureHandler extends GestureDetector.SimpleOnGestureListener
|
|||
//Log.i("GodotGesture", "onScroll");
|
||||
final int x = Math.round(distanceX);
|
||||
final int y = Math.round(distanceY);
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.scroll(x, y);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.scroll(x, y));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,22 +97,12 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
final int button = getGodotButton(keyCode);
|
||||
final int godotJoyId = mJoystickIds.get(deviceId);
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.joybutton(godotJoyId, button, false);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.joybutton(godotJoyId, button, false));
|
||||
}
|
||||
} else {
|
||||
final int scanCode = event.getScanCode();
|
||||
final int chr = event.getUnicodeChar(0);
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.key(keyCode, scanCode, chr, false);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.key(keyCode, scanCode, chr, false));
|
||||
};
|
||||
|
||||
return true;
|
||||
|
@ -143,22 +133,12 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
final int button = getGodotButton(keyCode);
|
||||
final int godotJoyId = mJoystickIds.get(deviceId);
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.joybutton(godotJoyId, button, true);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.joybutton(godotJoyId, button, true));
|
||||
}
|
||||
} else {
|
||||
final int scanCode = event.getScanCode();
|
||||
final int chr = event.getUnicodeChar(0);
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.key(keyCode, scanCode, chr, true);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.key(keyCode, scanCode, chr, true));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -190,9 +170,7 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
final int action = event.getActionMasked();
|
||||
final int pointer_idx = event.getPointerId(event.getActionIndex());
|
||||
|
||||
godotView.queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
godotView.queueEvent(() -> {
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
|
@ -203,7 +181,6 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
GodotLib.touch(event.getSource(), action, pointer_idx, evcount, arr);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
|
@ -228,13 +205,7 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
// save value to prevent repeats
|
||||
joystick.axesValues.put(axis, value);
|
||||
final int godotAxisIdx = i;
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.joyaxis(godotJoyId, godotAxisIdx, value);
|
||||
//Log.i(tag, "GodotLib.joyaxis("+godotJoyId+", "+godotAxisIdx+", "+value+");");
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.joyaxis(godotJoyId, godotAxisIdx, value));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,13 +215,7 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
if (joystick.hatX != hatX || joystick.hatY != hatY) {
|
||||
joystick.hatX = hatX;
|
||||
joystick.hatY = hatY;
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.joyhat(godotJoyId, hatX, hatY);
|
||||
//Log.i(tag, "GodotLib.joyhat("+godotJoyId+", "+hatX+", "+hatY+");");
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.joyhat(godotJoyId, hatX, hatY));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -259,12 +224,7 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
final float x = event.getX();
|
||||
final float y = event.getY();
|
||||
final int type = event.getAction();
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.hover(type, x, y);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.hover(type, x, y));
|
||||
return true;
|
||||
} else if ((event.isFromSource(InputDevice.SOURCE_MOUSE))) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
|
@ -355,12 +315,7 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
}
|
||||
mJoysticksDevices.put(deviceId, joystick);
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.joyconnectionchanged(id, true, joystick.name);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.joyconnectionchanged(id, true, joystick.name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -373,12 +328,7 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
mJoystickIds.delete(deviceId);
|
||||
mJoysticksDevices.delete(deviceId);
|
||||
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.joyconnectionchanged(godotJoyId, false, "");
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.joyconnectionchanged(godotJoyId, false, ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -467,12 +417,7 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
final float x = event.getX();
|
||||
final float y = event.getY();
|
||||
final int type = event.getAction();
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.hover(type, x, y);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.hover(type, x, y));
|
||||
return true;
|
||||
}
|
||||
case MotionEvent.ACTION_BUTTON_PRESS:
|
||||
|
@ -482,12 +427,7 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
final float y = event.getY();
|
||||
final int buttonsMask = event.getButtonState();
|
||||
final int action = event.getAction();
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.touch(event.getSource(), action, 0, 1, new float[] { 0, x, y }, buttonsMask);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.touch(event.getSource(), action, 0, 1, new float[] { 0, x, y }, buttonsMask));
|
||||
return true;
|
||||
}
|
||||
case MotionEvent.ACTION_SCROLL: {
|
||||
|
@ -497,12 +437,7 @@ public class GodotInputHandler implements InputDeviceListener {
|
|||
final int action = event.getAction();
|
||||
final float verticalFactor = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
|
||||
final float horizontalFactor = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
|
||||
queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GodotLib.touch(event.getSource(), action, 0, 1, new float[] { 0, x, y }, buttonsMask, verticalFactor, horizontalFactor);
|
||||
}
|
||||
});
|
||||
queueEvent(() -> GodotLib.touch(event.getSource(), action, 0, 1, new float[] { 0, x, y }, buttonsMask, verticalFactor, horizontalFactor));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -94,9 +94,7 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
|||
public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) {
|
||||
//Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after);
|
||||
|
||||
mView.queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mView.queueEvent(() -> {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, true);
|
||||
GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, false);
|
||||
|
@ -106,7 +104,6 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -118,9 +115,7 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
|||
for (int i = start; i < start + count; ++i) {
|
||||
newChars[i - start] = pCharSequence.charAt(i);
|
||||
}
|
||||
mView.queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mView.queueEvent(() -> {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
int key = newChars[i];
|
||||
if ((key == '\n') && !mEdit.isMultiline()) {
|
||||
|
@ -130,7 +125,6 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
|||
GodotLib.key(0, 0, key, true);
|
||||
GodotLib.key(0, 0, key, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -139,15 +133,12 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
|||
if (this.mEdit == pTextView && this.isFullScreenEdit()) {
|
||||
final String characters = pKeyEvent.getCharacters();
|
||||
|
||||
mView.queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mView.queueEvent(() -> {
|
||||
for (int i = 0; i < characters.length(); i++) {
|
||||
final int ch = characters.codePointAt(i);
|
||||
GodotLib.key(0, 0, ch, true);
|
||||
GodotLib.key(0, 0, ch, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue