Android: support lambda expressions in Java code

use -classpath instead of -bootclasspath param to allow
javac to use the default boot class path to support
building lambdas, pass the user Android class via -classpath.

Task-number: QTBUG-118077
Change-Id: I1ba8274d57e1bd528a1d5b7d779191e7f1412184
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
This commit is contained in:
Assam Boudjelthia 2023-11-16 20:18:49 +02:00
parent 323cf718f6
commit 64fe6d836c
10 changed files with 466 additions and 629 deletions

View File

@ -19,7 +19,8 @@ function(qt_internal_add_jar target)
set(javac_source_version "8") set(javac_source_version "8")
endif() endif()
set(CMAKE_JAVA_COMPILE_FLAGS -source "${javac_source_version}" -target "${javac_target_version}" -Xlint:unchecked -bootclasspath "${QT_ANDROID_JAR}") set(CMAKE_JAVA_COMPILE_FLAGS -source "${javac_source_version}" -target "${javac_target_version}"
-Xlint:unchecked -classpath "${QT_ANDROID_JAR}")
add_jar(${ARGV}) add_jar(${ARGV})
foreach(f IN LISTS arg_SOURCES) foreach(f IN LISTS arg_SOURCES)

View File

@ -63,12 +63,7 @@ public class QtActivityDelegate
setActionBarVisibility(false); setActionBarVisibility(false);
QtInputDelegate.KeyboardVisibilityListener keyboardVisibilityListener = QtInputDelegate.KeyboardVisibilityListener keyboardVisibilityListener =
new QtInputDelegate.KeyboardVisibilityListener() { () -> m_displayManager.updateFullScreen(m_activity);
@Override
public void onKeyboardVisibilityChange() {
m_displayManager.updateFullScreen(m_activity);
}
};
m_inputDelegate = new QtInputDelegate(m_activity, keyboardVisibilityListener); m_inputDelegate = new QtInputDelegate(m_activity, keyboardVisibilityListener);
try { try {
@ -98,13 +93,10 @@ public class QtActivityDelegate
@UsedFromNativeCode @UsedFromNativeCode
public void setSystemUiVisibility(int systemUiVisibility) public void setSystemUiVisibility(int systemUiVisibility)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
m_displayManager.setSystemUiVisibility(m_activity, systemUiVisibility); m_displayManager.setSystemUiVisibility(m_activity, systemUiVisibility);
m_layout.requestLayout(); m_layout.requestLayout();
QtNative.updateWindow(); QtNative.updateWindow();
}
}); });
} }
@ -160,9 +152,7 @@ public class QtActivityDelegate
if (m_surfaces != null) if (m_surfaces != null)
return; return;
Runnable startApplication = new Runnable() { Runnable startApplication = () -> {
@Override
public void run() {
try { try {
QtNative.startApplication(appParams, mainLib); QtNative.startApplication(appParams, mainLib);
m_started = true; m_started = true;
@ -170,7 +160,6 @@ public class QtActivityDelegate
e.printStackTrace(); e.printStackTrace();
m_activity.finish(); m_activity.finish();
} }
}
}; };
initMembers(startApplication); initMembers(startApplication);
@ -224,9 +213,7 @@ public class QtActivityDelegate
: m_activity.getDisplay().getRefreshRate(); : m_activity.getDisplay().getRefreshRate();
QtDisplayManager.handleRefreshRateChanged(refreshRate); QtDisplayManager.handleRefreshRateChanged(refreshRate);
m_layout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { m_layout.getViewTreeObserver().addOnPreDrawListener(() -> {
@Override
public boolean onPreDraw() {
if (!m_inputDelegate.isKeyboardVisible()) if (!m_inputDelegate.isKeyboardVisible())
return true; return true;
@ -244,7 +231,6 @@ public class QtActivityDelegate
QtInputDelegate.keyboardGeometryChanged(location[0], r.bottom - location[1], QtInputDelegate.keyboardGeometryChanged(location[0], r.bottom - location[1],
r.width(), kbHeight); r.width(), kbHeight);
return true; return true;
}
}); });
m_inputDelegate.setEditPopupMenu(new EditPopupMenu(m_activity, m_layout)); m_inputDelegate.setEditPopupMenu(new EditPopupMenu(m_activity, m_layout));
} }
@ -256,9 +242,7 @@ public class QtActivityDelegate
public void hideSplashScreen(final int duration) public void hideSplashScreen(final int duration)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
if (m_splashScreen == null) if (m_splashScreen == null)
return; return;
@ -288,7 +272,6 @@ public class QtActivityDelegate
}); });
m_splashScreen.startAnimation(fadeOut); m_splashScreen.startAnimation(fadeOut);
}
}); });
} }
@ -342,13 +325,8 @@ public class QtActivityDelegate
public void initializeAccessibility() public void initializeAccessibility()
{ {
final QtActivityDelegate currentDelegate = this; final QtActivityDelegate currentDelegate = this;
QtNative.runAction(new Runnable() { QtNative.runAction(() -> m_accessibilityDelegate = new QtAccessibilityDelegate(m_activity,
@Override m_layout, currentDelegate));
public void run() {
m_accessibilityDelegate = new QtAccessibilityDelegate(m_activity, m_layout,
currentDelegate);
}
});
} }
void handleUiModeChange(int uiMode) void handleUiModeChange(int uiMode)
@ -381,23 +359,13 @@ public class QtActivityDelegate
@UsedFromNativeCode @UsedFromNativeCode
public void resetOptionsMenu() public void resetOptionsMenu()
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> m_activity.invalidateOptionsMenu());
@Override
public void run() {
m_activity.invalidateOptionsMenu();
}
});
} }
@UsedFromNativeCode @UsedFromNativeCode
public void openOptionsMenu() public void openOptionsMenu()
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> m_activity.openOptionsMenu());
@Override
public void run() {
m_activity.openOptionsMenu();
}
});
} }
private boolean m_contextMenuVisible = false; private boolean m_contextMenuVisible = false;
@ -411,38 +379,22 @@ public class QtActivityDelegate
@UsedFromNativeCode @UsedFromNativeCode
public void openContextMenu(final int x, final int y, final int w, final int h) public void openContextMenu(final int x, final int y, final int w, final int h)
{ {
m_layout.postDelayed(new Runnable() { m_layout.postDelayed(() -> {
@Override
public void run() {
m_layout.setLayoutParams(m_inputDelegate.getQtEditText(), new QtLayout.LayoutParams(w, h, x, y), false); m_layout.setLayoutParams(m_inputDelegate.getQtEditText(), new QtLayout.LayoutParams(w, h, x, y), false);
PopupMenu popup = new PopupMenu(m_activity, m_inputDelegate.getQtEditText()); PopupMenu popup = new PopupMenu(m_activity, m_inputDelegate.getQtEditText());
QtActivityDelegate.this.onCreatePopupMenu(popup.getMenu()); QtActivityDelegate.this.onCreatePopupMenu(popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { popup.setOnMenuItemClickListener(menuItem ->
@Override m_activity.onContextItemSelected(menuItem));
public boolean onMenuItemClick(MenuItem menuItem) { popup.setOnDismissListener(popupMenu ->
return m_activity.onContextItemSelected(menuItem); m_activity.onContextMenuClosed(popupMenu.getMenu()));
}
});
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(PopupMenu popupMenu) {
m_activity.onContextMenuClosed(popupMenu.getMenu());
}
});
popup.show(); popup.show();
}
}, 100); }, 100);
} }
@UsedFromNativeCode @UsedFromNativeCode
public void closeContextMenu() public void closeContextMenu()
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> m_activity.closeContextMenu());
@Override
public void run() {
m_activity.closeContextMenu();
}
});
} }
void setActionBarVisibility(boolean visible) void setActionBarVisibility(boolean visible)
@ -457,9 +409,7 @@ public class QtActivityDelegate
@UsedFromNativeCode @UsedFromNativeCode
public void insertNativeView(int id, View view, int x, int y, int w, int h) { public void insertNativeView(int id, View view, int x, int y, int w, int h) {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
if (m_dummyView != null) { if (m_dummyView != null) {
m_layout.removeView(m_dummyView); m_layout.removeView(m_dummyView);
m_dummyView = null; m_dummyView = null;
@ -478,15 +428,12 @@ public class QtActivityDelegate
view.setId(id); view.setId(id);
m_layout.addView(view); m_layout.addView(view);
m_nativeViews.put(id, view); m_nativeViews.put(id, view);
}
}); });
} }
@UsedFromNativeCode @UsedFromNativeCode
public void createSurface(int id, boolean onTop, int x, int y, int w, int h, int imageDepth) { public void createSurface(int id, boolean onTop, int x, int y, int w, int h, int imageDepth) {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
if (m_surfaces.size() == 0) { if (m_surfaces.size() == 0) {
TypedValue attr = new TypedValue(); TypedValue attr = new TypedValue();
m_activity.getTheme().resolveAttribute(android.R.attr.windowBackground, attr, true); m_activity.getTheme().resolveAttribute(android.R.attr.windowBackground, attr, true);
@ -520,15 +467,12 @@ public class QtActivityDelegate
m_surfaces.put(id, surface); m_surfaces.put(id, surface);
if (!m_splashScreenSticky) if (!m_splashScreenSticky)
hideSplashScreen(); hideSplashScreen();
}
}); });
} }
@UsedFromNativeCode @UsedFromNativeCode
public void setSurfaceGeometry(int id, int x, int y, int w, int h) { public void setSurfaceGeometry(int id, int x, int y, int w, int h) {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
if (m_surfaces.containsKey(id)) { if (m_surfaces.containsKey(id)) {
QtSurface surface = m_surfaces.get(id); QtSurface surface = m_surfaces.get(id);
surface.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y)); surface.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
@ -537,17 +481,13 @@ public class QtActivityDelegate
view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y)); view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
} else { } else {
Log.e(QtNative.QtTAG, "Surface " + id + " not found!"); Log.e(QtNative.QtTAG, "Surface " + id + " not found!");
return;
}
} }
}); });
} }
@UsedFromNativeCode @UsedFromNativeCode
public void destroySurface(int id) { public void destroySurface(int id) {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
View view = null; View view = null;
if (m_surfaces.containsKey(id)) { if (m_surfaces.containsKey(id)) {
@ -568,7 +508,6 @@ public class QtActivityDelegate
} else { } else {
m_layout.removeView(view); m_layout.removeView(view);
} }
}
}); });
} }
@ -580,9 +519,7 @@ public class QtActivityDelegate
@UsedFromNativeCode @UsedFromNativeCode
public void bringChildToFront(int id) public void bringChildToFront(int id)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
View view = m_surfaces.get(id); View view = m_surfaces.get(id);
if (view != null) { if (view != null) {
final int surfaceCount = getSurfaceCount(); final int surfaceCount = getSurfaceCount();
@ -594,16 +531,13 @@ public class QtActivityDelegate
view = m_nativeViews.get(id); view = m_nativeViews.get(id);
if (view != null) if (view != null)
m_layout.moveChild(view, -1); m_layout.moveChild(view, -1);
}
}); });
} }
@UsedFromNativeCode @UsedFromNativeCode
public void bringChildToBack(int id) public void bringChildToBack(int id)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
View view = m_surfaces.get(id); View view = m_surfaces.get(id);
if (view != null) { if (view != null) {
m_layout.moveChild(view, 0); m_layout.moveChild(view, 0);
@ -615,7 +549,6 @@ public class QtActivityDelegate
final int index = getSurfaceCount(); final int index = getSurfaceCount();
m_layout.moveChild(view, index); m_layout.moveChild(view, index);
} }
}
}); });
} }
} }

