diff options
Diffstat (limited to 'src/android')
3 files changed, 170 insertions, 82 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 3e55164419..445896622a 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -59,6 +59,7 @@ import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.Surface; import android.view.View; import android.view.ViewConfiguration; @@ -76,7 +77,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; public class QtActivityDelegate { @@ -89,6 +89,7 @@ public class QtActivityDelegate private Method m_super_onKeyUp = null; private Method m_super_onConfigurationChanged = null; private Method m_super_onActivityResult = null; + private Method m_super_dispatchGenericMotionEvent = null; private static final String NATIVE_LIBRARIES_KEY = "native.libraries"; private static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries"; @@ -131,37 +132,32 @@ public class QtActivityDelegate if (m_fullScreen = enterFullScreen) { m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); - if (Build.VERSION.SDK_INT >= 19) { - try { - int ui_flag_immersive_sticky = View.class.getDeclaredField("SYSTEM_UI_FLAG_IMMERSIVE_STICKY").getInt(null); - int ui_flag_layout_stable = View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_STABLE").getInt(null); - int ui_flag_layout_hide_navigation = View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION").getInt(null); - int ui_flag_layout_fullscreen = View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN").getInt(null); - int ui_flag_hide_navigation = View.class.getDeclaredField("SYSTEM_UI_FLAG_HIDE_NAVIGATION").getInt(null); - int ui_flag_fullscreen = View.class.getDeclaredField("SYSTEM_UI_FLAG_FULLSCREEN").getInt(null); - + try { + if (Build.VERSION.SDK_INT >= 14) { + int flags = View.class.getDeclaredField("SYSTEM_UI_FLAG_HIDE_NAVIGATION").getInt(null); + if (Build.VERSION.SDK_INT >= 16) { + flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_STABLE").getInt(null); + flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION").getInt(null); + flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN").getInt(null); + flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_FULLSCREEN").getInt(null); + + if (Build.VERSION.SDK_INT >= 19) + flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_IMMERSIVE_STICKY").getInt(null); + } Method m = View.class.getMethod("setSystemUiVisibility", int.class); - m.invoke(m_activity.getWindow().getDecorView(), - ui_flag_layout_stable - | ui_flag_layout_hide_navigation - | ui_flag_layout_fullscreen - | ui_flag_hide_navigation - | ui_flag_fullscreen - | ui_flag_immersive_sticky - | View.INVISIBLE); - } catch (Exception e) { - e.printStackTrace(); + m.invoke(m_activity.getWindow().getDecorView(), flags | View.INVISIBLE); } + } catch (Exception e) { + e.printStackTrace(); } } else { m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - if (Build.VERSION.SDK_INT >= 19) { + if (Build.VERSION.SDK_INT >= 14) { try { int ui_flag_visible = View.class.getDeclaredField("SYSTEM_UI_FLAG_VISIBLE").getInt(null); Method m = View.class.getMethod("setSystemUiVisibility", int.class); - m.invoke(m_activity.getWindow().getDecorView(), - ui_flag_visible); + m.invoke(m_activity.getWindow().getDecorView(), ui_flag_visible); } catch (Exception e) { e.printStackTrace(); } @@ -203,11 +199,21 @@ public class QtActivityDelegate private final int ImhUrlCharactersOnly = 0x400000; private final int ImhLatinOnly = 0x800000; + // enter key type - must be kept in sync with QTDIR/src/corelib/global/qnamespace.h + private final int EnterKeyDefault = 0; + private final int EnterKeyReturn = 1; + private final int EnterKeyDone = 2; + private final int EnterKeyGo = 3; + private final int EnterKeySend = 4; + private final int EnterKeySearch = 5; + private final int EnterKeyNext = 6; + private final int EnterKeyPrevious = 7; + // application state - private final int ApplicationSuspended = 0x0; - private final int ApplicationHidden = 0x1; - private final int ApplicationInactive = 0x2; - private final int ApplicationActive = 0x4; + public static final int ApplicationSuspended = 0x0; + public static final int ApplicationHidden = 0x1; + public static final int ApplicationInactive = 0x2; + public static final int ApplicationActive = 0x4; public boolean setKeyboardVisibility(boolean visibility, long timeStamp) @@ -239,7 +245,7 @@ public class QtActivityDelegate }, 5); } - public void showSoftwareKeyboard(int x, int y, int width, int height, int inputHints) + public void showSoftwareKeyboard(int x, int y, int width, int height, int inputHints, int enterKeyType) { if (m_imm == null) return; @@ -258,7 +264,31 @@ public class QtActivityDelegate } int initialCapsMode = 0; + int imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_DONE; + + switch (enterKeyType) { + case EnterKeyReturn: + imeOptions = android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION; + break; + case EnterKeyGo: + imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_GO; + break; + case EnterKeySend: + imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_SEND; + break; + case EnterKeySearch: + imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_SEARCH; + break; + case EnterKeyNext: + imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_NEXT; + break; + case EnterKeyPrevious: + if (Build.VERSION.SDK_INT > 10) + imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_PREVIOUS; + break; + } + int inputType = android.text.InputType.TYPE_CLASS_TEXT; if ((inputHints & (ImhPreferNumbers | ImhDigitsOnly | ImhFormattedNumbersOnly)) != 0) { @@ -284,7 +314,9 @@ public class QtActivityDelegate if ((inputHints & (ImhEmailCharactersOnly | ImhUrlCharactersOnly)) != 0) { if ((inputHints & ImhUrlCharactersOnly) != 0) { inputType |= android.text.InputType.TYPE_TEXT_VARIATION_URI; - imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_GO; + + if (enterKeyType == 0) // not explicitly overridden + imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_GO; } else if ((inputHints & ImhEmailCharactersOnly) != 0) { inputType |= android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; } @@ -311,7 +343,7 @@ public class QtActivityDelegate } } - if ((inputHints & ImhMultiLine) != 0) + if (enterKeyType == 0 && (inputHints & ImhMultiLine) != 0) imeOptions = android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION; m_editText.setInitialCapsMode(initialCapsMode); @@ -444,6 +476,13 @@ public class QtActivityDelegate m_super_onKeyUp = m_activity.getClass().getMethod("super_onKeyUp", Integer.TYPE, KeyEvent.class); m_super_onConfigurationChanged = m_activity.getClass().getMethod("super_onConfigurationChanged", Configuration.class); m_super_onActivityResult = m_activity.getClass().getMethod("super_onActivityResult", Integer.TYPE, Integer.TYPE, Intent.class); + if (Build.VERSION.SDK_INT >= 12) { + try { + m_super_dispatchGenericMotionEvent = m_activity.getClass().getMethod("super_dispatchGenericMotionEvent", MotionEvent.class); + } catch (Exception e) { + } + } + } catch (Exception e) { e.printStackTrace(); return false; @@ -867,24 +906,15 @@ public class QtActivityDelegate public void onPause() { - QtNative.updateApplicationState(ApplicationInactive); + QtNative.setApplicationState(ApplicationInactive); } public void onResume() { - // fire all lostActions - synchronized (QtNative.m_mainActivityMutex) - { - Iterator<Runnable> itr = QtNative.getLostActions().iterator(); - while (itr.hasNext()) - m_activity.runOnUiThread(itr.next()); - - QtNative.updateApplicationState(ApplicationActive); - if (m_started) { - QtNative.clearLostActions(); - QtNative.updateWindow(); - updateFullScreen(); // Suspending the app clears the immersive mode, so we need to set it again. - } + QtNative.setApplicationState(ApplicationActive); + if (m_started) { + QtNative.updateWindow(); + updateFullScreen(); // Suspending the app clears the immersive mode, so we need to set it again. } } @@ -907,7 +937,7 @@ public class QtActivityDelegate public void onStop() { - QtNative.updateApplicationState(ApplicationSuspended); + QtNative.setApplicationState(ApplicationSuspended); } public Object onRetainNonConfigurationInstance() @@ -1012,6 +1042,9 @@ public class QtActivityDelegate QtNative.keyUp(0, event.getCharacters().charAt(0), event.getMetaState(), event.getRepeatCount() > 0); } + if (QtNative.dispatchKeyEvent(event)) + return true; + try { return (Boolean) m_super_dispatchKeyEvent.invoke(m_activity, event); } catch (Exception e) { @@ -1278,4 +1311,17 @@ public class QtActivityDelegate m_layout.moveChild(view, index); } } + + public boolean dispatchGenericMotionEvent (MotionEvent ev) + { + if (m_started && QtNative.dispatchGenericMotionEvent(ev)) + return true; + + try { + return (Boolean) m_super_dispatchGenericMotionEvent.invoke(m_activity, ev); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } } diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java index 040eba5e42..07ef6d657d 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java @@ -42,15 +42,20 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.Handler; +import android.os.Looper; import android.text.ClipboardManager; +import android.os.Build; import android.util.Log; import android.view.ContextMenu; +import android.view.KeyEvent; import android.view.Menu; import android.view.MotionEvent; import android.view.View; import java.security.KeyStore; import java.security.cert.X509Certificate; +import java.util.Iterator; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; @@ -58,6 +63,7 @@ import javax.net.ssl.X509TrustManager; public class QtNative { private static Activity m_activity = null; + private static boolean m_activityPaused = false; private static QtActivityDelegate m_activityDelegate = null; public static Object m_mainActivityMutex = new Object(); // mutex used to synchronize runnable operations @@ -162,24 +168,33 @@ public class QtNative } } - static public ArrayList<Runnable> getLostActions() + public static void setApplicationState(int state) { - return m_lostActions; - } - - static public void clearLostActions() - { - m_lostActions.clear(); + synchronized (m_mainActivityMutex) { + switch (state) { + case QtActivityDelegate.ApplicationActive: + m_activityPaused = false; + Iterator<Runnable> itr = m_lostActions.iterator(); + while (itr.hasNext()) + runAction(itr.next()); + m_lostActions.clear(); + break; + default: + m_activityPaused = true; + break; + } + } + updateApplicationState(state); } - private static boolean runAction(Runnable action) + private static void runAction(Runnable action) { synchronized (m_mainActivityMutex) { - if (m_activity == null) + final Looper mainLooper = Looper.getMainLooper(); + final Handler handler = new Handler(mainLooper); + final boolean actionIsQueued = !m_activityPaused && m_activity != null && mainLooper != null && handler.post(action); + if (!actionIsQueued) m_lostActions.add(action); - else - m_activity.runOnUiThread(action); - return m_activity != null; } } @@ -301,32 +316,49 @@ public class QtNative static public void sendTouchEvent(MotionEvent event, int id) { - //@ANDROID-5 - touchBegin(id); - for (int i=0;i<event.getPointerCount();i++) { - touchAdd(id, - event.getPointerId(i), - getAction(i, event), - i == 0, - (int)event.getX(i), - (int)event.getY(i), - event.getSize(i), - event.getPressure(i)); - } + int pointerType = 0; - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - touchEnd(id,0); + if (Build.VERSION.SDK_INT >= 14) { + switch (event.getToolType(0)) { + case MotionEvent.TOOL_TYPE_STYLUS: + pointerType = 1; // QTabletEvent::Pen break; - - case MotionEvent.ACTION_UP: - touchEnd(id,2); + case MotionEvent.TOOL_TYPE_ERASER: + pointerType = 3; // QTabletEvent::Eraser break; + // TODO TOOL_TYPE_MOUSE + } + } + + if (pointerType != 0) { + tabletEvent(id, event.getDeviceId(), event.getEventTime(), event.getAction(), pointerType, + event.getButtonState(), event.getX(), event.getY(), event.getPressure()); + } else { + touchBegin(id); + for (int i = 0; i < event.getPointerCount(); ++i) { + touchAdd(id, + event.getPointerId(i), + getAction(i, event), + i == 0, + (int)event.getX(i), + (int)event.getY(i), + event.getSize(i), + event.getPressure(i)); + } - default: - touchEnd(id,1); + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + touchEnd(id, 0); + break; + + case MotionEvent.ACTION_UP: + touchEnd(id, 2); + break; + + default: + touchEnd(id, 1); + } } - //@ANDROID-5 } static public void sendTrackballEvent(MotionEvent event, int id) @@ -371,12 +403,13 @@ public class QtNative final int y, final int width, final int height, - final int inputHints ) + final int inputHints, + final int enterKeyType) { runAction(new Runnable() { @Override public void run() { - m_activityDelegate.showSoftwareKeyboard(x, y, width, height, inputHints); + m_activityDelegate.showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType); } }); } @@ -602,12 +635,21 @@ public class QtNative public static native void longPress(int winId, int x, int y); // pointer methods + // tablet methods + public static native void tabletEvent(int winId, int deviceId, long time, int action, int pointerType, int buttonState, float x, float y, float pressure); + // tablet methods + // keyboard methods public static native void keyDown(int key, int unicode, int modifier, boolean autoRepeat); public static native void keyUp(int key, int unicode, int modifier, boolean autoRepeat); public static native void keyboardVisibilityChanged(boolean visibility); // keyboard methods + // dispatch events methods + public static native boolean dispatchGenericMotionEvent(MotionEvent ev); + public static native boolean dispatchKeyEvent(KeyEvent event); + // dispatch events methods + // surface methods public static native void setSurface(int id, Object surface, int w, int h); // surface methods diff --git a/src/android/java/src/org/qtproject/qt5/android/bindings/QtActivity.java b/src/android/java/src/org/qtproject/qt5/android/bindings/QtActivity.java index 23e08f537a..e5ed690f07 100644 --- a/src/android/java/src/org/qtproject/qt5/android/bindings/QtActivity.java +++ b/src/android/java/src/org/qtproject/qt5/android/bindings/QtActivity.java @@ -243,11 +243,11 @@ public class QtActivity extends Activity @SuppressWarnings("rawtypes") Class loaderClass = m_classLoader.loadClass(loaderParams.getString(LOADER_CLASS_NAME_KEY)); // load QtLoader class Object qtLoader = loaderClass.newInstance(); // create an instance - Method perpareAppMethod = qtLoader.getClass().getMethod("loadApplication", + Method prepareAppMethod = qtLoader.getClass().getMethod("loadApplication", Activity.class, ClassLoader.class, Bundle.class); - if (!(Boolean)perpareAppMethod.invoke(qtLoader, this, m_classLoader, loaderParams)) + if (!(Boolean)prepareAppMethod.invoke(qtLoader, this, m_classLoader, loaderParams)) throw new Exception(""); QtApplication.setQtActivityDelegate(qtLoader); |