diff options
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java')
-rw-r--r-- | src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java | 361 |
1 files changed, 70 insertions, 291 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java index fa7508921d..8f218d34f0 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -140,7 +140,6 @@ public class QtActivityDelegate private QtEditText m_editText = null; private InputMethodManager m_imm = null; private boolean m_quitApp = true; - private Process m_debuggerProcess = null; // debugger process private View m_dummyView = null; private boolean m_keyboardIsVisible = false; public boolean m_backKeyPressedSent = false; @@ -151,7 +150,6 @@ public class QtActivityDelegate private CursorHandle m_cursorHandle; private CursorHandle m_leftSelectionHandle; private CursorHandle m_rightSelectionHandle; - private EditMenu m_editMenu; private EditPopupMenu m_editPopupMenu; public void setFullScreen(boolean enterFullScreen) @@ -484,77 +482,87 @@ public class QtActivityDelegate } // Values coming from QAndroidInputContext::CursorHandleShowMode - private static final int CursorHandleNotShown = 0; - private static final int CursorHandleShowNormal = 1; - private static final int CursorHandleShowSelection = 2; - private static final int CursorHandleShowPopup = 3; + private static final int CursorHandleNotShown = 0; + private static final int CursorHandleShowNormal = 1; + private static final int CursorHandleShowSelection = 2; + private static final int CursorHandleShowEdit = 0x100; /* called from the C++ code when the position of the cursor or selection handles needs to be adjusted. mode is one of QAndroidInputContext::CursorHandleShowMode */ - public void updateHandles(int mode, int x1, int y1, int x2, int y2, boolean rtl) + public void updateHandles(int mode, int editX, int editY, int editButtons, int x1, int y1, int x2, int y2, boolean rtl) { - if (mode == CursorHandleNotShown) { - if (m_cursorHandle != null) - m_cursorHandle.hide(); - if (m_rightSelectionHandle != null) { - m_rightSelectionHandle.hide(); - m_leftSelectionHandle.hide(); - m_rightSelectionHandle = null; - m_leftSelectionHandle = null; - } - if (m_editMenu != null) - m_editMenu.hide(); - if (m_editPopupMenu != null) + switch (mode & 0xff) + { + case CursorHandleNotShown: + if (m_cursorHandle != null) { + m_cursorHandle.hide(); + m_cursorHandle = null; + } + if (m_rightSelectionHandle != null) { + m_rightSelectionHandle.hide(); + m_leftSelectionHandle.hide(); + m_rightSelectionHandle = null; + m_leftSelectionHandle = null; + } m_editPopupMenu.hide(); - } else if (mode == CursorHandleShowNormal || mode == CursorHandleShowPopup) { - if (m_cursorHandle == null) { - m_cursorHandle = new CursorHandle(m_activity, m_layout, QtNative.IdCursorHandle, - android.R.attr.textSelectHandle, false); - } - m_cursorHandle.setPosition(x1, y1); - if (m_rightSelectionHandle != null) { - m_rightSelectionHandle.hide(); - m_leftSelectionHandle.hide(); - m_rightSelectionHandle = null; - m_leftSelectionHandle = null; - } - } else if (mode == CursorHandleShowSelection) { - if (m_rightSelectionHandle == null) { - m_leftSelectionHandle = new CursorHandle(m_activity, m_layout, QtNative.IdLeftHandle, - !rtl ? android.R.attr.textSelectHandleLeft : - android.R.attr.textSelectHandleRight, - rtl); - m_rightSelectionHandle = new CursorHandle(m_activity, m_layout, QtNative.IdRightHandle, - !rtl ? android.R.attr.textSelectHandleRight : - android.R.attr.textSelectHandleLeft, - rtl); - } - m_leftSelectionHandle.setPosition(x1,y1); - m_rightSelectionHandle.setPosition(x2,y2); - if (m_cursorHandle != null) - m_cursorHandle.hide(); - - if (m_editMenu == null) - m_editMenu = new EditMenu(m_activity); - m_editMenu.show(); + break; + + case CursorHandleShowNormal: + if (m_cursorHandle == null) { + m_cursorHandle = new CursorHandle(m_activity, m_layout, QtNative.IdCursorHandle, + android.R.attr.textSelectHandle, false); + } + m_cursorHandle.setPosition(x1, y1); + if (m_rightSelectionHandle != null) { + m_rightSelectionHandle.hide(); + m_leftSelectionHandle.hide(); + m_rightSelectionHandle = null; + m_leftSelectionHandle = null; + } + break; + + case CursorHandleShowSelection: + if (m_rightSelectionHandle == null) { + m_leftSelectionHandle = new CursorHandle(m_activity, m_layout, QtNative.IdLeftHandle, + !rtl ? android.R.attr.textSelectHandleLeft : + android.R.attr.textSelectHandleRight, + rtl); + m_rightSelectionHandle = new CursorHandle(m_activity, m_layout, QtNative.IdRightHandle, + !rtl ? android.R.attr.textSelectHandleRight : + android.R.attr.textSelectHandleLeft, + rtl); + } + m_leftSelectionHandle.setPosition(x1,y1); + m_rightSelectionHandle.setPosition(x2,y2); + if (m_cursorHandle != null) { + m_cursorHandle.hide(); + m_cursorHandle = null; + } + mode |= CursorHandleShowEdit; + break; } - // show the edit popup menu - if (mode == CursorHandleShowPopup && (m_editMenu == null || !m_editMenu.isShown()) - && QtNative.hasClipboardText()) { - if (m_editPopupMenu == null) - m_editPopupMenu = new EditPopupMenu(m_activity, m_layout); - if (y2 < m_editPopupMenu.getHeight()) { - // If the popup cannot be shown over the text, it must be shown under the anchors - y2 = y1 + 2 * m_editPopupMenu.getHeight(); + if (QtNative.hasClipboardText()) + editButtons |= EditContextView.PASTE_BUTTON; + else + editButtons &= ~EditContextView.PASTE_BUTTON; + + if ((mode & CursorHandleShowEdit) == CursorHandleShowEdit && editButtons != 0) { + editY -= m_editPopupMenu.getHeight(); + if (editY < 0) { + if (m_cursorHandle != null) + editY = m_cursorHandle.bottom(); + else if (m_leftSelectionHandle != null && m_rightSelectionHandle != null) + editY = Math.max(m_leftSelectionHandle.bottom(), m_rightSelectionHandle.bottom()); + else + return; } - m_editPopupMenu.setPosition(x2, y2); - } else if (m_editPopupMenu != null) { + m_editPopupMenu.setPosition(editX, editY, editButtons); + } else { m_editPopupMenu.hide(); } - } public boolean loadApplication(Activity activity, ClassLoader classLoader, Bundle loaderParams) @@ -658,70 +666,6 @@ public class QtActivityDelegate return true; } - public static void debugLog(String msg) - { - Log.i(QtNative.QtTAG, "DEBUGGER: " + msg); - } - - private class DebugWaitRunnable implements Runnable { - - public DebugWaitRunnable(String pingPongSocket) throws IOException { - socket = new LocalServerSocket(pingPongSocket); - } - - public boolean wasFailure; - private LocalServerSocket socket; - - public void run() { - final int napTime = 200; // milliseconds between file accesses - final int timeOut = 30000; // ms until we give up on ping and pong - final int maxAttempts = timeOut / napTime; - - DataOutputStream outToClient = null; - try { - LocalSocket connectionFromClient = socket.accept(); - debugLog("Debug socket accepted"); - BufferedReader inFromClient = - new BufferedReader(new InputStreamReader(connectionFromClient.getInputStream())); - outToClient = new DataOutputStream(connectionFromClient.getOutputStream()); - outToClient.writeBytes("" + android.os.Process.myPid()); - - for (int i = 0; i < maxAttempts; i++) { - String clientData = inFromClient.readLine(); - debugLog("Incoming socket " + clientData); - if (!clientData.isEmpty()) - break; - - if (connectionFromClient.isClosed()) { - wasFailure = true; - break; - } - Thread.sleep(napTime); - } - } catch (IOException ioEx) { - ioEx.printStackTrace(); - wasFailure = true; - Log.e(QtNative.QtTAG,"Can't start debugger" + ioEx.getMessage()); - } catch (InterruptedException interruptEx) { - wasFailure = true; - Log.e(QtNative.QtTAG,"Can't start debugger" + interruptEx.getMessage()); - } finally { - try { - if (outToClient != null) - outToClient.close(); - } catch (IOException ignored) { } - } - } - - public void shutdown() throws IOException - { - wasFailure = true; - try { - socket.close(); - } catch (IOException ignored) { } - } - }; - public boolean startApplication() { // start application @@ -730,170 +674,6 @@ public class QtActivityDelegate Bundle extras = m_activity.getIntent().getExtras(); if (extras != null) { try { - final String dc = "--Added-by-androiddeployqt--/debugger.command"; - String debuggerCommand = - new BufferedReader(new InputStreamReader(m_activity.getAssets().open(dc))).readLine(); - if ( /*(ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0 - &&*/ extras.containsKey("debug_ping") - && extras.getString("debug_ping").equals("true")) { - try { - String packagePath = - m_activity.getPackageManager().getApplicationInfo(m_activity.getPackageName(), - PackageManager.GET_CONFIGURATIONS).dataDir + "/"; - - debugLog("extra parameters: " + extras); - String packageName = m_activity.getPackageName(); - String pingFile = extras.getString("ping_file"); - String pongFile = extras.getString("pong_file"); - String gdbserverSocket = extras.getString("gdbserver_socket"); - String gdbserverCommand = packagePath + debuggerCommand + gdbserverSocket; - String pingSocket = extras.getString("ping_socket"); - boolean usePing = pingFile != null; - boolean usePong = pongFile != null; - boolean useSocket = gdbserverSocket != null; - boolean usePingSocket = pingSocket != null; - int napTime = 200; // milliseconds between file accesses - int timeOut = 30000; // ms until we give up on ping and pong - int maxAttempts = timeOut / napTime; - - if (gdbserverSocket != null) { - debugLog("removing gdb socket " + gdbserverSocket); - new File(gdbserverSocket).delete(); - } - - if (usePing) { - debugLog("removing ping file " + pingFile); - File ping = new File(pingFile); - if (ping.exists()) { - if (!ping.delete()) - debugLog("ping file cannot be deleted"); - } - } - - if (usePong) { - debugLog("removing pong file " + pongFile); - File pong = new File(pongFile); - if (pong.exists()) { - if (!pong.delete()) - debugLog("pong file cannot be deleted"); - } - } - - debugLog("starting " + gdbserverCommand); - m_debuggerProcess = Runtime.getRuntime().exec(gdbserverCommand); - debugLog("gdbserver started"); - - if (useSocket) { - int i; - for (i = 0; i < maxAttempts; ++i) { - debugLog("waiting for socket at " + gdbserverSocket + ", attempt " + i); - File file = new File(gdbserverSocket); - if (file.exists()) { - file.setReadable(true, false); - file.setWritable(true, false); - file.setExecutable(true, false); - break; - } - Thread.sleep(napTime); - } - - if (i == maxAttempts) { - debugLog("time out when waiting for debug socket"); - return false; - } - - debugLog("socket ok"); - } else { - debugLog("socket not used"); - } - - if (usePingSocket) { - DebugWaitRunnable runnable = new DebugWaitRunnable(pingSocket); - Thread waitThread = new Thread(runnable); - waitThread.start(); - - int i; - for (i = 0; i < maxAttempts && waitThread.isAlive(); ++i) { - debugLog("Waiting for debug socket connect"); - debugLog("go to sleep"); - Thread.sleep(napTime); - } - - if (i == maxAttempts) { - debugLog("time out when waiting for ping socket"); - runnable.shutdown(); - return false; - } - - if (runnable.wasFailure) { - debugLog("Could not connect to debug client"); - return false; - } else { - debugLog("Got pid acknowledgment"); - } - } - - if (usePing) { - // Tell we are ready. - debugLog("writing ping at " + pingFile); - FileWriter writer = new FileWriter(pingFile); - writer.write("" + android.os.Process.myPid()); - writer.close(); - File file = new File(pingFile); - file.setReadable(true, false); - file.setWritable(true, false); - file.setExecutable(true, false); - debugLog("wrote ping"); - } else { - debugLog("ping not requested"); - } - - // Wait until other side is ready. - if (usePong) { - int i; - for (i = 0; i < maxAttempts; ++i) { - debugLog("waiting for pong at " + pongFile + ", attempt " + i); - File file = new File(pongFile); - if (file.exists()) { - file.delete(); - break; - } - debugLog("go to sleep"); - Thread.sleep(napTime); - } - debugLog("Removing pingFile " + pingFile); - new File(pingFile).delete(); - - if (i == maxAttempts) { - debugLog("time out when waiting for pong file"); - return false; - } - - debugLog("got pong " + pongFile); - } else { - debugLog("pong not requested"); - } - - } catch (IOException ioe) { - ioe.printStackTrace(); - } catch (SecurityException se) { - se.printStackTrace(); - } - } - - if (/*(ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0 - &&*/ extras.containsKey("qml_debug") - && extras.getString("qml_debug").equals("true")) { - String qmljsdebugger; - if (extras.containsKey("qmljsdebugger")) { - qmljsdebugger = extras.getString("qmljsdebugger"); - qmljsdebugger.replaceAll("\\s", ""); // remove whitespace for security - } else { - qmljsdebugger = "port:3768"; - } - m_applicationParameters += "\t-qmljsdebugger=" + qmljsdebugger; - } - if (extras.containsKey("extraenvvars")) { try { m_environmentVariables += "\t" + new String(Base64.decode(extras.getString("extraenvvars"), Base64.DEFAULT), "UTF-8"); @@ -1008,6 +788,7 @@ public class QtActivityDelegate return true; } }); + m_editPopupMenu = new EditPopupMenu(m_activity, m_layout); } public void hideSplashScreen() @@ -1081,8 +862,6 @@ public class QtActivityDelegate if (m_quitApp) { QtNative.terminateQt(); QtNative.setActivity(null, null); - if (m_debuggerProcess != null) - m_debuggerProcess.destroy(); QtNative.m_qtThread.exit(); System.exit(0); } |