View File

@ -52,12 +52,7 @@ public class QtActivityLoader extends QtLoader {
"fatal_error_msg", "string", packageName); "fatal_error_msg", "string", packageName);
errorDialog.setMessage(resources.getString(id)); errorDialog.setMessage(resources.getString(id));
errorDialog.setButton(Dialog.BUTTON_POSITIVE, resources.getString(android.R.string.ok), errorDialog.setButton(Dialog.BUTTON_POSITIVE, resources.getString(android.R.string.ok),
new DialogInterface.OnClickListener() { (dialog, which) -> finish());
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
errorDialog.show(); errorDialog.show();
} }

View File

@ -35,21 +35,14 @@ public class QtClipboardManager
{ {
if (context != null) { if (context != null) {
final Semaphore semaphore = new Semaphore(0); final Semaphore semaphore = new Semaphore(0);
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
m_clipboardManager = m_clipboardManager =
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (m_clipboardManager != null) { if (m_clipboardManager != null) {
m_clipboardManager.addPrimaryClipChangedListener( m_clipboardManager.addPrimaryClipChangedListener(
new ClipboardManager.OnPrimaryClipChangedListener() { () -> onClipboardDataChanged(m_nativePointer));
public void onPrimaryClipChanged() {
onClipboardDataChanged(m_nativePointer);
}
});
} }
semaphore.release(); semaphore.release();
}
}); });
try { try {
semaphore.acquire(); semaphore.acquire();

View File

@ -188,12 +188,9 @@ public class QtInputDelegate {
{ {
if (m_imm == null) if (m_imm == null)
return; return;
m_editText.postDelayed(new Runnable() { m_editText.postDelayed(() -> {
@Override
public void run() {
m_imm.restartInput(m_editText); m_imm.restartInput(m_editText);
m_editText.m_optionsChanged = false; m_editText.m_optionsChanged = false;
}
}, 5); }, 5);
} }
@ -201,9 +198,7 @@ public class QtInputDelegate {
final int x, final int y, final int width, final int height, final int x, final int y, final int width, final int height,
final int inputHints, final int enterKeyType) final int inputHints, final int enterKeyType)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
if (m_imm == null) if (m_imm == null)
return; return;
@ -217,9 +212,7 @@ public class QtInputDelegate {
layout.setLayoutParams(m_editText, layoutParams, false); layout.setLayoutParams(m_editText, layoutParams, false);
m_editText.requestFocus(); m_editText.requestFocus();
m_editText.postDelayed(new Runnable() { m_editText.postDelayed(() -> {
@Override
public void run() {
m_imm.showSoftInput(m_editText, 0, new ResultReceiver(new Handler()) { m_imm.showSoftInput(m_editText, 0, new ResultReceiver(new Handler()) {
@Override @Override
protected void onReceiveResult(int resultCode, Bundle resultData) { protected void onReceiveResult(int resultCode, Bundle resultData) {
@ -245,9 +238,7 @@ public class QtInputDelegate {
m_imm.restartInput(m_editText); m_imm.restartInput(m_editText);
m_editText.m_optionsChanged = false; m_editText.m_optionsChanged = false;
} }
}
}, 15); }, 15);
}
}); });
} }
@ -392,9 +383,7 @@ public class QtInputDelegate {
private void probeForKeyboardHeight(QtLayout layout, Activity activity, int x, int y, private void probeForKeyboardHeight(QtLayout layout, Activity activity, int x, int y,
int width, int height, int inputHints, int enterKeyType) int width, int height, int inputHints, int enterKeyType)
{ {
layout.postDelayed(new Runnable() { layout.postDelayed(() -> {
@Override
public void run() {
if (!m_keyboardIsVisible) if (!m_keyboardIsVisible)
return; return;
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
@ -421,16 +410,13 @@ public class QtInputDelegate {
if (m_probeKeyboardHeightDelayMs < 1000) if (m_probeKeyboardHeightDelayMs < 1000)
m_probeKeyboardHeightDelayMs *= 2; m_probeKeyboardHeightDelayMs *= 2;
} }
}
}, m_probeKeyboardHeightDelayMs); }, m_probeKeyboardHeightDelayMs);
} }
public void hideSoftwareKeyboard() public void hideSoftwareKeyboard()
{ {
m_isKeyboardHidingAnimationOngoing = true; m_isKeyboardHidingAnimationOngoing = true;
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
if (m_imm == null) if (m_imm == null)
return; return;
@ -450,7 +436,6 @@ public class QtInputDelegate {
} }
} }
}); });
}
}); });
} }
@ -458,14 +443,11 @@ public class QtInputDelegate {
public void updateSelection(final int selStart, final int selEnd, public void updateSelection(final int selStart, final int selEnd,
final int candidatesStart, final int candidatesEnd) final int candidatesStart, final int candidatesEnd)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
if (m_imm == null) if (m_imm == null)
return; return;
m_imm.updateSelection(m_editText, selStart, selEnd, candidatesStart, candidatesEnd); m_imm.updateSelection(m_editText, selStart, selEnd, candidatesStart, candidatesEnd);
}
}); });
} }
@ -490,13 +472,8 @@ public class QtInputDelegate {
int editX, int editY, int editButtons, int editX, int editY, int editButtons,
int x1, int y1, int x2, int y2, boolean rtl) int x1, int y1, int x2, int y2, boolean rtl)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> updateHandleImpl(activity, layout, mode, editX, editY, editButtons,
@Override x1, y1, x2, y2, rtl));
public void run() {
updateHandleImpl(activity, layout, mode, editX, editY, editButtons,
x1, y1, x2, y2, rtl);
}
});
} }
private void updateHandleImpl(Activity activity, QtLayout layout, int mode, private void updateHandleImpl(Activity activity, QtLayout layout, int mode,

View File

@ -462,13 +462,10 @@ public abstract class QtLoader {
ArrayList<String> oneEntryArray = new ArrayList<>(Collections.singletonList(mainLibName)); ArrayList<String> oneEntryArray = new ArrayList<>(Collections.singletonList(mainLibName));
String mainLibPath = getLibrariesFullPaths(oneEntryArray).get(0); String mainLibPath = getLibrariesFullPaths(oneEntryArray).get(0);
final boolean[] success = {true}; final boolean[] success = {true};
QtNative.getQtThread().run(new Runnable() { QtNative.getQtThread().run(() -> {
@Override
public void run() {
m_mainLib = loadLibraryHelper(mainLibPath); m_mainLib = loadLibraryHelper(mainLibPath);
if (m_mainLib == null) if (m_mainLib == null)
success[0] = false; success[0] = false;
}
}); });
return success[0]; return success[0];
@ -488,9 +485,7 @@ public abstract class QtLoader {
ArrayList<String> fullPathLibs = getLibrariesFullPaths(libraries); ArrayList<String> fullPathLibs = getLibrariesFullPaths(libraries);
final boolean[] success = {true}; final boolean[] success = {true};
QtNative.getQtThread().run(new Runnable() { QtNative.getQtThread().run(() -> {
@Override
public void run() {
for (int i = 0; i < fullPathLibs.size(); ++i) { for (int i = 0; i < fullPathLibs.size(); ++i) {
String libName = fullPathLibs.get(i); String libName = fullPathLibs.get(i);
if (loadLibraryHelper(libName) == null) { if (loadLibraryHelper(libName) == null) {
@ -498,7 +493,6 @@ public abstract class QtLoader {
break; break;
} }
} }
}
}); });
return success[0]; return success[0];

View File

@ -159,9 +159,7 @@ public class QtMessageDialogHelper
public void show(long handler) public void show(long handler)
{ {
m_handler = handler; m_handler = handler;
m_activity.runOnUiThread( new Runnable() { m_activity.runOnUiThread(() -> {
@Override
public void run() {
if (m_dialog != null && m_dialog.isShowing()) if (m_dialog != null && m_dialog.isShowing())
m_dialog.dismiss(); m_dialog.dismiss();
@ -170,12 +168,7 @@ public class QtMessageDialogHelper
if (m_title != null) if (m_title != null)
m_dialog.setTitle(m_title); m_dialog.setTitle(m_title);
m_dialog.setOnCancelListener( new DialogInterface.OnCancelListener() { m_dialog.setOnCancelListener(dialogInterface -> QtNativeDialogHelper.dialogResult(handler(), -1));
@Override
public void onCancel(DialogInterface dialogInterface) {
QtNativeDialogHelper.dialogResult(handler(), -1);
}
});
m_dialog.setCancelable(m_buttonsList == null); m_dialog.setCancelable(m_buttonsList == null);
m_dialog.setCanceledOnTouchOutside(m_buttonsList == null); m_dialog.setCanceledOnTouchOutside(m_buttonsList == null);
m_dialog.setIcon(getIconDrawable()); m_dialog.setIcon(getIconDrawable());
@ -183,16 +176,13 @@ public class QtMessageDialogHelper
RelativeLayout dialogLayout = new RelativeLayout(m_activity); RelativeLayout dialogLayout = new RelativeLayout(m_activity);
int id = 1; int id = 1;
View lastView = null; View lastView = null;
View.OnLongClickListener copyText = new View.OnLongClickListener() { View.OnLongClickListener copyText = view -> {
@Override
public boolean onLongClick(View view) {
TextView tv = (TextView)view; TextView tv = (TextView)view;
if (tv != null) { if (tv != null) {
ClipboardManager cm = (android.text.ClipboardManager) m_activity.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager cm = (ClipboardManager) m_activity.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(tv.getText()); cm.setText(tv.getText());
} }
return true; return true;
}
}; };
if (m_text != null) if (m_text != null)
{ {
@ -316,20 +306,16 @@ public class QtMessageDialogHelper
scrollView.addView(dialogLayout); scrollView.addView(dialogLayout);
m_dialog.setView(scrollView); m_dialog.setView(scrollView);
m_dialog.show(); m_dialog.show();
}
}); });
} }
@UsedFromNativeCode @UsedFromNativeCode
public void hide() public void hide()
{ {
m_activity.runOnUiThread( new Runnable() { m_activity.runOnUiThread(() -> {
@Override
public void run() {
if (m_dialog != null && m_dialog.isShowing()) if (m_dialog != null && m_dialog.isShowing())
m_dialog.dismiss(); m_dialog.dismiss();
reset(); reset();
}
}); });
} }

View File

@ -46,12 +46,7 @@ public class QtNative
private static final QtThread m_qtThread = new QtThread(); private static final QtThread m_qtThread = new QtThread();
private static ClassLoader m_classLoader = null; private static ClassLoader m_classLoader = null;
private static final Runnable runPendingCppRunnablesRunnable = new Runnable() { private static final Runnable runPendingCppRunnablesRunnable = QtNative::runPendingCppRunnables;
@Override
public void run() {
runPendingCppRunnables();
}
};
public static boolean isStarted() public static boolean isStarted()
{ {
@ -255,12 +250,7 @@ public class QtNative
@UsedFromNativeCode @UsedFromNativeCode
private static void setViewVisibility(final View view, final boolean visible) private static void setViewVisibility(final View view, final boolean visible)
{ {
runAction(new Runnable() { runAction(() -> view.setVisibility(visible ? View.VISIBLE : View.GONE));
@Override
public void run() {
view.setVisibility(visible ? View.VISIBLE : View.GONE);
}
});
} }
public static boolean startApplication(ArrayList<String> params, String mainLib) public static boolean startApplication(ArrayList<String> params, String mainLib)
@ -269,18 +259,8 @@ public class QtNative
synchronized (m_mainActivityMutex) { synchronized (m_mainActivityMutex) {
String paramsStr = String.join("\t", params); String paramsStr = String.join("\t", params);
final String qtParams = mainLib + "\t" + paramsStr; final String qtParams = mainLib + "\t" + paramsStr;
m_qtThread.run(new Runnable() { m_qtThread.run(() -> res[0] = startQtAndroidPlugin(qtParams));
@Override m_qtThread.post(QtNative::startQtApplication);
public void run() {
res[0] = startQtAndroidPlugin(qtParams);
}
});
m_qtThread.post(new Runnable() {
@Override
public void run() {
startQtApplication();
}
});
waitForServiceSetup(); waitForServiceSetup();
m_started = true; m_started = true;
} }
@ -289,9 +269,7 @@ public class QtNative
public static void quitApp() public static void quitApp()
{ {
runAction(new Runnable() { runAction(() -> {
@Override
public void run() {
quitQtAndroidPlugin(); quitQtAndroidPlugin();
if (isActivityValid()) if (isActivityValid())
m_activity.get().finish(); m_activity.get().finish();
@ -299,7 +277,6 @@ public class QtNative
m_service.get().stopSelf(); m_service.get().stopSelf();
m_started = false; m_started = false;
}
}); });
} }

View File

@ -45,12 +45,9 @@ public class QtThread {
public void run(final Runnable runnable) { public void run(final Runnable runnable) {
final Semaphore sem = new Semaphore(0); final Semaphore sem = new Semaphore(0);
synchronized (m_qtThread) { synchronized (m_qtThread) {
m_pendingRunnables.add(new Runnable() { m_pendingRunnables.add(() -> {
@Override
public void run() {
runnable.run(); runnable.run();
sem.release(); sem.release();
}
}); });
m_qtThread.notify(); m_qtThread.notify();
} }

View File

@ -161,30 +161,21 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate
public void notifyScrolledEvent(int viewId) public void notifyScrolledEvent(int viewId)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> sendEventForVirtualViewId(viewId,
@Override AccessibilityEvent.TYPE_VIEW_SCROLLED));
public void run() {
sendEventForVirtualViewId(viewId, AccessibilityEvent.TYPE_VIEW_SCROLLED);
}
});
} }
public void notifyLocationChange(int viewId) public void notifyLocationChange(int viewId)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
if (m_focusedVirtualViewId == viewId) if (m_focusedVirtualViewId == viewId)
invalidateVirtualViewId(m_focusedVirtualViewId); invalidateVirtualViewId(m_focusedVirtualViewId);
}
}); });
} }
public void notifyObjectHide(int viewId, int parentId) public void notifyObjectHide(int viewId, int parentId)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
// If the object had accessibility focus, we need to clear it. // If the object had accessibility focus, we need to clear it.
// Note: This code is mostly copied from // Note: This code is mostly copied from
// AccessibilityNodeProvider::performAction, but we remove the // AccessibilityNodeProvider::performAction, but we remove the
@ -198,30 +189,24 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate
// When the object is hidden, we need to notify its parent about // When the object is hidden, we need to notify its parent about
// content change, not the hidden object itself // content change, not the hidden object itself
invalidateVirtualViewId(parentId); invalidateVirtualViewId(parentId);
}
}); });
} }
public void notifyObjectFocus(int viewId) public void notifyObjectFocus(int viewId)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
if (m_view == null) if (m_view == null)
return; return;
m_focusedVirtualViewId = viewId; m_focusedVirtualViewId = viewId;
m_view.invalidate(); m_view.invalidate();
sendEventForVirtualViewId(viewId, sendEventForVirtualViewId(viewId,
AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED); AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
}
}); });
} }
public void notifyValueChanged(int viewId, String value) public void notifyValueChanged(int viewId, String value)
{ {
QtNative.runAction(new Runnable() { QtNative.runAction(() -> {
@Override
public void run() {
// Send a TYPE_ANNOUNCEMENT event with the new value // Send a TYPE_ANNOUNCEMENT event with the new value
if ((viewId == INVALID_ID) || !m_manager.isEnabled()) { if ((viewId == INVALID_ID) || !m_manager.isEnabled()) {
@ -253,7 +238,6 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate
if (!group.requestSendAccessibilityEvent(m_view, event)) if (!group.requestSendAccessibilityEvent(m_view, event))
Log.w(TAG, "Failed to send value change announcement for " + event.getClassName()); Log.w(TAG, "Failed to send value change announcement for " + event.getClassName());
}
}); });
} }