From 8a9bd001c947e6888d37e99fc456339fd2b51b36 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Fri, 17 Jan 2014 10:31:27 +0200 Subject: Support multiple native surfaces on Android. Support for multiple native surfaces is needed by applications that need to mix raster windows with GL windows. Rework the raster and opengl implementation, get rid of eglfs and fbconvenience dependencies. Create a single android platform plugin. [ChangeLog][Android] Rework the raster and opengl implementation. [ChangeLog][Android] Create a single android platform plugin. Task-number: QTBUG-34650 Change-Id: I9b1ab51554823329dda8cfbf8fef27c38f917c7b Reviewed-by: Paul Olav Tvete --- src/android/jar/AndroidManifest.xml | 1 + .../qtproject/qt5/android/QtActivityDelegate.java | 106 ++- .../src/org/qtproject/qt5/android/QtLayout.java | 11 + .../src/org/qtproject/qt5/android/QtNative.java | 66 +- .../src/org/qtproject/qt5/android/QtSurface.java | 103 +-- src/corelib/global/qlogging.cpp | 2 +- src/corelib/kernel/qjni_p.h | 12 +- src/opengl/opengl.pro | 3 - src/plugins/platforms/android/android.json | 3 + src/plugins/platforms/android/android.pro | 81 +- .../platforms/android/androidjniaccessibility.cpp | 272 +++++++ .../platforms/android/androidjniaccessibility.h | 51 ++ .../platforms/android/androidjniclipboard.cpp | 120 +++ .../platforms/android/androidjniclipboard.h | 61 ++ src/plugins/platforms/android/androidjniinput.cpp | 606 ++++++++++++++ src/plugins/platforms/android/androidjniinput.h | 59 ++ src/plugins/platforms/android/androidjnimain.cpp | 724 +++++++++++++++++ src/plugins/platforms/android/androidjnimain.h | 120 +++ src/plugins/platforms/android/androidjnimenu.cpp | 429 ++++++++++ src/plugins/platforms/android/androidjnimenu.h | 69 ++ .../platforms/android/androidplatformplugin.cpp | 66 ++ .../platforms/android/androidsurfaceclient.h | 58 ++ src/plugins/platforms/android/opengl/opengl.pro | 32 - .../android/qandroidassetsfileenginehandler.cpp | 309 +++++++ .../android/qandroidassetsfileenginehandler.h | 66 ++ .../platforms/android/qandroidinputcontext.cpp | 762 ++++++++++++++++++ .../platforms/android/qandroidinputcontext.h | 135 ++++ .../android/qandroidplatformaccessibility.cpp | 58 ++ .../android/qandroidplatformaccessibility.h | 61 ++ .../android/qandroidplatformbackingstore.cpp | 78 ++ .../android/qandroidplatformbackingstore.h | 66 ++ .../android/qandroidplatformclipboard.cpp | 79 ++ .../platforms/android/qandroidplatformclipboard.h | 63 ++ .../android/qandroidplatformdialoghelpers.cpp | 204 +++++ .../android/qandroidplatformdialoghelpers.h | 77 ++ .../android/qandroidplatformfontdatabase.cpp | 79 ++ .../android/qandroidplatformfontdatabase.h | 58 ++ .../android/qandroidplatformintegration.cpp | 286 +++++++ .../android/qandroidplatformintegration.h | 157 ++++ .../platforms/android/qandroidplatformmenu.cpp | 177 +++++ .../platforms/android/qandroidplatformmenu.h | 92 +++ .../platforms/android/qandroidplatformmenubar.cpp | 111 +++ .../platforms/android/qandroidplatformmenubar.h | 74 ++ .../platforms/android/qandroidplatformmenuitem.cpp | 180 +++++ .../platforms/android/qandroidplatformmenuitem.h | 99 +++ .../android/qandroidplatformopenglcontext.cpp | 84 ++ .../android/qandroidplatformopenglcontext.h | 63 ++ .../android/qandroidplatformopenglwindow.cpp | 160 ++++ .../android/qandroidplatformopenglwindow.h | 83 ++ .../android/qandroidplatformrasterwindow.cpp | 78 ++ .../android/qandroidplatformrasterwindow.h | 70 ++ .../platforms/android/qandroidplatformscreen.cpp | 352 ++++++++ .../platforms/android/qandroidplatformscreen.h | 120 +++ .../platforms/android/qandroidplatformservices.cpp | 79 ++ .../platforms/android/qandroidplatformservices.h | 61 ++ .../platforms/android/qandroidplatformtheme.cpp | 170 ++++ .../platforms/android/qandroidplatformtheme.h | 65 ++ .../platforms/android/qandroidplatformwindow.cpp | 157 ++++ .../platforms/android/qandroidplatformwindow.h | 87 ++ .../platforms/android/qandroidsystemlocale.cpp | 177 +++++ .../platforms/android/qandroidsystemlocale.h | 67 ++ src/plugins/platforms/android/raster/raster.pro | 19 - src/plugins/platforms/android/src/android.json | 3 - .../android/src/androidjniaccessibility.cpp | 272 ------- .../android/src/androidjniaccessibility.h | 51 -- .../platforms/android/src/androidjniclipboard.cpp | 120 --- .../platforms/android/src/androidjniclipboard.h | 61 -- .../platforms/android/src/androidjniinput.cpp | 606 -------------- .../platforms/android/src/androidjniinput.h | 59 -- .../platforms/android/src/androidjnimain.cpp | 884 --------------------- src/plugins/platforms/android/src/androidjnimain.h | 124 --- .../platforms/android/src/androidjnimenu.cpp | 426 ---------- src/plugins/platforms/android/src/androidjnimenu.h | 69 -- .../android/src/androidplatformplugin.cpp | 66 -- .../android/src/opengl/qandroidopenglcontext.cpp | 95 --- .../android/src/opengl/qandroidopenglcontext.h | 69 -- .../src/opengl/qandroidopenglplatformscreen.cpp | 61 -- .../src/opengl/qandroidopenglplatformscreen.h | 60 -- .../src/opengl/qandroidopenglplatformwindow.cpp | 178 ----- .../src/opengl/qandroidopenglplatformwindow.h | 91 --- .../android/src/opengl/qeglfshooks_android.cpp | 161 ---- .../src/qandroidassetsfileenginehandler.cpp | 309 ------- .../android/src/qandroidassetsfileenginehandler.h | 66 -- .../platforms/android/src/qandroidinputcontext.cpp | 762 ------------------ .../platforms/android/src/qandroidinputcontext.h | 135 ---- .../android/src/qandroidplatformaccessibility.cpp | 58 -- .../android/src/qandroidplatformaccessibility.h | 61 -- .../android/src/qandroidplatformclipboard.cpp | 79 -- .../android/src/qandroidplatformclipboard.h | 63 -- .../android/src/qandroidplatformdialoghelpers.cpp | 204 ----- .../android/src/qandroidplatformdialoghelpers.h | 77 -- .../android/src/qandroidplatformfontdatabase.cpp | 79 -- .../android/src/qandroidplatformfontdatabase.h | 58 -- .../android/src/qandroidplatformintegration.cpp | 343 -------- .../android/src/qandroidplatformintegration.h | 184 ----- .../platforms/android/src/qandroidplatformmenu.cpp | 177 ----- .../platforms/android/src/qandroidplatformmenu.h | 92 --- .../android/src/qandroidplatformmenubar.cpp | 111 --- .../android/src/qandroidplatformmenubar.h | 74 -- .../android/src/qandroidplatformmenuitem.cpp | 180 ----- .../android/src/qandroidplatformmenuitem.h | 99 --- .../android/src/qandroidplatformservices.cpp | 79 -- .../android/src/qandroidplatformservices.h | 61 -- .../android/src/qandroidplatformtheme.cpp | 170 ---- .../platforms/android/src/qandroidplatformtheme.h | 65 -- .../platforms/android/src/qandroidsystemlocale.cpp | 177 ----- .../platforms/android/src/qandroidsystemlocale.h | 67 -- .../android/src/raster/qandroidplatformscreen.cpp | 94 --- .../android/src/raster/qandroidplatformscreen.h | 62 -- .../android/src/raster/qandroidplatformwindow.cpp | 102 --- .../android/src/raster/qandroidplatformwindow.h | 64 -- .../platforms/android/src/raster/raster.pri | 7 - src/plugins/platforms/android/src/src.pri | 55 -- 113 files changed, 7987 insertions(+), 7901 deletions(-) create mode 100644 src/plugins/platforms/android/android.json create mode 100644 src/plugins/platforms/android/androidjniaccessibility.cpp create mode 100644 src/plugins/platforms/android/androidjniaccessibility.h create mode 100644 src/plugins/platforms/android/androidjniclipboard.cpp create mode 100644 src/plugins/platforms/android/androidjniclipboard.h create mode 100644 src/plugins/platforms/android/androidjniinput.cpp create mode 100644 src/plugins/platforms/android/androidjniinput.h create mode 100644 src/plugins/platforms/android/androidjnimain.cpp create mode 100644 src/plugins/platforms/android/androidjnimain.h create mode 100644 src/plugins/platforms/android/androidjnimenu.cpp create mode 100644 src/plugins/platforms/android/androidjnimenu.h create mode 100644 src/plugins/platforms/android/androidplatformplugin.cpp create mode 100644 src/plugins/platforms/android/androidsurfaceclient.h delete mode 100644 src/plugins/platforms/android/opengl/opengl.pro create mode 100644 src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp create mode 100644 src/plugins/platforms/android/qandroidassetsfileenginehandler.h create mode 100644 src/plugins/platforms/android/qandroidinputcontext.cpp create mode 100644 src/plugins/platforms/android/qandroidinputcontext.h create mode 100644 src/plugins/platforms/android/qandroidplatformaccessibility.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformaccessibility.h create mode 100644 src/plugins/platforms/android/qandroidplatformbackingstore.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformbackingstore.h create mode 100644 src/plugins/platforms/android/qandroidplatformclipboard.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformclipboard.h create mode 100644 src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformdialoghelpers.h create mode 100644 src/plugins/platforms/android/qandroidplatformfontdatabase.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformfontdatabase.h create mode 100644 src/plugins/platforms/android/qandroidplatformintegration.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformintegration.h create mode 100644 src/plugins/platforms/android/qandroidplatformmenu.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformmenu.h create mode 100644 src/plugins/platforms/android/qandroidplatformmenubar.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformmenubar.h create mode 100644 src/plugins/platforms/android/qandroidplatformmenuitem.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformmenuitem.h create mode 100644 src/plugins/platforms/android/qandroidplatformopenglcontext.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformopenglcontext.h create mode 100644 src/plugins/platforms/android/qandroidplatformopenglwindow.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformopenglwindow.h create mode 100644 src/plugins/platforms/android/qandroidplatformrasterwindow.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformrasterwindow.h create mode 100644 src/plugins/platforms/android/qandroidplatformscreen.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformscreen.h create mode 100644 src/plugins/platforms/android/qandroidplatformservices.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformservices.h create mode 100644 src/plugins/platforms/android/qandroidplatformtheme.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformtheme.h create mode 100644 src/plugins/platforms/android/qandroidplatformwindow.cpp create mode 100644 src/plugins/platforms/android/qandroidplatformwindow.h create mode 100644 src/plugins/platforms/android/qandroidsystemlocale.cpp create mode 100644 src/plugins/platforms/android/qandroidsystemlocale.h delete mode 100644 src/plugins/platforms/android/raster/raster.pro delete mode 100644 src/plugins/platforms/android/src/android.json delete mode 100644 src/plugins/platforms/android/src/androidjniaccessibility.cpp delete mode 100644 src/plugins/platforms/android/src/androidjniaccessibility.h delete mode 100644 src/plugins/platforms/android/src/androidjniclipboard.cpp delete mode 100644 src/plugins/platforms/android/src/androidjniclipboard.h delete mode 100644 src/plugins/platforms/android/src/androidjniinput.cpp delete mode 100644 src/plugins/platforms/android/src/androidjniinput.h delete mode 100644 src/plugins/platforms/android/src/androidjnimain.cpp delete mode 100644 src/plugins/platforms/android/src/androidjnimain.h delete mode 100644 src/plugins/platforms/android/src/androidjnimenu.cpp delete mode 100644 src/plugins/platforms/android/src/androidjnimenu.h delete mode 100644 src/plugins/platforms/android/src/androidplatformplugin.cpp delete mode 100644 src/plugins/platforms/android/src/opengl/qandroidopenglcontext.cpp delete mode 100644 src/plugins/platforms/android/src/opengl/qandroidopenglcontext.h delete mode 100644 src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.cpp delete mode 100644 src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.h delete mode 100644 src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp delete mode 100644 src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.h delete mode 100644 src/plugins/platforms/android/src/opengl/qeglfshooks_android.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidassetsfileenginehandler.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidassetsfileenginehandler.h delete mode 100644 src/plugins/platforms/android/src/qandroidinputcontext.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidinputcontext.h delete mode 100644 src/plugins/platforms/android/src/qandroidplatformaccessibility.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidplatformaccessibility.h delete mode 100644 src/plugins/platforms/android/src/qandroidplatformclipboard.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidplatformclipboard.h delete mode 100644 src/plugins/platforms/android/src/qandroidplatformdialoghelpers.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidplatformdialoghelpers.h delete mode 100644 src/plugins/platforms/android/src/qandroidplatformfontdatabase.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidplatformfontdatabase.h delete mode 100644 src/plugins/platforms/android/src/qandroidplatformintegration.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidplatformintegration.h delete mode 100644 src/plugins/platforms/android/src/qandroidplatformmenu.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidplatformmenu.h delete mode 100644 src/plugins/platforms/android/src/qandroidplatformmenubar.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidplatformmenubar.h delete mode 100644 src/plugins/platforms/android/src/qandroidplatformmenuitem.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidplatformmenuitem.h delete mode 100644 src/plugins/platforms/android/src/qandroidplatformservices.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidplatformservices.h delete mode 100644 src/plugins/platforms/android/src/qandroidplatformtheme.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidplatformtheme.h delete mode 100644 src/plugins/platforms/android/src/qandroidsystemlocale.cpp delete mode 100644 src/plugins/platforms/android/src/qandroidsystemlocale.h delete mode 100644 src/plugins/platforms/android/src/raster/qandroidplatformscreen.cpp delete mode 100644 src/plugins/platforms/android/src/raster/qandroidplatformscreen.h delete mode 100644 src/plugins/platforms/android/src/raster/qandroidplatformwindow.cpp delete mode 100644 src/plugins/platforms/android/src/raster/qandroidplatformwindow.h delete mode 100644 src/plugins/platforms/android/src/raster/raster.pri delete mode 100644 src/plugins/platforms/android/src/src.pri diff --git a/src/android/jar/AndroidManifest.xml b/src/android/jar/AndroidManifest.xml index ebc6fcfea7..cef88f7f19 100644 --- a/src/android/jar/AndroidManifest.xml +++ b/src/android/jar/AndroidManifest.xml @@ -1,4 +1,5 @@ + 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 d8c560933f..6c71bed7bc 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -1,7 +1,7 @@ /**************************************************************************** ** +** Copyright (C) 2014 BogDan Vatra ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Copyright (C) 2012 BogDan Vatra ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Android port of the Qt Toolkit. @@ -73,6 +73,7 @@ import java.io.FileWriter; import java.io.IOException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; public class QtActivityDelegate @@ -105,7 +106,7 @@ public class QtActivityDelegate private int m_lastChar = 0; private boolean m_fullScreen = false; private boolean m_started = false; - private QtSurface m_surface = null; + private HashMap m_surfaces = null; private QtLayout m_layout = null; private QtEditText m_editText = null; private InputMethodManager m_imm = null; @@ -116,21 +117,6 @@ public class QtActivityDelegate public boolean m_backKeyPressedSent = false; - public QtLayout getQtLayout() - { - return m_layout; - } - - public QtSurface getQtSurface() - { - return m_surface; - } - - public void redrawWindow(int left, int top, int right, int bottom) - { - m_surface.drawBitmap(new Rect(left, top, right, bottom)); - } - public void setFullScreen(boolean enterFullScreen) { if (m_fullScreen == enterFullScreen) @@ -175,6 +161,7 @@ public class QtActivityDelegate } } } + m_layout.requestLayout(); } @@ -233,7 +220,8 @@ public class QtActivityDelegate { if (m_imm == null) return; - if (height > m_surface.getHeight()*2/3) + + if (height > m_layout.getHeight() * 2 / 3) m_activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); else m_activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); @@ -330,7 +318,7 @@ public class QtActivityDelegate { if (m_imm == null) return; - m_imm.hideSoftInputFromWindow(m_editText.getWindowToken(), 0, new ResultReceiver( new Handler()){ + m_imm.hideSoftInputFromWindow(m_editText.getWindowToken(), 0, new ResultReceiver(new Handler()) { @Override protected void onReceiveResult(int resultCode, Bundle resultData) { switch (resultCode) { @@ -358,7 +346,7 @@ public class QtActivityDelegate if (size < 36 || size > 512) { // check size sanity DisplayMetrics metrics = new DisplayMetrics(); a.getWindowManager().getDefaultDisplay().getMetrics(metrics); - size = metrics.densityDpi/10*3; + size = metrics.densityDpi / 10 * 3; if (size < 36) size = 36; @@ -626,13 +614,13 @@ public class QtActivityDelegate m_applicationParameters += "\t-qmljsdebugger=" + qmljsdebugger; } - if (null == m_surface) + if (null == m_surfaces) onCreate(null); String nativeLibraryDir = QtNativeLibrariesDir.nativeLibrariesDir(m_activity); - m_surface.applicationStarted( QtNative.startApplication(m_applicationParameters, - m_environmentVariables, - m_mainLib, - nativeLibraryDir)); + QtNative.startApplication(m_applicationParameters, + m_environmentVariables, + m_mainLib, + nativeLibraryDir); m_started = true; return true; } catch (Exception e) { @@ -657,14 +645,12 @@ public class QtActivityDelegate metrics.xdpi, metrics.ydpi, metrics.scaledDensity); } m_layout = new QtLayout(m_activity); - m_surface = new QtSurface(m_activity, 0); m_editText = new QtEditText(m_activity, this); m_imm = (InputMethodManager)m_activity.getSystemService(Context.INPUT_METHOD_SERVICE); - m_layout.addView(m_surface, 0); + m_surfaces = new HashMap(); m_activity.setContentView(m_layout, - new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, - ViewGroup.LayoutParams.FILL_PARENT)); - m_layout.bringChildToFront(m_surface); + new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); m_activity.registerForContextMenu(m_layout); int orientation = m_activity.getResources().getConfiguration().orientation; @@ -704,18 +690,6 @@ public class QtActivityDelegate } } - public void onRestoreInstanceState(Bundle savedInstanceState) - { - try { - m_super_onRestoreInstanceState.invoke(m_activity, savedInstanceState); - } catch (Exception e) { - e.printStackTrace(); - } - m_started = savedInstanceState.getBoolean("Started"); - if (m_started) - m_surface.applicationStarted(true); - } - public void onPause() { QtNative.updateApplicationState(ApplicationInactive); @@ -768,6 +742,19 @@ public class QtActivityDelegate } outState.putBoolean("FullScreen", m_fullScreen); outState.putBoolean("Started", m_started); + // It should never + } + + public void onRestoreInstanceState(Bundle savedInstanceState) + { + try { + m_super_onRestoreInstanceState.invoke(m_activity, savedInstanceState); + } catch (Exception e) { + e.printStackTrace(); + } + m_started = savedInstanceState.getBoolean("Started"); + // FIXME restore all surfaces + } public boolean onKeyDown(int keyCode, KeyEvent event) @@ -967,4 +954,39 @@ public class QtActivityDelegate } } } + + public void createSurface(int id, boolean onTop, int x, int y, int w, int h) { + if (m_surfaces.containsKey(id)) + m_layout.removeView(m_surfaces.remove(id)); + + QtSurface surface = new QtSurface(m_activity, id, onTop); + if (w < 0 || h < 0) { + surface.setLayoutParams( new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); + } else { + surface.setLayoutParams( new QtLayout.LayoutParams(w, h, x, y)); + } + + m_layout.addView(surface); + if (onTop) + m_layout.bringChildToFront(surface); + m_surfaces.put(id, surface); + } + + public void setSurfaceGeometry(int id, int x, int y, int w, int h) { + if (!m_surfaces.containsKey(id)) { + Log.e(QtNative.QtTAG, "Surface " + id +" not found!"); + return; + } + QtSurface surface = m_surfaces.get(id); + surface.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y)); + m_layout.requestLayout(); + } + + public void destroySurface(int id) { + if (m_surfaces.containsKey(id)) + m_layout.removeView(m_surfaces.remove(id)); + else + Log.e(QtNative.QtTAG, "Surface " + id +" not found!"); + } } diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java b/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java index 043dab5ce8..058b10750f 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtLayout.java @@ -42,8 +42,10 @@ package org.qtproject.qt5.android; +import android.app.Activity; import android.content.Context; import android.util.AttributeSet; +import android.util.DisplayMetrics; import android.view.View; import android.view.ViewGroup; @@ -64,6 +66,15 @@ public class QtLayout extends ViewGroup super(context, attrs, defStyle); } + @Override + protected void onSizeChanged (int w, int h, int oldw, int oldh) + { + DisplayMetrics metrics = new DisplayMetrics(); + ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics); + QtNative.setApplicationDisplayMetrics(metrics.widthPixels, + metrics.heightPixels, w, h, metrics.xdpi, metrics.ydpi, metrics.scaledDensity); + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 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 57f3642b56..2437752545 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java @@ -1,7 +1,7 @@ /**************************************************************************** ** +** Copyright (C) 2014 BogDan Vatra ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Copyright (C) 2012 BogDan Vatra ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Android port of the Qt Toolkit. @@ -250,29 +250,10 @@ public class QtNative } } - public static void pauseApplication() - { - synchronized (m_mainActivityMutex) { - if (m_started) - pauseQtApp(); - } - } - public static void resumeApplication() - { - synchronized (m_mainActivityMutex) { - if (m_started) { - resumeQtApp(); - updateWindow(); - } - } - } // application methods public static native void startQtApplication(String params, String env); - public static native void startQtApp(String params, String env); - public static native void pauseQtApp(); - public static native void resumeQtApp(); public static native boolean startQtAndroidPlugin(); public static native void quitQtAndroidPlugin(); public static native void terminateQt(); @@ -283,16 +264,6 @@ public class QtNative m_activity.finish(); } - private static void redrawSurface(final int left, final int top, final int right, final int bottom ) - { - runAction(new Runnable() { - @Override - public void run() { - m_activityDelegate.redrawWindow(left, top, right, bottom); - } - }); - } - //@ANDROID-9 static private int getAction(int index, MotionEvent event) { @@ -539,6 +510,36 @@ public class QtNative return certificateArray; } + private static void createSurface(final int id, final boolean onTop, final int x, final int y, final int w, final int h) + { + runAction(new Runnable() { + @Override + public void run() { + m_activityDelegate.createSurface(id, onTop, x, y, w, h); + } + }); + } + + private static void setSurfaceGeometry(final int id, final int x, final int y, final int w, final int h) + { + runAction(new Runnable() { + @Override + public void run() { + m_activityDelegate.setSurfaceGeometry(id, x, y, w, h); + } + }); + } + + private static void destroySurface(final int id) + { + runAction(new Runnable() { + @Override + public void run() { + m_activityDelegate.destroySurface(id); + } + }); + } + // screen methods public static native void setDisplayMetrics(int screenWidthPixels, int screenHeightPixels, @@ -567,10 +568,7 @@ public class QtNative // keyboard methods // surface methods - public static native void destroySurface(); - public static native void setSurface(Object surface); - public static native void lockSurface(); - public static native void unlockSurface(); + public static native void setSurface(int id, Object surface, int w, int h); // surface methods // window methods diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java b/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java index c499dc3898..f9f5f16845 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java @@ -1,7 +1,7 @@ /**************************************************************************** ** +** Copyright (C) 2014 BogDan Vatra ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Copyright (C) 2012 BogDan Vatra ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Android port of the Qt Toolkit. @@ -44,11 +44,7 @@ package org.qtproject.qt5.android; import android.app.Activity; import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Rect; import android.graphics.PixelFormat; -import android.util.DisplayMetrics; import android.util.Log; import android.view.GestureDetector; import android.view.MotionEvent; @@ -60,61 +56,34 @@ import java.lang.reflect.Method; public class QtSurface extends SurfaceView implements SurfaceHolder.Callback { - private Bitmap m_bitmap = null; - private boolean m_started = false; - private boolean m_usesGL = false; private GestureDetector m_gestureDetector; private Object m_accessibilityDelegate = null; + private boolean m_onTop; - public QtSurface(Context context, int id) + public QtSurface(Context context, int id, boolean onTop) { super(context); setFocusable(false); setFocusableInTouchMode(false); - + m_onTop = onTop; + setZOrderMediaOverlay(onTop); getHolder().addCallback(this); + getHolder().setFormat(PixelFormat.RGBA_8888); getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU); setId(id); m_gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { public void onLongPress(MotionEvent event) { - if (!m_started) - return; QtNative.longPress(getId(), (int) event.getX(), (int) event.getY()); } }); m_gestureDetector.setIsLongpressEnabled(true); } - public void applicationStarted(boolean usesGL) - { - m_started = true; - m_usesGL = usesGL; - if (getWidth() < 1 || getHeight() < 1) - return; - if (m_usesGL) { - QtNative.setSurface(getHolder().getSurface()); - } else { - QtNative.lockSurface(); - QtNative.setSurface(null); - m_bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.RGB_565); - QtNative.setSurface(m_bitmap); - QtNative.unlockSurface(); - } - } - @Override public void surfaceCreated(SurfaceHolder holder) { - DisplayMetrics metrics = new DisplayMetrics(); - ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics); - QtNative.setApplicationDisplayMetrics(metrics.widthPixels, - metrics.heightPixels, getWidth(), getHeight(), metrics.xdpi, metrics.ydpi, metrics.scaledDensity); - - if (m_usesGL) - holder.setFormat(PixelFormat.RGBA_8888); - - + QtNative.setSurface(getId(), holder.getSurface(), getWidth(), getHeight()); // Initialize Accessibility // The accessibility code depends on android API level 16, so dynamically resolve it if (android.os.Build.VERSION.SDK_INT >= 16) { @@ -158,71 +127,21 @@ public class QtSurface extends SurfaceView implements SurfaceHolder.Callback @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - if (width<1 || height<1) - return; - - DisplayMetrics metrics = new DisplayMetrics(); - ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics); - QtNative.setApplicationDisplayMetrics(metrics.widthPixels, - metrics.heightPixels, - width, - height, - metrics.xdpi, - metrics.ydpi, - metrics.scaledDensity); - - if (!m_started) + if (width < 1 || height < 1) return; - if (m_usesGL) { - QtNative.setSurface(holder.getSurface()); - } else { - QtNative.lockSurface(); - QtNative.setSurface(null); - m_bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); - QtNative.setSurface(m_bitmap); - QtNative.unlockSurface(); - QtNative.updateWindow(); - } + QtNative.setSurface(getId(), holder.getSurface(), width, height); } @Override public void surfaceDestroyed(SurfaceHolder holder) { - if (m_usesGL) { - QtNative.destroySurface(); - } else { - if (!m_started) - return; - - QtNative.lockSurface(); - QtNative.setSurface(null); - QtNative.unlockSurface(); - } - } - - public void drawBitmap(Rect rect) - { - if (!m_started) - return; - QtNative.lockSurface(); - if (null != m_bitmap) { - try { - Canvas cv = getHolder().lockCanvas(rect); - cv.drawBitmap(m_bitmap, rect, rect, null); - getHolder().unlockCanvasAndPost(cv); - } catch (Exception e) { - Log.e(QtNative.QtTAG, "Can't create main activity", e); - } - } - QtNative.unlockSurface(); + QtNative.setSurface(getId(), null, 0, 0); } @Override public boolean onTouchEvent(MotionEvent event) { - if (!m_started) - return false; QtNative.sendTouchEvent(event, getId()); m_gestureDetector.onTouchEvent(event); return true; @@ -231,8 +150,6 @@ public class QtSurface extends SurfaceView implements SurfaceHolder.Callback @Override public boolean onTrackballEvent(MotionEvent event) { - if (!m_started) - return false; QtNative.sendTrackballEvent(event, getId()); return true; } diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index cc20891c76..076582373e 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -871,7 +871,7 @@ static void android_default_message_handler(QtMsgType type, const QMessageLogContext &context, const QString &message) { - android_LogPriority priority; + android_LogPriority priority = ANDROID_LOG_DEBUG; switch (type) { case QtDebugMsg: priority = ANDROID_LOG_DEBUG; break; case QtWarningMsg: priority = ANDROID_LOG_WARN; break; diff --git a/src/corelib/kernel/qjni_p.h b/src/corelib/kernel/qjni_p.h index ab98aec1bf..b1f0011b94 100644 --- a/src/corelib/kernel/qjni_p.h +++ b/src/corelib/kernel/qjni_p.h @@ -178,11 +178,13 @@ public: jobject jobj = static_cast(o); if (!isSameObject(jobj)) { d = QSharedPointer(new QJNIObjectData()); - QJNIEnvironmentPrivate env; - d->m_jobject = env->NewGlobalRef(jobj); - jclass objectClass = env->GetObjectClass(jobj); - d->m_jclass = static_cast(env->NewGlobalRef(objectClass)); - env->DeleteLocalRef(objectClass); + if (jobj) { + QJNIEnvironmentPrivate env; + d->m_jobject = env->NewGlobalRef(jobj); + jclass objectClass = env->GetObjectClass(jobj); + d->m_jclass = static_cast(env->NewGlobalRef(objectClass)); + env->DeleteLocalRef(objectClass); + } } return *this; diff --git a/src/opengl/opengl.pro b/src/opengl/opengl.pro index b01ca80829..4d9208d983 100644 --- a/src/opengl/opengl.pro +++ b/src/opengl/opengl.pro @@ -8,9 +8,6 @@ irix-cc*:QMAKE_CXXFLAGS += -no_prelink -ptused QMAKE_DOCS = $$PWD/doc/qtopengl.qdocconf -ANDROID_LIB_DEPENDENCY_REPLACEMENTS = \ - "plugins/platforms/android/libqtforandroid.so:plugins/platforms/android/libqtforandroidGL.so" - load(qt_module) contains(QT_CONFIG, opengl):CONFIG += opengl diff --git a/src/plugins/platforms/android/android.json b/src/plugins/platforms/android/android.json new file mode 100644 index 0000000000..6843bd3301 --- /dev/null +++ b/src/plugins/platforms/android/android.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "android" ] +} diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index aa5ab4ddbd..4d873dd986 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -1,3 +1,80 @@ -TEMPLATE = subdirs +TARGET = qtforandroid -SUBDIRS += raster opengl +PLUGIN_TYPE = platforms + +# STATICPLUGIN needed because there's a Q_IMPORT_PLUGIN in androidjnimain.cpp +# Yes, the plugin imports itself statically +DEFINES += QT_STATICPLUGIN + +load(qt_plugin) + +!contains(ANDROID_PLATFORM, android-9) { + INCLUDEPATH += $$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/include + LIBS += -L$$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/lib -ljnigraphics -landroid +} else { + LIBS += -ljnigraphics -landroid +} + +QT += core-private gui-private platformsupport-private + +CONFIG += qpa/genericunixfontdatabase + +OTHER_FILES += $$PWD/android.json + +INCLUDEPATH += $$PWD + +SOURCES += $$PWD/androidplatformplugin.cpp \ + $$PWD/androidjnimain.cpp \ + $$PWD/androidjniaccessibility.cpp \ + $$PWD/androidjniinput.cpp \ + $$PWD/androidjnimenu.cpp \ + $$PWD/androidjniclipboard.cpp \ + $$PWD/qandroidplatformintegration.cpp \ + $$PWD/qandroidplatformservices.cpp \ + $$PWD/qandroidassetsfileenginehandler.cpp \ + $$PWD/qandroidinputcontext.cpp \ + $$PWD/qandroidplatformaccessibility.cpp \ + $$PWD/qandroidplatformfontdatabase.cpp \ + $$PWD/qandroidplatformdialoghelpers.cpp \ + $$PWD/qandroidplatformclipboard.cpp \ + $$PWD/qandroidplatformtheme.cpp \ + $$PWD/qandroidplatformmenubar.cpp \ + $$PWD/qandroidplatformmenu.cpp \ + $$PWD/qandroidplatformmenuitem.cpp \ + $$PWD/qandroidsystemlocale.cpp \ + $$PWD/qandroidplatformscreen.cpp \ + $$PWD/qandroidplatformwindow.cpp \ + $$PWD/qandroidplatformopenglwindow.cpp \ + $$PWD/qandroidplatformrasterwindow.cpp \ + $$PWD/qandroidplatformbackingstore.cpp \ + $$PWD/qandroidplatformopenglcontext.cpp + +HEADERS += $$PWD/qandroidplatformintegration.h \ + $$PWD/androidjnimain.h \ + $$PWD/androidjniaccessibility.h \ + $$PWD/androidjniinput.h \ + $$PWD/androidjnimenu.h \ + $$PWD/androidjniclipboard.h \ + $$PWD/qandroidplatformservices.h \ + $$PWD/qandroidassetsfileenginehandler.h \ + $$PWD/qandroidinputcontext.h \ + $$PWD/qandroidplatformaccessibility.h \ + $$PWD/qandroidplatformfontdatabase.h \ + $$PWD/qandroidplatformclipboard.h \ + $$PWD/qandroidplatformdialoghelpers.h \ + $$PWD/qandroidplatformtheme.h \ + $$PWD/qandroidplatformmenubar.h \ + $$PWD/qandroidplatformmenu.h \ + $$PWD/qandroidplatformmenuitem.h \ + $$PWD/qandroidsystemlocale.h \ + $$PWD/androidsurfaceclient.h \ + $$PWD/qandroidplatformscreen.h \ + $$PWD/qandroidplatformwindow.h \ + $$PWD/qandroidplatformopenglwindow.h \ + $$PWD/qandroidplatformrasterwindow.h \ + $$PWD/qandroidplatformbackingstore.h \ + $$PWD/qandroidplatformopenglcontext.h + +#Non-standard install directory, QTBUG-29859 +DESTDIR = $$DESTDIR/android +target.path = $${target.path}/android diff --git a/src/plugins/platforms/android/androidjniaccessibility.cpp b/src/plugins/platforms/android/androidjniaccessibility.cpp new file mode 100644 index 0000000000..b987c49c9c --- /dev/null +++ b/src/plugins/platforms/android/androidjniaccessibility.cpp @@ -0,0 +1,272 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidjniaccessibility.h" +#include "androidjnimain.h" +#include "qandroidplatformintegration.h" +#include "qpa/qplatformaccessibility.h" +#include "qguiapplication.h" +#include "qwindow.h" +#include "qrect.h" +#include "QtGui/qaccessible.h" + +#include "qdebug.h" + +static const char m_qtTag[] = "QtA11y"; +static const char m_classErrorMsg[] = "Can't find class \"%s\""; +static const char m_methodErrorMsg[] = "Can't find method \"%s%s\""; + +namespace QtAndroidAccessibility +{ + static void setActive(JNIEnv */*env*/, jobject /*thiz*/, jboolean active) + { + QAndroidPlatformIntegration *platformIntegration = QtAndroid::androidPlatformIntegration(); + if (platformIntegration) + platformIntegration->accessibility()->setActive(active); + else + __android_log_print(ANDROID_LOG_WARN, m_qtTag, "Could not activate platform accessibility."); + } + + QAccessibleInterface *interfaceFromId(jint objectId) + { + QAccessibleInterface *iface = 0; + if (objectId == -1) { + QWindow *win = qApp->focusWindow(); + if (win) + iface = win->accessibleRoot(); + } else { + iface = QAccessible::accessibleInterface(objectId); + } + return iface; + } + + static jintArray childIdListForAccessibleObject(JNIEnv *env, jobject /*thiz*/, jint objectId) + { + QAccessibleInterface *iface = interfaceFromId(objectId); + if (iface) { + jintArray jArray = env->NewIntArray(jsize(iface->childCount())); + for (int i = 0; i < iface->childCount(); ++i) { + QAccessibleInterface *child = iface->child(i); + if (child) { + QAccessible::Id ifaceId = QAccessible::uniqueId(child); + jint jid = ifaceId; + env->SetIntArrayRegion(jArray, i, 1, &jid); + } + } + return jArray; + } + + return env->NewIntArray(jsize(0)); + } + + static jint parentId(JNIEnv */*env*/, jobject /*thiz*/, jint objectId) + { + QAccessibleInterface *iface = interfaceFromId(objectId); + if (iface) { + QAccessibleInterface *parent = iface->parent(); + if (parent) { + if (parent->role() == QAccessible::Application) + return -1; + return QAccessible::uniqueId(parent); + } + } + return -1; + } + + static jobject screenRect(JNIEnv *env, jobject /*thiz*/, jint objectId) + { + QRect rect; + QAccessibleInterface *iface = interfaceFromId(objectId); + if (iface && iface->isValid()) { + rect = iface->rect(); + } + + jclass rectClass = env->FindClass("android/graphics/Rect"); + jmethodID ctor = env->GetMethodID(rectClass, "", "(IIII)V"); + jobject jrect = env->NewObject(rectClass, ctor, rect.left(), rect.top(), rect.right(), rect.bottom()); + return jrect; + } + + static jint hitTest(JNIEnv */*env*/, jobject /*thiz*/, jfloat x, jfloat y) + { + QAccessibleInterface *root = interfaceFromId(-1); + if (root) { + QAccessibleInterface *child = root->childAt((int)x, (int)y); + QAccessibleInterface *lastChild = 0; + while (child && (child != lastChild)) { + lastChild = child; + child = child->childAt((int)x, (int)y); + } + if (lastChild) + return QAccessible::uniqueId(lastChild); + } + return -1; + } + + static jboolean clickAction(JNIEnv */*env*/, jobject /*thiz*/, jint objectId) + { +// qDebug() << "A11Y: CLICK: " << objectId; + QAccessibleInterface *iface = interfaceFromId(objectId); + if (iface && iface->actionInterface()) { + if (iface->actionInterface()->actionNames().contains(QAccessibleActionInterface::pressAction())) + iface->actionInterface()->doAction(QAccessibleActionInterface::pressAction()); + else + iface->actionInterface()->doAction(QAccessibleActionInterface::toggleAction()); + } + return false; + } + + +#define FIND_AND_CHECK_CLASS(CLASS_NAME) \ +clazz = env->FindClass(CLASS_NAME); \ +if (!clazz) { \ + __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_classErrorMsg, CLASS_NAME); \ + return JNI_FALSE; \ +} + + //__android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); + +#define CALL_METHOD(OBJECT, METHOD_NAME, METHOD_SIGNATURE, ...) \ +{ \ + jclass clazz = env->GetObjectClass(OBJECT); \ + jmethodID method = env->GetMethodID(clazz, METHOD_NAME, METHOD_SIGNATURE); \ + if (!method) { \ + __android_log_print(ANDROID_LOG_WARN, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \ + return; \ + } \ + env->CallVoidMethod(OBJECT, method, __VA_ARGS__); \ +} + + + static jstring descriptionForAccessibleObject(JNIEnv *env, jobject /*thiz*/, jint objectId) + { + QString desc; + QAccessibleInterface *iface = interfaceFromId(objectId); + if (iface && iface->isValid()) { + desc = iface->text(QAccessible::Name); + if (desc.isEmpty()) + desc = iface->text(QAccessible::Description); + + desc += QChar(' ') + QString::fromUtf8(qAccessibleRoleString(iface->role())); + } + + jstring jdesc = env->NewString((jchar*) desc.constData(), (jsize) desc.size()); + return jdesc; + } + + static void populateNode(JNIEnv *env, jobject /*thiz*/, jint objectId, jobject node) + { + QAccessibleInterface *iface = interfaceFromId(objectId); + if (!iface || !iface->isValid()) { + __android_log_print(ANDROID_LOG_WARN, m_qtTag, "Accessibility: populateNode for Invalid ID"); + return; + } + QAccessible::State state = iface->state(); + + // try to fill in the text property, this is what the screen reader reads + QString desc = iface->text(QAccessible::Value); + if (desc.isEmpty()) + desc = iface->text(QAccessible::Name); + if (desc.isEmpty()) + desc = iface->text(QAccessible::Description); + if (QAccessibleTextInterface *textIface = iface->textInterface()) { + if (textIface->selectionCount() > 0) { + int startSelection; + int endSelection; + textIface->selection(0, &startSelection, &endSelection); + CALL_METHOD(node, "setTextSelection", "(II)V", startSelection, endSelection) + } + } + + if ((iface->role() != QAccessible::NoRole) && + (iface->role() != QAccessible::Client) && + (iface->role() != QAccessible::Pane)) { + desc += QChar(' ') + QString::fromUtf8(qAccessibleRoleString(iface->role())); + } + + CALL_METHOD(node, "setEnabled", "(Z)V", !state.disabled) + //CALL_METHOD(node, "setFocusable", "(Z)V", state.focusable) + CALL_METHOD(node, "setFocusable", "(Z)V", true) + //CALL_METHOD(node, "setFocused", "(Z)V", state.focused) + CALL_METHOD(node, "setCheckable", "(Z)V", state.checkable) + CALL_METHOD(node, "setChecked", "(Z)V", state.checked) + CALL_METHOD(node, "setVisibleToUser", "(Z)V", !state.invisible) + + if (iface->actionInterface()) { + QStringList actions = iface->actionInterface()->actionNames(); + bool clickable = actions.contains(QAccessibleActionInterface::pressAction()); + bool toggle = actions.contains(QAccessibleActionInterface::toggleAction()); + if (clickable || toggle) { + CALL_METHOD(node, "setClickable", "(Z)V", clickable) + CALL_METHOD(node, "addAction", "(I)V", 16) // ACTION_CLICK defined in AccessibilityNodeInfo + } + } + + jstring jdesc = env->NewString((jchar*) desc.constData(), (jsize) desc.size()); + //CALL_METHOD(node, "setText", "(Ljava/lang/CharSequence;)V", jdesc) + CALL_METHOD(node, "setContentDescription", "(Ljava/lang/CharSequence;)V", jdesc) + } + + static JNINativeMethod methods[] = { + {"setActive","(Z)V",(void*)setActive}, + {"childIdListForAccessibleObject", "(I)[I", (jintArray)childIdListForAccessibleObject}, + {"parentId", "(I)I", (void*)parentId}, + {"descriptionForAccessibleObject", "(I)Ljava/lang/String;", (jstring)descriptionForAccessibleObject}, + {"screenRect", "(I)Landroid/graphics/Rect;", (jobject)screenRect}, + {"hitTest", "(FF)I", (void*)hitTest}, + {"populateNode", "(ILandroid/view/accessibility/AccessibilityNodeInfo;)V", (void*)populateNode}, + {"clickAction", "(I)Z", (void*)clickAction}, + }; + + bool registerNatives(JNIEnv *env) + { + jclass clazz; + FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/accessibility/QtNativeAccessibility"); + jclass appClass = static_cast(env->NewGlobalRef(clazz)); + + if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { + __android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed"); + return false; + } + + return true; + } +} diff --git a/src/plugins/platforms/android/androidjniaccessibility.h b/src/plugins/platforms/android/androidjniaccessibility.h new file mode 100644 index 0000000000..e708138c33 --- /dev/null +++ b/src/plugins/platforms/android/androidjniaccessibility.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDJNIACCESSIBILITY_H +#define ANDROIDJNIACCESSIBILITY_H +#include + +namespace QtAndroidAccessibility +{ + bool registerNatives(JNIEnv *env); +} + +#endif // ANDROIDJNIINPUT_H diff --git a/src/plugins/platforms/android/androidjniclipboard.cpp b/src/plugins/platforms/android/androidjniclipboard.cpp new file mode 100644 index 0000000000..05270ac374 --- /dev/null +++ b/src/plugins/platforms/android/androidjniclipboard.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidjniclipboard.h" +#include "androidjnimain.h" + +using namespace QtAndroid; +namespace QtAndroidClipboard +{ + // Clipboard support + static jmethodID m_registerClipboardManagerMethodID = 0; + static jmethodID m_setClipboardTextMethodID = 0; + static jmethodID m_hasClipboardTextMethodID = 0; + static jmethodID m_getClipboardTextMethodID = 0; + // Clipboard support + + void setClipboardListener(QAndroidPlatformClipboard *listener) + { + Q_UNUSED(listener); + + AttachedJNIEnv env; + if (!env.jniEnv) + return; + + env.jniEnv->CallStaticVoidMethod(applicationClass(), m_registerClipboardManagerMethodID); + } + + void setClipboardText(const QString &text) + { + AttachedJNIEnv env; + if (!env.jniEnv) + return; + + jstring jtext = env.jniEnv->NewString(reinterpret_cast(text.data()), + text.length()); + env.jniEnv->CallStaticVoidMethod(applicationClass(), m_setClipboardTextMethodID, jtext); + env.jniEnv->DeleteLocalRef(jtext); + } + + bool hasClipboardText() + { + AttachedJNIEnv env; + if (!env.jniEnv) + return false; + + return env.jniEnv->CallStaticBooleanMethod(applicationClass(), m_hasClipboardTextMethodID); + } + + QString clipboardText() + { + AttachedJNIEnv env; + if (!env.jniEnv) + return QString(); + + jstring text = reinterpret_cast(env.jniEnv->CallStaticObjectMethod(applicationClass(), + m_getClipboardTextMethodID)); + const jchar *jstr = env.jniEnv->GetStringChars(text, 0); + QString str(reinterpret_cast(jstr), env.jniEnv->GetStringLength(text)); + env.jniEnv->ReleaseStringChars(text, jstr); + return str; + } + + +#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ + VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ + if (!VAR) { \ + __android_log_print(ANDROID_LOG_FATAL, qtTagText(), methodErrorMsgFmt(), METHOD_NAME, METHOD_SIGNATURE); \ + return false; \ + } + + bool registerNatives(JNIEnv *env) + { + jclass appClass = QtAndroid::applicationClass(); + + GET_AND_CHECK_STATIC_METHOD(m_registerClipboardManagerMethodID, appClass, "registerClipboardManager", "()V"); + GET_AND_CHECK_STATIC_METHOD(m_setClipboardTextMethodID, appClass, "setClipboardText", "(Ljava/lang/String;)V"); + GET_AND_CHECK_STATIC_METHOD(m_hasClipboardTextMethodID, appClass, "hasClipboardText", "()Z"); + GET_AND_CHECK_STATIC_METHOD(m_getClipboardTextMethodID, appClass, "getClipboardText", "()Ljava/lang/String;"); + + return true; + } +} diff --git a/src/plugins/platforms/android/androidjniclipboard.h b/src/plugins/platforms/android/androidjniclipboard.h new file mode 100644 index 0000000000..15cd93202e --- /dev/null +++ b/src/plugins/platforms/android/androidjniclipboard.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDJNICLIPBOARD_H +#define ANDROIDJNICLIPBOARD_H + +#include +#include + +class QAndroidPlatformClipboard; +namespace QtAndroidClipboard +{ + // Clipboard support + void setClipboardListener(QAndroidPlatformClipboard *listener); + void setClipboardText(const QString &text); + bool hasClipboardText(); + QString clipboardText(); + // Clipboard support + + bool registerNatives(JNIEnv *env); +} + +#endif // ANDROIDJNICLIPBOARD_H diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp new file mode 100644 index 0000000000..55d44b7377 --- /dev/null +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -0,0 +1,606 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidjniinput.h" +#include "androidjnimain.h" +#include "qandroidplatformintegration.h" + +#include +#include +#include + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL +# include +#endif + +using namespace QtAndroid; + +namespace QtAndroidInput +{ + static jmethodID m_showSoftwareKeyboardMethodID = 0; + static jmethodID m_resetSoftwareKeyboardMethodID = 0; + static jmethodID m_hideSoftwareKeyboardMethodID = 0; + static jmethodID m_isSoftwareKeyboardVisibleMethodID = 0; + static jmethodID m_updateSelectionMethodID = 0; + + static bool m_ignoreMouseEvents = false; + + static QList m_touchPoints; + + static QPointer m_mouseGrabber; + + static int m_lastCursorPos = -1; + + void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd) + { + AttachedJNIEnv env; + if (!env.jniEnv) + return; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << ">>> UPDATESELECTION" << selStart << selEnd << candidatesStart << candidatesEnd; +#endif + if (candidatesStart == -1 && candidatesEnd == -1 && selStart == selEnd) { + // Qt only gives us position inside the block, so if we move to the + // same position in another block, the Android keyboard will believe + // we have not changed position, and be terribly confused. + if (selStart == m_lastCursorPos) { +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << ">>> FAKEUPDATESELECTION" << selStart+1; +#endif + env.jniEnv->CallStaticVoidMethod(applicationClass(), m_updateSelectionMethodID, + selStart+1, selEnd+1, candidatesStart, candidatesEnd); + } + m_lastCursorPos = selStart; + } else { + m_lastCursorPos = -1; + } + env.jniEnv->CallStaticVoidMethod(applicationClass(), m_updateSelectionMethodID, + selStart, selEnd, candidatesStart, candidatesEnd); + } + + void showSoftwareKeyboard(int left, int top, int width, int height, int inputHints) + { + AttachedJNIEnv env; + if (!env.jniEnv) + return; + + env.jniEnv->CallStaticVoidMethod(applicationClass(), + m_showSoftwareKeyboardMethodID, + left, + top, + width, + height, + inputHints); +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ SHOWSOFTWAREKEYBOARD" << left << top << width << height << inputHints; +#endif + } + + void resetSoftwareKeyboard() + { + AttachedJNIEnv env; + if (!env.jniEnv) + return; + + env.jniEnv->CallStaticVoidMethod(applicationClass(), m_resetSoftwareKeyboardMethodID); +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ RESETSOFTWAREKEYBOARD"; +#endif + } + + void hideSoftwareKeyboard() + { + AttachedJNIEnv env; + if (!env.jniEnv) + return; + + env.jniEnv->CallStaticVoidMethod(applicationClass(), m_hideSoftwareKeyboardMethodID); +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ HIDESOFTWAREKEYBOARD"; +#endif + } + + bool isSoftwareKeyboardVisible() + { + AttachedJNIEnv env; + if (!env.jniEnv) + return false; + + bool visibility = env.jniEnv->CallStaticBooleanMethod(applicationClass(), m_isSoftwareKeyboardVisibleMethodID); +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ ISSOFTWAREKEYBOARDVISIBLE" << visibility; +#endif + return visibility; + } + + + static void mouseDown(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) + { + if (m_ignoreMouseEvents) + return; + + QPoint globalPos(x,y); + QWindow *tlw = topLevelWindowAt(globalPos); + m_mouseGrabber = tlw; + QPoint localPos = tlw ? (globalPos - tlw->position()) : globalPos; + QWindowSystemInterface::handleMouseEvent(tlw, + localPos, + globalPos, + Qt::MouseButtons(Qt::LeftButton)); + } + + static void mouseUp(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) + { + QPoint globalPos(x,y); + QWindow *tlw = m_mouseGrabber.data(); + if (!tlw) + tlw = topLevelWindowAt(globalPos); + QPoint localPos = tlw ? (globalPos -tlw->position()) : globalPos; + QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos + , Qt::MouseButtons(Qt::NoButton)); + m_ignoreMouseEvents = false; + m_mouseGrabber = 0; + } + + static void mouseMove(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) + { + + if (m_ignoreMouseEvents) + return; + + QPoint globalPos(x,y); + QWindow *tlw = m_mouseGrabber.data(); + if (!tlw) + tlw = topLevelWindowAt(globalPos); + QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos; + QWindowSystemInterface::handleMouseEvent(tlw, + localPos, + globalPos, + Qt::MouseButtons(Qt::LeftButton)); + } + + static void longPress(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) + { + //### TODO: add proper API for Qt 5.2 + static bool rightMouseFromLongPress = qgetenv("QT_NECESSITAS_COMPATIBILITY_LONG_PRESS").toInt(); + if (!rightMouseFromLongPress) + return; + m_ignoreMouseEvents = true; + QPoint globalPos(x,y); + QWindow *tlw = topLevelWindowAt(globalPos); + QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos; + + // Release left button + QWindowSystemInterface::handleMouseEvent(tlw, + localPos, + globalPos, + Qt::MouseButtons(Qt::NoButton)); + + // Press right button + QWindowSystemInterface::handleMouseEvent(tlw, + localPos, + globalPos, + Qt::MouseButtons(Qt::RightButton)); + } + + static void touchBegin(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/) + { + m_touchPoints.clear(); + } + + static void touchAdd(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint id, jint action, jboolean /*primary*/, jint x, jint y, jfloat size, jfloat pressure) + { + Qt::TouchPointState state = Qt::TouchPointStationary; + switch (action) { + case 0: + state = Qt::TouchPointPressed; + break; + case 1: + state = Qt::TouchPointMoved; + break; + case 2: + state = Qt::TouchPointStationary; + break; + case 3: + state = Qt::TouchPointReleased; + break; + } + + const int dw = desktopWidthPixels(); + const int dh = desktopHeightPixels(); + QWindowSystemInterface::TouchPoint touchPoint; + touchPoint.id = id; + touchPoint.pressure = pressure; + touchPoint.normalPosition = QPointF(double(x / dw), double(y / dh)); + touchPoint.state = state; + touchPoint.area = QRectF(x - double(dw*size) / 2.0, + y - double(dh*size) / 2.0, + double(dw*size), + double(dh*size)); + m_touchPoints.push_back(touchPoint); + } + + static void touchEnd(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint /*action*/) + { + if (m_touchPoints.isEmpty()) + return; + + QAndroidPlatformIntegration *platformIntegration = QtAndroid::androidPlatformIntegration(); + if (!platformIntegration) + return; + + QTouchDevice *touchDevice = platformIntegration->touchDevice(); + if (touchDevice == 0) { + touchDevice = new QTouchDevice; + touchDevice->setType(QTouchDevice::TouchScreen); + touchDevice->setCapabilities(QTouchDevice::Position + | QTouchDevice::Area + | QTouchDevice::Pressure + | QTouchDevice::NormalizedPosition); + QWindowSystemInterface::registerTouchDevice(touchDevice); + platformIntegration->setTouchDevice(touchDevice); + } + + QWindow *window = QtAndroid::topLevelWindowAt(m_touchPoints.at(0).area.center().toPoint()); + QWindowSystemInterface::handleTouchEvent(window, touchDevice, m_touchPoints); + } + + static int mapAndroidKey(int key) + { + // 0--9 0x00000007 -- 0x00000010 + if (key >= 0x00000007 && key <= 0x00000010) + return Qt::Key_0 + key - 0x00000007; + + // A--Z 0x0000001d -- 0x00000036 + if (key >= 0x0000001d && key <= 0x00000036) + return Qt::Key_A + key - 0x0000001d; + + switch (key) { + case 0x00000039: + case 0x0000003a: + return Qt::Key_Alt; + + case 0x0000004b: + return Qt::Key_Apostrophe; + + case 0x00000004: // KEYCODE_BACK + return Qt::Key_Back; + + case 0x00000049: + return Qt::Key_Backslash; + + case 0x00000005: + return Qt::Key_Call; + + case 0x0000001b: // KEYCODE_CAMERA + return Qt::Key_Camera; + + case 0x0000001c: + return Qt::Key_Clear; + + case 0x00000037: + return Qt::Key_Comma; + + case 0x00000043: // KEYCODE_DEL + return Qt::Key_Backspace; + + case 0x00000017: // KEYCODE_DPAD_CENTER + return Qt::Key_Enter; + + case 0x00000014: // KEYCODE_DPAD_DOWN + return Qt::Key_Down; + + case 0x00000015: //KEYCODE_DPAD_LEFT + return Qt::Key_Left; + + case 0x00000016: //KEYCODE_DPAD_RIGHT + return Qt::Key_Right; + + case 0x00000013: //KEYCODE_DPAD_UP + return Qt::Key_Up; + + case 0x00000006: //KEYCODE_ENDCALL + return Qt::Key_Hangup; + + case 0x00000042: + return Qt::Key_Return; + + case 0x00000041: //KEYCODE_ENVELOPE + return Qt::Key_LaunchMail; + + case 0x00000046: + return Qt::Key_Equal; + + case 0x00000040: + return Qt::Key_Explorer; + + case 0x00000003: + return Qt::Key_Home; + + case 0x00000047: + return Qt::Key_BracketLeft; + + case 0x0000005a: // KEYCODE_MEDIA_FAST_FORWARD + return Qt::Key_AudioForward; + + case 0x00000057: + return Qt::Key_MediaNext; + + case 0x00000055: + return Qt::Key_MediaPlay; + + case 0x00000058: + return Qt::Key_MediaPrevious; + + case 0x00000059: // KEYCODE_MEDIA_REWIND + return Qt::Key_AudioRewind; + + case 0x00000056: + return Qt::Key_MediaStop; + + case 0x00000052: //KEYCODE_MENU + return Qt::Key_Menu; + + case 0x00000045: + return Qt::Key_Minus; + + case 0x0000005b: // KEYCODE_MUTE + return Qt::Key_MicMute; + + case 0x0000004e: + return Qt::Key_NumLock; + + case 0x00000038: + return Qt::Key_Period; + + case 0x00000051: + return Qt::Key_Plus; + + case 0x0000001a: + return Qt::Key_PowerOff; + + case 0x00000048: + return Qt::Key_BracketRight; + + case 0x00000054: + return Qt::Key_Search; + + case 0x0000004a: + return Qt::Key_Semicolon; + + case 0x0000003b: + case 0x0000003c: + return Qt::Key_Shift; + + case 0x0000004c: + return Qt::Key_Slash; + + case 0x00000001: + return Qt::Key_Left; + + case 0x00000002: + return Qt::Key_Right; + + case 0x0000003e: + return Qt::Key_Space; + + case 0x0000003f: // KEYCODE_SYM + return Qt::Key_Meta; + + case 0x0000003d: + return Qt::Key_Tab; + + case 0x00000019: + return Qt::Key_VolumeDown; + + case 0x000000a4: // KEYCODE_VOLUME_MUTE + return Qt::Key_VolumeMute; + + case 0x00000018: + return Qt::Key_VolumeUp; + + case 0x00000011: // KEYCODE_STAR + return Qt::Key_Asterisk; + + case 0x00000012: // KEYCODE_POUND + return Qt::Key_NumberSign; + + case 0x00000050: // KEYCODE_FOCUS + return Qt::Key_CameraFocus; + + case 0x00000070: // KEYCODE_FORWARD_DEL + return Qt::Key_Delete; + + case 0x00000080: // KEYCODE_MEDIA_CLOSE + return Qt::Key_Close; + + case 0x00000081: // KEYCODE_MEDIA_EJECT + return Qt::Key_Eject; + + case 0x00000082: // KEYCODE_MEDIA_RECORD + return Qt::Key_MediaRecord; + + case 0x000000b7: // KEYCODE_PROG_RED + return Qt::Key_Red; + + case 0x000000b8: // KEYCODE_PROG_GREEN + return Qt::Key_Green; + + case 0x000000b9: // KEYCODE_PROG_YELLOW + return Qt::Key_Yellow; + + case 0x000000ba: // KEYCODE_PROG_BLUE + return Qt::Key_Blue; + + case 0x000000a5: // KEYCODE_INFO + return Qt::Key_Info; + + case 0x000000a6: // KEYCODE_CHANNEL_UP + return Qt::Key_ChannelUp; + + case 0x000000a7: // KEYCODE_CHANNEL_DOWN + return Qt::Key_ChannelDown; + + case 0x000000a8: // KEYCODE_ZOOM_IN + return Qt::Key_ZoomIn; + + case 0x000000a9: // KEYCODE_ZOOM_OUT + return Qt::Key_ZoomOut; + + case 0x000000ac: // KEYCODE_GUIDE + return Qt::Key_Guide; + + case 0x000000af: // KEYCODE_CAPTIONS + return Qt::Key_Subtitle; + + case 0x000000b0: // KEYCODE_SETTINGS + return Qt::Key_Settings; + + case 0x000000d0: // KEYCODE_CALENDAR + return Qt::Key_Calendar; + + case 0x000000d1: // KEYCODE_MUSIC + return Qt::Key_Music; + + case 0x000000d2: // KEYCODE_CALCULATOR + return Qt::Key_Calculator; + + case 0x00000000: // KEYCODE_UNKNOWN + return Qt::Key_unknown; + + case 0x00000053: // KEYCODE_NOTIFICATION ?!?!? + case 0x0000004f: // KEYCODE_HEADSETHOOK ?!?!? + case 0x00000044: // KEYCODE_GRAVE ?!?!? + return Qt::Key_Any; + + default: + return 0; + } + } + + static void keyDown(JNIEnv */*env*/, jobject /*thiz*/, jint key, jint unicode, jint modifier) + { + Qt::KeyboardModifiers modifiers; + if (modifier & 1) + modifiers |= Qt::ShiftModifier; + + if (modifier & 2) + modifiers |= Qt::AltModifier; + + if (modifier & 4) + modifiers |= Qt::MetaModifier; + + QWindowSystemInterface::handleKeyEvent(0, + QEvent::KeyPress, + mapAndroidKey(key), + modifiers, + QChar(unicode), + false); + } + + static void keyUp(JNIEnv */*env*/, jobject /*thiz*/, jint key, jint unicode, jint modifier) + { + Qt::KeyboardModifiers modifiers; + if (modifier & 1) + modifiers |= Qt::ShiftModifier; + + if (modifier & 2) + modifiers |= Qt::AltModifier; + + if (modifier & 4) + modifiers |= Qt::MetaModifier; + + QWindowSystemInterface::handleKeyEvent(0, + QEvent::KeyRelease, + mapAndroidKey(key), + modifiers, + QChar(unicode), + false); + } + + static void keyboardVisibilityChanged(JNIEnv */*env*/, jobject /*thiz*/, jboolean /*visibility*/) + { + QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext(); + if (inputContext) + inputContext->emitInputPanelVisibleChanged(); +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ KEYBOARDVISIBILITYCHANGED" << inputContext; +#endif + } + + static JNINativeMethod methods[] = { + {"touchBegin","(I)V",(void*)touchBegin}, + {"touchAdd","(IIIZIIFF)V",(void*)touchAdd}, + {"touchEnd","(II)V",(void*)touchEnd}, + {"mouseDown", "(III)V", (void *)mouseDown}, + {"mouseUp", "(III)V", (void *)mouseUp}, + {"mouseMove", "(III)V", (void *)mouseMove}, + {"longPress", "(III)V", (void *)longPress}, + {"keyDown", "(III)V", (void *)keyDown}, + {"keyUp", "(III)V", (void *)keyUp}, + {"keyboardVisibilityChanged", "(Z)V", (void *)keyboardVisibilityChanged} + }; + +#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ + VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ + if (!VAR) { \ + __android_log_print(ANDROID_LOG_FATAL, qtTagText(), methodErrorMsgFmt(), METHOD_NAME, METHOD_SIGNATURE); \ + return false; \ + } + + bool registerNatives(JNIEnv *env) + { + jclass appClass = QtAndroid::applicationClass(); + + if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { + __android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed"); + return false; + } + + GET_AND_CHECK_STATIC_METHOD(m_showSoftwareKeyboardMethodID, appClass, "showSoftwareKeyboard", "(IIIII)V"); + GET_AND_CHECK_STATIC_METHOD(m_resetSoftwareKeyboardMethodID, appClass, "resetSoftwareKeyboard", "()V"); + GET_AND_CHECK_STATIC_METHOD(m_hideSoftwareKeyboardMethodID, appClass, "hideSoftwareKeyboard", "()V"); + GET_AND_CHECK_STATIC_METHOD(m_isSoftwareKeyboardVisibleMethodID, appClass, "isSoftwareKeyboardVisible", "()Z"); + GET_AND_CHECK_STATIC_METHOD(m_updateSelectionMethodID, appClass, "updateSelection", "(IIII)V"); + return true; + } +} diff --git a/src/plugins/platforms/android/androidjniinput.h b/src/plugins/platforms/android/androidjniinput.h new file mode 100644 index 0000000000..a78c7519db --- /dev/null +++ b/src/plugins/platforms/android/androidjniinput.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDJNIINPUT_H +#define ANDROIDJNIINPUT_H +#include + +namespace QtAndroidInput +{ + // Software keyboard support + void showSoftwareKeyboard(int top, int left, int width, int height, int inputHints); + void resetSoftwareKeyboard(); + void hideSoftwareKeyboard(); + bool isSoftwareKeyboardVisible(); + void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd); + // Software keyboard support + + bool registerNatives(JNIEnv *env); +} + +#endif // ANDROIDJNIINPUT_H diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp new file mode 100644 index 0000000000..ee62c002d8 --- /dev/null +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -0,0 +1,724 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "androidjnimain.h" +#include "androidjniaccessibility.h" +#include "androidjniinput.h" +#include "androidjniclipboard.h" +#include "androidjnimenu.h" +#include "qandroidplatformdialoghelpers.h" +#include "qandroidplatformintegration.h" +#include + +#include + +#include +#include +#include "qandroidassetsfileenginehandler.h" +#include + +#include + +Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin) + +static JavaVM *m_javaVM = NULL; +static jclass m_applicationClass = NULL; +static jobject m_classLoaderObject = NULL; +static jmethodID m_loadClassMethodID = NULL; +static AAssetManager *m_assetManager = NULL; +static jobject m_resourcesObj; +static jobject m_activityObject = NULL; +static jmethodID m_createSurfaceMethodID = 0; +static jmethodID m_setSurfaceGeometryMethodID = 0; +static jmethodID m_destroySurfaceMethodID = 0; + +static bool m_activityActive = true; // defaults to true because when the platform plugin is + // initialized, QtActivity::onResume() has already been called + +static jclass m_bitmapClass = 0; +static jmethodID m_createBitmapMethodID = 0; +static jobject m_ARGB_8888_BitmapConfigValue = 0; +static jobject m_RGB_565_BitmapConfigValue = 0; + +jmethodID m_setFullScreenMethodID = 0; +static bool m_statusBarShowing = true; + +static jclass m_bitmapDrawableClass = 0; +static jmethodID m_bitmapDrawableConstructorMethodID = 0; + +extern "C" typedef int (*Main)(int, char **); //use the standard main method to start the application +static Main m_main = NULL; +static void *m_mainLibraryHnd = NULL; +static QList m_applicationParams; + +struct SurfaceData +{ + ~SurfaceData() { delete surface; } + QJNIObjectPrivate *surface = 0; + AndroidSurfaceClient *client = 0; +}; + +QHash m_surfaces; + +static QMutex m_surfacesMutex; +static int m_surfaceId = 1; + +static QSemaphore m_quitAppSemaphore; +static QSemaphore m_pauseApplicationSemaphore; +static QMutex m_pauseApplicationMutex; + +static QAndroidPlatformIntegration *m_androidPlatformIntegration = 0; + +static int m_desktopWidthPixels = 0; +static int m_desktopHeightPixels = 0; +static double m_scaledDensity = 0; + +static volatile bool m_pauseApplication; + +static AndroidAssetsFileEngineHandler *m_androidAssetsFileEngineHandler = 0; + + + +static const char m_qtTag[] = "Qt"; +static const char m_classErrorMsg[] = "Can't find class \"%s\""; +static const char m_methodErrorMsg[] = "Can't find method \"%s%s\""; + +namespace QtAndroid +{ + void setAndroidPlatformIntegration(QAndroidPlatformIntegration *androidPlatformIntegration) + { + m_surfacesMutex.lock(); + m_androidPlatformIntegration = androidPlatformIntegration; + m_surfacesMutex.unlock(); + } + + QAndroidPlatformIntegration *androidPlatformIntegration() + { + QMutexLocker locker(&m_surfacesMutex); + return m_androidPlatformIntegration; + } + + QWindow *topLevelWindowAt(const QPoint &globalPos) + { + return m_androidPlatformIntegration + ? m_androidPlatformIntegration->screen()->topLevelAt(globalPos) + : 0; + } + + int desktopWidthPixels() + { + return m_desktopWidthPixels; + } + + int desktopHeightPixels() + { + return m_desktopHeightPixels; + } + + double scaledDensity() + { + return m_scaledDensity; + } + + JavaVM *javaVM() + { + return m_javaVM; + } + + jclass findClass(const QString &className, JNIEnv *env) + { + return static_cast(env->CallObjectMethod(m_classLoaderObject, + m_loadClassMethodID, + env->NewString(reinterpret_cast(className.constData()), + jsize(className.length())))); + } + + AAssetManager *assetManager() + { + return m_assetManager; + } + + jclass applicationClass() + { + return m_applicationClass; + } + + jobject activity() + { + return m_activityObject; + } + + void showStatusBar() + { + if (m_statusBarShowing) + return; + + QtAndroid::AttachedJNIEnv env; + if (env.jniEnv == 0) { + qWarning("Failed to get JNI Environment."); + return; + } + + env.jniEnv->CallStaticVoidMethod(m_applicationClass, m_setFullScreenMethodID, false); + m_statusBarShowing = true; + } + + void hideStatusBar() + { + if (!m_statusBarShowing) + return; + + QtAndroid::AttachedJNIEnv env; + if (env.jniEnv == 0) { + qWarning("Failed to get JNI Environment."); + return; + } + + env.jniEnv->CallStaticVoidMethod(m_applicationClass, m_setFullScreenMethodID, true); + m_statusBarShowing = false; + } + + void setApplicationActive() + { + if (m_activityActive) + QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive); + } + + jobject createBitmap(QImage img, JNIEnv *env) + { + if (img.format() != QImage::Format_RGBA8888 && img.format() != QImage::Format_RGB16) + img = img.convertToFormat(QImage::Format_RGBA8888); + + jobject bitmap = env->CallStaticObjectMethod(m_bitmapClass, + m_createBitmapMethodID, + img.width(), + img.height(), + img.format() == QImage::Format_RGBA8888 + ? m_ARGB_8888_BitmapConfigValue + : m_RGB_565_BitmapConfigValue); + if (!bitmap) + return 0; + + AndroidBitmapInfo info; + if (AndroidBitmap_getInfo(env, bitmap, &info) < 0) { + env->DeleteLocalRef(bitmap); + return 0; + } + + void *pixels; + if (AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0) { + env->DeleteLocalRef(bitmap); + return 0; + } + + if (info.stride == uint(img.bytesPerLine()) + && info.width == uint(img.width()) + && info.height == uint(img.height())) { + memcpy(pixels, img.constBits(), info.stride * info.height); + } else { + uchar *bmpPtr = static_cast(pixels); + const unsigned width = qMin(info.width, (uint)img.width()); //should be the same + const unsigned height = qMin(info.height, (uint)img.height()); //should be the same + for (unsigned y = 0; y < height; y++, bmpPtr += info.stride) + memcpy(bmpPtr, img.constScanLine(y), width); + } + AndroidBitmap_unlockPixels(env, bitmap); + return bitmap; + } + + jobject createBitmap(int width, int height, QImage::Format format, JNIEnv *env) + { + if (format != QImage::Format_RGBA8888 + && format != QImage::Format_RGB16) + return 0; + + return env->CallStaticObjectMethod(m_bitmapClass, + m_createBitmapMethodID, + width, + height, + format == QImage::Format_RGB16 + ? m_RGB_565_BitmapConfigValue + : m_ARGB_8888_BitmapConfigValue); + } + + jobject createBitmapDrawable(jobject bitmap, JNIEnv *env) + { + if (!bitmap) + return 0; + + return env->NewObject(m_bitmapDrawableClass, + m_bitmapDrawableConstructorMethodID, + m_resourcesObj, + bitmap); + } + + const char *classErrorMsgFmt() + { + return m_classErrorMsg; + } + + const char *methodErrorMsgFmt() + { + return m_methodErrorMsg; + } + + const char *qtTagText() + { + return m_qtTag; + } + + int createSurface(AndroidSurfaceClient *client, const QRect &geometry, bool onTop) + { + QJNIEnvironmentPrivate env; + if (!env) + return 0; + + m_surfacesMutex.lock(); + int surfaceId = m_surfaceId++; + m_surfaces[surfaceId] = client; + m_surfacesMutex.unlock(); + + jint x = 0, y = 0, w = -1, h = -1; + if (!geometry.isNull()) { + x = geometry.x(); + y = geometry.y(); + w = std::max(geometry.width(), 1); + h = std::max(geometry.height(), 1); + } + env->CallStaticVoidMethod(m_applicationClass, + m_createSurfaceMethodID, + surfaceId, + jboolean(onTop), + x, y, w, h); + return surfaceId; + } + + void setSurfaceGeometry(int surfaceId, const QRect &geometry) + { + QJNIEnvironmentPrivate env; + if (!env) + return; + jint x = 0, y = 0, w = -1, h = -1; + if (!geometry.isNull()) { + x = geometry.x(); + y = geometry.y(); + w = geometry.width(); + h = geometry.height(); + } + env->CallStaticVoidMethod(m_applicationClass, + m_setSurfaceGeometryMethodID, + surfaceId, + x, y, w, h); + } + + void destroySurface(int surfaceId) + { + QMutexLocker lock(&m_surfacesMutex); + const auto &it = m_surfaces.find(surfaceId); + if (it == m_surfaces.end()) + return; + + m_surfaces.remove(surfaceId); + QJNIEnvironmentPrivate env; + if (!env) + return; + + env->CallStaticVoidMethod(m_applicationClass, + m_destroySurfaceMethodID, + surfaceId); + } +} + +static jboolean startQtAndroidPlugin(JNIEnv* /*env*/, jobject /*object*//*, jobject applicationAssetManager*/) +{ + m_androidPlatformIntegration = 0; + m_androidAssetsFileEngineHandler = new AndroidAssetsFileEngineHandler(); + return true; +} + +static void *startMainMethod(void */*data*/) +{ + QVarLengthArray params(m_applicationParams.size()); + for (int i = 0; i < m_applicationParams.size(); i++) + params[i] = static_cast(m_applicationParams[i].constData()); + + int ret = m_main(m_applicationParams.length(), const_cast(params.data())); + Q_UNUSED(ret); + + if (m_mainLibraryHnd) { + int res = dlclose(m_mainLibraryHnd); + if (res < 0) + qWarning() << "dlclose failed:" << dlerror(); + } + + QtAndroid::AttachedJNIEnv env; + if (!env.jniEnv) + return 0; + + if (m_applicationClass) { + jmethodID quitApp = env.jniEnv->GetStaticMethodID(m_applicationClass, "quitApp", "()V"); + env.jniEnv->CallStaticVoidMethod(m_applicationClass, quitApp); + } + + return 0; +} + +static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring paramsString, jstring environmentString) +{ + m_mainLibraryHnd = NULL; + const char *nativeString = env->GetStringUTFChars(environmentString, 0); + QByteArray string = nativeString; + env->ReleaseStringUTFChars(environmentString, nativeString); + m_applicationParams=string.split('\t'); + foreach (string, m_applicationParams) { + if (!string.isEmpty() && putenv(string.constData())) + qWarning() << "Can't set environment" << string; + } + + nativeString = env->GetStringUTFChars(paramsString, 0); + string = nativeString; + env->ReleaseStringUTFChars(paramsString, nativeString); + + m_applicationParams=string.split('\t'); + + // Go home + QDir::setCurrent(QDir::homePath()); + + //look for main() + if (m_applicationParams.length()) { + // Obtain a handle to the main library (the library that contains the main() function). + // This library should already be loaded, and calling dlopen() will just return a reference to it. + m_mainLibraryHnd = dlopen(m_applicationParams.first().data(), 0); + if (m_mainLibraryHnd == NULL) { + qCritical() << "dlopen failed:" << dlerror(); + return false; + } + m_main = (Main)dlsym(m_mainLibraryHnd, "main"); + } else { + qWarning() << "No main library was specified; searching entire process (this is slow!)"; + m_main = (Main)dlsym(RTLD_DEFAULT, "main"); + } + + if (!m_main) { + qCritical() << "dlsym failed:" << dlerror(); + qCritical() << "Could not find main method"; + return false; + } + + pthread_t appThread; + return pthread_create(&appThread, NULL, startMainMethod, NULL) == 0; +} + + +static void quitQtAndroidPlugin(JNIEnv *env, jclass /*clazz*/) +{ + Q_UNUSED(env); + m_androidPlatformIntegration = 0; + delete m_androidAssetsFileEngineHandler; +} + +static void terminateQt(JNIEnv *env, jclass /*clazz*/) +{ + env->DeleteGlobalRef(m_applicationClass); + env->DeleteGlobalRef(m_classLoaderObject); + env->DeleteGlobalRef(m_resourcesObj); + env->DeleteGlobalRef(m_activityObject); + env->DeleteGlobalRef(m_bitmapClass); + env->DeleteGlobalRef(m_ARGB_8888_BitmapConfigValue); + env->DeleteGlobalRef(m_RGB_565_BitmapConfigValue); + env->DeleteGlobalRef(m_bitmapDrawableClass); + m_androidPlatformIntegration = 0; + delete m_androidAssetsFileEngineHandler; +} + +static void setSurface(JNIEnv *env, jobject /*thiz*/, jint id, jobject jSurface, jint w, jint h) +{ + QMutexLocker lock(&m_surfacesMutex); + const auto &it = m_surfaces.find(id); + if (it == m_surfaces.end()) { + qWarning()<<"Can't find surface" << id; + return; + } + it.value()->surfaceChanged(env, jSurface, w, h); +} + +static void setDisplayMetrics(JNIEnv */*env*/, jclass /*clazz*/, + jint /*widthPixels*/, jint /*heightPixels*/, + jint desktopWidthPixels, jint desktopHeightPixels, + jdouble xdpi, jdouble ydpi, jdouble scaledDensity) +{ + m_desktopWidthPixels = desktopWidthPixels; + m_desktopHeightPixels = desktopHeightPixels; + m_scaledDensity = scaledDensity; + + if (!m_androidPlatformIntegration) { + QAndroidPlatformIntegration::setDefaultDisplayMetrics(desktopWidthPixels,desktopHeightPixels, + qRound(double(desktopWidthPixels) / xdpi * 25.4), + qRound(double(desktopHeightPixels) / ydpi * 25.4)); + } else { + m_androidPlatformIntegration->setDisplayMetrics(qRound(double(desktopWidthPixels) / xdpi * 25.4), + qRound(double(desktopHeightPixels) / ydpi * 25.4)); + m_androidPlatformIntegration->setDesktopSize(desktopWidthPixels, desktopHeightPixels); + } +} + +static void updateWindow(JNIEnv */*env*/, jobject /*thiz*/) +{ + if (!m_androidPlatformIntegration) + return; + + if (QGuiApplication::instance() != 0) { + foreach (QWindow *w, QGuiApplication::topLevelWindows()) + QWindowSystemInterface::handleExposeEvent(w, QRegion(w->geometry())); + } + + QAndroidPlatformScreen *screen = static_cast(m_androidPlatformIntegration->screen()); + QMetaObject::invokeMethod(screen, "setDirty", Qt::QueuedConnection, Q_ARG(QRect,screen->geometry())); +} + +static void updateApplicationState(JNIEnv */*env*/, jobject /*thiz*/, jint state) +{ + m_activityActive = (state == Qt::ApplicationActive); + + if (!m_androidPlatformIntegration || !QGuiApplicationPrivate::platformIntegration()) + return; + + QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState(state)); +} + +static void handleOrientationChanged(JNIEnv */*env*/, jobject /*thiz*/, jint newRotation, jint nativeOrientation) +{ + // Array of orientations rotated in 90 degree increments, counterclockwise + // (same direction as Android measures angles) + static const Qt::ScreenOrientation orientations[] = { + Qt::PortraitOrientation, + Qt::LandscapeOrientation, + Qt::InvertedPortraitOrientation, + Qt::InvertedLandscapeOrientation + }; + + // The Android API defines the following constants: + // ROTATION_0 : 0 + // ROTATION_90 : 1 + // ROTATION_180 : 2 + // ROTATION_270 : 3 + // ORIENTATION_PORTRAIT : 1 + // ORIENTATION_LANDSCAPE : 2 + + // and newRotation is how much the current orientation is rotated relative to nativeOrientation + + // which means that we can be really clever here :) + Qt::ScreenOrientation screenOrientation = orientations[(nativeOrientation - 1 + newRotation) % 4]; + Qt::ScreenOrientation native = orientations[nativeOrientation - 1]; + + QAndroidPlatformIntegration::setScreenOrientation(screenOrientation, native); + if (m_androidPlatformIntegration) { + QPlatformScreen *screen = m_androidPlatformIntegration->screen(); + QWindowSystemInterface::handleScreenOrientationChange(screen->screen(), + screenOrientation); + } +} + +static JNINativeMethod methods[] = { + {"startQtAndroidPlugin", "()Z", (void *)startQtAndroidPlugin}, + {"startQtApplication", "(Ljava/lang/String;Ljava/lang/String;)V", (void *)startQtApplication}, + {"quitQtAndroidPlugin", "()V", (void *)quitQtAndroidPlugin}, + {"terminateQt", "()V", (void *)terminateQt}, + {"setDisplayMetrics", "(IIIIDDD)V", (void *)setDisplayMetrics}, + {"setSurface", "(ILjava/lang/Object;II)V", (void *)setSurface}, + {"updateWindow", "()V", (void *)updateWindow}, + {"updateApplicationState", "(I)V", (void *)updateApplicationState}, + {"handleOrientationChanged", "(II)V", (void *)handleOrientationChanged} +}; + +#define FIND_AND_CHECK_CLASS(CLASS_NAME) \ +clazz = env->FindClass(CLASS_NAME); \ +if (!clazz) { \ + __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_classErrorMsg, CLASS_NAME); \ + return JNI_FALSE; \ +} + +#define GET_AND_CHECK_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ +VAR = env->GetMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ +if (!VAR) { \ + __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \ + return JNI_FALSE; \ +} + +#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ +VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ +if (!VAR) { \ + __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \ + return JNI_FALSE; \ +} + +#define GET_AND_CHECK_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \ +VAR = env->GetFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \ +if (!VAR) { \ + __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, FIELD_NAME, FIELD_SIGNATURE); \ + return JNI_FALSE; \ +} + +#define GET_AND_CHECK_STATIC_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \ +VAR = env->GetStaticFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \ +if (!VAR) { \ + __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, FIELD_NAME, FIELD_SIGNATURE); \ + return JNI_FALSE; \ +} + +static int registerNatives(JNIEnv *env) +{ + jclass clazz; + FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/QtNative"); + m_applicationClass = static_cast(env->NewGlobalRef(clazz)); + GET_AND_CHECK_STATIC_METHOD(m_setFullScreenMethodID, m_applicationClass, "setFullScreen", "(Z)V"); + + if (env->RegisterNatives(m_applicationClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { + __android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed"); + return JNI_FALSE; + } + + GET_AND_CHECK_STATIC_METHOD(m_createSurfaceMethodID, m_applicationClass, "createSurface", "(IZIIII)V"); + GET_AND_CHECK_STATIC_METHOD(m_setSurfaceGeometryMethodID, m_applicationClass, "setSurfaceGeometry", "(IIIII)V"); + GET_AND_CHECK_STATIC_METHOD(m_destroySurfaceMethodID, m_applicationClass, "destroySurface", "(I)V"); + + jmethodID methodID; + GET_AND_CHECK_STATIC_METHOD(methodID, m_applicationClass, "activity", "()Landroid/app/Activity;"); + jobject activityObject = env->CallStaticObjectMethod(m_applicationClass, methodID); + m_activityObject = env->NewGlobalRef(activityObject); + GET_AND_CHECK_STATIC_METHOD(methodID, m_applicationClass, "classLoader", "()Ljava/lang/ClassLoader;"); + m_classLoaderObject = env->NewGlobalRef(env->CallStaticObjectMethod(m_applicationClass, methodID)); + + clazz = env->GetObjectClass(m_classLoaderObject); + GET_AND_CHECK_METHOD(m_loadClassMethodID, clazz, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); + + FIND_AND_CHECK_CLASS("android/content/ContextWrapper"); + GET_AND_CHECK_METHOD(methodID, clazz, "getAssets", "()Landroid/content/res/AssetManager;"); + m_assetManager = AAssetManager_fromJava(env, env->CallObjectMethod(activityObject, methodID)); + + GET_AND_CHECK_METHOD(methodID, clazz, "getResources", "()Landroid/content/res/Resources;"); + m_resourcesObj = env->NewGlobalRef(env->CallObjectMethod(activityObject, methodID)); + + FIND_AND_CHECK_CLASS("android/graphics/Bitmap"); + m_bitmapClass = static_cast(env->NewGlobalRef(clazz)); + GET_AND_CHECK_STATIC_METHOD(m_createBitmapMethodID, m_bitmapClass + , "createBitmap", "(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;"); + + FIND_AND_CHECK_CLASS("android/graphics/Bitmap$Config"); + jfieldID fieldId; + GET_AND_CHECK_STATIC_FIELD(fieldId, clazz, "ARGB_8888", "Landroid/graphics/Bitmap$Config;"); + m_ARGB_8888_BitmapConfigValue = env->NewGlobalRef(env->GetStaticObjectField(clazz, fieldId)); + GET_AND_CHECK_STATIC_FIELD(fieldId, clazz, "RGB_565", "Landroid/graphics/Bitmap$Config;"); + m_RGB_565_BitmapConfigValue = env->NewGlobalRef(env->GetStaticObjectField(clazz, fieldId)); + + FIND_AND_CHECK_CLASS("android/graphics/drawable/BitmapDrawable"); + m_bitmapDrawableClass = static_cast(env->NewGlobalRef(clazz)); + GET_AND_CHECK_METHOD(m_bitmapDrawableConstructorMethodID, + m_bitmapDrawableClass, + "", + "(Landroid/content/res/Resources;Landroid/graphics/Bitmap;)V"); + + return JNI_TRUE; +} + +jint androidApiLevel(JNIEnv *env) +{ + jclass clazz; + FIND_AND_CHECK_CLASS("android/os/Build$VERSION"); + jfieldID fieldId; + GET_AND_CHECK_STATIC_FIELD(fieldId, clazz, "SDK_INT", "I"); + return env->GetStaticIntField(clazz, fieldId); +} + +Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/) +{ + typedef union { + JNIEnv *nativeEnvironment; + void *venv; + } UnionJNIEnvToVoid; + + __android_log_print(ANDROID_LOG_INFO, "Qt", "qt start"); + UnionJNIEnvToVoid uenv; + uenv.venv = NULL; + m_javaVM = 0; + + if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) { + __android_log_print(ANDROID_LOG_FATAL, "Qt", "GetEnv failed"); + return -1; + } + + JNIEnv *env = uenv.nativeEnvironment; + if (!registerNatives(env) + || !QtAndroidInput::registerNatives(env) + || !QtAndroidClipboard::registerNatives(env) + || !QtAndroidMenu::registerNatives(env) + || !QtAndroidAccessibility::registerNatives(env) + || !QtAndroidDialogHelpers::registerNatives(env)) { + __android_log_print(ANDROID_LOG_FATAL, "Qt", "registerNatives failed"); + return -1; + } + + jint apiLevel = androidApiLevel(env); + if (apiLevel >= 16 && !QtAndroidAccessibility::registerNatives(env)) { + __android_log_print(ANDROID_LOG_FATAL, "Qt A11y", "registerNatives failed"); + return -1; + } + + m_javaVM = vm; + return JNI_VERSION_1_4; +} diff --git a/src/plugins/platforms/android/androidjnimain.h b/src/plugins/platforms/android/androidjnimain.h new file mode 100644 index 0000000000..24287df474 --- /dev/null +++ b/src/plugins/platforms/android/androidjnimain.h @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROID_APP_H +#define ANDROID_APP_H + +#include + +#include +#include + +#include + +class QRect; +class QPoint; +class QThread; +class QAndroidPlatformIntegration; +class QWidget; +class QString; +class QWindow; +class AndroidSurfaceClient; + +namespace QtAndroid +{ + QAndroidPlatformIntegration *androidPlatformIntegration(); + void setAndroidPlatformIntegration(QAndroidPlatformIntegration *androidPlatformIntegration); + void setQtThread(QThread *thread); + + + int createSurface(AndroidSurfaceClient * client, const QRect &geometry, bool onTop); + void setSurfaceGeometry(int surfaceId, const QRect &geometry); + void destroySurface(int surfaceId); + + QWindow *topLevelWindowAt(const QPoint &globalPos); + int desktopWidthPixels(); + int desktopHeightPixels(); + double scaledDensity(); + JavaVM *javaVM(); + jclass findClass(const QString &className, JNIEnv *env); + AAssetManager *assetManager(); + jclass applicationClass(); + jobject activity(); + + void setApplicationActive(); + + void showStatusBar(); + void hideStatusBar(); + + jobject createBitmap(QImage img, JNIEnv *env = 0); + jobject createBitmap(int width, int height, QImage::Format format, JNIEnv *env); + jobject createBitmapDrawable(jobject bitmap, JNIEnv *env = 0); + + struct AttachedJNIEnv + { + AttachedJNIEnv() + { + attached = false; + if (QtAndroid::javaVM()->GetEnv((void**)&jniEnv, JNI_VERSION_1_6) < 0) { + if (QtAndroid::javaVM()->AttachCurrentThread(&jniEnv, NULL) < 0) { + __android_log_print(ANDROID_LOG_ERROR, "Qt", "AttachCurrentThread failed"); + jniEnv = 0; + return; + } + attached = true; + } + } + + ~AttachedJNIEnv() + { + if (attached) + QtAndroid::javaVM()->DetachCurrentThread(); + } + bool attached; + JNIEnv *jniEnv; + }; + const char *classErrorMsgFmt(); + const char *methodErrorMsgFmt(); + const char *qtTagText(); + +} +#endif // ANDROID_APP_H diff --git a/src/plugins/platforms/android/androidjnimenu.cpp b/src/plugins/platforms/android/androidjnimenu.cpp new file mode 100644 index 0000000000..db9249e7fe --- /dev/null +++ b/src/plugins/platforms/android/androidjnimenu.cpp @@ -0,0 +1,429 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidjnimenu.h" +#include "androidjnimain.h" +#include "qandroidplatformmenubar.h" +#include "qandroidplatformmenu.h" +#include "qandroidplatformmenuitem.h" + +#include +#include +#include +#include + +using namespace QtAndroid; + +namespace QtAndroidMenu +{ + static QQueue pendingContextMenus; + static QAndroidPlatformMenu *visibleMenu = 0; + static QMutex visibleMenuMutex(QMutex::Recursive); + + static QSet menuBars; + static QAndroidPlatformMenuBar *visibleMenuBar = 0; + static QWindow *activeTopLevelWindow = 0; + static QMutex menuBarMutex(QMutex::Recursive); + + static jmethodID openContextMenuMethodID = 0; + static jmethodID closeContextMenuMethodID = 0; + static jmethodID resetOptionsMenuMethodID = 0; + + static jmethodID clearMenuMethodID = 0; + static jmethodID addMenuItemMethodID = 0; + static int menuNoneValue = 0; + static jmethodID setHeaderTitleContextMenuMethodID = 0; + + static jmethodID setCheckableMenuItemMethodID = 0; + static jmethodID setCheckedMenuItemMethodID = 0; + static jmethodID setEnabledMenuItemMethodID = 0; + static jmethodID setIconMenuItemMethodID = 0; + static jmethodID setVisibleMenuItemMethodID = 0; + + void resetMenuBar() + { + AttachedJNIEnv env; + if (env.jniEnv) + env.jniEnv->CallStaticVoidMethod(applicationClass(), resetOptionsMenuMethodID); + } + + void showContextMenu(QAndroidPlatformMenu *menu, JNIEnv *env) + { + QMutexLocker lock(&visibleMenuMutex); + if (visibleMenu) { + pendingContextMenus.enqueue(menu); + } else { + visibleMenu = menu; + menu->aboutToShow(); + if (env) { + env->CallStaticVoidMethod(applicationClass(), openContextMenuMethodID); + } else { + AttachedJNIEnv aenv; + if (aenv.jniEnv) + aenv.jniEnv->CallStaticVoidMethod(applicationClass(), openContextMenuMethodID); + } + } + } + + void hideContextMenu(QAndroidPlatformMenu *menu) + { + QMutexLocker lock(&visibleMenuMutex); + if (visibleMenu == menu) { + AttachedJNIEnv env; + if (env.jniEnv) + env.jniEnv->CallStaticVoidMethod(applicationClass(), openContextMenuMethodID); + } else { + pendingContextMenus.removeOne(menu); + } + } + + void syncMenu(QAndroidPlatformMenu */*menu*/) + { +// QMutexLocker lock(&visibleMenuMutex); +// if (visibleMenu == menu) +// { +// hideContextMenu(menu); +// showContextMenu(menu); +// } + } + + void androidPlatformMenuDestroyed(QAndroidPlatformMenu *menu) + { + QMutexLocker lock(&visibleMenuMutex); + if (visibleMenu == menu) + visibleMenu = 0; + } + + void setMenuBar(QAndroidPlatformMenuBar *menuBar, QWindow *window) + { + if (activeTopLevelWindow == window && visibleMenuBar != menuBar) { + visibleMenuBar = menuBar; + resetMenuBar(); + } + } + + void setActiveTopLevelWindow(QWindow *window) + { + Qt::WindowFlags flags = window ? window->flags() : Qt::WindowFlags(); + if (!window) + return; + + bool isNonRegularWindow = flags & (Qt::Desktop | Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window; + if (isNonRegularWindow) + return; + + QMutexLocker lock(&menuBarMutex); + if (activeTopLevelWindow == window) + return; + + visibleMenuBar = 0; + activeTopLevelWindow = window; + foreach (QAndroidPlatformMenuBar *menuBar, menuBars) { + if (menuBar->parentWindow() == window) { + visibleMenuBar = menuBar; + resetMenuBar(); + break; + } + } + + } + + void addMenuBar(QAndroidPlatformMenuBar *menuBar) + { + QMutexLocker lock(&menuBarMutex); + menuBars.insert(menuBar); + } + + void removeMenuBar(QAndroidPlatformMenuBar *menuBar) + { + QMutexLocker lock(&menuBarMutex); + menuBars.remove(menuBar); + if (visibleMenuBar == menuBar) { + visibleMenuBar = 0; + resetMenuBar(); + } + } + + static QString removeAmpersandEscapes(QString s) + { + int i = 0; + while (i < s.size()) { + ++i; + if (s.at(i-1) != QLatin1Char('&')) + continue; + if (i < s.size() && s.at(i) == QLatin1Char('&')) + ++i; + s.remove(i-1,1); + } + return s.trimmed(); + } + + static void fillMenuItem(JNIEnv *env, jobject menuItem, bool checkable, bool checked, bool enabled, bool visible, const QIcon &icon=QIcon()) + { + env->CallObjectMethod(menuItem, setCheckableMenuItemMethodID, checkable); + env->CallObjectMethod(menuItem, setCheckedMenuItemMethodID, checked); + env->CallObjectMethod(menuItem, setEnabledMenuItemMethodID, enabled); + + if (!icon.isNull()) { // isNull() only checks the d pointer, not the actual image data. + int sz = qMax(36, qgetenv("QT_ANDROID_APP_ICON_SIZE").toInt()); + QImage img = icon.pixmap(QSize(sz,sz), + enabled + ? QIcon::Normal + : QIcon::Disabled, + QIcon::On).toImage(); + if (!img.isNull()) { // Make sure we have a valid image. + env->CallObjectMethod(menuItem, + setIconMenuItemMethodID, + createBitmapDrawable(createBitmap(img, env), env)); + } + } + + env->CallObjectMethod(menuItem, setVisibleMenuItemMethodID, visible); + } + + static int addAllMenuItemsToMenu(JNIEnv *env, jobject menu, QAndroidPlatformMenu *platformMenu) { + int order = 0; + QMutexLocker lock(platformMenu->menuItemsMutex()); + foreach (QAndroidPlatformMenuItem *item, platformMenu->menuItems()) { + if (item->isSeparator()) + continue; + QString itemText = removeAmpersandEscapes(item->text()); + jstring jtext = env->NewString(reinterpret_cast(itemText.data()), + itemText.length()); + jobject menuItem = env->CallObjectMethod(menu, + addMenuItemMethodID, + menuNoneValue, + int(item->tag()), + order++, + jtext); + env->DeleteLocalRef(jtext); + fillMenuItem(env, + menuItem, + item->isCheckable(), + item->isChecked(), + item->isEnabled(), + item->isVisible(), + item->icon()); + } + + return order; + } + + static jboolean onPrepareOptionsMenu(JNIEnv *env, jobject /*thiz*/, jobject menu) + { + env->CallVoidMethod(menu, clearMenuMethodID); + QMutexLocker lock(&menuBarMutex); + if (!visibleMenuBar) + return JNI_FALSE; + + const QAndroidPlatformMenuBar::PlatformMenusType &menus = visibleMenuBar->menus(); + int order = 0; + QMutexLocker lockMenuBarMutex(visibleMenuBar->menusListMutex()); + if (menus.size() == 1) { // Expand the menu + order = addAllMenuItemsToMenu(env, menu, static_cast(menus.front())); + } else { + foreach (QAndroidPlatformMenu *item, menus) { + QString itemText = removeAmpersandEscapes(item->text()); + jstring jtext = env->NewString(reinterpret_cast(itemText.data()), + itemText.length()); + jobject menuItem = env->CallObjectMethod(menu, + addMenuItemMethodID, + menuNoneValue, + int(item->tag()), + order++, + jtext); + env->DeleteLocalRef(jtext); + + fillMenuItem(env, + menuItem, + false, + false, + item->isEnabled(), + item->isVisible(), + item->icon()); + } + } + return order ? JNI_TRUE : JNI_FALSE; + } + + static jboolean onOptionsItemSelected(JNIEnv *env, jobject /*thiz*/, jint menuId, jboolean checked) + { + QMutexLocker lock(&menuBarMutex); + if (!visibleMenuBar) + return JNI_FALSE; + + const QAndroidPlatformMenuBar::PlatformMenusType &menus = visibleMenuBar->menus(); + if (menus.size() == 1) { // Expanded menu + QAndroidPlatformMenuItem *item = static_cast(menus.front()->menuItemForTag(menuId)); + if (item) { + if (item->menu()) { + showContextMenu(item->menu(), env); + } else { + if (item->isCheckable()) + item->setChecked(checked); + item->activated(); + } + } + } else { + QAndroidPlatformMenu *menu = static_cast(visibleMenuBar->menuForTag(menuId)); + if (menu) + showContextMenu(menu, env); + } + + return JNI_TRUE; + } + + static void onOptionsMenuClosed(JNIEnv */*env*/, jobject /*thiz*/, jobject /*menu*/) + { + } + + static void onCreateContextMenu(JNIEnv *env, jobject /*thiz*/, jobject menu) + { + env->CallVoidMethod(menu, clearMenuMethodID); + QMutexLocker lock(&visibleMenuMutex); + if (!visibleMenu) + return; + + QString menuText = removeAmpersandEscapes(visibleMenu->text()); + jstring jtext = env->NewString(reinterpret_cast(menuText.data()), + menuText.length()); + env->CallObjectMethod(menu, setHeaderTitleContextMenuMethodID, jtext); + env->DeleteLocalRef(jtext); + addAllMenuItemsToMenu(env, menu, visibleMenu); + } + + static jboolean onContextItemSelected(JNIEnv *env, jobject /*thiz*/, jint menuId, jboolean checked) + { + QMutexLocker lock(&visibleMenuMutex); + QAndroidPlatformMenuItem * item = static_cast(visibleMenu->menuItemForTag(menuId)); + if (item) { + if (item->menu()) { + showContextMenu(item->menu(), env); + } else { + if (item->isCheckable()) + item->setChecked(checked); + item->activated(); + } + } + return JNI_TRUE; + } + + static void onContextMenuClosed(JNIEnv *env, jobject /*thiz*/, jobject /*menu*/) + { + QMutexLocker lock(&visibleMenuMutex); + if (!visibleMenu) + return; + visibleMenu->aboutToHide(); + visibleMenu = 0; + if (!pendingContextMenus.empty()) + showContextMenu(pendingContextMenus.dequeue(), env); + } + + static JNINativeMethod methods[] = { + {"onPrepareOptionsMenu", "(Landroid/view/Menu;)Z", (void *)onPrepareOptionsMenu}, + {"onOptionsItemSelected", "(IZ)Z", (void *)onOptionsItemSelected}, + {"onOptionsMenuClosed", "(Landroid/view/Menu;)V", (void*)onOptionsMenuClosed}, + {"onCreateContextMenu", "(Landroid/view/ContextMenu;)V", (void *)onCreateContextMenu}, + {"onContextItemSelected", "(IZ)Z", (void *)onContextItemSelected}, + {"onContextMenuClosed", "(Landroid/view/Menu;)V", (void*)onContextMenuClosed}, + }; + +#define FIND_AND_CHECK_CLASS(CLASS_NAME) \ + clazz = env->FindClass(CLASS_NAME); \ + if (!clazz) { \ + __android_log_print(ANDROID_LOG_FATAL, qtTagText(), classErrorMsgFmt(), CLASS_NAME); \ + return false; \ + } + +#define GET_AND_CHECK_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ + VAR = env->GetMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ + if (!VAR) { \ + __android_log_print(ANDROID_LOG_FATAL, qtTagText(), methodErrorMsgFmt(), METHOD_NAME, METHOD_SIGNATURE); \ + return false; \ + } + +#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ + VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ + if (!VAR) { \ + __android_log_print(ANDROID_LOG_FATAL, qtTagText(), methodErrorMsgFmt(), METHOD_NAME, METHOD_SIGNATURE); \ + return false; \ + } + +#define GET_AND_CHECK_STATIC_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \ + VAR = env->GetStaticFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \ + if (!VAR) { \ + __android_log_print(ANDROID_LOG_FATAL, qtTagText(), methodErrorMsgFmt(), FIELD_NAME, FIELD_SIGNATURE); \ + return false; \ + } + + bool registerNatives(JNIEnv *env) + { + jclass appClass = applicationClass(); + + if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { + __android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed"); + return false; + } + + GET_AND_CHECK_STATIC_METHOD(openContextMenuMethodID, appClass, "openContextMenu", "()V"); + GET_AND_CHECK_STATIC_METHOD(closeContextMenuMethodID, appClass, "closeContextMenu", "()V"); + GET_AND_CHECK_STATIC_METHOD(resetOptionsMenuMethodID, appClass, "resetOptionsMenu", "()V"); + + jclass clazz; + FIND_AND_CHECK_CLASS("android/view/Menu"); + GET_AND_CHECK_METHOD(clearMenuMethodID, clazz, "clear", "()V"); + GET_AND_CHECK_METHOD(addMenuItemMethodID, clazz, "add", "(IIILjava/lang/CharSequence;)Landroid/view/MenuItem;"); + jfieldID menuNoneFiledId; + GET_AND_CHECK_STATIC_FIELD(menuNoneFiledId, clazz, "NONE", "I"); + menuNoneValue = env->GetStaticIntField(clazz, menuNoneFiledId); + + FIND_AND_CHECK_CLASS("android/view/ContextMenu"); + GET_AND_CHECK_METHOD(setHeaderTitleContextMenuMethodID, clazz, "setHeaderTitle","(Ljava/lang/CharSequence;)Landroid/view/ContextMenu;"); + + FIND_AND_CHECK_CLASS("android/view/MenuItem"); + GET_AND_CHECK_METHOD(setCheckableMenuItemMethodID, clazz, "setCheckable", "(Z)Landroid/view/MenuItem;"); + GET_AND_CHECK_METHOD(setCheckedMenuItemMethodID, clazz, "setChecked", "(Z)Landroid/view/MenuItem;"); + GET_AND_CHECK_METHOD(setEnabledMenuItemMethodID, clazz, "setEnabled", "(Z)Landroid/view/MenuItem;"); + GET_AND_CHECK_METHOD(setIconMenuItemMethodID, clazz, "setIcon", "(Landroid/graphics/drawable/Drawable;)Landroid/view/MenuItem;"); + GET_AND_CHECK_METHOD(setVisibleMenuItemMethodID, clazz, "setVisible", "(Z)Landroid/view/MenuItem;"); + return true; + } +} diff --git a/src/plugins/platforms/android/androidjnimenu.h b/src/plugins/platforms/android/androidjnimenu.h new file mode 100644 index 0000000000..7c5422f67b --- /dev/null +++ b/src/plugins/platforms/android/androidjnimenu.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDJNIMENU_H +#define ANDROIDJNIMENU_H + +#include + +class QAndroidPlatformMenuBar; +class QAndroidPlatformMenu; +class QAndroidPlatformMenuItem; +class QWindow; + +namespace QtAndroidMenu +{ + // Menu support + void showContextMenu(QAndroidPlatformMenu *menu, JNIEnv *env = 0); + void hideContextMenu(QAndroidPlatformMenu *menu); + void syncMenu(QAndroidPlatformMenu *menu); + void androidPlatformMenuDestroyed(QAndroidPlatformMenu *menu); + + void setMenuBar(QAndroidPlatformMenuBar *menuBar, QWindow *window); + void setActiveTopLevelWindow(QWindow *window); + void addMenuBar(QAndroidPlatformMenuBar *menuBar); + void removeMenuBar(QAndroidPlatformMenuBar *menuBar); + + // Menu support + bool registerNatives(JNIEnv *env); +} + +#endif // ANDROIDJNIMENU_H diff --git a/src/plugins/platforms/android/androidplatformplugin.cpp b/src/plugins/platforms/android/androidplatformplugin.cpp new file mode 100644 index 0000000000..2cf5aa1e01 --- /dev/null +++ b/src/plugins/platforms/android/androidplatformplugin.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "qandroidplatformintegration.h" + +QT_BEGIN_NAMESPACE + +class QAndroidPlatformIntegrationPlugin: public QPlatformIntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2" FILE "android.json") +public: + QPlatformIntegration *create(const QString &key, const QStringList ¶mList); +}; + + +QPlatformIntegration *QAndroidPlatformIntegrationPlugin::create(const QString &key, const QStringList ¶mList) +{ + Q_UNUSED(paramList); + if (!key.compare(QLatin1String("android"), Qt::CaseInsensitive)) + return new QAndroidPlatformIntegration(paramList); + return 0; +} + +QT_END_NAMESPACE +#include "androidplatformplugin.moc" + diff --git a/src/plugins/platforms/android/androidsurfaceclient.h b/src/plugins/platforms/android/androidsurfaceclient.h new file mode 100644 index 0000000000..254e47123b --- /dev/null +++ b/src/plugins/platforms/android/androidsurfaceclient.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDSURFACECLIENT_H +#define ANDROIDSURFACECLIENT_H +#include +#include + +class AndroidSurfaceClient +{ +public: + virtual void surfaceChanged(JNIEnv *jniEnv, jobject surface, int w, int h) = 0; + void lockSurface() { m_surfaceMutex.lock(); } + void unlockSurface() { m_surfaceMutex.unlock(); } + +protected: + QMutex m_surfaceMutex; +}; + +#endif // ANDROIDSURFACECLIENT_H diff --git a/src/plugins/platforms/android/opengl/opengl.pro b/src/plugins/platforms/android/opengl/opengl.pro deleted file mode 100644 index ea050ca3a0..0000000000 --- a/src/plugins/platforms/android/opengl/opengl.pro +++ /dev/null @@ -1,32 +0,0 @@ -TARGET = qtforandroidGL - -PLUGIN_TYPE = platforms -load(qt_plugin) - -# STATICPLUGIN needed because there's a Q_IMPORT_PLUGIN in androidjnimain.cpp -# Yes, the plugin imports itself statically -DEFINES += QT_STATICPLUGIN ANDROID_PLUGIN_OPENGL - -!equals(ANDROID_PLATFORM, android-9) { - INCLUDEPATH += $$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/include - LIBS += -L$$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/lib -ljnigraphics -landroid -} else { - LIBS += -ljnigraphics -landroid -} - -EGLFS_PLATFORM_HOOKS_SOURCES = $$PWD/../src/opengl/qeglfshooks_android.cpp - -INCLUDEPATH += $$PWD/../src/opengl/ - -HEADERS += \ - $$PWD/../src/opengl/qandroidopenglcontext.h \ - $$PWD/../src/opengl/qandroidopenglplatformwindow.h \ - $$PWD/../src/opengl/qandroidopenglplatformscreen.h - -SOURCES += \ - $$PWD/../src/opengl/qandroidopenglcontext.cpp \ - $$PWD/../src/opengl/qandroidopenglplatformwindow.cpp \ - $$PWD/../src/opengl/qandroidopenglplatformscreen.cpp - -include($$PWD/../../eglfs/eglfs.pri) -include($$PWD/../src/src.pri) diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp new file mode 100644 index 0000000000..95844fc649 --- /dev/null +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp @@ -0,0 +1,309 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidassetsfileenginehandler.h" +#include "androidjnimain.h" + +#include +#include + +typedef QVector FilesList; + +struct AndroidAssetDir +{ + AndroidAssetDir(AAssetDir* ad) + { + const char *fileName; + while ((fileName = AAssetDir_getNextFileName(ad))) + m_items.push_back(QString::fromUtf8(fileName)); + AAssetDir_close(ad); + } + FilesList m_items; +}; + +class AndroidAbstractFileEngineIterator: public QAbstractFileEngineIterator +{ +public: + AndroidAbstractFileEngineIterator(QDir::Filters filters, + const QStringList &nameFilters, + QSharedPointer asset, + const QString &path) + : QAbstractFileEngineIterator(filters, nameFilters) + { + m_items = asset->m_items; + m_index = -1; + m_path = path; + } + + virtual QFileInfo currentFileInfo() const + { + return QFileInfo(currentFilePath()); + } + + virtual QString currentFileName() const + { + if (m_index < 0 || m_index >= m_items.size()) + return QString(); + return m_items[m_index]; + } + + virtual QString currentFilePath() const + { + return m_path + currentFileName(); + } + + virtual bool hasNext() const + { + return m_items.size() && (m_index < m_items.size() - 1); + } + + virtual QString next() + { + if (!hasNext()) + return QString(); + m_index++; + return currentFileName(); + } + +private: + QString m_path; + FilesList m_items; + int m_index; +}; + +class AndroidAbstractFileEngine: public QAbstractFileEngine +{ +public: + explicit AndroidAbstractFileEngine(AAsset *asset, const QString &fileName) + { + m_assetFile = asset; + m_fileName = fileName; + } + + explicit AndroidAbstractFileEngine(QSharedPointer asset, const QString &fileName) + { + m_assetFile = 0; + m_assetDir = asset; + m_fileName = fileName; + if (!m_fileName.endsWith(QChar(QLatin1Char('/')))) + m_fileName += "/"; + } + + ~AndroidAbstractFileEngine() + { + close(); + } + + virtual bool open(QIODevice::OpenMode openMode) + { + if (m_assetFile) + return openMode & QIODevice::ReadOnly; + return false; + } + + virtual bool close() + { + if (m_assetFile) { + AAsset_close(m_assetFile); + m_assetFile = 0; + return true; + } + return false; + } + + virtual qint64 size() const + { + if (m_assetFile) + return AAsset_getLength(m_assetFile); + return -1; + } + + virtual qint64 pos() const + { + if (m_assetFile) + return AAsset_seek(m_assetFile, 0, SEEK_CUR); + return -1; + } + + virtual bool seek(qint64 pos) + { + if (m_assetFile) + return pos == AAsset_seek(m_assetFile, pos, SEEK_SET); + return false; + } + + virtual qint64 read(char *data, qint64 maxlen) + { + if (m_assetFile) + return AAsset_read(m_assetFile, data, maxlen); + return -1; + } + + virtual bool isSequential() const + { + return false; + } + + virtual bool caseSensitive() const + { + return true; + } + + virtual bool isRelativePath() const + { + return false; + } + + virtual FileFlags fileFlags(FileFlags type = FileInfoAll) const + { + FileFlags flags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm|ExistsFlag); + if (m_assetFile) + flags |= FileType; + if (!m_assetDir.isNull()) + flags |= DirectoryType; + + return type & flags; + } + + virtual QString fileName(FileName file = DefaultName) const + { + int pos; + switch (file) { + case DefaultName: + case AbsoluteName: + case CanonicalName: + return m_fileName; + case BaseName: + if ((pos = m_fileName.lastIndexOf(QChar(QLatin1Char('/')))) != -1) + return m_fileName.mid(pos); + else + return m_fileName; + case PathName: + case AbsolutePathName: + case CanonicalPathName: + if ((pos = m_fileName.lastIndexOf(QChar(QLatin1Char('/')))) != -1) + return m_fileName.left(pos); + else + return m_fileName; + default: + return QString(); + } + } + + virtual void setFileName(const QString &file) + { + if (file == m_fileName) + return; + + m_fileName = file; + if (!m_fileName.endsWith(QChar(QLatin1Char('/')))) + m_fileName += "/"; + + close(); + } + + virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) + { + if (!m_assetDir.isNull()) + return new AndroidAbstractFileEngineIterator(filters, filterNames, m_assetDir, m_fileName); + return 0; + } + +private: + AAsset *m_assetFile; + QSharedPointer m_assetDir; + QString m_fileName; +}; + + +AndroidAssetsFileEngineHandler::AndroidAssetsFileEngineHandler():m_assetsCache(std::max(5, qgetenv("QT_ANDROID_MAX_ASSETS_CACHE_SIZE").toInt())) +{ + m_assetManager = QtAndroid::assetManager(); +} + +AndroidAssetsFileEngineHandler::~AndroidAssetsFileEngineHandler() +{ +} + +QAbstractFileEngine * AndroidAssetsFileEngineHandler::create(const QString &fileName) const +{ + if (fileName.isEmpty()) + return 0; + + if (!fileName.startsWith(QLatin1String("assets:/"))) + return 0; + + int prefixSize=8; + + QByteArray path; + if (!fileName.endsWith(QLatin1Char('/'))) { + path = fileName.toUtf8(); + AAsset *asset = AAssetManager_open(m_assetManager, + path.constData() + prefixSize, + AASSET_MODE_BUFFER); + if (asset) + return new AndroidAbstractFileEngine(asset, fileName); + } + + if (!path.size()) + path = fileName.left(fileName.length() - 1).toUtf8(); + + m_assetsCacheMutext.lock(); + QSharedPointer *aad = m_assetsCache.object(path); + m_assetsCacheMutext.unlock(); + if (!aad) { + AAssetDir *assetDir = AAssetManager_openDir(m_assetManager, path.constData() + prefixSize); + if (assetDir) { + if (AAssetDir_getNextFileName(assetDir)) { + aad = new QSharedPointer(new AndroidAssetDir(assetDir)); + m_assetsCacheMutext.lock(); + m_assetsCache.insert(path, aad); + m_assetsCacheMutext.unlock(); + return new AndroidAbstractFileEngine(*aad, fileName); + } else { + AAssetDir_close(assetDir); + } + } + } else { + return new AndroidAbstractFileEngine(*aad, fileName); + } + return 0; +} diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.h b/src/plugins/platforms/android/qandroidassetsfileenginehandler.h new file mode 100644 index 0000000000..7bd560886c --- /dev/null +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDASSETSFILEENGINEHANDLER_H +#define QANDROIDASSETSFILEENGINEHANDLER_H + +#include +#include +#include +#include + +#include + +struct AndroidAssetDir; +class AndroidAssetsFileEngineHandler: public QAbstractFileEngineHandler +{ +public: + AndroidAssetsFileEngineHandler(); + virtual ~AndroidAssetsFileEngineHandler(); + QAbstractFileEngine *create(const QString &fileName) const; + +private: + AAssetManager *m_assetManager; + mutable QCache> m_assetsCache; + mutable QMutex m_assetsCacheMutext; +}; + +#endif // QANDROIDASSETSFILEENGINEHANDLER_H diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp new file mode 100644 index 0000000000..326972e71e --- /dev/null +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -0,0 +1,762 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "qandroidinputcontext.h" +#include "androidjnimain.h" +#include "androidjniinput.h" +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +static QAndroidInputContext *m_androidInputContext = 0; +static char const *const QtNativeInputConnectionClassName = "org.qtproject.qt5.android.QtNativeInputConnection"; +static char const *const QtExtractedTextClassName = "org.qtproject.qt5.android.QtExtractedText"; +static jclass m_extractedTextClass = 0; +static jmethodID m_classConstructorMethodID = 0; +static jfieldID m_partialEndOffsetFieldID = 0; +static jfieldID m_partialStartOffsetFieldID = 0; +static jfieldID m_selectionEndFieldID = 0; +static jfieldID m_selectionStartFieldID = 0; +static jfieldID m_startOffsetFieldID = 0; +static jfieldID m_textFieldID = 0; + +static jboolean commitText(JNIEnv *env, jobject /*thiz*/, jstring text, jint newCursorPosition) +{ + if (!m_androidInputContext) + return JNI_FALSE; + + jboolean isCopy; + const jchar *jstr = env->GetStringChars(text, &isCopy); + QString str(reinterpret_cast(jstr), env->GetStringLength(text)); + env->ReleaseStringChars(text, jstr); + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ COMMIT" << str; +#endif + return m_androidInputContext->commitText(str, newCursorPosition); +} + +static jboolean deleteSurroundingText(JNIEnv */*env*/, jobject /*thiz*/, jint leftLength, jint rightLength) +{ + if (!m_androidInputContext) + return JNI_FALSE; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ DELETE" << leftLength << rightLength; +#endif + return m_androidInputContext->deleteSurroundingText(leftLength, rightLength); +} + +static jboolean finishComposingText(JNIEnv */*env*/, jobject /*thiz*/) +{ + if (!m_androidInputContext) + return JNI_FALSE; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ FINISH"; +#endif + return m_androidInputContext->finishComposingText(); +} + +static jint getCursorCapsMode(JNIEnv */*env*/, jobject /*thiz*/, jint reqModes) +{ + if (!m_androidInputContext) + return 0; + + return m_androidInputContext->getCursorCapsMode(reqModes); +} + +static jobject getExtractedText(JNIEnv *env, jobject /*thiz*/, int hintMaxChars, int hintMaxLines, jint flags) +{ + if (!m_androidInputContext) + return 0; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ GETEX"; +#endif + const QAndroidInputContext::ExtractedText &extractedText = + m_androidInputContext->getExtractedText(hintMaxChars, hintMaxLines, flags); + + jobject object = env->NewObject(m_extractedTextClass, m_classConstructorMethodID); + env->SetIntField(object, m_partialStartOffsetFieldID, extractedText.partialStartOffset); + env->SetIntField(object, m_partialEndOffsetFieldID, extractedText.partialEndOffset); + env->SetIntField(object, m_selectionStartFieldID, extractedText.selectionStart); + env->SetIntField(object, m_selectionEndFieldID, extractedText.selectionEnd); + env->SetIntField(object, m_startOffsetFieldID, extractedText.startOffset); + env->SetObjectField(object, + m_textFieldID, + env->NewString(reinterpret_cast(extractedText.text.constData()), + jsize(extractedText.text.length()))); + + return object; +} + +static jstring getSelectedText(JNIEnv *env, jobject /*thiz*/, jint flags) +{ + if (!m_androidInputContext) + return 0; + + const QString &text = m_androidInputContext->getSelectedText(flags); +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ GETSEL" << text; +#endif + return env->NewString(reinterpret_cast(text.constData()), jsize(text.length())); +} + +static jstring getTextAfterCursor(JNIEnv *env, jobject /*thiz*/, jint length, jint flags) +{ + if (!m_androidInputContext) + return 0; + + const QString &text = m_androidInputContext->getTextAfterCursor(length, flags); +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ GET" << length << text; +#endif + return env->NewString(reinterpret_cast(text.constData()), jsize(text.length())); +} + +static jstring getTextBeforeCursor(JNIEnv *env, jobject /*thiz*/, jint length, jint flags) +{ + if (!m_androidInputContext) + return 0; + + const QString &text = m_androidInputContext->getTextBeforeCursor(length, flags); +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ GET" << length << text; +#endif + return env->NewString(reinterpret_cast(text.constData()), jsize(text.length())); +} + +static jboolean setComposingText(JNIEnv *env, jobject /*thiz*/, jstring text, jint newCursorPosition) +{ + if (!m_androidInputContext) + return JNI_FALSE; + + jboolean isCopy; + const jchar *jstr = env->GetStringChars(text, &isCopy); + QString str(reinterpret_cast(jstr), env->GetStringLength(text)); + env->ReleaseStringChars(text, jstr); + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ SET" << str; +#endif + return m_androidInputContext->setComposingText(str, newCursorPosition); +} + +static jboolean setComposingRegion(JNIEnv */*env*/, jobject /*thiz*/, jint start, jint end) +{ + if (!m_androidInputContext) + return JNI_FALSE; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ SETR" << start << end; +#endif + return m_androidInputContext->setComposingRegion(start, end); +} + + +static jboolean setSelection(JNIEnv */*env*/, jobject /*thiz*/, jint start, jint end) +{ + if (!m_androidInputContext) + return JNI_FALSE; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ SETSEL" << start << end; +#endif + return m_androidInputContext->setSelection(start, end); +} + +static jboolean selectAll(JNIEnv */*env*/, jobject /*thiz*/) +{ + if (!m_androidInputContext) + return JNI_FALSE; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@ SELALL"; +#endif + return m_androidInputContext->selectAll(); +} + +static jboolean cut(JNIEnv */*env*/, jobject /*thiz*/) +{ + if (!m_androidInputContext) + return JNI_FALSE; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@"; +#endif + return m_androidInputContext->cut(); +} + +static jboolean copy(JNIEnv */*env*/, jobject /*thiz*/) +{ + if (!m_androidInputContext) + return JNI_FALSE; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@"; +#endif + return m_androidInputContext->copy(); +} + +static jboolean copyURL(JNIEnv */*env*/, jobject /*thiz*/) +{ + if (!m_androidInputContext) + return JNI_FALSE; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@"; +#endif + return m_androidInputContext->copyURL(); +} + +static jboolean paste(JNIEnv */*env*/, jobject /*thiz*/) +{ + if (!m_androidInputContext) + return JNI_FALSE; + +#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL + qDebug() << "@@@"; +#endif + return m_androidInputContext->paste(); +} + + +static JNINativeMethod methods[] = { + {"commitText", "(Ljava/lang/String;I)Z", (void *)commitText}, + {"deleteSurroundingText", "(II)Z", (void *)deleteSurroundingText}, + {"finishComposingText", "()Z", (void *)finishComposingText}, + {"getCursorCapsMode", "(I)I", (void *)getCursorCapsMode}, + {"getExtractedText", "(III)Lorg/qtproject/qt5/android/QtExtractedText;", (void *)getExtractedText}, + {"getSelectedText", "(I)Ljava/lang/String;", (void *)getSelectedText}, + {"getTextAfterCursor", "(II)Ljava/lang/String;", (void *)getTextAfterCursor}, + {"getTextBeforeCursor", "(II)Ljava/lang/String;", (void *)getTextBeforeCursor}, + {"setComposingText", "(Ljava/lang/String;I)Z", (void *)setComposingText}, + {"setComposingRegion", "(II)Z", (void *)setComposingRegion}, + {"setSelection", "(II)Z", (void *)setSelection}, + {"selectAll", "()Z", (void *)selectAll}, + {"cut", "()Z", (void *)cut}, + {"copy", "()Z", (void *)copy}, + {"copyURL", "()Z", (void *)copyURL}, + {"paste", "()Z", (void *)paste} +}; + + +QAndroidInputContext::QAndroidInputContext() + : QPlatformInputContext(), m_blockUpdateSelection(false) +{ + QtAndroid::AttachedJNIEnv env; + if (!env.jniEnv) + return; + + jclass clazz = QtAndroid::findClass(QtNativeInputConnectionClassName, env.jniEnv); + if (clazz == NULL) { + qCritical() << "Native registration unable to find class '" + << QtNativeInputConnectionClassName + << "'"; + return; + } + + if (env.jniEnv->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])) < 0) { + qCritical() << "RegisterNatives failed for '" + << QtNativeInputConnectionClassName + << "'"; + return; + } + + clazz = QtAndroid::findClass(QtExtractedTextClassName, env.jniEnv); + if (clazz == NULL) { + qCritical() << "Native registration unable to find class '" + << QtExtractedTextClassName + << "'"; + return; + } + + m_extractedTextClass = static_cast(env.jniEnv->NewGlobalRef(clazz)); + m_classConstructorMethodID = env.jniEnv->GetMethodID(m_extractedTextClass, "", "()V"); + if (m_classConstructorMethodID == NULL) { + qCritical() << "GetMethodID failed"; + return; + } + + m_partialEndOffsetFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "partialEndOffset", "I"); + if (m_partialEndOffsetFieldID == NULL) { + qCritical() << "Can't find field partialEndOffset"; + return; + } + + m_partialStartOffsetFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "partialStartOffset", "I"); + if (m_partialStartOffsetFieldID == NULL) { + qCritical() << "Can't find field partialStartOffset"; + return; + } + + m_selectionEndFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "selectionEnd", "I"); + if (m_selectionEndFieldID == NULL) { + qCritical() << "Can't find field selectionEnd"; + return; + } + + m_selectionStartFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "selectionStart", "I"); + if (m_selectionStartFieldID == NULL) { + qCritical() << "Can't find field selectionStart"; + return; + } + + m_startOffsetFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "startOffset", "I"); + if (m_startOffsetFieldID == NULL) { + qCritical() << "Can't find field startOffset"; + return; + } + + m_textFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "text", "Ljava/lang/String;"); + if (m_textFieldID == NULL) { + qCritical() << "Can't find field text"; + return; + } + qRegisterMetaType("QInputMethodEvent*"); + qRegisterMetaType("QInputMethodQueryEvent*"); + m_androidInputContext = this; +} + +QAndroidInputContext::~QAndroidInputContext() +{ + m_androidInputContext = 0; + m_extractedTextClass = 0; + m_partialEndOffsetFieldID = 0; + m_partialStartOffsetFieldID = 0; + m_selectionEndFieldID = 0; + m_selectionStartFieldID = 0; + m_startOffsetFieldID = 0; + m_textFieldID = 0; +} + +QAndroidInputContext *QAndroidInputContext::androidInputContext() +{ + return m_androidInputContext; +} + +void QAndroidInputContext::reset() +{ + clear(); + if (qGuiApp->focusObject()) + QtAndroidInput::resetSoftwareKeyboard(); + else + QtAndroidInput::hideSoftwareKeyboard(); +} + +void QAndroidInputContext::commit() +{ + finishComposingText(); +} + +void QAndroidInputContext::updateCursorPosition() +{ + QSharedPointer query = focusObjectInputMethodQuery(); + if (!query.isNull() && !m_blockUpdateSelection) { + const int cursorPos = query->value(Qt::ImCursorPosition).toInt(); + QtAndroidInput::updateSelection(cursorPos, cursorPos, -1, -1); //selection empty and no pre-edit text + } +} + +void QAndroidInputContext::update(Qt::InputMethodQueries queries) +{ + QSharedPointer query = focusObjectInputMethodQuery(queries); + if (query.isNull()) + return; +#warning TODO extract the needed data from query +} + +void QAndroidInputContext::invokeAction(QInputMethod::Action action, int cursorPosition) +{ +#warning TODO Handle at least QInputMethod::ContextMenu action + Q_UNUSED(action) + Q_UNUSED(cursorPosition) + + if (action == QInputMethod::Click) + commit(); +} + +QRectF QAndroidInputContext::keyboardRect() const +{ + return QPlatformInputContext::keyboardRect(); +} + +bool QAndroidInputContext::isAnimating() const +{ + return false; +} + +void QAndroidInputContext::showInputPanel() +{ + QSharedPointer query = focusObjectInputMethodQuery(); + if (query.isNull()) + return; + + disconnect(m_updateCursorPosConnection); + if (qGuiApp->focusObject()->metaObject()->indexOfSignal("cursorPositionChanged(int,int)") >= 0) // QLineEdit breaks the pattern + m_updateCursorPosConnection = connect(qGuiApp->focusObject(), SIGNAL(cursorPositionChanged(int,int)), this, SLOT(updateCursorPosition())); + else + m_updateCursorPosConnection = connect(qGuiApp->focusObject(), SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition())); + QRectF itemRect = qGuiApp->inputMethod()->inputItemRectangle(); + QRect rect = qGuiApp->inputMethod()->inputItemTransform().mapRect(itemRect).toRect(); + QWindow *window = qGuiApp->focusWindow(); + if (window) + rect = QRect(window->mapToGlobal(rect.topLeft()), rect.size()); + + QtAndroidInput::showSoftwareKeyboard(rect.left(), + rect.top(), + rect.width(), + rect.height(), + query->value(Qt::ImHints).toUInt()); +} + +void QAndroidInputContext::hideInputPanel() +{ + QtAndroidInput::hideSoftwareKeyboard(); +} + +bool QAndroidInputContext::isInputPanelVisible() const +{ + return QtAndroidInput::isSoftwareKeyboardVisible(); +} + +bool QAndroidInputContext::isComposing() const +{ + return m_composingText.length(); +} + +void QAndroidInputContext::clear() +{ + m_composingText.clear(); + m_extractedText.clear(); +} + +void QAndroidInputContext::sendEvent(QObject *receiver, QInputMethodEvent *event) +{ + QCoreApplication::sendEvent(receiver, event); +} + +void QAndroidInputContext::sendEvent(QObject *receiver, QInputMethodQueryEvent *event) +{ + QCoreApplication::sendEvent(receiver, event); +} + +jboolean QAndroidInputContext::commitText(const QString &text, jint /*newCursorPosition*/) +{ + m_composingText = text; + return finishComposingText(); +} + +jboolean QAndroidInputContext::deleteSurroundingText(jint leftLength, jint rightLength) +{ + QSharedPointer query = focusObjectInputMethodQuery(); + if (query.isNull()) + return JNI_TRUE; + + m_composingText.clear(); + + QInputMethodEvent event; + event.setCommitString(QString(), -leftLength, leftLength+rightLength); + sendInputMethodEvent(&event); + clear(); + + return JNI_TRUE; +} + +jboolean QAndroidInputContext::finishComposingText() +{ + QInputMethodEvent event; + event.setCommitString(m_composingText); + sendInputMethodEvent(&event); + clear(); + + return JNI_TRUE; +} + +jint QAndroidInputContext::getCursorCapsMode(jint /*reqModes*/) +{ + jint res = 0; + QSharedPointer query = focusObjectInputMethodQuery(); + if (query.isNull()) + return res; + + const uint qtInputMethodHints = query->value(Qt::ImHints).toUInt(); + + if (qtInputMethodHints & Qt::ImhPreferUppercase) + res = CAP_MODE_SENTENCES; + + if (qtInputMethodHints & Qt::ImhUppercaseOnly) + res = CAP_MODE_CHARACTERS; + + return res; +} + +const QAndroidInputContext::ExtractedText &QAndroidInputContext::getExtractedText(jint hintMaxChars, jint /*hintMaxLines*/, jint /*flags*/) +{ + QSharedPointer query = focusObjectInputMethodQuery(); + if (query.isNull()) + return m_extractedText; + + if (hintMaxChars) + m_extractedText.text = query->value(Qt::ImSurroundingText).toString().right(hintMaxChars); + + m_extractedText.startOffset = query->value(Qt::ImCursorPosition).toInt(); + const QString &selection = query->value(Qt::ImCurrentSelection).toString(); + const int selLen = selection.length(); + if (selLen) { + m_extractedText.selectionStart = query->value(Qt::ImAnchorPosition).toInt(); + m_extractedText.selectionEnd = m_extractedText.startOffset; + } + + return m_extractedText; +} + +QString QAndroidInputContext::getSelectedText(jint /*flags*/) +{ + QSharedPointer query = focusObjectInputMethodQuery(); + if (query.isNull()) + return QString(); + + return query->value(Qt::ImCurrentSelection).toString(); +} + +QString QAndroidInputContext::getTextAfterCursor(jint length, jint /*flags*/) +{ + QSharedPointer query = focusObjectInputMethodQuery(); + if (query.isNull()) + return QString(); + + QString text = query->value(Qt::ImSurroundingText).toString(); + if (!text.length()) + return text; + + int cursorPos = query->value(Qt::ImCursorPosition).toInt(); + return text.mid(cursorPos, length); +} + +QString QAndroidInputContext::getTextBeforeCursor(jint length, jint /*flags*/) +{ + QSharedPointer query = focusObjectInputMethodQuery(); + if (query.isNull()) + return QString(); + + QString text = query->value(Qt::ImSurroundingText).toString(); + if (!text.length()) + return text; + + int cursorPos = query->value(Qt::ImCursorPosition).toInt(); + const int wordLeftPos = cursorPos - length; + return text.mid(wordLeftPos > 0 ? wordLeftPos : 0, cursorPos); +} + +jboolean QAndroidInputContext::setComposingText(const QString &text, jint newCursorPosition) +{ + if (newCursorPosition > 0) + newCursorPosition += text.length() - 1; + m_composingText = text; + QList attributes; + attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, + newCursorPosition, + 1, + QVariant())); + // Show compose text underlined + QTextCharFormat underlined; + underlined.setFontUnderline(true); + attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,0, text.length(), + QVariant(underlined))); + + QInputMethodEvent event(m_composingText, attributes); + sendInputMethodEvent(&event); + + QSharedPointer query = focusObjectInputMethodQuery(); + if (!query.isNull() && !m_blockUpdateSelection) { + int cursorPos = query->value(Qt::ImCursorPosition).toInt(); + int preeditLength = text.length(); + QtAndroidInput::updateSelection(cursorPos+preeditLength, cursorPos+preeditLength, cursorPos, cursorPos+preeditLength); + } + + return JNI_TRUE; +} + +// Android docs say: +// * start may be after end, same meaning as if swapped +// * this function must not trigger updateSelection +// * if start == end then we should stop composing +jboolean QAndroidInputContext::setComposingRegion(jint start, jint end) +{ + QSharedPointer query = focusObjectInputMethodQuery(); + if (query.isNull()) + return JNI_FALSE; + + if (start > end) + qSwap(start, end); + + /* + start and end are cursor positions, not character positions, + i.e. selecting the first character is done by start == 0 and end == 1, + and start == end means no character selected + + Therefore, the length of the region is end - start + */ + int length = end - start; + + bool updateSelectionWasBlocked = m_blockUpdateSelection; + m_blockUpdateSelection = true; + + QString text = query->value(Qt::ImSurroundingText).toString(); + m_composingText = text.mid(start, length); + + //in the Qt text controls, cursor pos is the start of the preedit + int cursorPos = query->value(Qt::ImCursorPosition).toInt(); + int relativeStart = start - cursorPos; + + QList attributes; + + // Show compose text underlined + QTextCharFormat underlined; + underlined.setFontUnderline(true); + attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,0, length, + QVariant(underlined))); + + QInputMethodEvent event(m_composingText, attributes); + event.setCommitString(QString(), relativeStart, length); + sendInputMethodEvent(&event); + + m_blockUpdateSelection = updateSelectionWasBlocked; + return JNI_TRUE; +} + +jboolean QAndroidInputContext::setSelection(jint start, jint end) +{ + QList attributes; + attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, + start, + end - start, + QVariant())); + + QInputMethodEvent event(QString(), attributes); + sendInputMethodEvent(&event); + return JNI_TRUE; +} + +jboolean QAndroidInputContext::selectAll() +{ +#warning TODO + return JNI_FALSE; +} + +jboolean QAndroidInputContext::cut() +{ +#warning TODO + return JNI_FALSE; +} + +jboolean QAndroidInputContext::copy() +{ +#warning TODO + return JNI_FALSE; +} + +jboolean QAndroidInputContext::copyURL() +{ +#warning TODO + return JNI_FALSE; +} + +jboolean QAndroidInputContext::paste() +{ +#warning TODO + return JNI_FALSE; +} + +QSharedPointer QAndroidInputContext::focusObjectInputMethodQuery(Qt::InputMethodQueries queries) +{ +#warning TODO make qGuiApp->focusObject() thread safe !!! + QObject *focusObject = qGuiApp->focusObject(); + if (!focusObject) + return QSharedPointer(); + + QSharedPointer ret = QSharedPointer(new QInputMethodQueryEvent(queries)); + if (qGuiApp->thread()==QThread::currentThread()) { + QCoreApplication::sendEvent(focusObject, ret.data()); + } else { + QMetaObject::invokeMethod(this, + "sendEvent", + Qt::BlockingQueuedConnection, + Q_ARG(QObject*, focusObject), + Q_ARG(QInputMethodQueryEvent*, ret.data())); + } + + return ret; +} + +void QAndroidInputContext::sendInputMethodEvent(QInputMethodEvent *event) +{ +#warning TODO make qGuiApp->focusObject() thread safe !!! + QObject *focusObject = qGuiApp->focusObject(); + if (!focusObject) + return; + + if (qGuiApp->thread() == QThread::currentThread()) { + QCoreApplication::sendEvent(focusObject, event); + } else { + QMetaObject::invokeMethod(this, + "sendEvent", + Qt::BlockingQueuedConnection, + Q_ARG(QObject*, focusObject), + Q_ARG(QInputMethodEvent*, event)); + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidinputcontext.h b/src/plugins/platforms/android/qandroidinputcontext.h new file mode 100644 index 0000000000..041bd0dc49 --- /dev/null +++ b/src/plugins/platforms/android/qandroidinputcontext.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDINPUTCONTEXT_H +#define ANDROIDINPUTCONTEXT_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QAndroidInputContext: public QPlatformInputContext +{ + Q_OBJECT + enum CapsMode + { + CAP_MODE_CHARACTERS = 0x00001000, + CAP_MODE_SENTENCES = 0x00004000, + CAP_MODE_WORDS = 0x00002000 + }; + +public: + struct ExtractedText + { + ExtractedText() { clear(); } + + void clear() + { + partialEndOffset = partialStartOffset = selectionEnd = selectionStart = startOffset = -1; + text.clear(); + } + + int partialEndOffset; + int partialStartOffset; + int selectionEnd; + int selectionStart; + int startOffset; + QString text; + }; + +public: + QAndroidInputContext(); + ~QAndroidInputContext(); + static QAndroidInputContext * androidInputContext(); + bool isValid() const { return true; } + + void reset(); + void commit(); + void update(Qt::InputMethodQueries queries); + void invokeAction(QInputMethod::Action action, int cursorPosition); + QRectF keyboardRect() const; + bool isAnimating() const; + void showInputPanel(); + void hideInputPanel(); + bool isInputPanelVisible() const; + + bool isComposing() const; + void clear(); + + //---------------// + jboolean commitText(const QString &text, jint newCursorPosition); + jboolean deleteSurroundingText(jint leftLength, jint rightLength); + jboolean finishComposingText(); + jint getCursorCapsMode(jint reqModes); + const ExtractedText &getExtractedText(jint hintMaxChars, jint hintMaxLines, jint flags); + QString getSelectedText(jint flags); + QString getTextAfterCursor(jint length, jint flags); + QString getTextBeforeCursor(jint length, jint flags); + jboolean setComposingText(const QString &text, jint newCursorPosition); + jboolean setComposingRegion(jint start, jint end); + jboolean setSelection(jint start, jint end); + jboolean selectAll(); + jboolean cut(); + jboolean copy(); + jboolean copyURL(); + jboolean paste(); + +private: + QSharedPointer focusObjectInputMethodQuery(Qt::InputMethodQueries queries = Qt::ImQueryAll); + void sendInputMethodEvent(QInputMethodEvent *event); + +private slots: + virtual void sendEvent(QObject *receiver, QInputMethodEvent *event); + virtual void sendEvent(QObject *receiver, QInputMethodQueryEvent *event); + void updateCursorPosition(); + +private: + ExtractedText m_extractedText; + QString m_composingText; + QMetaObject::Connection m_updateCursorPosConnection; + bool m_blockUpdateSelection; +}; + +QT_END_NAMESPACE + +#endif // ANDROIDINPUTCONTEXT_H diff --git a/src/plugins/platforms/android/qandroidplatformaccessibility.cpp b/src/plugins/platforms/android/qandroidplatformaccessibility.cpp new file mode 100644 index 0000000000..229368345b --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformaccessibility.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "qandroidplatformaccessibility.h" + +QT_BEGIN_NAMESPACE + +QAndroidPlatformAccessibility::QAndroidPlatformAccessibility() +{} + +QAndroidPlatformAccessibility::~QAndroidPlatformAccessibility() +{} + +void QAndroidPlatformAccessibility::notifyAccessibilityUpdate(QAccessibleEvent */*event*/) +{ + // FIXME send events +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformaccessibility.h b/src/plugins/platforms/android/qandroidplatformaccessibility.h new file mode 100644 index 0000000000..1b87f11919 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformaccessibility.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QANDROIDPLATFORMACCESSIBILITY_H +#define QANDROIDPLATFORMACCESSIBILITY_H + +#include + +QT_BEGIN_NAMESPACE + +class QAndroidPlatformAccessibility: public QPlatformAccessibility +{ +public: + QAndroidPlatformAccessibility(); + ~QAndroidPlatformAccessibility(); + + virtual void notifyAccessibilityUpdate(QAccessibleEvent *event); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/android/qandroidplatformbackingstore.cpp b/src/plugins/platforms/android/qandroidplatformbackingstore.cpp new file mode 100644 index 0000000000..1df7ce3179 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformbackingstore.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformbackingstore.h" +#include "qandroidplatformscreen.h" +#include "qandroidplatformrasterwindow.h" +#include + +QT_BEGIN_NAMESPACE + +QAndroidPlatformBackingStore::QAndroidPlatformBackingStore(QWindow *window) + : QPlatformBackingStore(window) +{ + Q_ASSERT(window->handle()); + (static_cast(window->handle()))->setBackingStore(this); +} + +QPaintDevice *QAndroidPlatformBackingStore::paintDevice() +{ + return &m_image; +} + +void QAndroidPlatformBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(window); + Q_UNUSED(offset); + + (static_cast(window->handle()))->repaint(region); +} + +void QAndroidPlatformBackingStore::resize(const QSize &size, const QRegion &staticContents) +{ + Q_UNUSED(staticContents); + + if (m_image.size() != size) + m_image = QImage(size, window()->screen()->handle()->format()); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformbackingstore.h b/src/plugins/platforms/android/qandroidplatformbackingstore.h new file mode 100644 index 0000000000..e6ea3dcce0 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformbackingstore.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMBACKINGSTORE_H +#define QANDROIDPLATFORMBACKINGSTORE_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QAndroidPlatformBackingStore : public QPlatformBackingStore +{ +public: + explicit QAndroidPlatformBackingStore(QWindow *window); + virtual QPaintDevice *paintDevice(); + virtual void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); + virtual void resize(const QSize &size, const QRegion &staticContents); + const QImage image() { return m_image; } + +protected: + QImage m_image; +}; + +QT_END_NAMESPACE + +#endif // QANDROIDPLATFORMBACKINGSTORE_H diff --git a/src/plugins/platforms/android/qandroidplatformclipboard.cpp b/src/plugins/platforms/android/qandroidplatformclipboard.cpp new file mode 100644 index 0000000000..bc48b4935b --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformclipboard.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformclipboard.h" +#include "androidjniclipboard.h" +#ifndef QT_NO_CLIPBOARD +#include + +QT_BEGIN_NAMESPACE + +QAndroidPlatformClipboard::QAndroidPlatformClipboard() +{ + QtAndroidClipboard::setClipboardListener(this); +} + +QMimeData *QAndroidPlatformClipboard::mimeData(QClipboard::Mode mode) +{ + if (QClipboard::Clipboard != mode || !QtAndroidClipboard::hasClipboardText()) + return 0; + + QMimeData *mimeData = new QMimeData(); + mimeData->setText(QtAndroidClipboard::clipboardText()); + return mimeData; +} + +void QAndroidPlatformClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) +{ + if (!data || !data->hasText() || QClipboard::Clipboard != mode) + return; + + QtAndroidClipboard::setClipboardText(data->text()); +} + +bool QAndroidPlatformClipboard::supportsMode(QClipboard::Mode mode) const +{ + return QClipboard::Clipboard == mode; +} + +QT_END_NAMESPACE + +#endif // QT_NO_CLIPBOARD diff --git a/src/plugins/platforms/android/qandroidplatformclipboard.h b/src/plugins/platforms/android/qandroidplatformclipboard.h new file mode 100644 index 0000000000..644f326934 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformclipboard.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMCLIPBOARD_H +#define QANDROIDPLATFORMCLIPBOARD_H + +#include + +#ifndef QT_NO_CLIPBOARD +QT_BEGIN_NAMESPACE + +class QAndroidPlatformClipboard: public QPlatformClipboard +{ +public: + QAndroidPlatformClipboard(); + + virtual QMimeData *mimeData(QClipboard::Mode mode = QClipboard::Clipboard); + virtual void setMimeData(QMimeData *data, QClipboard::Mode mode = QClipboard::Clipboard); + virtual bool supportsMode(QClipboard::Mode mode) const; +}; + +QT_END_NAMESPACE +#endif // QT_NO_CLIPBOARD + +#endif // QANDROIDPLATFORMCLIPBOARD_H diff --git a/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp b/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp new file mode 100644 index 0000000000..4c91e76e0f --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "qandroidplatformdialoghelpers.h" +#include "androidjnimain.h" + +namespace QtAndroidDialogHelpers { +static jclass g_messageDialogHelperClass = 0; + +QAndroidPlatformMessageDialogHelper::QAndroidPlatformMessageDialogHelper() + :m_buttonId(-1) + ,m_javaMessageDialog(g_messageDialogHelperClass, "(Landroid/app/Activity;)V", QtAndroid::activity()) + ,m_shown(false) +{ +} + +void QAndroidPlatformMessageDialogHelper::exec() +{ + if (!m_shown) + show(Qt::Dialog, Qt::ApplicationModal, 0); + m_loop.exec(); +} + +static QString standardButtonText(int sbutton) +{ + switch (sbutton) { + case QMessageDialogOptions::Ok: + return QAndroidPlatformMessageDialogHelper::tr("OK"); + case QMessageDialogOptions::Save: + return QAndroidPlatformMessageDialogHelper::tr("Save"); + case QMessageDialogOptions::Open: + return QAndroidPlatformMessageDialogHelper::tr("Open"); + case QMessageDialogOptions::Cancel: + return QAndroidPlatformMessageDialogHelper::tr("Cancel"); + case QMessageDialogOptions::Close: + return QAndroidPlatformMessageDialogHelper::tr("Close"); + case QMessageDialogOptions::Apply: + return QAndroidPlatformMessageDialogHelper::tr("Apply"); + case QMessageDialogOptions::Reset: + return QAndroidPlatformMessageDialogHelper::tr("Reset"); + case QMessageDialogOptions::Help: + return QAndroidPlatformMessageDialogHelper::tr("Help"); + case QMessageDialogOptions::Discard: + return QAndroidPlatformMessageDialogHelper::tr("Discard"); + case QMessageDialogOptions::Yes: + return QAndroidPlatformMessageDialogHelper::tr("Yes"); + case QMessageDialogOptions::YesToAll: + return QAndroidPlatformMessageDialogHelper::tr("Yes to All"); + case QMessageDialogOptions::No: + return QAndroidPlatformMessageDialogHelper::tr("No"); + case QMessageDialogOptions::NoToAll: + return QAndroidPlatformMessageDialogHelper::tr("No to All"); + case QMessageDialogOptions::SaveAll: + return QAndroidPlatformMessageDialogHelper::tr("Save All"); + case QMessageDialogOptions::Abort: + return QAndroidPlatformMessageDialogHelper::tr("Abort"); + case QMessageDialogOptions::Retry: + return QAndroidPlatformMessageDialogHelper::tr("Retry"); + case QMessageDialogOptions::Ignore: + return QAndroidPlatformMessageDialogHelper::tr("Ignore"); + case QMessageDialogOptions::RestoreDefaults: + return QAndroidPlatformMessageDialogHelper::tr("Restore Defaults"); + } // switch + return QString(); +} + +bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags + , Qt::WindowModality windowModality + , QWindow *parent) +{ + Q_UNUSED(windowFlags) + Q_UNUSED(windowModality) + Q_UNUSED(parent) + QSharedPointer opt = options(); + if (!opt.data()) + return false; + + m_javaMessageDialog.callMethod("setIcon", "(I)V", opt->icon()); + + QString str = opt->windowTitle(); + if (!str.isEmpty()) + m_javaMessageDialog.callMethod("setTile", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object()); + + str = opt->text(); + if (!str.isEmpty()) + m_javaMessageDialog.callMethod("setText", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object()); + + str = opt->informativeText(); + if (!str.isEmpty()) + m_javaMessageDialog.callMethod("setInformativeText", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object()); + + str = opt->detailedText(); + if (!str.isEmpty()) + m_javaMessageDialog.callMethod("setDetailedText", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object()); + + for (int i = QMessageDialogOptions::FirstButton; i < QMessageDialogOptions::LastButton; i<<=1) { + if ( opt->standardButtons() & i ) + m_javaMessageDialog.callMethod("addButton", "(ILjava/lang/String;)V", i, QJNIObjectPrivate::fromString(standardButtonText(i)).object()); + } + + m_javaMessageDialog.callMethod("show", "(J)V", jlong(static_cast(this))); + m_shown = true; + return true; +} + +void QAndroidPlatformMessageDialogHelper::hide() +{ + m_javaMessageDialog.callMethod("hide", "()V"); + m_shown = false; +} + +void QAndroidPlatformMessageDialogHelper::dialogResult(int buttonID) +{ + m_buttonId = buttonID; + if (m_loop.isRunning()) + m_loop.exit(); + if (m_buttonId < 0) { + emit reject(); + return; + } + + QMessageDialogOptions::StandardButton standardButton = static_cast(buttonID); + QMessageDialogOptions::ButtonRole role = QMessageDialogOptions::buttonRole(standardButton); + emit clicked(standardButton, role); +} + +static void dialogResult(JNIEnv * /*env*/, jobject /*thiz*/, jlong handler, int buttonID) +{ + QObject *object = reinterpret_cast(handler); + QMetaObject::invokeMethod(object, "dialogResult", Qt::QueuedConnection, Q_ARG(int, buttonID)); +} + +static JNINativeMethod methods[] = { + {"dialogResult", "(JI)V", (void *)dialogResult} +}; + + +#define FIND_AND_CHECK_CLASS(CLASS_NAME) \ + clazz = env->FindClass(CLASS_NAME); \ + if (!clazz) { \ + __android_log_print(ANDROID_LOG_FATAL, QtAndroid::qtTagText(), QtAndroid::classErrorMsgFmt(), CLASS_NAME); \ + return false; \ + } + +bool registerNatives(JNIEnv *env) +{ + jclass clazz = QtAndroid::findClass("org.qtproject.qt5.android.QtMessageDialogHelper", env); + if (!clazz) { + __android_log_print(ANDROID_LOG_FATAL, QtAndroid::qtTagText(), QtAndroid::classErrorMsgFmt() + , "org/qtproject/qt5/android/QtMessageDialogHelper"); + return false; + } + g_messageDialogHelperClass = static_cast(env->NewGlobalRef(clazz)); + FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/QtNativeDialogHelper"); + jclass appClass = static_cast(env->NewGlobalRef(clazz)); + + if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { + __android_log_print(ANDROID_LOG_FATAL, "Qt", "RegisterNatives failed"); + return false; + } + + return true; +} +} diff --git a/src/plugins/platforms/android/qandroidplatformdialoghelpers.h b/src/plugins/platforms/android/qandroidplatformdialoghelpers.h new file mode 100644 index 0000000000..88ec91d936 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformdialoghelpers.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMDIALOGHELPERS_H +#define QANDROIDPLATFORMDIALOGHELPERS_H +#include +#include +#include +#include + +namespace QtAndroidDialogHelpers { + +class QAndroidPlatformMessageDialogHelper: public QPlatformMessageDialogHelper +{ + Q_OBJECT +public: + QAndroidPlatformMessageDialogHelper(); + void exec(); + bool show(Qt::WindowFlags windowFlags, + Qt::WindowModality windowModality, + QWindow *parent); + void hide(); + +public slots: + void dialogResult(int buttonID); + +private: + int m_buttonId; + QEventLoop m_loop; + QJNIObjectPrivate m_javaMessageDialog; + bool m_shown; +}; + + +bool registerNatives(JNIEnv *env); + +} + +#endif // QANDROIDPLATFORMDIALOGHELPERS_H diff --git a/src/plugins/platforms/android/qandroidplatformfontdatabase.cpp b/src/plugins/platforms/android/qandroidplatformfontdatabase.cpp new file mode 100644 index 0000000000..7f68b44ed8 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformfontdatabase.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "qandroidplatformfontdatabase.h" + +QString QAndroidPlatformFontDatabase::fontDir() const +{ + return QLatin1String("/system/fonts"); +} + +void QAndroidPlatformFontDatabase::populateFontDatabase() +{ + QString fontpath = fontDir(); + + if (!QFile::exists(fontpath)) { + qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?", + qPrintable(fontpath)); + } + + QDir dir(fontpath, QLatin1String("*.ttf")); + for (int i = 0; i < int(dir.count()); ++i) { + const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); + addTTFile(QByteArray(), file); + } +} + +QStringList QAndroidPlatformFontDatabase::fallbacksForFamily(const QString &family, + QFont::Style style, + QFont::StyleHint styleHint, + QChar::Script script) const +{ + Q_UNUSED(family); + Q_UNUSED(style); + Q_UNUSED(script); + if (styleHint == QFont::Monospace) + return QString(qgetenv("QT_ANDROID_FONTS_MONOSPACE")).split(";"); + + return QString(qgetenv("QT_ANDROID_FONTS")).split(";"); +} diff --git a/src/plugins/platforms/android/qandroidplatformfontdatabase.h b/src/plugins/platforms/android/qandroidplatformfontdatabase.h new file mode 100644 index 0000000000..3cbfe95d36 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformfontdatabase.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMFONTDATABASE_H +#define QANDROIDPLATFORMFONTDATABASE_H + +#include + +class QAndroidPlatformFontDatabase: public QBasicFontDatabase +{ +public: + QString fontDir() const; + void populateFontDatabase(); + QStringList fallbacksForFamily(const QString &family, + QFont::Style style, + QFont::StyleHint styleHint, + QChar::Script script) const; +}; + +#endif // QANDROIDPLATFORMFONTDATABASE_H diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp new file mode 100644 index 0000000000..2fc6b987ab --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -0,0 +1,286 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformintegration.h" + +#include +#include +#include + +#include + +#include +#include + +#warning sort the headers +#include "androidjnimain.h" +#include "qabstracteventdispatcher.h" +#include "qandroidplatformrasterwindow.h" +#include "qandroidplatformopenglwindow.h" +#include "qandroidplatformbackingstore.h" +#include "qandroidplatformservices.h" +#include "qandroidplatformfontdatabase.h" +#include "qandroidplatformclipboard.h" +#include "qandroidplatformaccessibility.h" +#include "qandroidplatformopenglcontext.h" +#include "qandroidplatformscreen.h" +#include "qandroidplatformtheme.h" +#include "qandroidsystemlocale.h" + + +QT_BEGIN_NAMESPACE + +int QAndroidPlatformIntegration::m_defaultGeometryWidth = 320; +int QAndroidPlatformIntegration::m_defaultGeometryHeight = 455; +int QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth = 50; +int QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight = 71; + +Qt::ScreenOrientation QAndroidPlatformIntegration::m_orientation = Qt::PrimaryOrientation; +Qt::ScreenOrientation QAndroidPlatformIntegration::m_nativeOrientation = Qt::PrimaryOrientation; + +void *QAndroidPlatformNativeInterface::nativeResourceForIntegration(const QByteArray &resource) +{ + if (resource=="JavaVM") + return QtAndroid::javaVM(); + if (resource == "QtActivity") + return QtAndroid::activity(); + if (resource == "AndroidStylePalettes") + return &m_palettes; + if (resource == "AndroidStyleFonts") + return &m_fonts; + return 0; +} + +QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶mList) + : m_touchDevice(0) +#ifndef QT_NO_ACCESSIBILITY + , m_accessibility(0) +#endif +{ + Q_UNUSED(paramList); + + m_androidPlatformNativeInterface = new QAndroidPlatformNativeInterface(); + + if (!eglBindAPI(EGL_OPENGL_ES_API)) + qFatal("Could not bind GL_ES API"); + + m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (m_eglDisplay == EGL_NO_DISPLAY) + qFatal("Could not open egl display"); + + EGLint major, minor; + if (!eglInitialize(m_eglDisplay, &major, &minor)) + qFatal("Could not initialize egl display"); + + m_primaryScreen = new QAndroidPlatformScreen(); + screenAdded(m_primaryScreen); + m_primaryScreen->setPhysicalSize(QSize(m_defaultPhysicalSizeWidth, m_defaultPhysicalSizeHeight)); + m_primaryScreen->setGeometry(QRect(0, 0, m_defaultGeometryWidth, m_defaultGeometryHeight)); + + m_mainThread = QThread::currentThread(); + QtAndroid::setAndroidPlatformIntegration(this); + + m_androidFDB = new QAndroidPlatformFontDatabase(); + m_androidPlatformServices = new QAndroidPlatformServices(); + m_androidPlatformClipboard = new QAndroidPlatformClipboard(); + + m_androidSystemLocale = new QAndroidSystemLocale; +} + +bool QAndroidPlatformIntegration::hasCapability(Capability cap) const +{ + switch (cap) { + case ThreadedPixmaps: return true; + case ApplicationState: return true; + case NativeWidgets: return true; + case OpenGL: return true; + case ThreadedOpenGL: return true; + default: + return QPlatformIntegration::hasCapability(cap); + } +} + +QPlatformBackingStore *QAndroidPlatformIntegration::createPlatformBackingStore(QWindow *window) const +{ + return new QAndroidPlatformBackingStore(window); +} + +QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const +{ + QSurfaceFormat format(context->format()); + format.setAlphaBufferSize(8); + format.setRedBufferSize(8); + format.setGreenBufferSize(8); + format.setBlueBufferSize(8); + return new QAndroidPlatformOpenGLContext(format, context->shareHandle(), m_eglDisplay); +} + +QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const +{ + if (window->surfaceType() == QSurface::RasterSurface) + return new QAndroidPlatformRasterWindow(window); + else + return new QAndroidPlatformOpenGLWindow(window, m_eglDisplay); +} + +QAbstractEventDispatcher *QAndroidPlatformIntegration::createEventDispatcher() const +{ + return createUnixEventDispatcher(); +} + +QAndroidPlatformIntegration::~QAndroidPlatformIntegration() +{ + if (m_eglDisplay != EGL_NO_DISPLAY) + eglTerminate(m_eglDisplay); + + delete m_androidPlatformNativeInterface; + delete m_androidFDB; + delete m_androidSystemLocale; + QtAndroid::setAndroidPlatformIntegration(NULL); +} + +QPlatformFontDatabase *QAndroidPlatformIntegration::fontDatabase() const +{ + return m_androidFDB; +} + +#ifndef QT_NO_CLIPBOARD +QPlatformClipboard *QAndroidPlatformIntegration::clipboard() const +{ +static QAndroidPlatformClipboard *clipboard = 0; + if (!clipboard) + clipboard = new QAndroidPlatformClipboard; + + return clipboard; +} +#endif + +QPlatformInputContext *QAndroidPlatformIntegration::inputContext() const +{ + return &m_platformInputContext; +} + +QPlatformNativeInterface *QAndroidPlatformIntegration::nativeInterface() const +{ + return m_androidPlatformNativeInterface; +} + +QPlatformServices *QAndroidPlatformIntegration::services() const +{ + return m_androidPlatformServices; +} + +QVariant QAndroidPlatformIntegration::styleHint(StyleHint hint) const +{ + switch (hint) { + case ShowIsMaximized: + return true; + default: + return QPlatformIntegration::styleHint(hint); + } +} + +Qt::WindowState QAndroidPlatformIntegration::defaultWindowState(Qt::WindowFlags flags) const +{ + // Don't maximize dialogs on Android + if (flags & Qt::Dialog & ~Qt::Window) + return Qt::WindowNoState; + + return QPlatformIntegration::defaultWindowState(flags); +} + +static const QLatin1String androidThemeName("android"); +QStringList QAndroidPlatformIntegration::themeNames() const +{ + return QStringList(QString(androidThemeName)); +} + +QPlatformTheme *QAndroidPlatformIntegration::createPlatformTheme(const QString &name) const +{ + if (androidThemeName == name) + return new QAndroidPlatformTheme(m_androidPlatformNativeInterface); + + return 0; +} + +void QAndroidPlatformIntegration::setDefaultDisplayMetrics(int gw, int gh, int sw, int sh) +{ + m_defaultGeometryWidth = gw; + m_defaultGeometryHeight = gh; + m_defaultPhysicalSizeWidth = sw; + m_defaultPhysicalSizeHeight = sh; +} + +void QAndroidPlatformIntegration::setDefaultDesktopSize(int gw, int gh) +{ + m_defaultGeometryWidth = gw; + m_defaultGeometryHeight = gh; +} + +void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation currentOrientation, + Qt::ScreenOrientation nativeOrientation) +{ + m_orientation = currentOrientation; + m_nativeOrientation = nativeOrientation; +} + +#ifndef QT_NO_ACCESSIBILITY +QPlatformAccessibility *QAndroidPlatformIntegration::accessibility() const +{ + if (!m_accessibility) + m_accessibility = new QAndroidPlatformAccessibility(); + return m_accessibility; +} +#endif + +void QAndroidPlatformIntegration::setDesktopSize(int width, int height) +{ + if (m_primaryScreen) + QMetaObject::invokeMethod(m_primaryScreen, "setGeometry", Qt::AutoConnection, Q_ARG(QRect, QRect(0,0,width, height))); +} + +void QAndroidPlatformIntegration::setDisplayMetrics(int width, int height) +{ + if (m_primaryScreen) + QMetaObject::invokeMethod(m_primaryScreen, "setPhysicalSize", Qt::AutoConnection, Q_ARG(QSize, QSize(width, height))); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformintegration.h b/src/plugins/platforms/android/qandroidplatformintegration.h new file mode 100644 index 0000000000..a6cba7ac16 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformintegration.h @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMINTERATION_H +#define QANDROIDPLATFORMINTERATION_H + +#include +#include +#include +#include + +#include +#include +#include "qandroidinputcontext.h" + +#include "qandroidplatformscreen.h" + +QT_BEGIN_NAMESPACE + +class QDesktopWidget; +class QAndroidPlatformServices; +class QAndroidSystemLocale; +class QPlatformAccessibility; + +class QAndroidPlatformNativeInterface: public QPlatformNativeInterface +{ +public: + void *nativeResourceForIntegration(const QByteArray &resource); + QHash m_palettes; + QHash m_fonts; +}; + +class QAndroidPlatformIntegration : public QPlatformIntegration +{ + friend class QAndroidPlatformScreen; + +public: + QAndroidPlatformIntegration(const QStringList ¶mList); + ~QAndroidPlatformIntegration(); + + bool hasCapability(QPlatformIntegration::Capability cap) const; + + QPlatformWindow *createPlatformWindow(QWindow *window) const; + QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; + QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; + QAbstractEventDispatcher *createEventDispatcher() const; + QAndroidPlatformScreen *screen() { return m_primaryScreen; } + + virtual void setDesktopSize(int width, int height); + virtual void setDisplayMetrics(int width, int height); + bool isVirtualDesktop() { return true; } + + QPlatformFontDatabase *fontDatabase() const; + +#ifndef QT_NO_CLIPBOARD + QPlatformClipboard *clipboard() const; +#endif + + QPlatformInputContext *inputContext() const; + QPlatformNativeInterface *nativeInterface() const; + QPlatformServices *services() const; + +#ifndef QT_NO_ACCESSIBILITY + virtual QPlatformAccessibility *accessibility() const; +#endif + + QVariant styleHint(StyleHint hint) const; + Qt::WindowState defaultWindowState(Qt::WindowFlags flags) const; + + QStringList themeNames() const; + QPlatformTheme *createPlatformTheme(const QString &name) const; + + static void setDefaultDisplayMetrics(int gw, int gh, int sw, int sh); + static void setDefaultDesktopSize(int gw, int gh); + static void setScreenOrientation(Qt::ScreenOrientation currentOrientation, + Qt::ScreenOrientation nativeOrientation); + + static QSize defaultDesktopSize() + { + return QSize(m_defaultGeometryWidth, m_defaultGeometryHeight); + } + + QTouchDevice *touchDevice() const { return m_touchDevice; } + void setTouchDevice(QTouchDevice *touchDevice) { m_touchDevice = touchDevice; } + +private: + EGLDisplay m_eglDisplay; + + QTouchDevice *m_touchDevice; + + QAndroidPlatformScreen *m_primaryScreen; + + QThread *m_mainThread; + + static int m_defaultGeometryWidth; + static int m_defaultGeometryHeight; + static int m_defaultPhysicalSizeWidth; + static int m_defaultPhysicalSizeHeight; + + static Qt::ScreenOrientation m_orientation; + static Qt::ScreenOrientation m_nativeOrientation; + + QPlatformFontDatabase *m_androidFDB; + QImage *m_FbScreenImage; + QPainter *m_compositePainter; + QAndroidPlatformNativeInterface *m_androidPlatformNativeInterface; + QAndroidPlatformServices *m_androidPlatformServices; + QPlatformClipboard *m_androidPlatformClipboard; + QAndroidSystemLocale *m_androidSystemLocale; +#ifndef QT_NO_ACCESSIBILITY + mutable QPlatformAccessibility *m_accessibility; +#endif + + mutable QAndroidInputContext m_platformInputContext; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/android/qandroidplatformmenu.cpp b/src/plugins/platforms/android/qandroidplatformmenu.cpp new file mode 100644 index 0000000000..1ecabb25e2 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformmenu.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformmenu.h" +#include "qandroidplatformmenuitem.h" +#include "androidjnimenu.h" + +QAndroidPlatformMenu::QAndroidPlatformMenu() +{ + m_tag = reinterpret_cast(this); // QMenu will overwrite this later, but we need a unique ID for QtQuick + m_enabled = true; + m_isVisible = true; +} + +QAndroidPlatformMenu::~QAndroidPlatformMenu() +{ + QtAndroidMenu::androidPlatformMenuDestroyed(this); +} + +void QAndroidPlatformMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) +{ + QMutexLocker lock(&m_menuItemsMutex); + m_menuItems.insert(qFind(m_menuItems.begin(), + m_menuItems.end(), + static_cast(before)), + static_cast(menuItem)); +} + +void QAndroidPlatformMenu::removeMenuItem(QPlatformMenuItem *menuItem) +{ + QMutexLocker lock(&m_menuItemsMutex); + PlatformMenuItemsType::iterator it = qFind(m_menuItems.begin(), + m_menuItems.end(), + static_cast(menuItem)); + if (it != m_menuItems.end()) + m_menuItems.erase(it); +} + +void QAndroidPlatformMenu::syncMenuItem(QPlatformMenuItem *menuItem) +{ + PlatformMenuItemsType::iterator it; + for (it = m_menuItems.begin(); it != m_menuItems.end(); ++it) { + if ((*it)->tag() == menuItem->tag()) + break; + } + + if (it != m_menuItems.end()) + QtAndroidMenu::syncMenu(this); +} + +void QAndroidPlatformMenu::syncSeparatorsCollapsible(bool enable) +{ + Q_UNUSED(enable) +} + +void QAndroidPlatformMenu::setTag(quintptr tag) +{ + m_tag = tag; +} + +quintptr QAndroidPlatformMenu::tag() const +{ + return m_tag; +} + +void QAndroidPlatformMenu::setText(const QString &text) +{ + m_text = text; +} + +QString QAndroidPlatformMenu::text() const +{ + return m_text; +} + +void QAndroidPlatformMenu::setIcon(const QIcon &icon) +{ + m_icon = icon; +} + +QIcon QAndroidPlatformMenu::icon() const +{ + return m_icon; +} + +void QAndroidPlatformMenu::setEnabled(bool enabled) +{ + m_enabled = enabled; +} + +bool QAndroidPlatformMenu::isEnabled() const +{ + return m_enabled; +} + +void QAndroidPlatformMenu::setVisible(bool visible) +{ + m_isVisible = visible; +} + +bool QAndroidPlatformMenu::isVisible() const +{ + return m_isVisible; +} + +void QAndroidPlatformMenu::showPopup(const QWindow *parentWindow, QPoint pos, const QPlatformMenuItem *item) +{ + Q_UNUSED(parentWindow); + Q_UNUSED(pos); + Q_UNUSED(item); + setVisible(true); + QtAndroidMenu::showContextMenu(this); +} + +QPlatformMenuItem *QAndroidPlatformMenu::menuItemAt(int position) const +{ + if (position < m_menuItems.size()) + return m_menuItems[position]; + return 0; +} + +QPlatformMenuItem *QAndroidPlatformMenu::menuItemForTag(quintptr tag) const +{ + foreach (QPlatformMenuItem *menuItem, m_menuItems) { + if (menuItem->tag() == tag) + return menuItem; + } + return 0; +} + +QAndroidPlatformMenu::PlatformMenuItemsType QAndroidPlatformMenu::menuItems() const +{ + return m_menuItems; +} + +QMutex *QAndroidPlatformMenu::menuItemsMutex() +{ + return &m_menuItemsMutex; +} diff --git a/src/plugins/platforms/android/qandroidplatformmenu.h b/src/plugins/platforms/android/qandroidplatformmenu.h new file mode 100644 index 0000000000..305b64168a --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformmenu.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMMENU_H +#define QANDROIDPLATFORMMENU_H + +#include +#include +#include + +class QAndroidPlatformMenuItem; +class QAndroidPlatformMenu: public QPlatformMenu +{ +public: + typedef QVector PlatformMenuItemsType; + +public: + QAndroidPlatformMenu(); + ~QAndroidPlatformMenu(); + + void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before); + void removeMenuItem(QPlatformMenuItem *menuItem); + void syncMenuItem(QPlatformMenuItem *menuItem); + void syncSeparatorsCollapsible(bool enable); + + void setTag(quintptr tag); + quintptr tag() const; + void setText(const QString &text); + QString text() const; + void setIcon(const QIcon &icon); + QIcon icon() const; + void setEnabled(bool enabled); + bool isEnabled() const; + void setVisible(bool visible); + bool isVisible() const; + void showPopup(const QWindow *parentWindow, QPoint pos, const QPlatformMenuItem *item); + + QPlatformMenuItem *menuItemAt(int position) const; + QPlatformMenuItem *menuItemForTag(quintptr tag) const; + + PlatformMenuItemsType menuItems() const; + QMutex *menuItemsMutex(); + +private: + PlatformMenuItemsType m_menuItems; + quintptr m_tag; + QString m_text; + QIcon m_icon; + bool m_enabled; + bool m_isVisible; + QMutex m_menuItemsMutex; +}; + +#endif // QANDROIDPLATFORMMENU_H diff --git a/src/plugins/platforms/android/qandroidplatformmenubar.cpp b/src/plugins/platforms/android/qandroidplatformmenubar.cpp new file mode 100644 index 0000000000..134062fb32 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformmenubar.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformmenubar.h" +#include "qandroidplatformmenu.h" +#include "androidjnimenu.h" + + +QAndroidPlatformMenuBar::QAndroidPlatformMenuBar() +{ + m_parentWindow = 0; + QtAndroidMenu::addMenuBar(this); +} + +QAndroidPlatformMenuBar::~QAndroidPlatformMenuBar() +{ + QtAndroidMenu::removeMenuBar(this); +} + +void QAndroidPlatformMenuBar::insertMenu(QPlatformMenu *menu, QPlatformMenu *before) +{ + QMutexLocker lock(&m_menusListMutex); + m_menus.insert(qFind(m_menus.begin(), + m_menus.end(), + static_cast(before)), + static_cast(menu)); +} + +void QAndroidPlatformMenuBar::removeMenu(QPlatformMenu *menu) +{ + QMutexLocker lock(&m_menusListMutex); + m_menus.erase(qFind(m_menus.begin(), + m_menus.end(), + static_cast(menu))); +} + +void QAndroidPlatformMenuBar::syncMenu(QPlatformMenu *menu) +{ + QtAndroidMenu::syncMenu(static_cast(menu)); +} + +void QAndroidPlatformMenuBar::handleReparent(QWindow *newParentWindow) +{ + if (m_parentWindow == newParentWindow) + return; + m_parentWindow = newParentWindow; + QtAndroidMenu::setMenuBar(this, newParentWindow); +} + +QPlatformMenu *QAndroidPlatformMenuBar::menuForTag(quintptr tag) const +{ + foreach (QPlatformMenu *menu, m_menus) { + if (menu->tag() == tag) + return menu; + } + + return 0; +} + +QWindow *QAndroidPlatformMenuBar::parentWindow() const +{ + return m_parentWindow; +} + +QAndroidPlatformMenuBar::PlatformMenusType QAndroidPlatformMenuBar::menus() const +{ + return m_menus; +} + +QMutex *QAndroidPlatformMenuBar::menusListMutex() +{ + return &m_menusListMutex; +} diff --git a/src/plugins/platforms/android/qandroidplatformmenubar.h b/src/plugins/platforms/android/qandroidplatformmenubar.h new file mode 100644 index 0000000000..56915335c2 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformmenubar.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMMENUBAR_H +#define QANDROIDPLATFORMMENUBAR_H + +#include +#include +#include + +class QAndroidPlatformMenu; +class QAndroidPlatformMenuBar: public QPlatformMenuBar +{ +public: + typedef QVector PlatformMenusType; +public: + QAndroidPlatformMenuBar(); + ~QAndroidPlatformMenuBar(); + + void insertMenu(QPlatformMenu *menu, QPlatformMenu *before); + void removeMenu(QPlatformMenu *menu); + void syncMenu(QPlatformMenu *menu); + void handleReparent(QWindow *newParentWindow); + QPlatformMenu *menuForTag(quintptr tag) const; + + QWindow *parentWindow() const; + PlatformMenusType menus() const; + QMutex *menusListMutex(); + +private: + PlatformMenusType m_menus; + QWindow *m_parentWindow; + QMutex m_menusListMutex; +}; + +#endif // QANDROIDPLATFORMMENUBAR_H diff --git a/src/plugins/platforms/android/qandroidplatformmenuitem.cpp b/src/plugins/platforms/android/qandroidplatformmenuitem.cpp new file mode 100644 index 0000000000..bd37834d2a --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformmenuitem.cpp @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformmenuitem.h" +#include "qandroidplatformmenu.h" + +QAndroidPlatformMenuItem::QAndroidPlatformMenuItem() +{ + m_tag = reinterpret_cast(this); // QMenu will overwrite this later, but we need a unique ID for QtQuick + m_menu = 0; + m_isVisible = true; + m_isSeparator = false; + m_role = NoRole; + m_isCheckable = false; + m_isChecked = false; + m_isEnabled = true; +} + +void QAndroidPlatformMenuItem::setTag(quintptr tag) +{ + m_tag = tag; +} + +quintptr QAndroidPlatformMenuItem::tag() const +{ + return m_tag; +} + +void QAndroidPlatformMenuItem::setText(const QString &text) +{ + m_text = text; + if (m_menu) + m_menu->setText(m_text); +} + +QString QAndroidPlatformMenuItem::text() const +{ + return m_text; +} + +void QAndroidPlatformMenuItem::setIcon(const QIcon &icon) +{ + m_icon = icon; + if (m_menu) + m_menu->setIcon(m_icon); +} + +QIcon QAndroidPlatformMenuItem::icon() const +{ + return m_icon; +} + +void QAndroidPlatformMenuItem::setMenu(QPlatformMenu *menu) +{ + m_menu = static_cast(menu); + if (!m_menu) + return; + + m_menu->setText(m_text); + m_menu->setIcon(m_icon); + m_menu->setVisible(m_isVisible); + m_menu->setEnabled(m_isEnabled); +} + +QAndroidPlatformMenu *QAndroidPlatformMenuItem::menu() const +{ + return m_menu; +} + +void QAndroidPlatformMenuItem::setVisible(bool isVisible) +{ + m_isVisible = isVisible; + if (m_menu) + m_menu->setVisible(m_isVisible); +} + +bool QAndroidPlatformMenuItem::isVisible() const +{ + return m_isVisible; +} + +void QAndroidPlatformMenuItem::setIsSeparator(bool isSeparator) +{ + m_isSeparator = isSeparator; +} + +bool QAndroidPlatformMenuItem::isSeparator() const +{ + return m_isSeparator; +} + +void QAndroidPlatformMenuItem::setFont(const QFont &font) +{ + Q_UNUSED(font) +} + +void QAndroidPlatformMenuItem::setRole(QPlatformMenuItem::MenuRole role) +{ + m_role = role; +} + +QPlatformMenuItem::MenuRole QAndroidPlatformMenuItem::role() const +{ + return m_role; +} + +void QAndroidPlatformMenuItem::setCheckable(bool checkable) +{ + m_isCheckable = checkable; +} + +bool QAndroidPlatformMenuItem::isCheckable() const +{ + return m_isCheckable; +} + +void QAndroidPlatformMenuItem::setChecked(bool isChecked) +{ + m_isChecked = isChecked; +} + +bool QAndroidPlatformMenuItem::isChecked() const +{ + return m_isChecked; +} + +void QAndroidPlatformMenuItem::setShortcut(const QKeySequence &shortcut) +{ + Q_UNUSED(shortcut) +} + +void QAndroidPlatformMenuItem::setEnabled(bool enabled) +{ + m_isEnabled = enabled; + if (m_menu) + m_menu->setEnabled(m_isEnabled); +} + +bool QAndroidPlatformMenuItem::isEnabled() const +{ + return m_isEnabled; +} diff --git a/src/plugins/platforms/android/qandroidplatformmenuitem.h b/src/plugins/platforms/android/qandroidplatformmenuitem.h new file mode 100644 index 0000000000..5861e8e195 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformmenuitem.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMMENUITEM_H +#define QANDROIDPLATFORMMENUITEM_H +#include + +class QAndroidPlatformMenu; + +class QAndroidPlatformMenuItem: public QPlatformMenuItem +{ +public: + QAndroidPlatformMenuItem(); + void setTag(quintptr tag); + quintptr tag() const; + + void setText(const QString &text); + QString text() const; + + void setIcon(const QIcon &icon); + QIcon icon() const; + + void setMenu(QPlatformMenu *menu); + QAndroidPlatformMenu *menu() const; + + void setVisible(bool isVisible); + bool isVisible() const; + + void setIsSeparator(bool isSeparator); + bool isSeparator() const; + + void setFont(const QFont &font); + + void setRole(MenuRole role); + MenuRole role() const; + + void setCheckable(bool checkable); + bool isCheckable() const; + + void setChecked(bool isChecked); + bool isChecked() const; + + void setShortcut(const QKeySequence &shortcut); + + void setEnabled(bool enabled); + bool isEnabled() const; + +private: + quintptr m_tag; + QString m_text; + QIcon m_icon; + QAndroidPlatformMenu *m_menu; + bool m_isVisible; + bool m_isSeparator; + MenuRole m_role; + bool m_isCheckable; + bool m_isChecked; + bool m_isEnabled; +}; + +#endif // QANDROIDPLATFORMMENUITEM_H diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp new file mode 100644 index 0000000000..d99cafe6b7 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformopenglcontext.h" +#include "qandroidplatformopenglwindow.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +QAndroidPlatformOpenGLContext::QAndroidPlatformOpenGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display) + :QEGLPlatformContext(format, share, display, EGL_OPENGL_ES_API) +{ +} + +void QAndroidPlatformOpenGLContext::swapBuffers(QPlatformSurface *surface) +{ + QEGLPlatformContext::swapBuffers(surface); + + if (surface->surface()->surfaceClass() == QSurface::Window) + static_cast(surface)->checkNativeSurface(eglConfig()); +} + +bool QAndroidPlatformOpenGLContext::makeCurrent(QPlatformSurface *surface) +{ + bool ret = QEGLPlatformContext::makeCurrent(surface); + + const char *rendererString = reinterpret_cast(glGetString(GL_RENDERER)); + if (rendererString != 0 && qstrncmp(rendererString, "Android Emulator", 16) == 0) { + QOpenGLContextPrivate *ctx_d = QOpenGLContextPrivate::get(context()); + ctx_d->workaround_missingPrecisionQualifiers = true; + } + + return ret; +} + +EGLSurface QAndroidPlatformOpenGLContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface) +{ + if (surface->surface()->surfaceClass() == QSurface::Window) + return static_cast(surface)->eglSurface(eglConfig()); + return EGL_NO_SURFACE; +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.h b/src/plugins/platforms/android/qandroidplatformopenglcontext.h new file mode 100644 index 0000000000..29e5f596d5 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMOPENGLCONTEXT_H +#define QANDROIDPLATFORMOPENGLCONTEXT_H + +#include + +QT_BEGIN_NAMESPACE + +class QAndroidPlatformOpenGLContext : public QEGLPlatformContext +{ +public: + QAndroidPlatformOpenGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display); + void swapBuffers(QPlatformSurface *surface); + bool makeCurrent(QPlatformSurface *surface); + +private: + virtual EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface); +}; + +QT_END_NAMESPACE + +#endif // QANDROIDPLATFORMOPENGLCONTEXT_H diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp new file mode 100644 index 0000000000..498f59be88 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformopenglwindow.h" + +#include "androidjnimain.h" + +#include + +#include + +#include +#include + +#warning remove me +#include + +QT_BEGIN_NAMESPACE + +QAndroidPlatformOpenGLWindow::QAndroidPlatformOpenGLWindow(QWindow *window, EGLDisplay display) + :QAndroidPlatformWindow(window), m_eglDisplay(display) +{ + lockSurface(); + m_nativeSurfaceId = QtAndroid::createSurface(this, geometry(), bool(window->flags() & Qt::WindowStaysOnTopHint)); + m_surfaceWaitCondition.wait(&m_surfaceMutex); + unlockSurface(); +} + +QAndroidPlatformOpenGLWindow::~QAndroidPlatformOpenGLWindow() +{ + m_surfaceWaitCondition.wakeOne(); + lockSurface(); + if (m_nativeSurfaceId != -1) + QtAndroid::destroySurface(m_nativeSurfaceId); + clearEgl(); + unlockSurface(); +} + +void QAndroidPlatformOpenGLWindow::setGeometry(const QRect &rect) +{ + if (rect == geometry()) + return; + + qDebug() << rect; + QAndroidPlatformWindow::setGeometry(rect); + QtAndroid::setSurfaceGeometry(m_nativeSurfaceId, rect); +} + +EGLSurface QAndroidPlatformOpenGLWindow::eglSurface(EGLConfig config) +{ + QMutexLocker lock(&m_surfaceMutex); + if (m_eglSurface == EGL_NO_SURFACE) { + m_surfaceMutex.unlock(); + checkNativeSurface(config); + m_surfaceMutex.lock(); + } + return m_eglSurface; +} + +void QAndroidPlatformOpenGLWindow::checkNativeSurface(EGLConfig config) +{ + QMutexLocker lock(&m_surfaceMutex); + qDebug() << geometry() << m_changedAndroidSurface.isValid(); + if (m_nativeSurfaceId == -1 || !m_changedAndroidSurface.isValid()) + return; + + createEgl(config); + + // we've create another surface, the window should be repainted + QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); +} + +void QAndroidPlatformOpenGLWindow::createEgl(EGLConfig config) +{ + clearEgl(); + m_androidSurface = QJNIObjectPrivate(); + m_androidSurface = m_changedAndroidSurface; + m_changedAndroidSurface = QJNIObjectPrivate(); + QJNIEnvironmentPrivate env; + m_nativeWindow = ANativeWindow_fromSurface(env, m_androidSurface.object()); + if (m_nativeWindow) + ANativeWindow_acquire(m_nativeWindow); + + m_eglSurface = eglCreateWindowSurface(m_eglDisplay, config, m_nativeWindow, NULL); + if (m_eglSurface == EGL_NO_SURFACE) { + EGLint error = eglGetError(); + eglTerminate(m_eglDisplay); + qFatal("EGL Error : Could not create the egl surface: error = 0x%x\n", error); + } +} + +void QAndroidPlatformOpenGLWindow::clearEgl() +{ + eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (m_eglSurface != EGL_NO_SURFACE) { + eglDestroySurface(m_eglDisplay, m_eglSurface); + m_eglSurface = EGL_NO_SURFACE; + } + + if (m_nativeWindow) { + ANativeWindow_release(m_nativeWindow); + m_nativeWindow = 0; + } +} + +void QAndroidPlatformOpenGLWindow::surfaceChanged(JNIEnv *jniEnv, jobject surface, int w, int h) +{ + Q_UNUSED(jniEnv); + Q_UNUSED(w); + Q_UNUSED(h); + qDebug() << w << h; + lockSurface(); + m_changedAndroidSurface = surface; + m_surfaceWaitCondition.wakeOne(); + unlockSurface(); + + // repaint the window + QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.h b/src/plugins/platforms/android/qandroidplatformopenglwindow.h new file mode 100644 index 0000000000..820453ab01 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMOPENGLWINDOW_H +#define QANDROIDPLATFORMOPENGLWINDOW_H + +#include +#include +#include + +#include "androidsurfaceclient.h" +#include "qandroidplatformwindow.h" + +QT_BEGIN_NAMESPACE + +class QAndroidPlatformOpenGLWindow : public QAndroidPlatformWindow, public AndroidSurfaceClient +{ +public: + explicit QAndroidPlatformOpenGLWindow(QWindow *window, EGLDisplay display); + ~QAndroidPlatformOpenGLWindow(); + + void setGeometry(const QRect &rect); + EGLSurface eglSurface(EGLConfig config); + + void checkNativeSurface(EGLConfig config); + +protected: + virtual void surfaceChanged(JNIEnv *jniEnv, jobject surface, int w, int h); + void createEgl(EGLConfig config); + void clearEgl(); + +private: + EGLDisplay m_eglDisplay; + EGLSurface m_eglSurface = EGL_NO_SURFACE; + EGLNativeWindowType m_nativeWindow = nullptr; + + int m_nativeSurfaceId = -1; + QJNIObjectPrivate m_androidSurface; + QJNIObjectPrivate m_changedAndroidSurface; + QWaitCondition m_surfaceWaitCondition; +}; + +QT_END_NAMESPACE +#endif // QANDROIDPLATFORMOPENGLWINDOW_H diff --git a/src/plugins/platforms/android/qandroidplatformrasterwindow.cpp b/src/plugins/platforms/android/qandroidplatformrasterwindow.cpp new file mode 100644 index 0000000000..113a69427d --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformrasterwindow.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformrasterwindow.h" + +#include "qandroidplatformscreen.h" + +QT_BEGIN_NAMESPACE + +QAndroidPlatformRasterWindow::QAndroidPlatformRasterWindow(QWindow *window) + :QAndroidPlatformWindow(window) +{ + +} + +void QAndroidPlatformRasterWindow::repaint(const QRegion ®ion) +{ + QRect currentGeometry = geometry(); + + QRect dirtyClient = region.boundingRect(); + QRect dirtyRegion(currentGeometry.left() + dirtyClient.left(), + currentGeometry.top() + dirtyClient.top(), + dirtyClient.width(), + dirtyClient.height()); + QRect mOldGeometryLocal = m_oldGeometry; + m_oldGeometry = currentGeometry; + // If this is a move, redraw the previous location + if (mOldGeometryLocal != currentGeometry) + platformScreen()->setDirty(mOldGeometryLocal); + platformScreen()->setDirty(dirtyRegion); +} + +void QAndroidPlatformRasterWindow::setGeometry(const QRect &rect) +{ + m_oldGeometry = geometry(); + QAndroidPlatformWindow::setGeometry(rect); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformrasterwindow.h b/src/plugins/platforms/android/qandroidplatformrasterwindow.h new file mode 100644 index 0000000000..50c0d497af --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformrasterwindow.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMRASTERWINDOW_H +#define QANDROIDPLATFORMRASTERWINDOW_H + +#include "qandroidplatformwindow.h" +QT_BEGIN_NAMESPACE + +class QAndroidPlatformBackingStore; +class QAndroidPlatformRasterWindow : public QObject, public QAndroidPlatformWindow +{ + Q_OBJECT +public: + QAndroidPlatformRasterWindow(QWindow *window); + + void setBackingStore(QAndroidPlatformBackingStore *store) { m_backingStore = store; } + QAndroidPlatformBackingStore *backingStore() const { return m_backingStore; } + void repaint(const QRegion®ion); + +public slots: + void setGeometry(const QRect &rect); + +private: + QAndroidPlatformBackingStore *m_backingStore = nullptr; + QRect m_oldGeometry; + +}; + +QT_END_NAMESPACE +#endif // QANDROIDPLATFORMRASTERWINDOW_H diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp new file mode 100644 index 0000000000..4f956f7a4f --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp @@ -0,0 +1,352 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include + +#include "qandroidplatformscreen.h" +#include "qandroidplatformbackingstore.h" +#include "qandroidplatformintegration.h" +#include "androidjnimain.h" +#include "androidjnimenu.h" +#include "qandroidplatformrasterwindow.h" + +#include + +QT_BEGIN_NAMESPACE + +#warning REMOVE ME +class ScopedProfiler +{ +public: + ScopedProfiler(const QString &msg) + { + m_msg = msg; + } + ~ScopedProfiler() + { + qDebug() << m_msg << m_timer.elapsed(); + } + +private: + QTime m_timer; + QString m_msg; +}; + +#define PROFILE_SCOPE ScopedProfiler ___sp___(__func__) + +QAndroidPlatformScreen::QAndroidPlatformScreen():QObject(),QPlatformScreen() +{ + m_geometry = QRect(0, 0, QAndroidPlatformIntegration::m_defaultGeometryWidth, QAndroidPlatformIntegration::m_defaultGeometryHeight); + // Raster only apps should set QT_ANDROID_RASTER_IMAGE_DEPTH to 16 + // is way much faster than 32 + if (qgetenv("QT_ANDROID_RASTER_IMAGE_DEPTH").toInt() == 16) { + m_format = QImage::Format_RGB16; + m_depth = 16; + } else { + m_format = QImage::Format_RGBA8888; + m_depth = 32; + } + m_physicalSize.setHeight(QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight); + m_physicalSize.setWidth(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth); + m_redrawTimer.setSingleShot(true); + m_redrawTimer.setInterval(0); + connect(&m_redrawTimer, SIGNAL(timeout()), this, SLOT(doRedraw())); +} + +QAndroidPlatformScreen::~QAndroidPlatformScreen() +{ + if (m_id != -1) { + QtAndroid::destroySurface(m_id); + m_surfaceWaitCondition.wakeOne(); + if (m_bitmap) + QtAndroid::AttachedJNIEnv().jniEnv->DeleteGlobalRef(m_bitmap); + } +} + +QWindow *QAndroidPlatformScreen::topWindow() const +{ + foreach (QAndroidPlatformWindow *w, m_windowStack) + if (w->window()->type() == Qt::Window || w->window()->type() == Qt::Dialog) + return w->window(); + return 0; +} + +QWindow *QAndroidPlatformScreen::topLevelAt(const QPoint &p) const +{ + foreach (QAndroidPlatformWindow *w, m_windowStack) { + if (w->geometry().contains(p, false) && w->window()->isVisible()) + return w->window(); + } + return 0; +} + +void QAndroidPlatformScreen::addWindow(QAndroidPlatformWindow *window) +{ + m_windowStack.prepend(window); + if (window->isRaster()) + setDirty(window->geometry()); + + QWindow *w = topWindow(); + QWindowSystemInterface::handleWindowActivated(w); + topWindowChanged(w); +} + +void QAndroidPlatformScreen::removeWindow(QAndroidPlatformWindow *window) +{ + m_windowStack.removeOne(window); + if (window->isRaster()) { + setDirty(window->geometry()); + } + QWindow *w = topWindow(); + QWindowSystemInterface::handleWindowActivated(w); + topWindowChanged(w); +} + +void QAndroidPlatformScreen::raise(QAndroidPlatformWindow *window) +{ + int index = m_windowStack.indexOf(window); + if (index <= 0) + return; + m_windowStack.move(index, 0); + if (window->isRaster()) { + setDirty(window->geometry()); + } + QWindow *w = topWindow(); + QWindowSystemInterface::handleWindowActivated(w); + topWindowChanged(w); +} + +void QAndroidPlatformScreen::lower(QAndroidPlatformWindow *window) +{ + int index = m_windowStack.indexOf(window); + if (index == -1 || index == (m_windowStack.size() - 1)) + return; + m_windowStack.move(index, m_windowStack.size() - 1); + if (window->isRaster()) { + setDirty(window->geometry()); + } + QWindow *w = topWindow(); + QWindowSystemInterface::handleWindowActivated(w); + topWindowChanged(w); +} + +void QAndroidPlatformScreen::scheduleUpdate() +{ + if (!m_redrawTimer.isActive()) + m_redrawTimer.start(); +} + +void QAndroidPlatformScreen::setDirty(const QRect &rect) +{ + QRect intersection = rect.intersected(m_geometry); + QPoint screenOffset = m_geometry.topLeft(); + m_repaintRegion += intersection.translated(-screenOffset); // global to local translation + scheduleUpdate(); +} + +void QAndroidPlatformScreen::setPhysicalSize(const QSize &size) +{ + m_physicalSize = size; +} + +void QAndroidPlatformScreen::setGeometry(const QRect &rect) +{ + QMutexLocker lock(&m_surfaceMutex); + if (m_geometry == rect) + return; + + m_geometry = rect; + QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), geometry()); + QWindowSystemInterface::handleScreenAvailableGeometryChange(QPlatformScreen::screen(), availableGeometry()); + resizeMaximizedWindows(); + + if (m_id != -1) { + if (m_bitmap) { + QtAndroid::AttachedJNIEnv().jniEnv->DeleteGlobalRef(m_bitmap); + m_bitmap = 0; + } + QtAndroid::setSurfaceGeometry(m_id, rect); + } +} + +void QAndroidPlatformScreen::topWindowChanged(QWindow *w) +{ + QtAndroidMenu::setActiveTopLevelWindow(w); + + if (w != 0) { + QAndroidPlatformWindow *platformWindow = static_cast(w->handle()); + if (platformWindow != 0) + platformWindow->updateStatusBarVisibility(); + } +} + +void QAndroidPlatformScreen::doRedraw() +{ + PROFILE_SCOPE; + + if (m_repaintRegion.isEmpty()) + return; + + QVector rects = m_repaintRegion.rects(); + + QMutexLocker lock(&m_surfaceMutex); + if (m_id == -1) { + m_id = QtAndroid::createSurface(this, m_geometry, true); + m_surfaceWaitCondition.wait(&m_surfaceMutex); + } + + if (!m_bitmap || !m_surface.isValid()) + return; + + QJNIEnvironmentPrivate env; + if (!env) + return; + + int ret; + void *pixels; + + if ((ret = AndroidBitmap_lockPixels(env, m_bitmap, &pixels)) < 0) { + qWarning() << "AndroidBitmap_lockPixels() failed! error=" << ret; + return; + } + + QImage mScreenImage(reinterpret_cast(pixels), m_bitmapWidth, m_bitmapHeight, m_bitmapStride, m_format); + QPainter mCompositePainter(&mScreenImage); + + for (int rectIndex = 0; rectIndex < rects.size(); rectIndex++) { + QRegion visibleRegion = rects[rectIndex]; + foreach (QAndroidPlatformWindow *window, m_windowStack) { + if (!window->window()->isVisible() + || !window->isRaster()) + continue; + + foreach (const QRect &rect, visibleRegion.rects()) { + QRect targetRect = window->geometry(); + targetRect &= rect; + + if (targetRect.isNull()) + continue; + + visibleRegion -= targetRect; + QRect windowRect = targetRect.translated(-window->geometry().topLeft()); + QAndroidPlatformBackingStore *backingStore = static_cast(window)->backingStore(); + if (backingStore) + mCompositePainter.drawImage(targetRect, backingStore->image(), windowRect); + } + } + + foreach (const QRect &rect, visibleRegion.rects()) + mCompositePainter.fillRect(rect, Qt::transparent); + } + + + QRect br = m_repaintRegion.boundingRect(); + m_repaintRegion = QRegion(); + AndroidBitmap_unlockPixels(env, m_bitmap); + + QJNIObjectPrivate jrect("android.graphics.Rect", "(IIII)V", + jint(br.left()), + jint(br.top()), + jint(br.right() + 1), + jint(br.bottom() + 1)); + + QJNIObjectPrivate canvas = m_surface.callObjectMethod("lockCanvas", + "(Landroid/graphics/Rect;)Landroid/graphics/Canvas;", + jrect.object()); + if (!canvas.isValid()) { + qWarning() << "Can't lockCanvas"; + return; + } + canvas.callMethod("drawBitmap", + "(Landroid/graphics/Bitmap;Landroid/graphics/Rect;Landroid/graphics/Rect;Landroid/graphics/Paint;)V", + m_bitmap, jrect.object(), jrect.object(), jobject(0)); + + m_surface.callMethod("unlockCanvasAndPost", "(Landroid/graphics/Canvas;)V", canvas.object()); +} + +QDpi QAndroidPlatformScreen::logicalDpi() const +{ + qreal lDpi = QtAndroid::scaledDensity() * 72; + return QDpi(lDpi, lDpi); +} + +Qt::ScreenOrientation QAndroidPlatformScreen::orientation() const +{ + return QAndroidPlatformIntegration::m_orientation; +} + +Qt::ScreenOrientation QAndroidPlatformScreen::nativeOrientation() const +{ + return QAndroidPlatformIntegration::m_nativeOrientation; +} + +void QAndroidPlatformScreen::surfaceChanged(JNIEnv *env, jobject surface, int w, int h) +{ + lockSurface(); + m_surface = surface; + + if (surface && w && h) { + if (w != m_bitmapWidth || h != m_bitmapHeight) { + if (m_bitmap) + env->DeleteGlobalRef(m_bitmap); + m_bitmap = env->NewGlobalRef(QtAndroid::createBitmap(w, h, m_format, env)); + AndroidBitmapInfo info; + int res = AndroidBitmap_getInfo(env, m_bitmap, &info); + Q_ASSERT(res > -1); + m_bitmapStride = info.stride; + m_bitmapWidth = info.width; + m_bitmapHeight = info.height; + } + } else { + if (m_bitmap) { + env->DeleteGlobalRef(m_bitmap); + m_bitmap = 0; + } + } + unlockSurface(); + m_surfaceWaitCondition.wakeOne(); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformscreen.h b/src/plugins/platforms/android/qandroidplatformscreen.h new file mode 100644 index 0000000000..2310b31a51 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformscreen.h @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMSCREEN_H +#define QANDROIDPLATFORMSCREEN_H + +#include +#include +#include +#include +#include +#include + +#include "androidsurfaceclient.h" + +QT_BEGIN_NAMESPACE + +class QAndroidPlatformWindow; +class QAndroidPlatformBackingStore; + +class QAndroidPlatformScreen: public QObject, public QPlatformScreen, public AndroidSurfaceClient +{ + Q_OBJECT +public: + QAndroidPlatformScreen(); + ~QAndroidPlatformScreen(); + + QRect geometry() const { return m_geometry; } + int depth() const { return m_depth; } + QImage::Format format() const { return m_format; } + QSizeF physicalSize() const { return m_physicalSize; } + + inline QWindow *topWindow() const; + QWindow *topLevelAt(const QPoint & p) const; + + // compositor api + void addWindow(QAndroidPlatformWindow *window); + void removeWindow(QAndroidPlatformWindow *window); + void raise(QAndroidPlatformWindow *window); + void lower(QAndroidPlatformWindow *window); + + void scheduleUpdate(); + void topWindowChanged(QWindow *w); + +public slots: + void setDirty(const QRect &rect); + void setPhysicalSize(const QSize &size); + void setGeometry(const QRect &rect); + +protected: + typedef QList WindowStackType; + WindowStackType m_windowStack; + QRegion m_repaintRegion; + QTimer m_redrawTimer; + + QRect m_geometry; + int m_depth; + QImage::Format m_format; + QSizeF m_physicalSize; + +private: + QDpi logicalDpi() const; + Qt::ScreenOrientation orientation() const; + Qt::ScreenOrientation nativeOrientation() const; + void surfaceChanged(JNIEnv *env, jobject surface, int w, int h); + +private slots: + void doRedraw(); + +private: + int m_id = -1; + QJNIObjectPrivate m_surface; + jobject m_bitmap = nullptr; + QWaitCondition m_surfaceWaitCondition; + int m_bitmapStride = -1; + int m_bitmapWidth = -1; + int m_bitmapHeight = -1; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/plugins/platforms/android/qandroidplatformservices.cpp b/src/plugins/platforms/android/qandroidplatformservices.cpp new file mode 100644 index 0000000000..0df882f1f0 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformservices.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformservices.h" +#include +#include +#include + +QAndroidPlatformServices::QAndroidPlatformServices() +{ + QtAndroid::AttachedJNIEnv env; + if (!env.jniEnv) + return; + + m_openURIMethodID = env.jniEnv->GetStaticMethodID(QtAndroid::applicationClass(), + "openURL", + "(Ljava/lang/String;)V"); +} + +bool QAndroidPlatformServices::openUrl(const QUrl &url) +{ + QtAndroid::AttachedJNIEnv env; + if (!env.jniEnv) + return false; + + jstring string = env.jniEnv->NewString(reinterpret_cast(url.toString().constData()), + url.toString().length()); + env.jniEnv->CallStaticVoidMethod(QtAndroid::applicationClass(), m_openURIMethodID, string); + env.jniEnv->DeleteLocalRef(string); + return true; +} + +bool QAndroidPlatformServices::openDocument(const QUrl &url) +{ + return openUrl(url); +} + +QByteArray QAndroidPlatformServices::desktopEnvironment() const +{ + return QByteArray("Android"); +} diff --git a/src/plugins/platforms/android/qandroidplatformservices.h b/src/plugins/platforms/android/qandroidplatformservices.h new file mode 100644 index 0000000000..8368b19043 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformservices.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDPLATFORMDESKTOPSERVICE_H +#define ANDROIDPLATFORMDESKTOPSERVICE_H + +#include +#include "androidjnimain.h" +#include + +class QAndroidPlatformServices: public QPlatformServices +{ +public: + QAndroidPlatformServices(); + bool openUrl(const QUrl &url); + bool openDocument(const QUrl &url); + QByteArray desktopEnvironment() const; +private: + jmethodID m_openURIMethodID; + +}; + +#endif // ANDROIDPLATFORMDESKTOPSERVICE_H diff --git a/src/plugins/platforms/android/qandroidplatformtheme.cpp b/src/plugins/platforms/android/qandroidplatformtheme.cpp new file mode 100644 index 0000000000..308bb70faf --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformtheme.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformtheme.h" +#include "qandroidplatformmenubar.h" +#include "qandroidplatformmenu.h" +#include "qandroidplatformmenuitem.h" +#include "qandroidplatformdialoghelpers.h" +#include +#include +#include + +QAndroidPlatformTheme::QAndroidPlatformTheme(QAndroidPlatformNativeInterface *androidPlatformNativeInterface) +{ + m_androidPlatformNativeInterface = androidPlatformNativeInterface; +} + +QPlatformMenuBar *QAndroidPlatformTheme::createPlatformMenuBar() const +{ + return new QAndroidPlatformMenuBar; +} + +QPlatformMenu *QAndroidPlatformTheme::createPlatformMenu() const +{ + return new QAndroidPlatformMenu; +} + +QPlatformMenuItem *QAndroidPlatformTheme::createPlatformMenuItem() const +{ + return new QAndroidPlatformMenuItem; +} + +static inline int paletteType(QPlatformTheme::Palette type) +{ + switch (type) { + case QPlatformTheme::ToolButtonPalette: + case QPlatformTheme::ButtonPalette: + return QPlatformTheme::ButtonPalette; + + case QPlatformTheme::CheckBoxPalette: + return QPlatformTheme::CheckBoxPalette; + + case QPlatformTheme::RadioButtonPalette: + return QPlatformTheme::RadioButtonPalette; + + case QPlatformTheme::ComboBoxPalette: + return QPlatformTheme::ComboBoxPalette; + + case QPlatformTheme::TextEditPalette: + case QPlatformTheme::TextLineEditPalette: + return QPlatformTheme::TextLineEditPalette; + + case QPlatformTheme::ItemViewPalette: + return QPlatformTheme::ItemViewPalette; + + default: + return QPlatformTheme::SystemPalette; + } +} + +const QPalette *QAndroidPlatformTheme::palette(Palette type) const +{ + QHash::const_iterator it = m_androidPlatformNativeInterface->m_palettes.find(paletteType(type)); + if (it != m_androidPlatformNativeInterface->m_palettes.end()) + return &(it.value()); + return 0; +} + +static inline int fontType(QPlatformTheme::Font type) +{ + switch (type) { + case QPlatformTheme::LabelFont: + return QPlatformTheme::SystemFont; + + case QPlatformTheme::ToolButtonFont: + return QPlatformTheme::PushButtonFont; + + default: + return type; + } +} + +const QFont *QAndroidPlatformTheme::font(Font type) const +{ + QHash::const_iterator it = m_androidPlatformNativeInterface->m_fonts.find(fontType(type)); + if (it != m_androidPlatformNativeInterface->m_fonts.end()) + return &(it.value()); + + // default in case the style has not set a font + static QFont systemFont("Roboto", 14.0 * 100 / 72); // keep default size the same after changing from 100 dpi to 72 dpi + if (type == QPlatformTheme::SystemFont) + return &systemFont; + return 0; +} + +static const QLatin1String STYLES_PATH("/data/data/org.kde.necessitas.ministro/files/dl/style/"); +static const QLatin1String STYLE_FILE("/style.json"); + +QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const +{ + switch (hint) { + case StyleNames: + if (qgetenv("QT_USE_ANDROID_NATIVE_STYLE").toInt() + && (!qgetenv("MINISTRO_ANDROID_STYLE_PATH").isEmpty() + || QFileInfo(STYLES_PATH + + QLatin1String(qgetenv("QT_ANDROID_THEME_DISPLAY_DPI")) + + STYLE_FILE).exists())) { + return QStringList("android"); + } + return QStringList("fusion"); + break; + default: + return QPlatformTheme::themeHint(hint); + } +} + +bool QAndroidPlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const +{ + if (type == MessageDialog) + return qgetenv("QT_USE_ANDROID_NATIVE_DIALOGS").toInt() == 1; + return false; +} + +QPlatformDialogHelper *QAndroidPlatformTheme::createPlatformDialogHelper(QPlatformTheme::DialogType type) const +{ + switch (type) { + case MessageDialog: + return new QtAndroidDialogHelpers::QAndroidPlatformMessageDialogHelper; + default: + return 0; + } +} diff --git a/src/plugins/platforms/android/qandroidplatformtheme.h b/src/plugins/platforms/android/qandroidplatformtheme.h new file mode 100644 index 0000000000..ec259a9b0a --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformtheme.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMTHEME_H +#define QANDROIDPLATFORMTHEME_H + +#include +class QAndroidPlatformNativeInterface; +class QAndroidPlatformTheme: public QPlatformTheme +{ +public: + QAndroidPlatformTheme(QAndroidPlatformNativeInterface * androidPlatformNativeInterface); + virtual QPlatformMenuBar *createPlatformMenuBar() const; + virtual QPlatformMenu *createPlatformMenu() const; + virtual QPlatformMenuItem *createPlatformMenuItem() const; + virtual const QPalette *palette(Palette type = SystemPalette) const; + virtual const QFont *font(Font type = SystemFont) const; + virtual QVariant themeHint(ThemeHint hint) const; + virtual bool usePlatformNativeDialog(DialogType type) const; + virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const; + + +private: + QAndroidPlatformNativeInterface * m_androidPlatformNativeInterface; +}; + +#endif // QANDROIDPLATFORMTHEME_H diff --git a/src/plugins/platforms/android/qandroidplatformwindow.cpp b/src/plugins/platforms/android/qandroidplatformwindow.cpp new file mode 100644 index 0000000000..7c2dfd6bac --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformwindow.cpp @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformwindow.h" +#include "qandroidplatformopenglcontext.h" +#include "qandroidplatformscreen.h" + +#include "androidjnimain.h" +#include + +QT_BEGIN_NAMESPACE + +QAndroidPlatformWindow::QAndroidPlatformWindow(QWindow *window) + : QPlatformWindow(window) +{ + m_windowFlags = Qt::Widget; + m_windowState = Qt::WindowNoState; + static QAtomicInt winIdGenerator(1); + m_windowId = winIdGenerator.fetchAndAddRelaxed(1); + setWindowState(window->windowState()); +} + +void QAndroidPlatformWindow::lower() +{ + platformScreen()->lower(this); +} + +void QAndroidPlatformWindow::raise() +{ + updateStatusBarVisibility(); + platformScreen()->raise(this); +} + +void QAndroidPlatformWindow::setGeometry(const QRect &rect) +{ + QWindowSystemInterface::handleGeometryChange(window(), rect); + QPlatformWindow::setGeometry(rect); +} + +void QAndroidPlatformWindow::setVisible(bool visible) +{ + if (visible) + updateStatusBarVisibility(); + + if (visible) { + if (m_windowState & Qt::WindowFullScreen) + setGeometry(platformScreen()->geometry()); + else if (m_windowState & Qt::WindowMaximized) + setGeometry(platformScreen()->availableGeometry()); + } + + QPlatformWindow::setVisible(visible); + + if (visible) + platformScreen()->addWindow(this); + else + platformScreen()->removeWindow(this); + + // The Android Activity is activated before Qt is initialized, causing the application state to + // never be set to 'active'. We explicitly set this state when the first window becomes visible. + if (visible) + QtAndroid::setApplicationActive(); +} + +void QAndroidPlatformWindow::setWindowState(Qt::WindowState state) +{ + if (m_windowState == state) + return; + + QPlatformWindow::setWindowState(state); + m_windowState = state; + + if (window()->isVisible()) + updateStatusBarVisibility(); +} + +void QAndroidPlatformWindow::setWindowFlags(Qt::WindowFlags flags) +{ + if (m_windowFlags == flags) + return; + + m_windowFlags = flags; +} + +Qt::WindowFlags QAndroidPlatformWindow::windowFlags() const +{ + return m_windowFlags; +} + +QAndroidPlatformScreen *QAndroidPlatformWindow::platformScreen() const +{ + return static_cast(window()->screen()->handle()); +} + +void QAndroidPlatformWindow::propagateSizeHints() +{ + //shut up warning from default implementation +} + +void QAndroidPlatformWindow::requestActivateWindow() +{ + platformScreen()->topWindowChanged(window()); +} + +void QAndroidPlatformWindow::updateStatusBarVisibility() +{ + Qt::WindowFlags flags = window()->flags(); + bool isNonRegularWindow = flags & (Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window; + if (!isNonRegularWindow) { + if (m_windowState & Qt::WindowFullScreen) + QtAndroid::hideStatusBar(); + else if (m_windowState & Qt::WindowMaximized) + QtAndroid::showStatusBar(); + } +} + + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformwindow.h b/src/plugins/platforms/android/qandroidplatformwindow.h new file mode 100644 index 0000000000..db3cb35368 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformwindow.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDPLATFORMWINDOW_H +#define ANDROIDPLATFORMWINDOW_H +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QAndroidPlatformScreen; + +class QAndroidPlatformWindow: public QPlatformWindow +{ +public: + explicit QAndroidPlatformWindow(QWindow *window); + + void lower(); + void raise(); + + void setVisible(bool visible); + + void setWindowState(Qt::WindowState state); + void setWindowFlags(Qt::WindowFlags flags); + Qt::WindowFlags windowFlags() const; + + WId winId() const { return m_windowId; } + + QAndroidPlatformScreen *platformScreen() const; + + void propagateSizeHints(); + void requestActivateWindow(); + void updateStatusBarVisibility(); + inline bool isRaster() const { return window()->surfaceType() == QSurface::RasterSurface; } + +protected: + void setGeometry(const QRect &rect); + +protected: + Qt::WindowFlags m_windowFlags; + Qt::WindowState m_windowState; + + WId m_windowId; +}; + +QT_END_NAMESPACE +#endif // ANDROIDPLATFORMWINDOW_H diff --git a/src/plugins/platforms/android/qandroidsystemlocale.cpp b/src/plugins/platforms/android/qandroidsystemlocale.cpp new file mode 100644 index 0000000000..a20f970a44 --- /dev/null +++ b/src/plugins/platforms/android/qandroidsystemlocale.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidsystemlocale.h" +#include "androidjnimain.h" +#include +#include "qdatetime.h" +#include "qstringlist.h" +#include "qvariant.h" + +QT_BEGIN_NAMESPACE + +QAndroidSystemLocale::QAndroidSystemLocale() : m_locale(QLocale::C) +{ +} + +void QAndroidSystemLocale::getLocaleFromJava() const +{ + QWriteLocker locker(&m_lock); + + QJNIObjectPrivate javaLocaleObject; + QJNIObjectPrivate javaActivity(QtAndroid::activity()); + if (javaActivity.isValid()) { + QJNIObjectPrivate resources = javaActivity.callObjectMethod("getResources", "()Landroid/content/res/Resources;"); + QJNIObjectPrivate configuration = resources.callObjectMethod("getConfiguration", "()Landroid/content/res/Configuration;"); + + javaLocaleObject = configuration.getObjectField("locale", "Ljava/util/Locale;"); + } else { + javaLocaleObject = QJNIObjectPrivate::callStaticObjectMethod("java/util/Locale", "getDefault", "()Ljava/util/Locale;"); + } + + QString languageCode = javaLocaleObject.callObjectMethod("getLanguage", "()Ljava/lang/String;").toString(); + QString countryCode = javaLocaleObject.callObjectMethod("getCountry", "()Ljava/lang/String;").toString(); + + m_locale = QLocale(languageCode + QLatin1Char('_') + countryCode); +} + +QVariant QAndroidSystemLocale::query(QueryType type, QVariant in) const +{ + if (type == LocaleChanged) { + getLocaleFromJava(); + return QVariant(); + } + + QReadLocker locker(&m_lock); + + switch (type) { + case DecimalPoint: + return m_locale.decimalPoint(); + case GroupSeparator: + return m_locale.groupSeparator(); + case ZeroDigit: + return m_locale.zeroDigit(); + case NegativeSign: + return m_locale.negativeSign(); + case DateFormatLong: + return m_locale.dateFormat(QLocale::LongFormat); + case DateFormatShort: + return m_locale.dateFormat(QLocale::ShortFormat); + case TimeFormatLong: + return m_locale.timeFormat(QLocale::LongFormat); + case TimeFormatShort: + return m_locale.timeFormat(QLocale::ShortFormat); + case DayNameLong: + return m_locale.dayName(in.toInt(), QLocale::LongFormat); + case DayNameShort: + return m_locale.dayName(in.toInt(), QLocale::ShortFormat); + case MonthNameLong: + return m_locale.monthName(in.toInt(), QLocale::LongFormat); + case MonthNameShort: + return m_locale.monthName(in.toInt(), QLocale::ShortFormat); + case StandaloneMonthNameLong: + return m_locale.standaloneMonthName(in.toInt(), QLocale::LongFormat); + case StandaloneMonthNameShort: + return m_locale.standaloneMonthName(in.toInt(), QLocale::ShortFormat); + case DateToStringLong: + return m_locale.toString(in.toDate(), QLocale::LongFormat); + case DateToStringShort: + return m_locale.toString(in.toDate(), QLocale::ShortFormat); + case TimeToStringLong: + return m_locale.toString(in.toTime(), QLocale::LongFormat); + case TimeToStringShort: + return m_locale.toString(in.toTime(), QLocale::ShortFormat); + case DateTimeFormatLong: + return m_locale.dateTimeFormat(QLocale::LongFormat); + case DateTimeFormatShort: + return m_locale.dateTimeFormat(QLocale::ShortFormat); + case DateTimeToStringLong: + return m_locale.toString(in.toDateTime(), QLocale::LongFormat); + case DateTimeToStringShort: + return m_locale.toString(in.toDateTime(), QLocale::ShortFormat); + case PositiveSign: + return m_locale.positiveSign(); + case AMText: + return m_locale.amText(); + case PMText: + return m_locale.pmText(); + case FirstDayOfWeek: + return m_locale.firstDayOfWeek(); + case CurrencySymbol: + return m_locale .currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt())); + case CurrencyToString: { + switch (in.type()) { + case QVariant::Int: + return m_locale .toCurrencyString(in.toInt()); + case QVariant::UInt: + return m_locale .toCurrencyString(in.toUInt()); + case QVariant::Double: + return m_locale .toCurrencyString(in.toDouble()); + case QVariant::LongLong: + return m_locale .toCurrencyString(in.toLongLong()); + case QVariant::ULongLong: + return m_locale .toCurrencyString(in.toULongLong()); + default: + break; + } + return QString(); + } + case StringToStandardQuotation: + return m_locale.quoteString(in.value()); + case StringToAlternateQuotation: + return m_locale.quoteString(in.value(), QLocale::AlternateQuotation); + case ListToSeparatedString: + return m_locale.createSeparatedList(in.value()); + case LocaleChanged: + Q_ASSERT_X(false, Q_FUNC_INFO, "This can't happen."); + default: + break; + } + return QVariant(); +} + +QLocale QAndroidSystemLocale::fallbackUiLocale() const +{ + QReadLocker locker(&m_lock); + return m_locale; +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidsystemlocale.h b/src/plugins/platforms/android/qandroidsystemlocale.h new file mode 100644 index 0000000000..fc2f6fad98 --- /dev/null +++ b/src/plugins/platforms/android/qandroidsystemlocale.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDSYSTEMLOCALE_H +#define QANDROIDSYSTEMLOCALE_H + +#include "private/qlocale_p.h" +#include + +QT_BEGIN_NAMESPACE + +class QAndroidSystemLocale : public QSystemLocale +{ +public: + QAndroidSystemLocale(); + + virtual QVariant query(QueryType type, QVariant in) const; + virtual QLocale fallbackUiLocale() const; + +private: + void getLocaleFromJava() const; + + mutable QLocale m_locale; + mutable QReadWriteLock m_lock; +}; + +QT_END_NAMESPACE + +#endif // QANDROIDSYSTEMLOCALE_H diff --git a/src/plugins/platforms/android/raster/raster.pro b/src/plugins/platforms/android/raster/raster.pro deleted file mode 100644 index 53d8ee7a2b..0000000000 --- a/src/plugins/platforms/android/raster/raster.pro +++ /dev/null @@ -1,19 +0,0 @@ -TARGET = qtforandroid - -PLUGIN_TYPE = platforms - -# STATICPLUGIN needed because there's a Q_IMPORT_PLUGIN in androidjnimain.cpp -# Yes, the plugin imports itself statically -DEFINES += QT_STATICPLUGIN - -load(qt_plugin) - -!contains(ANDROID_PLATFORM, android-9) { - INCLUDEPATH += $$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/include - LIBS += -L$$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/lib -ljnigraphics -landroid -} else { - LIBS += -ljnigraphics -landroid -} - -include($$PWD/../src/src.pri) -include($$PWD/../src/raster/raster.pri) diff --git a/src/plugins/platforms/android/src/android.json b/src/plugins/platforms/android/src/android.json deleted file mode 100644 index 6843bd3301..0000000000 --- a/src/plugins/platforms/android/src/android.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "Keys": [ "android" ] -} diff --git a/src/plugins/platforms/android/src/androidjniaccessibility.cpp b/src/plugins/platforms/android/src/androidjniaccessibility.cpp deleted file mode 100644 index b987c49c9c..0000000000 --- a/src/plugins/platforms/android/src/androidjniaccessibility.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "androidjniaccessibility.h" -#include "androidjnimain.h" -#include "qandroidplatformintegration.h" -#include "qpa/qplatformaccessibility.h" -#include "qguiapplication.h" -#include "qwindow.h" -#include "qrect.h" -#include "QtGui/qaccessible.h" - -#include "qdebug.h" - -static const char m_qtTag[] = "QtA11y"; -static const char m_classErrorMsg[] = "Can't find class \"%s\""; -static const char m_methodErrorMsg[] = "Can't find method \"%s%s\""; - -namespace QtAndroidAccessibility -{ - static void setActive(JNIEnv */*env*/, jobject /*thiz*/, jboolean active) - { - QAndroidPlatformIntegration *platformIntegration = QtAndroid::androidPlatformIntegration(); - if (platformIntegration) - platformIntegration->accessibility()->setActive(active); - else - __android_log_print(ANDROID_LOG_WARN, m_qtTag, "Could not activate platform accessibility."); - } - - QAccessibleInterface *interfaceFromId(jint objectId) - { - QAccessibleInterface *iface = 0; - if (objectId == -1) { - QWindow *win = qApp->focusWindow(); - if (win) - iface = win->accessibleRoot(); - } else { - iface = QAccessible::accessibleInterface(objectId); - } - return iface; - } - - static jintArray childIdListForAccessibleObject(JNIEnv *env, jobject /*thiz*/, jint objectId) - { - QAccessibleInterface *iface = interfaceFromId(objectId); - if (iface) { - jintArray jArray = env->NewIntArray(jsize(iface->childCount())); - for (int i = 0; i < iface->childCount(); ++i) { - QAccessibleInterface *child = iface->child(i); - if (child) { - QAccessible::Id ifaceId = QAccessible::uniqueId(child); - jint jid = ifaceId; - env->SetIntArrayRegion(jArray, i, 1, &jid); - } - } - return jArray; - } - - return env->NewIntArray(jsize(0)); - } - - static jint parentId(JNIEnv */*env*/, jobject /*thiz*/, jint objectId) - { - QAccessibleInterface *iface = interfaceFromId(objectId); - if (iface) { - QAccessibleInterface *parent = iface->parent(); - if (parent) { - if (parent->role() == QAccessible::Application) - return -1; - return QAccessible::uniqueId(parent); - } - } - return -1; - } - - static jobject screenRect(JNIEnv *env, jobject /*thiz*/, jint objectId) - { - QRect rect; - QAccessibleInterface *iface = interfaceFromId(objectId); - if (iface && iface->isValid()) { - rect = iface->rect(); - } - - jclass rectClass = env->FindClass("android/graphics/Rect"); - jmethodID ctor = env->GetMethodID(rectClass, "", "(IIII)V"); - jobject jrect = env->NewObject(rectClass, ctor, rect.left(), rect.top(), rect.right(), rect.bottom()); - return jrect; - } - - static jint hitTest(JNIEnv */*env*/, jobject /*thiz*/, jfloat x, jfloat y) - { - QAccessibleInterface *root = interfaceFromId(-1); - if (root) { - QAccessibleInterface *child = root->childAt((int)x, (int)y); - QAccessibleInterface *lastChild = 0; - while (child && (child != lastChild)) { - lastChild = child; - child = child->childAt((int)x, (int)y); - } - if (lastChild) - return QAccessible::uniqueId(lastChild); - } - return -1; - } - - static jboolean clickAction(JNIEnv */*env*/, jobject /*thiz*/, jint objectId) - { -// qDebug() << "A11Y: CLICK: " << objectId; - QAccessibleInterface *iface = interfaceFromId(objectId); - if (iface && iface->actionInterface()) { - if (iface->actionInterface()->actionNames().contains(QAccessibleActionInterface::pressAction())) - iface->actionInterface()->doAction(QAccessibleActionInterface::pressAction()); - else - iface->actionInterface()->doAction(QAccessibleActionInterface::toggleAction()); - } - return false; - } - - -#define FIND_AND_CHECK_CLASS(CLASS_NAME) \ -clazz = env->FindClass(CLASS_NAME); \ -if (!clazz) { \ - __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_classErrorMsg, CLASS_NAME); \ - return JNI_FALSE; \ -} - - //__android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); - -#define CALL_METHOD(OBJECT, METHOD_NAME, METHOD_SIGNATURE, ...) \ -{ \ - jclass clazz = env->GetObjectClass(OBJECT); \ - jmethodID method = env->GetMethodID(clazz, METHOD_NAME, METHOD_SIGNATURE); \ - if (!method) { \ - __android_log_print(ANDROID_LOG_WARN, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \ - return; \ - } \ - env->CallVoidMethod(OBJECT, method, __VA_ARGS__); \ -} - - - static jstring descriptionForAccessibleObject(JNIEnv *env, jobject /*thiz*/, jint objectId) - { - QString desc; - QAccessibleInterface *iface = interfaceFromId(objectId); - if (iface && iface->isValid()) { - desc = iface->text(QAccessible::Name); - if (desc.isEmpty()) - desc = iface->text(QAccessible::Description); - - desc += QChar(' ') + QString::fromUtf8(qAccessibleRoleString(iface->role())); - } - - jstring jdesc = env->NewString((jchar*) desc.constData(), (jsize) desc.size()); - return jdesc; - } - - static void populateNode(JNIEnv *env, jobject /*thiz*/, jint objectId, jobject node) - { - QAccessibleInterface *iface = interfaceFromId(objectId); - if (!iface || !iface->isValid()) { - __android_log_print(ANDROID_LOG_WARN, m_qtTag, "Accessibility: populateNode for Invalid ID"); - return; - } - QAccessible::State state = iface->state(); - - // try to fill in the text property, this is what the screen reader reads - QString desc = iface->text(QAccessible::Value); - if (desc.isEmpty()) - desc = iface->text(QAccessible::Name); - if (desc.isEmpty()) - desc = iface->text(QAccessible::Description); - if (QAccessibleTextInterface *textIface = iface->textInterface()) { - if (textIface->selectionCount() > 0) { - int startSelection; - int endSelection; - textIface->selection(0, &startSelection, &endSelection); - CALL_METHOD(node, "setTextSelection", "(II)V", startSelection, endSelection) - } - } - - if ((iface->role() != QAccessible::NoRole) && - (iface->role() != QAccessible::Client) && - (iface->role() != QAccessible::Pane)) { - desc += QChar(' ') + QString::fromUtf8(qAccessibleRoleString(iface->role())); - } - - CALL_METHOD(node, "setEnabled", "(Z)V", !state.disabled) - //CALL_METHOD(node, "setFocusable", "(Z)V", state.focusable) - CALL_METHOD(node, "setFocusable", "(Z)V", true) - //CALL_METHOD(node, "setFocused", "(Z)V", state.focused) - CALL_METHOD(node, "setCheckable", "(Z)V", state.checkable) - CALL_METHOD(node, "setChecked", "(Z)V", state.checked) - CALL_METHOD(node, "setVisibleToUser", "(Z)V", !state.invisible) - - if (iface->actionInterface()) { - QStringList actions = iface->actionInterface()->actionNames(); - bool clickable = actions.contains(QAccessibleActionInterface::pressAction()); - bool toggle = actions.contains(QAccessibleActionInterface::toggleAction()); - if (clickable || toggle) { - CALL_METHOD(node, "setClickable", "(Z)V", clickable) - CALL_METHOD(node, "addAction", "(I)V", 16) // ACTION_CLICK defined in AccessibilityNodeInfo - } - } - - jstring jdesc = env->NewString((jchar*) desc.constData(), (jsize) desc.size()); - //CALL_METHOD(node, "setText", "(Ljava/lang/CharSequence;)V", jdesc) - CALL_METHOD(node, "setContentDescription", "(Ljava/lang/CharSequence;)V", jdesc) - } - - static JNINativeMethod methods[] = { - {"setActive","(Z)V",(void*)setActive}, - {"childIdListForAccessibleObject", "(I)[I", (jintArray)childIdListForAccessibleObject}, - {"parentId", "(I)I", (void*)parentId}, - {"descriptionForAccessibleObject", "(I)Ljava/lang/String;", (jstring)descriptionForAccessibleObject}, - {"screenRect", "(I)Landroid/graphics/Rect;", (jobject)screenRect}, - {"hitTest", "(FF)I", (void*)hitTest}, - {"populateNode", "(ILandroid/view/accessibility/AccessibilityNodeInfo;)V", (void*)populateNode}, - {"clickAction", "(I)Z", (void*)clickAction}, - }; - - bool registerNatives(JNIEnv *env) - { - jclass clazz; - FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/accessibility/QtNativeAccessibility"); - jclass appClass = static_cast(env->NewGlobalRef(clazz)); - - if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { - __android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed"); - return false; - } - - return true; - } -} diff --git a/src/plugins/platforms/android/src/androidjniaccessibility.h b/src/plugins/platforms/android/src/androidjniaccessibility.h deleted file mode 100644 index e708138c33..0000000000 --- a/src/plugins/platforms/android/src/androidjniaccessibility.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ANDROIDJNIACCESSIBILITY_H -#define ANDROIDJNIACCESSIBILITY_H -#include - -namespace QtAndroidAccessibility -{ - bool registerNatives(JNIEnv *env); -} - -#endif // ANDROIDJNIINPUT_H diff --git a/src/plugins/platforms/android/src/androidjniclipboard.cpp b/src/plugins/platforms/android/src/androidjniclipboard.cpp deleted file mode 100644 index 05270ac374..0000000000 --- a/src/plugins/platforms/android/src/androidjniclipboard.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "androidjniclipboard.h" -#include "androidjnimain.h" - -using namespace QtAndroid; -namespace QtAndroidClipboard -{ - // Clipboard support - static jmethodID m_registerClipboardManagerMethodID = 0; - static jmethodID m_setClipboardTextMethodID = 0; - static jmethodID m_hasClipboardTextMethodID = 0; - static jmethodID m_getClipboardTextMethodID = 0; - // Clipboard support - - void setClipboardListener(QAndroidPlatformClipboard *listener) - { - Q_UNUSED(listener); - - AttachedJNIEnv env; - if (!env.jniEnv) - return; - - env.jniEnv->CallStaticVoidMethod(applicationClass(), m_registerClipboardManagerMethodID); - } - - void setClipboardText(const QString &text) - { - AttachedJNIEnv env; - if (!env.jniEnv) - return; - - jstring jtext = env.jniEnv->NewString(reinterpret_cast(text.data()), - text.length()); - env.jniEnv->CallStaticVoidMethod(applicationClass(), m_setClipboardTextMethodID, jtext); - env.jniEnv->DeleteLocalRef(jtext); - } - - bool hasClipboardText() - { - AttachedJNIEnv env; - if (!env.jniEnv) - return false; - - return env.jniEnv->CallStaticBooleanMethod(applicationClass(), m_hasClipboardTextMethodID); - } - - QString clipboardText() - { - AttachedJNIEnv env; - if (!env.jniEnv) - return QString(); - - jstring text = reinterpret_cast(env.jniEnv->CallStaticObjectMethod(applicationClass(), - m_getClipboardTextMethodID)); - const jchar *jstr = env.jniEnv->GetStringChars(text, 0); - QString str(reinterpret_cast(jstr), env.jniEnv->GetStringLength(text)); - env.jniEnv->ReleaseStringChars(text, jstr); - return str; - } - - -#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ - VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ - if (!VAR) { \ - __android_log_print(ANDROID_LOG_FATAL, qtTagText(), methodErrorMsgFmt(), METHOD_NAME, METHOD_SIGNATURE); \ - return false; \ - } - - bool registerNatives(JNIEnv *env) - { - jclass appClass = QtAndroid::applicationClass(); - - GET_AND_CHECK_STATIC_METHOD(m_registerClipboardManagerMethodID, appClass, "registerClipboardManager", "()V"); - GET_AND_CHECK_STATIC_METHOD(m_setClipboardTextMethodID, appClass, "setClipboardText", "(Ljava/lang/String;)V"); - GET_AND_CHECK_STATIC_METHOD(m_hasClipboardTextMethodID, appClass, "hasClipboardText", "()Z"); - GET_AND_CHECK_STATIC_METHOD(m_getClipboardTextMethodID, appClass, "getClipboardText", "()Ljava/lang/String;"); - - return true; - } -} diff --git a/src/plugins/platforms/android/src/androidjniclipboard.h b/src/plugins/platforms/android/src/androidjniclipboard.h deleted file mode 100644 index 15cd93202e..0000000000 --- a/src/plugins/platforms/android/src/androidjniclipboard.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ANDROIDJNICLIPBOARD_H -#define ANDROIDJNICLIPBOARD_H - -#include -#include - -class QAndroidPlatformClipboard; -namespace QtAndroidClipboard -{ - // Clipboard support - void setClipboardListener(QAndroidPlatformClipboard *listener); - void setClipboardText(const QString &text); - bool hasClipboardText(); - QString clipboardText(); - // Clipboard support - - bool registerNatives(JNIEnv *env); -} - -#endif // ANDROIDJNICLIPBOARD_H diff --git a/src/plugins/platforms/android/src/androidjniinput.cpp b/src/plugins/platforms/android/src/androidjniinput.cpp deleted file mode 100644 index 55d44b7377..0000000000 --- a/src/plugins/platforms/android/src/androidjniinput.cpp +++ /dev/null @@ -1,606 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "androidjniinput.h" -#include "androidjnimain.h" -#include "qandroidplatformintegration.h" - -#include -#include -#include - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL -# include -#endif - -using namespace QtAndroid; - -namespace QtAndroidInput -{ - static jmethodID m_showSoftwareKeyboardMethodID = 0; - static jmethodID m_resetSoftwareKeyboardMethodID = 0; - static jmethodID m_hideSoftwareKeyboardMethodID = 0; - static jmethodID m_isSoftwareKeyboardVisibleMethodID = 0; - static jmethodID m_updateSelectionMethodID = 0; - - static bool m_ignoreMouseEvents = false; - - static QList m_touchPoints; - - static QPointer m_mouseGrabber; - - static int m_lastCursorPos = -1; - - void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd) - { - AttachedJNIEnv env; - if (!env.jniEnv) - return; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << ">>> UPDATESELECTION" << selStart << selEnd << candidatesStart << candidatesEnd; -#endif - if (candidatesStart == -1 && candidatesEnd == -1 && selStart == selEnd) { - // Qt only gives us position inside the block, so if we move to the - // same position in another block, the Android keyboard will believe - // we have not changed position, and be terribly confused. - if (selStart == m_lastCursorPos) { -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << ">>> FAKEUPDATESELECTION" << selStart+1; -#endif - env.jniEnv->CallStaticVoidMethod(applicationClass(), m_updateSelectionMethodID, - selStart+1, selEnd+1, candidatesStart, candidatesEnd); - } - m_lastCursorPos = selStart; - } else { - m_lastCursorPos = -1; - } - env.jniEnv->CallStaticVoidMethod(applicationClass(), m_updateSelectionMethodID, - selStart, selEnd, candidatesStart, candidatesEnd); - } - - void showSoftwareKeyboard(int left, int top, int width, int height, int inputHints) - { - AttachedJNIEnv env; - if (!env.jniEnv) - return; - - env.jniEnv->CallStaticVoidMethod(applicationClass(), - m_showSoftwareKeyboardMethodID, - left, - top, - width, - height, - inputHints); -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ SHOWSOFTWAREKEYBOARD" << left << top << width << height << inputHints; -#endif - } - - void resetSoftwareKeyboard() - { - AttachedJNIEnv env; - if (!env.jniEnv) - return; - - env.jniEnv->CallStaticVoidMethod(applicationClass(), m_resetSoftwareKeyboardMethodID); -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ RESETSOFTWAREKEYBOARD"; -#endif - } - - void hideSoftwareKeyboard() - { - AttachedJNIEnv env; - if (!env.jniEnv) - return; - - env.jniEnv->CallStaticVoidMethod(applicationClass(), m_hideSoftwareKeyboardMethodID); -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ HIDESOFTWAREKEYBOARD"; -#endif - } - - bool isSoftwareKeyboardVisible() - { - AttachedJNIEnv env; - if (!env.jniEnv) - return false; - - bool visibility = env.jniEnv->CallStaticBooleanMethod(applicationClass(), m_isSoftwareKeyboardVisibleMethodID); -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ ISSOFTWAREKEYBOARDVISIBLE" << visibility; -#endif - return visibility; - } - - - static void mouseDown(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) - { - if (m_ignoreMouseEvents) - return; - - QPoint globalPos(x,y); - QWindow *tlw = topLevelWindowAt(globalPos); - m_mouseGrabber = tlw; - QPoint localPos = tlw ? (globalPos - tlw->position()) : globalPos; - QWindowSystemInterface::handleMouseEvent(tlw, - localPos, - globalPos, - Qt::MouseButtons(Qt::LeftButton)); - } - - static void mouseUp(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) - { - QPoint globalPos(x,y); - QWindow *tlw = m_mouseGrabber.data(); - if (!tlw) - tlw = topLevelWindowAt(globalPos); - QPoint localPos = tlw ? (globalPos -tlw->position()) : globalPos; - QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos - , Qt::MouseButtons(Qt::NoButton)); - m_ignoreMouseEvents = false; - m_mouseGrabber = 0; - } - - static void mouseMove(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) - { - - if (m_ignoreMouseEvents) - return; - - QPoint globalPos(x,y); - QWindow *tlw = m_mouseGrabber.data(); - if (!tlw) - tlw = topLevelWindowAt(globalPos); - QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos; - QWindowSystemInterface::handleMouseEvent(tlw, - localPos, - globalPos, - Qt::MouseButtons(Qt::LeftButton)); - } - - static void longPress(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) - { - //### TODO: add proper API for Qt 5.2 - static bool rightMouseFromLongPress = qgetenv("QT_NECESSITAS_COMPATIBILITY_LONG_PRESS").toInt(); - if (!rightMouseFromLongPress) - return; - m_ignoreMouseEvents = true; - QPoint globalPos(x,y); - QWindow *tlw = topLevelWindowAt(globalPos); - QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos; - - // Release left button - QWindowSystemInterface::handleMouseEvent(tlw, - localPos, - globalPos, - Qt::MouseButtons(Qt::NoButton)); - - // Press right button - QWindowSystemInterface::handleMouseEvent(tlw, - localPos, - globalPos, - Qt::MouseButtons(Qt::RightButton)); - } - - static void touchBegin(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/) - { - m_touchPoints.clear(); - } - - static void touchAdd(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint id, jint action, jboolean /*primary*/, jint x, jint y, jfloat size, jfloat pressure) - { - Qt::TouchPointState state = Qt::TouchPointStationary; - switch (action) { - case 0: - state = Qt::TouchPointPressed; - break; - case 1: - state = Qt::TouchPointMoved; - break; - case 2: - state = Qt::TouchPointStationary; - break; - case 3: - state = Qt::TouchPointReleased; - break; - } - - const int dw = desktopWidthPixels(); - const int dh = desktopHeightPixels(); - QWindowSystemInterface::TouchPoint touchPoint; - touchPoint.id = id; - touchPoint.pressure = pressure; - touchPoint.normalPosition = QPointF(double(x / dw), double(y / dh)); - touchPoint.state = state; - touchPoint.area = QRectF(x - double(dw*size) / 2.0, - y - double(dh*size) / 2.0, - double(dw*size), - double(dh*size)); - m_touchPoints.push_back(touchPoint); - } - - static void touchEnd(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint /*action*/) - { - if (m_touchPoints.isEmpty()) - return; - - QAndroidPlatformIntegration *platformIntegration = QtAndroid::androidPlatformIntegration(); - if (!platformIntegration) - return; - - QTouchDevice *touchDevice = platformIntegration->touchDevice(); - if (touchDevice == 0) { - touchDevice = new QTouchDevice; - touchDevice->setType(QTouchDevice::TouchScreen); - touchDevice->setCapabilities(QTouchDevice::Position - | QTouchDevice::Area - | QTouchDevice::Pressure - | QTouchDevice::NormalizedPosition); - QWindowSystemInterface::registerTouchDevice(touchDevice); - platformIntegration->setTouchDevice(touchDevice); - } - - QWindow *window = QtAndroid::topLevelWindowAt(m_touchPoints.at(0).area.center().toPoint()); - QWindowSystemInterface::handleTouchEvent(window, touchDevice, m_touchPoints); - } - - static int mapAndroidKey(int key) - { - // 0--9 0x00000007 -- 0x00000010 - if (key >= 0x00000007 && key <= 0x00000010) - return Qt::Key_0 + key - 0x00000007; - - // A--Z 0x0000001d -- 0x00000036 - if (key >= 0x0000001d && key <= 0x00000036) - return Qt::Key_A + key - 0x0000001d; - - switch (key) { - case 0x00000039: - case 0x0000003a: - return Qt::Key_Alt; - - case 0x0000004b: - return Qt::Key_Apostrophe; - - case 0x00000004: // KEYCODE_BACK - return Qt::Key_Back; - - case 0x00000049: - return Qt::Key_Backslash; - - case 0x00000005: - return Qt::Key_Call; - - case 0x0000001b: // KEYCODE_CAMERA - return Qt::Key_Camera; - - case 0x0000001c: - return Qt::Key_Clear; - - case 0x00000037: - return Qt::Key_Comma; - - case 0x00000043: // KEYCODE_DEL - return Qt::Key_Backspace; - - case 0x00000017: // KEYCODE_DPAD_CENTER - return Qt::Key_Enter; - - case 0x00000014: // KEYCODE_DPAD_DOWN - return Qt::Key_Down; - - case 0x00000015: //KEYCODE_DPAD_LEFT - return Qt::Key_Left; - - case 0x00000016: //KEYCODE_DPAD_RIGHT - return Qt::Key_Right; - - case 0x00000013: //KEYCODE_DPAD_UP - return Qt::Key_Up; - - case 0x00000006: //KEYCODE_ENDCALL - return Qt::Key_Hangup; - - case 0x00000042: - return Qt::Key_Return; - - case 0x00000041: //KEYCODE_ENVELOPE - return Qt::Key_LaunchMail; - - case 0x00000046: - return Qt::Key_Equal; - - case 0x00000040: - return Qt::Key_Explorer; - - case 0x00000003: - return Qt::Key_Home; - - case 0x00000047: - return Qt::Key_BracketLeft; - - case 0x0000005a: // KEYCODE_MEDIA_FAST_FORWARD - return Qt::Key_AudioForward; - - case 0x00000057: - return Qt::Key_MediaNext; - - case 0x00000055: - return Qt::Key_MediaPlay; - - case 0x00000058: - return Qt::Key_MediaPrevious; - - case 0x00000059: // KEYCODE_MEDIA_REWIND - return Qt::Key_AudioRewind; - - case 0x00000056: - return Qt::Key_MediaStop; - - case 0x00000052: //KEYCODE_MENU - return Qt::Key_Menu; - - case 0x00000045: - return Qt::Key_Minus; - - case 0x0000005b: // KEYCODE_MUTE - return Qt::Key_MicMute; - - case 0x0000004e: - return Qt::Key_NumLock; - - case 0x00000038: - return Qt::Key_Period; - - case 0x00000051: - return Qt::Key_Plus; - - case 0x0000001a: - return Qt::Key_PowerOff; - - case 0x00000048: - return Qt::Key_BracketRight; - - case 0x00000054: - return Qt::Key_Search; - - case 0x0000004a: - return Qt::Key_Semicolon; - - case 0x0000003b: - case 0x0000003c: - return Qt::Key_Shift; - - case 0x0000004c: - return Qt::Key_Slash; - - case 0x00000001: - return Qt::Key_Left; - - case 0x00000002: - return Qt::Key_Right; - - case 0x0000003e: - return Qt::Key_Space; - - case 0x0000003f: // KEYCODE_SYM - return Qt::Key_Meta; - - case 0x0000003d: - return Qt::Key_Tab; - - case 0x00000019: - return Qt::Key_VolumeDown; - - case 0x000000a4: // KEYCODE_VOLUME_MUTE - return Qt::Key_VolumeMute; - - case 0x00000018: - return Qt::Key_VolumeUp; - - case 0x00000011: // KEYCODE_STAR - return Qt::Key_Asterisk; - - case 0x00000012: // KEYCODE_POUND - return Qt::Key_NumberSign; - - case 0x00000050: // KEYCODE_FOCUS - return Qt::Key_CameraFocus; - - case 0x00000070: // KEYCODE_FORWARD_DEL - return Qt::Key_Delete; - - case 0x00000080: // KEYCODE_MEDIA_CLOSE - return Qt::Key_Close; - - case 0x00000081: // KEYCODE_MEDIA_EJECT - return Qt::Key_Eject; - - case 0x00000082: // KEYCODE_MEDIA_RECORD - return Qt::Key_MediaRecord; - - case 0x000000b7: // KEYCODE_PROG_RED - return Qt::Key_Red; - - case 0x000000b8: // KEYCODE_PROG_GREEN - return Qt::Key_Green; - - case 0x000000b9: // KEYCODE_PROG_YELLOW - return Qt::Key_Yellow; - - case 0x000000ba: // KEYCODE_PROG_BLUE - return Qt::Key_Blue; - - case 0x000000a5: // KEYCODE_INFO - return Qt::Key_Info; - - case 0x000000a6: // KEYCODE_CHANNEL_UP - return Qt::Key_ChannelUp; - - case 0x000000a7: // KEYCODE_CHANNEL_DOWN - return Qt::Key_ChannelDown; - - case 0x000000a8: // KEYCODE_ZOOM_IN - return Qt::Key_ZoomIn; - - case 0x000000a9: // KEYCODE_ZOOM_OUT - return Qt::Key_ZoomOut; - - case 0x000000ac: // KEYCODE_GUIDE - return Qt::Key_Guide; - - case 0x000000af: // KEYCODE_CAPTIONS - return Qt::Key_Subtitle; - - case 0x000000b0: // KEYCODE_SETTINGS - return Qt::Key_Settings; - - case 0x000000d0: // KEYCODE_CALENDAR - return Qt::Key_Calendar; - - case 0x000000d1: // KEYCODE_MUSIC - return Qt::Key_Music; - - case 0x000000d2: // KEYCODE_CALCULATOR - return Qt::Key_Calculator; - - case 0x00000000: // KEYCODE_UNKNOWN - return Qt::Key_unknown; - - case 0x00000053: // KEYCODE_NOTIFICATION ?!?!? - case 0x0000004f: // KEYCODE_HEADSETHOOK ?!?!? - case 0x00000044: // KEYCODE_GRAVE ?!?!? - return Qt::Key_Any; - - default: - return 0; - } - } - - static void keyDown(JNIEnv */*env*/, jobject /*thiz*/, jint key, jint unicode, jint modifier) - { - Qt::KeyboardModifiers modifiers; - if (modifier & 1) - modifiers |= Qt::ShiftModifier; - - if (modifier & 2) - modifiers |= Qt::AltModifier; - - if (modifier & 4) - modifiers |= Qt::MetaModifier; - - QWindowSystemInterface::handleKeyEvent(0, - QEvent::KeyPress, - mapAndroidKey(key), - modifiers, - QChar(unicode), - false); - } - - static void keyUp(JNIEnv */*env*/, jobject /*thiz*/, jint key, jint unicode, jint modifier) - { - Qt::KeyboardModifiers modifiers; - if (modifier & 1) - modifiers |= Qt::ShiftModifier; - - if (modifier & 2) - modifiers |= Qt::AltModifier; - - if (modifier & 4) - modifiers |= Qt::MetaModifier; - - QWindowSystemInterface::handleKeyEvent(0, - QEvent::KeyRelease, - mapAndroidKey(key), - modifiers, - QChar(unicode), - false); - } - - static void keyboardVisibilityChanged(JNIEnv */*env*/, jobject /*thiz*/, jboolean /*visibility*/) - { - QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext(); - if (inputContext) - inputContext->emitInputPanelVisibleChanged(); -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ KEYBOARDVISIBILITYCHANGED" << inputContext; -#endif - } - - static JNINativeMethod methods[] = { - {"touchBegin","(I)V",(void*)touchBegin}, - {"touchAdd","(IIIZIIFF)V",(void*)touchAdd}, - {"touchEnd","(II)V",(void*)touchEnd}, - {"mouseDown", "(III)V", (void *)mouseDown}, - {"mouseUp", "(III)V", (void *)mouseUp}, - {"mouseMove", "(III)V", (void *)mouseMove}, - {"longPress", "(III)V", (void *)longPress}, - {"keyDown", "(III)V", (void *)keyDown}, - {"keyUp", "(III)V", (void *)keyUp}, - {"keyboardVisibilityChanged", "(Z)V", (void *)keyboardVisibilityChanged} - }; - -#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ - VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ - if (!VAR) { \ - __android_log_print(ANDROID_LOG_FATAL, qtTagText(), methodErrorMsgFmt(), METHOD_NAME, METHOD_SIGNATURE); \ - return false; \ - } - - bool registerNatives(JNIEnv *env) - { - jclass appClass = QtAndroid::applicationClass(); - - if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { - __android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed"); - return false; - } - - GET_AND_CHECK_STATIC_METHOD(m_showSoftwareKeyboardMethodID, appClass, "showSoftwareKeyboard", "(IIIII)V"); - GET_AND_CHECK_STATIC_METHOD(m_resetSoftwareKeyboardMethodID, appClass, "resetSoftwareKeyboard", "()V"); - GET_AND_CHECK_STATIC_METHOD(m_hideSoftwareKeyboardMethodID, appClass, "hideSoftwareKeyboard", "()V"); - GET_AND_CHECK_STATIC_METHOD(m_isSoftwareKeyboardVisibleMethodID, appClass, "isSoftwareKeyboardVisible", "()Z"); - GET_AND_CHECK_STATIC_METHOD(m_updateSelectionMethodID, appClass, "updateSelection", "(IIII)V"); - return true; - } -} diff --git a/src/plugins/platforms/android/src/androidjniinput.h b/src/plugins/platforms/android/src/androidjniinput.h deleted file mode 100644 index a78c7519db..0000000000 --- a/src/plugins/platforms/android/src/androidjniinput.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ANDROIDJNIINPUT_H -#define ANDROIDJNIINPUT_H -#include - -namespace QtAndroidInput -{ - // Software keyboard support - void showSoftwareKeyboard(int top, int left, int width, int height, int inputHints); - void resetSoftwareKeyboard(); - void hideSoftwareKeyboard(); - bool isSoftwareKeyboardVisible(); - void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd); - // Software keyboard support - - bool registerNatives(JNIEnv *env); -} - -#endif // ANDROIDJNIINPUT_H diff --git a/src/plugins/platforms/android/src/androidjnimain.cpp b/src/plugins/platforms/android/src/androidjnimain.cpp deleted file mode 100644 index 3064e5d4e2..0000000000 --- a/src/plugins/platforms/android/src/androidjnimain.cpp +++ /dev/null @@ -1,884 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "androidjnimain.h" -#include "androidjniaccessibility.h" -#include "androidjniinput.h" -#include "androidjniclipboard.h" -#include "androidjnimenu.h" -#include "qandroidplatformdialoghelpers.h" -#include "qandroidplatformintegration.h" -#include - -#include - -#include -#include -#include "qandroidassetsfileenginehandler.h" -#include - -#include - -#ifdef ANDROID_PLUGIN_OPENGL -# include "qandroidopenglplatformwindow.h" -#endif - -#include - -static jmethodID m_redrawSurfaceMethodID = 0; - -Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin) - -static JavaVM *m_javaVM = NULL; -static jclass m_applicationClass = NULL; -static jobject m_classLoaderObject = NULL; -static jmethodID m_loadClassMethodID = NULL; -static AAssetManager *m_assetManager = NULL; -static jobject m_resourcesObj; -static jobject m_activityObject = NULL; - -static bool m_activityActive = true; // defaults to true because when the platform plugin is - // initialized, QtActivity::onResume() has already been called - -static jclass m_bitmapClass = 0; -static jmethodID m_createBitmapMethodID = 0; -static jobject m_ARGB_8888_BitmapConfigValue = 0; -static jobject m_RGB_565_BitmapConfigValue = 0; - -jmethodID m_setFullScreenMethodID = 0; -static bool m_statusBarShowing = true; - -static jclass m_bitmapDrawableClass = 0; -static jmethodID m_bitmapDrawableConstructorMethodID = 0; - -extern "C" typedef int (*Main)(int, char **); //use the standard main method to start the application -static Main m_main = NULL; -static void *m_mainLibraryHnd = NULL; -static QList m_applicationParams; - -#ifndef ANDROID_PLUGIN_OPENGL -static jobject m_surface = NULL; -#else -static EGLNativeWindowType m_nativeWindow = 0; -static QSemaphore m_waitForWindowSemaphore; -static bool m_waitForWindow = false; -#endif - - -static QSemaphore m_quitAppSemaphore; -static QMutex m_surfaceMutex(QMutex::Recursive); -static QSemaphore m_pauseApplicationSemaphore; -static QMutex m_pauseApplicationMutex; - -static QAndroidPlatformIntegration *m_androidPlatformIntegration = 0; - -static int m_desktopWidthPixels = 0; -static int m_desktopHeightPixels = 0; -static double m_scaledDensity = 0; - -static volatile bool m_pauseApplication; - -static AndroidAssetsFileEngineHandler *m_androidAssetsFileEngineHandler = 0; - - - -static const char m_qtTag[] = "Qt"; -static const char m_classErrorMsg[] = "Can't find class \"%s\""; -static const char m_methodErrorMsg[] = "Can't find method \"%s%s\""; - -static inline void checkPauseApplication() -{ - m_pauseApplicationMutex.lock(); - if (m_pauseApplication) { - m_pauseApplicationMutex.unlock(); - m_pauseApplicationSemaphore.acquire(); // wait until surface is created - - m_pauseApplicationMutex.lock(); - m_pauseApplication = false; - m_pauseApplicationMutex.unlock(); - - //FIXME -// QWindowSystemInterface::handleScreenAvailableGeometryChange(0); -// QWindowSystemInterface::handleScreenGeometryChange(0); - } else { - m_pauseApplicationMutex.unlock(); - } -} - -namespace QtAndroid -{ -#ifndef ANDROID_PLUGIN_OPENGL - void flushImage(const QPoint &pos, const QImage &image, const QRect &destinationRect) - { - checkPauseApplication(); - QMutexLocker locker(&m_surfaceMutex); - if (!m_surface) - return; - AttachedJNIEnv env; - if (!env.jniEnv) - return; - - int bpp = 2; - AndroidBitmapInfo info; - int ret; - - if ((ret = AndroidBitmap_getInfo(env.jniEnv, m_surface, &info)) < 0) { - qWarning() << "AndroidBitmap_getInfo() failed ! error=" << ret; - m_javaVM->DetachCurrentThread(); - return; - } - - if (info.format != ANDROID_BITMAP_FORMAT_RGB_565) { - qWarning() << "Bitmap format is not RGB_565!"; - m_javaVM->DetachCurrentThread(); - return; - } - - void *pixels; - unsigned char *screenBits; - if ((ret = AndroidBitmap_lockPixels(env.jniEnv, m_surface, &pixels)) < 0) { - qWarning() << "AndroidBitmap_lockPixels() failed! error=" << ret; - m_javaVM->DetachCurrentThread(); - return; - } - - screenBits = static_cast(pixels); - int sbpl = info.stride; - int swidth = info.width; - int sheight = info.height; - - unsigned sposx = pos.x() + destinationRect.x(); - unsigned sposy = pos.y() + destinationRect.y(); - - screenBits += sposy * sbpl; - - unsigned ibpl = image.bytesPerLine(); - unsigned iposx = destinationRect.x(); - unsigned iposy = destinationRect.y(); - - const unsigned char *imageBits = static_cast(image.bits()); - imageBits += iposy * ibpl; - - unsigned width = swidth - sposx < unsigned(destinationRect.width()) - ? (swidth-sposx) - : destinationRect.width(); - unsigned height = sheight - sposy < unsigned(destinationRect.height()) - ? (sheight - sposy) - : destinationRect.height(); - - for (unsigned y = 0; y < height; y++) { - memcpy(screenBits + y*sbpl + sposx*bpp, - imageBits + y*ibpl + iposx*bpp, - width*bpp); - } - AndroidBitmap_unlockPixels(env.jniEnv, m_surface); - - env.jniEnv->CallStaticVoidMethod(m_applicationClass, - m_redrawSurfaceMethodID, - jint(destinationRect.left()), - jint(destinationRect.top()), - jint(destinationRect.right() + 1), - jint(destinationRect.bottom() + 1)); -#warning FIXME dirty hack, figure out why it needs to add 1 to right and bottom !!!! - } - -#else // for #ifndef ANDROID_PLUGIN_OPENGL - EGLNativeWindowType nativeWindow(bool waitForWindow) - { - m_surfaceMutex.lock(); - if (!m_nativeWindow && waitForWindow) { - m_waitForWindow = true; - m_surfaceMutex.unlock(); - m_waitForWindowSemaphore.acquire(); - m_waitForWindow = false; - return m_nativeWindow; - } - m_surfaceMutex.unlock(); - return m_nativeWindow; - } -#endif - - void setAndroidPlatformIntegration(QAndroidPlatformIntegration *androidPlatformIntegration) - { - m_surfaceMutex.lock(); - m_androidPlatformIntegration = androidPlatformIntegration; - m_surfaceMutex.unlock(); - } - - QAndroidPlatformIntegration *androidPlatformIntegration() - { - QMutexLocker locker(&m_surfaceMutex); - return m_androidPlatformIntegration; - } - - QWindow *topLevelWindowAt(const QPoint &globalPos) - { - return m_androidPlatformIntegration - ? m_androidPlatformIntegration->screen()->topLevelAt(globalPos) - : 0; - } - - int desktopWidthPixels() - { - return m_desktopWidthPixels; - } - - int desktopHeightPixels() - { - return m_desktopHeightPixels; - } - - double scaledDensity() - { - return m_scaledDensity; - } - - JavaVM *javaVM() - { - return m_javaVM; - } - - jclass findClass(const QString &className, JNIEnv *env) - { - return static_cast(env->CallObjectMethod(m_classLoaderObject, - m_loadClassMethodID, - env->NewString(reinterpret_cast(className.constData()), - jsize(className.length())))); - } - - AAssetManager *assetManager() - { - return m_assetManager; - } - - jclass applicationClass() - { - return m_applicationClass; - } - - jobject activity() - { - return m_activityObject; - } - - void showStatusBar() - { - if (m_statusBarShowing) - return; - - QtAndroid::AttachedJNIEnv env; - if (env.jniEnv == 0) { - qWarning("Failed to get JNI Environment."); - return; - } - - env.jniEnv->CallStaticVoidMethod(m_applicationClass, m_setFullScreenMethodID, false); - m_statusBarShowing = true; - } - - void hideStatusBar() - { - if (!m_statusBarShowing) - return; - - QtAndroid::AttachedJNIEnv env; - if (env.jniEnv == 0) { - qWarning("Failed to get JNI Environment."); - return; - } - - env.jniEnv->CallStaticVoidMethod(m_applicationClass, m_setFullScreenMethodID, true); - m_statusBarShowing = false; - } - - void setApplicationActive() - { - if (m_activityActive) - QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive); - } - - jobject createBitmap(QImage img, JNIEnv *env) - { - if (img.format() != QImage::Format_ARGB32 && img.format() != QImage::Format_RGB16) - img = img.convertToFormat(QImage::Format_ARGB32); - - jobject bitmap = env->CallStaticObjectMethod(m_bitmapClass, - m_createBitmapMethodID, - img.width(), - img.height(), - img.format() == QImage::Format_ARGB32 - ? m_ARGB_8888_BitmapConfigValue - : m_RGB_565_BitmapConfigValue); - if (!bitmap) - return 0; - - AndroidBitmapInfo info; - if (AndroidBitmap_getInfo(env, bitmap, &info) < 0) { - env->DeleteLocalRef(bitmap); - return 0; - } - - void *pixels; - if (AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0) { - env->DeleteLocalRef(bitmap); - return 0; - } - - if (info.stride == uint(img.bytesPerLine()) - && info.width == uint(img.width()) - && info.height == uint(img.height())) { - memcpy(pixels, img.constBits(), info.stride * info.height); - } else { - uchar *bmpPtr = static_cast(pixels); - const unsigned width = qMin(info.width, (uint)img.width()); //should be the same - const unsigned height = qMin(info.height, (uint)img.height()); //should be the same - for (unsigned y = 0; y < height; y++, bmpPtr += info.stride) - memcpy(bmpPtr, img.constScanLine(y), width); - } - AndroidBitmap_unlockPixels(env, bitmap); - return bitmap; - } - - jobject createBitmapDrawable(jobject bitmap, JNIEnv *env) - { - if (!bitmap) - return 0; - - return env->NewObject(m_bitmapDrawableClass, - m_bitmapDrawableConstructorMethodID, - m_resourcesObj, - bitmap); - } - - const char *classErrorMsgFmt() - { - return m_classErrorMsg; - } - - const char *methodErrorMsgFmt() - { - return m_methodErrorMsg; - } - - const char *qtTagText() - { - return m_qtTag; - } -} - -static jboolean startQtAndroidPlugin(JNIEnv* /*env*/, jobject /*object*//*, jobject applicationAssetManager*/) -{ -#ifndef ANDROID_PLUGIN_OPENGL - m_surface = 0; -#else - m_nativeWindow = 0; - m_waitForWindow = false; -#endif - - m_androidPlatformIntegration = 0; - m_androidAssetsFileEngineHandler = new AndroidAssetsFileEngineHandler(); - -#ifdef ANDROID_PLUGIN_OPENGL - return true; -#else - return false; -#endif -} - -static void *startMainMethod(void */*data*/) -{ - QVarLengthArray params(m_applicationParams.size()); - for (int i = 0; i < m_applicationParams.size(); i++) - params[i] = static_cast(m_applicationParams[i].constData()); - - int ret = m_main(m_applicationParams.length(), const_cast(params.data())); - Q_UNUSED(ret); - - if (m_mainLibraryHnd) { - int res = dlclose(m_mainLibraryHnd); - if (res < 0) - qWarning() << "dlclose failed:" << dlerror(); - } - - QtAndroid::AttachedJNIEnv env; - if (!env.jniEnv) - return 0; - - if (m_applicationClass) { - jmethodID quitApp = env.jniEnv->GetStaticMethodID(m_applicationClass, "quitApp", "()V"); - env.jniEnv->CallStaticVoidMethod(m_applicationClass, quitApp); - } - - return 0; -} - -static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring paramsString, jstring environmentString) -{ - m_mainLibraryHnd = NULL; - const char *nativeString = env->GetStringUTFChars(environmentString, 0); - QByteArray string = nativeString; - env->ReleaseStringUTFChars(environmentString, nativeString); - m_applicationParams=string.split('\t'); - foreach (string, m_applicationParams) { - if (!string.isEmpty() && putenv(string.constData())) - qWarning() << "Can't set environment" << string; - } - - nativeString = env->GetStringUTFChars(paramsString, 0); - string = nativeString; - env->ReleaseStringUTFChars(paramsString, nativeString); - - m_applicationParams=string.split('\t'); - - // Go home - QDir::setCurrent(QDir::homePath()); - - //look for main() - if (m_applicationParams.length()) { - // Obtain a handle to the main library (the library that contains the main() function). - // This library should already be loaded, and calling dlopen() will just return a reference to it. - m_mainLibraryHnd = dlopen(m_applicationParams.first().data(), 0); - if (m_mainLibraryHnd == NULL) { - qCritical() << "dlopen failed:" << dlerror(); - return false; - } - m_main = (Main)dlsym(m_mainLibraryHnd, "main"); - } else { - qWarning() << "No main library was specified; searching entire process (this is slow!)"; - m_main = (Main)dlsym(RTLD_DEFAULT, "main"); - } - - if (!m_main) { - qCritical() << "dlsym failed:" << dlerror(); - qCritical() << "Could not find main method"; - return false; - } - - pthread_t appThread; - return pthread_create(&appThread, NULL, startMainMethod, NULL) == 0; -} - -static void pauseQtApp(JNIEnv */*env*/, jobject /*thiz*/) -{ - m_surfaceMutex.lock(); - m_pauseApplicationMutex.lock(); - - if (m_androidPlatformIntegration) - m_androidPlatformIntegration->pauseApp(); - m_pauseApplication = true; - - m_pauseApplicationMutex.unlock(); - m_surfaceMutex.unlock(); -} - -static void resumeQtApp(JNIEnv */*env*/, jobject /*thiz*/) -{ - m_surfaceMutex.lock(); - m_pauseApplicationMutex.lock(); - if (m_androidPlatformIntegration) - m_androidPlatformIntegration->resumeApp(); - - if (m_pauseApplication) - m_pauseApplicationSemaphore.release(); - - m_pauseApplicationMutex.unlock(); - m_surfaceMutex.unlock(); -} - -static void quitQtAndroidPlugin(JNIEnv *env, jclass /*clazz*/) -{ -#ifndef ANDROID_PLUGIN_OPENGL - if (m_surface) { - env->DeleteGlobalRef(m_surface); - m_surface = 0; - } -#else - Q_UNUSED(env); -#endif - - m_androidPlatformIntegration = 0; - delete m_androidAssetsFileEngineHandler; -} - -static void terminateQt(JNIEnv *env, jclass /*clazz*/) -{ -#ifndef ANDROID_PLUGIN_OPENGL - if (m_surface) - env->DeleteGlobalRef(m_surface); -#endif - env->DeleteGlobalRef(m_applicationClass); - env->DeleteGlobalRef(m_classLoaderObject); - env->DeleteGlobalRef(m_resourcesObj); - env->DeleteGlobalRef(m_activityObject); - env->DeleteGlobalRef(m_bitmapClass); - env->DeleteGlobalRef(m_ARGB_8888_BitmapConfigValue); - env->DeleteGlobalRef(m_RGB_565_BitmapConfigValue); - env->DeleteGlobalRef(m_bitmapDrawableClass); -} - -static void setSurface(JNIEnv *env, jobject /*thiz*/, jobject jSurface) -{ -#ifndef ANDROID_PLUGIN_OPENGL - if (m_surface) - env->DeleteGlobalRef(m_surface); - m_surface = env->NewGlobalRef(jSurface); -#else - m_surfaceMutex.lock(); - EGLNativeWindowType nativeWindow = ANativeWindow_fromSurface(env, jSurface); - bool sameNativeWindow = (nativeWindow != 0 && nativeWindow == m_nativeWindow); - - m_nativeWindow = nativeWindow; - if (m_waitForWindow) - m_waitForWindowSemaphore.release(); - - if (m_androidPlatformIntegration) { - // Use the desktop size. - // On some devices, the getters for the native window size gives wrong values - QSize size = QAndroidPlatformIntegration::defaultDesktopSize(); - - QPlatformScreen *screen = m_androidPlatformIntegration->screen(); - QRect geometry(QPoint(0, 0), size); - if (screen) { - QWindowSystemInterface::handleScreenAvailableGeometryChange(screen->screen(), geometry); - QWindowSystemInterface::handleScreenGeometryChange(screen->screen(), geometry); - } - - if (!sameNativeWindow) { - m_surfaceMutex.unlock(); - m_androidPlatformIntegration->surfaceChanged(); - } else { - // Resize all top level windows, since they share the same surface - foreach (QWindow *w, QGuiApplication::topLevelWindows()) { - QAndroidOpenGLPlatformWindow *window = - static_cast(w->handle()); - - if (window != 0) { - window->lock(); - window->scheduleResize(size); - - QWindowSystemInterface::handleExposeEvent(window->window(), - QRegion(window->window()->geometry())); - window->unlock(); - } - } - - m_surfaceMutex.unlock(); - } - - } else { - m_surfaceMutex.unlock(); - } -#endif // for #ifndef ANDROID_PLUGIN_OPENGL -} - -static void destroySurface(JNIEnv *env, jobject /*thiz*/) -{ -#ifndef ANDROID_PLUGIN_OPENGL - if (m_surface) { - env->DeleteGlobalRef(m_surface); - m_surface = 0; - } -#else - Q_UNUSED(env); - m_nativeWindow = 0; - if (m_androidPlatformIntegration != 0) - m_androidPlatformIntegration->invalidateNativeSurface(); -#endif -} - -static void setDisplayMetrics(JNIEnv */*env*/, jclass /*clazz*/, - jint /*widthPixels*/, jint /*heightPixels*/, - jint desktopWidthPixels, jint desktopHeightPixels, - jdouble xdpi, jdouble ydpi, jdouble scaledDensity) -{ - m_desktopWidthPixels = desktopWidthPixels; - m_desktopHeightPixels = desktopHeightPixels; - m_scaledDensity = scaledDensity; - - if (!m_androidPlatformIntegration) { - QAndroidPlatformIntegration::setDefaultDisplayMetrics(desktopWidthPixels,desktopHeightPixels, - qRound(double(desktopWidthPixels) / xdpi * 25.4), - qRound(double(desktopHeightPixels) / ydpi * 25.4)); - } else { - m_androidPlatformIntegration->setDisplayMetrics(qRound(double(desktopWidthPixels) / xdpi * 25.4), - qRound(double(desktopHeightPixels) / ydpi * 25.4)); - m_androidPlatformIntegration->setDesktopSize(desktopWidthPixels, desktopHeightPixels); - } -} - -static void lockSurface(JNIEnv */*env*/, jobject /*thiz*/) -{ - m_surfaceMutex.lock(); -} - -static void unlockSurface(JNIEnv */*env*/, jobject /*thiz*/) -{ - m_surfaceMutex.unlock(); -} - -static void updateWindow(JNIEnv */*env*/, jobject /*thiz*/) -{ - if (!m_androidPlatformIntegration) - return; - - if (QGuiApplication::instance() != 0) { - foreach (QWindow *w, QGuiApplication::topLevelWindows()) - QWindowSystemInterface::handleExposeEvent(w, QRegion(w->geometry())); - } - -#ifndef ANDROID_PLUGIN_OPENGL - QAndroidPlatformScreen *screen = static_cast(m_androidPlatformIntegration->screen()); - QMetaObject::invokeMethod(screen, "setDirty", Qt::QueuedConnection, Q_ARG(QRect,screen->geometry())); -#else - qWarning("updateWindow: Dirty screen not implemented yet on OpenGL"); -#endif -} - -static void updateApplicationState(JNIEnv */*env*/, jobject /*thiz*/, jint state) -{ - m_activityActive = (state == Qt::ApplicationActive); - - if (!m_androidPlatformIntegration || !QGuiApplicationPrivate::platformIntegration()) - return; - - QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState(state)); -} - -static void handleOrientationChanged(JNIEnv */*env*/, jobject /*thiz*/, jint newRotation, jint nativeOrientation) -{ - // Array of orientations rotated in 90 degree increments, counterclockwise - // (same direction as Android measures angles) - static const Qt::ScreenOrientation orientations[] = { - Qt::PortraitOrientation, - Qt::LandscapeOrientation, - Qt::InvertedPortraitOrientation, - Qt::InvertedLandscapeOrientation - }; - - // The Android API defines the following constants: - // ROTATION_0 : 0 - // ROTATION_90 : 1 - // ROTATION_180 : 2 - // ROTATION_270 : 3 - // ORIENTATION_PORTRAIT : 1 - // ORIENTATION_LANDSCAPE : 2 - - // and newRotation is how much the current orientation is rotated relative to nativeOrientation - - // which means that we can be really clever here :) - Qt::ScreenOrientation screenOrientation = orientations[(nativeOrientation - 1 + newRotation) % 4]; - Qt::ScreenOrientation native = orientations[nativeOrientation - 1]; - - QAndroidPlatformIntegration::setScreenOrientation(screenOrientation, native); - if (m_androidPlatformIntegration) { - QPlatformScreen *screen = m_androidPlatformIntegration->screen(); - QWindowSystemInterface::handleScreenOrientationChange(screen->screen(), - screenOrientation); - } -} - -static JNINativeMethod methods[] = { - {"startQtAndroidPlugin", "()Z", (void *)startQtAndroidPlugin}, - {"startQtApplication", "(Ljava/lang/String;Ljava/lang/String;)V", (void *)startQtApplication}, - {"pauseQtApp", "()V", (void *)pauseQtApp}, - {"resumeQtApp", "()V", (void *)resumeQtApp}, - {"quitQtAndroidPlugin", "()V", (void *)quitQtAndroidPlugin}, - {"terminateQt", "()V", (void *)terminateQt}, - {"setDisplayMetrics", "(IIIIDDD)V", (void *)setDisplayMetrics}, - {"setSurface", "(Ljava/lang/Object;)V", (void *)setSurface}, - {"destroySurface", "()V", (void *)destroySurface}, - {"lockSurface", "()V", (void *)lockSurface}, - {"unlockSurface", "()V", (void *)unlockSurface}, - {"updateWindow", "()V", (void *)updateWindow}, - {"updateApplicationState", "(I)V", (void *)updateApplicationState}, - {"handleOrientationChanged", "(II)V", (void *)handleOrientationChanged} -}; - -#define FIND_AND_CHECK_CLASS(CLASS_NAME) \ -clazz = env->FindClass(CLASS_NAME); \ -if (!clazz) { \ - __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_classErrorMsg, CLASS_NAME); \ - return JNI_FALSE; \ -} - -#define GET_AND_CHECK_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ -VAR = env->GetMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ -if (!VAR) { \ - __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \ - return JNI_FALSE; \ -} - -#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ -VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ -if (!VAR) { \ - __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \ - return JNI_FALSE; \ -} - -#define GET_AND_CHECK_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \ -VAR = env->GetFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \ -if (!VAR) { \ - __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, FIELD_NAME, FIELD_SIGNATURE); \ - return JNI_FALSE; \ -} - -#define GET_AND_CHECK_STATIC_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \ -VAR = env->GetStaticFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \ -if (!VAR) { \ - __android_log_print(ANDROID_LOG_FATAL, m_qtTag, m_methodErrorMsg, FIELD_NAME, FIELD_SIGNATURE); \ - return JNI_FALSE; \ -} - -static int registerNatives(JNIEnv *env) -{ - jclass clazz; - FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/QtNative"); - m_applicationClass = static_cast(env->NewGlobalRef(clazz)); - GET_AND_CHECK_STATIC_METHOD(m_setFullScreenMethodID, m_applicationClass, "setFullScreen", "(Z)V"); - - if (env->RegisterNatives(m_applicationClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { - __android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed"); - return JNI_FALSE; - } - - GET_AND_CHECK_STATIC_METHOD(m_redrawSurfaceMethodID, m_applicationClass, "redrawSurface", "(IIII)V"); - - jmethodID methodID; - GET_AND_CHECK_STATIC_METHOD(methodID, m_applicationClass, "activity", "()Landroid/app/Activity;"); - jobject activityObject = env->CallStaticObjectMethod(m_applicationClass, methodID); - m_activityObject = env->NewGlobalRef(activityObject); - GET_AND_CHECK_STATIC_METHOD(methodID, m_applicationClass, "classLoader", "()Ljava/lang/ClassLoader;"); - m_classLoaderObject = env->NewGlobalRef(env->CallStaticObjectMethod(m_applicationClass, methodID)); - - clazz = env->GetObjectClass(m_classLoaderObject); - GET_AND_CHECK_METHOD(m_loadClassMethodID, clazz, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); - - FIND_AND_CHECK_CLASS("android/content/ContextWrapper"); - GET_AND_CHECK_METHOD(methodID, clazz, "getAssets", "()Landroid/content/res/AssetManager;"); - m_assetManager = AAssetManager_fromJava(env, env->CallObjectMethod(activityObject, methodID)); - - GET_AND_CHECK_METHOD(methodID, clazz, "getResources", "()Landroid/content/res/Resources;"); - m_resourcesObj = env->NewGlobalRef(env->CallObjectMethod(activityObject, methodID)); - - FIND_AND_CHECK_CLASS("android/graphics/Bitmap"); - m_bitmapClass = static_cast(env->NewGlobalRef(clazz)); - GET_AND_CHECK_STATIC_METHOD(m_createBitmapMethodID, m_bitmapClass - , "createBitmap", "(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;"); - - FIND_AND_CHECK_CLASS("android/graphics/Bitmap$Config"); - jfieldID fieldId; - GET_AND_CHECK_STATIC_FIELD(fieldId, clazz, "ARGB_8888", "Landroid/graphics/Bitmap$Config;"); - m_ARGB_8888_BitmapConfigValue = env->NewGlobalRef(env->GetStaticObjectField(clazz, fieldId)); - GET_AND_CHECK_STATIC_FIELD(fieldId, clazz, "RGB_565", "Landroid/graphics/Bitmap$Config;"); - m_RGB_565_BitmapConfigValue = env->NewGlobalRef(env->GetStaticObjectField(clazz, fieldId)); - - FIND_AND_CHECK_CLASS("android/graphics/drawable/BitmapDrawable"); - m_bitmapDrawableClass = static_cast(env->NewGlobalRef(clazz)); - GET_AND_CHECK_METHOD(m_bitmapDrawableConstructorMethodID, - m_bitmapDrawableClass, - "", - "(Landroid/content/res/Resources;Landroid/graphics/Bitmap;)V"); - - return JNI_TRUE; -} - -jint androidApiLevel(JNIEnv *env) -{ - jclass clazz; - FIND_AND_CHECK_CLASS("android/os/Build$VERSION"); - jfieldID fieldId; - GET_AND_CHECK_STATIC_FIELD(fieldId, clazz, "SDK_INT", "I"); - return env->GetStaticIntField(clazz, fieldId); -} - -Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/) -{ - typedef union { - JNIEnv *nativeEnvironment; - void *venv; - } UnionJNIEnvToVoid; - - __android_log_print(ANDROID_LOG_INFO, "Qt", "qt start"); - UnionJNIEnvToVoid uenv; - uenv.venv = NULL; - m_javaVM = 0; - - if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) { - __android_log_print(ANDROID_LOG_FATAL, "Qt", "GetEnv failed"); - return -1; - } - - JNIEnv *env = uenv.nativeEnvironment; - if (!registerNatives(env) - || !QtAndroidInput::registerNatives(env) - || !QtAndroidClipboard::registerNatives(env) - || !QtAndroidMenu::registerNatives(env) - || !QtAndroidAccessibility::registerNatives(env) - || !QtAndroidDialogHelpers::registerNatives(env)) { - __android_log_print(ANDROID_LOG_FATAL, "Qt", "registerNatives failed"); - return -1; - } - - jint apiLevel = androidApiLevel(env); - if (apiLevel >= 16 && !QtAndroidAccessibility::registerNatives(env)) { - __android_log_print(ANDROID_LOG_FATAL, "Qt A11y", "registerNatives failed"); - return -1; - } - - m_javaVM = vm; - return JNI_VERSION_1_4; -} diff --git a/src/plugins/platforms/android/src/androidjnimain.h b/src/plugins/platforms/android/src/androidjnimain.h deleted file mode 100644 index 11d3573404..0000000000 --- a/src/plugins/platforms/android/src/androidjnimain.h +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ANDROID_APP_H -#define ANDROID_APP_H - -#include - -#ifdef ANDROID_PLUGIN_OPENGL -# include -#endif - -#include - -#include -#include - -class QImage; -class QRect; -class QPoint; -class QThread; -class QAndroidPlatformIntegration; -class QWidget; -class QString; -class QWindow; - -namespace QtAndroid -{ - QAndroidPlatformIntegration *androidPlatformIntegration(); - void setAndroidPlatformIntegration(QAndroidPlatformIntegration *androidPlatformIntegration); - void setQtThread(QThread *thread); - -#ifndef ANDROID_PLUGIN_OPENGL - void flushImage(const QPoint &pos, const QImage &image, const QRect &rect); -#else - EGLNativeWindowType nativeWindow(bool waitToCreate = true); -#endif - - QWindow *topLevelWindowAt(const QPoint &globalPos); - int desktopWidthPixels(); - int desktopHeightPixels(); - double scaledDensity(); - JavaVM *javaVM(); - jclass findClass(const QString &className, JNIEnv *env); - AAssetManager *assetManager(); - jclass applicationClass(); - jobject activity(); - - void setApplicationActive(); - - void showStatusBar(); - void hideStatusBar(); - - jobject createBitmap(QImage img, JNIEnv *env = 0); - jobject createBitmapDrawable(jobject bitmap, JNIEnv *env = 0); - - struct AttachedJNIEnv - { - AttachedJNIEnv() - { - attached = false; - if (QtAndroid::javaVM()->GetEnv((void**)&jniEnv, JNI_VERSION_1_6) < 0) { - if (QtAndroid::javaVM()->AttachCurrentThread(&jniEnv, NULL) < 0) { - __android_log_print(ANDROID_LOG_ERROR, "Qt", "AttachCurrentThread failed"); - jniEnv = 0; - return; - } - attached = true; - } - } - - ~AttachedJNIEnv() - { - if (attached) - QtAndroid::javaVM()->DetachCurrentThread(); - } - bool attached; - JNIEnv *jniEnv; - }; - const char *classErrorMsgFmt(); - const char *methodErrorMsgFmt(); - const char *qtTagText(); - -} -#endif // ANDROID_APP_H diff --git a/src/plugins/platforms/android/src/androidjnimenu.cpp b/src/plugins/platforms/android/src/androidjnimenu.cpp deleted file mode 100644 index dbdd7c9b8e..0000000000 --- a/src/plugins/platforms/android/src/androidjnimenu.cpp +++ /dev/null @@ -1,426 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "androidjnimenu.h" -#include "androidjnimain.h" -#include "qandroidplatformmenubar.h" -#include "qandroidplatformmenu.h" -#include "qandroidplatformmenuitem.h" - -#include -#include -#include -#include - -using namespace QtAndroid; - -namespace QtAndroidMenu -{ - static QQueue pendingContextMenus; - static QAndroidPlatformMenu *visibleMenu = 0; - static QMutex visibleMenuMutex(QMutex::Recursive); - - static QSet menuBars; - static QAndroidPlatformMenuBar *visibleMenuBar = 0; - static QWindow *activeTopLevelWindow = 0; - static QMutex menuBarMutex(QMutex::Recursive); - - static jmethodID openContextMenuMethodID = 0; - static jmethodID closeContextMenuMethodID = 0; - static jmethodID resetOptionsMenuMethodID = 0; - - static jmethodID clearMenuMethodID = 0; - static jmethodID addMenuItemMethodID = 0; - static int menuNoneValue = 0; - static jmethodID setHeaderTitleContextMenuMethodID = 0; - - static jmethodID setCheckableMenuItemMethodID = 0; - static jmethodID setCheckedMenuItemMethodID = 0; - static jmethodID setEnabledMenuItemMethodID = 0; - static jmethodID setIconMenuItemMethodID = 0; - static jmethodID setVisibleMenuItemMethodID = 0; - - void resetMenuBar() - { - AttachedJNIEnv env; - if (env.jniEnv) - env.jniEnv->CallStaticVoidMethod(applicationClass(), resetOptionsMenuMethodID); - } - - void showContextMenu(QAndroidPlatformMenu *menu, JNIEnv *env) - { - QMutexLocker lock(&visibleMenuMutex); - if (visibleMenu) { - pendingContextMenus.enqueue(menu); - } else { - visibleMenu = menu; - menu->aboutToShow(); - if (env) { - env->CallStaticVoidMethod(applicationClass(), openContextMenuMethodID); - } else { - AttachedJNIEnv aenv; - if (aenv.jniEnv) - aenv.jniEnv->CallStaticVoidMethod(applicationClass(), openContextMenuMethodID); - } - } - } - - void hideContextMenu(QAndroidPlatformMenu *menu) - { - QMutexLocker lock(&visibleMenuMutex); - if (visibleMenu == menu) { - AttachedJNIEnv env; - if (env.jniEnv) - env.jniEnv->CallStaticVoidMethod(applicationClass(), openContextMenuMethodID); - } else { - pendingContextMenus.removeOne(menu); - } - } - - void syncMenu(QAndroidPlatformMenu */*menu*/) - { -// QMutexLocker lock(&visibleMenuMutex); -// if (visibleMenu == menu) -// { -// hideContextMenu(menu); -// showContextMenu(menu); -// } - } - - void androidPlatformMenuDestroyed(QAndroidPlatformMenu *menu) - { - QMutexLocker lock(&visibleMenuMutex); - if (visibleMenu == menu) - visibleMenu = 0; - } - - void setMenuBar(QAndroidPlatformMenuBar *menuBar, QWindow *window) - { - if (activeTopLevelWindow == window && visibleMenuBar != menuBar) { - visibleMenuBar = menuBar; - resetMenuBar(); - } - } - - void setActiveTopLevelWindow(QWindow *window) - { - Qt::WindowFlags flags = window ? window->flags() : Qt::WindowFlags(); - bool isNonRegularWindow = flags & (Qt::Desktop | Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window; - if (isNonRegularWindow) - return; - - QMutexLocker lock(&menuBarMutex); - if (activeTopLevelWindow == window) - return; - - visibleMenuBar = 0; - activeTopLevelWindow = window; - foreach (QAndroidPlatformMenuBar *menuBar, menuBars) { - if (menuBar->parentWindow() == window) { - visibleMenuBar = menuBar; - resetMenuBar(); - break; - } - } - - } - - void addMenuBar(QAndroidPlatformMenuBar *menuBar) - { - QMutexLocker lock(&menuBarMutex); - menuBars.insert(menuBar); - } - - void removeMenuBar(QAndroidPlatformMenuBar *menuBar) - { - QMutexLocker lock(&menuBarMutex); - menuBars.remove(menuBar); - if (visibleMenuBar == menuBar) { - visibleMenuBar = 0; - resetMenuBar(); - } - } - - static QString removeAmpersandEscapes(QString s) - { - int i = 0; - while (i < s.size()) { - ++i; - if (s.at(i-1) != QLatin1Char('&')) - continue; - if (i < s.size() && s.at(i) == QLatin1Char('&')) - ++i; - s.remove(i-1,1); - } - return s.trimmed(); - } - - static void fillMenuItem(JNIEnv *env, jobject menuItem, bool checkable, bool checked, bool enabled, bool visible, const QIcon &icon=QIcon()) - { - env->CallObjectMethod(menuItem, setCheckableMenuItemMethodID, checkable); - env->CallObjectMethod(menuItem, setCheckedMenuItemMethodID, checked); - env->CallObjectMethod(menuItem, setEnabledMenuItemMethodID, enabled); - - if (!icon.isNull()) { // isNull() only checks the d pointer, not the actual image data. - int sz = qMax(36, qgetenv("QT_ANDROID_APP_ICON_SIZE").toInt()); - QImage img = icon.pixmap(QSize(sz,sz), - enabled - ? QIcon::Normal - : QIcon::Disabled, - QIcon::On).toImage(); - if (!img.isNull()) { // Make sure we have a valid image. - env->CallObjectMethod(menuItem, - setIconMenuItemMethodID, - createBitmapDrawable(createBitmap(img, env), env)); - } - } - - env->CallObjectMethod(menuItem, setVisibleMenuItemMethodID, visible); - } - - static int addAllMenuItemsToMenu(JNIEnv *env, jobject menu, QAndroidPlatformMenu *platformMenu) { - int order = 0; - QMutexLocker lock(platformMenu->menuItemsMutex()); - foreach (QAndroidPlatformMenuItem *item, platformMenu->menuItems()) { - if (item->isSeparator()) - continue; - QString itemText = removeAmpersandEscapes(item->text()); - jstring jtext = env->NewString(reinterpret_cast(itemText.data()), - itemText.length()); - jobject menuItem = env->CallObjectMethod(menu, - addMenuItemMethodID, - menuNoneValue, - int(item->tag()), - order++, - jtext); - env->DeleteLocalRef(jtext); - fillMenuItem(env, - menuItem, - item->isCheckable(), - item->isChecked(), - item->isEnabled(), - item->isVisible(), - item->icon()); - } - - return order; - } - - static jboolean onPrepareOptionsMenu(JNIEnv *env, jobject /*thiz*/, jobject menu) - { - env->CallVoidMethod(menu, clearMenuMethodID); - QMutexLocker lock(&menuBarMutex); - if (!visibleMenuBar) - return JNI_FALSE; - - const QAndroidPlatformMenuBar::PlatformMenusType &menus = visibleMenuBar->menus(); - int order = 0; - QMutexLocker lockMenuBarMutex(visibleMenuBar->menusListMutex()); - if (menus.size() == 1) { // Expand the menu - order = addAllMenuItemsToMenu(env, menu, static_cast(menus.front())); - } else { - foreach (QAndroidPlatformMenu *item, menus) { - QString itemText = removeAmpersandEscapes(item->text()); - jstring jtext = env->NewString(reinterpret_cast(itemText.data()), - itemText.length()); - jobject menuItem = env->CallObjectMethod(menu, - addMenuItemMethodID, - menuNoneValue, - int(item->tag()), - order++, - jtext); - env->DeleteLocalRef(jtext); - - fillMenuItem(env, - menuItem, - false, - false, - item->isEnabled(), - item->isVisible(), - item->icon()); - } - } - return order ? JNI_TRUE : JNI_FALSE; - } - - static jboolean onOptionsItemSelected(JNIEnv *env, jobject /*thiz*/, jint menuId, jboolean checked) - { - QMutexLocker lock(&menuBarMutex); - if (!visibleMenuBar) - return JNI_FALSE; - - const QAndroidPlatformMenuBar::PlatformMenusType &menus = visibleMenuBar->menus(); - if (menus.size() == 1) { // Expanded menu - QAndroidPlatformMenuItem *item = static_cast(menus.front()->menuItemForTag(menuId)); - if (item) { - if (item->menu()) { - showContextMenu(item->menu(), env); - } else { - if (item->isCheckable()) - item->setChecked(checked); - item->activated(); - } - } - } else { - QAndroidPlatformMenu *menu = static_cast(visibleMenuBar->menuForTag(menuId)); - if (menu) - showContextMenu(menu, env); - } - - return JNI_TRUE; - } - - static void onOptionsMenuClosed(JNIEnv */*env*/, jobject /*thiz*/, jobject /*menu*/) - { - } - - static void onCreateContextMenu(JNIEnv *env, jobject /*thiz*/, jobject menu) - { - env->CallVoidMethod(menu, clearMenuMethodID); - QMutexLocker lock(&visibleMenuMutex); - if (!visibleMenu) - return; - - QString menuText = removeAmpersandEscapes(visibleMenu->text()); - jstring jtext = env->NewString(reinterpret_cast(menuText.data()), - menuText.length()); - env->CallObjectMethod(menu, setHeaderTitleContextMenuMethodID, jtext); - env->DeleteLocalRef(jtext); - addAllMenuItemsToMenu(env, menu, visibleMenu); - } - - static jboolean onContextItemSelected(JNIEnv *env, jobject /*thiz*/, jint menuId, jboolean checked) - { - QMutexLocker lock(&visibleMenuMutex); - QAndroidPlatformMenuItem * item = static_cast(visibleMenu->menuItemForTag(menuId)); - if (item) { - if (item->menu()) { - showContextMenu(item->menu(), env); - } else { - if (item->isCheckable()) - item->setChecked(checked); - item->activated(); - } - } - return JNI_TRUE; - } - - static void onContextMenuClosed(JNIEnv *env, jobject /*thiz*/, jobject /*menu*/) - { - QMutexLocker lock(&visibleMenuMutex); - if (!visibleMenu) - return; - visibleMenu->aboutToHide(); - visibleMenu = 0; - if (!pendingContextMenus.empty()) - showContextMenu(pendingContextMenus.dequeue(), env); - } - - static JNINativeMethod methods[] = { - {"onPrepareOptionsMenu", "(Landroid/view/Menu;)Z", (void *)onPrepareOptionsMenu}, - {"onOptionsItemSelected", "(IZ)Z", (void *)onOptionsItemSelected}, - {"onOptionsMenuClosed", "(Landroid/view/Menu;)V", (void*)onOptionsMenuClosed}, - {"onCreateContextMenu", "(Landroid/view/ContextMenu;)V", (void *)onCreateContextMenu}, - {"onContextItemSelected", "(IZ)Z", (void *)onContextItemSelected}, - {"onContextMenuClosed", "(Landroid/view/Menu;)V", (void*)onContextMenuClosed}, - }; - -#define FIND_AND_CHECK_CLASS(CLASS_NAME) \ - clazz = env->FindClass(CLASS_NAME); \ - if (!clazz) { \ - __android_log_print(ANDROID_LOG_FATAL, qtTagText(), classErrorMsgFmt(), CLASS_NAME); \ - return false; \ - } - -#define GET_AND_CHECK_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ - VAR = env->GetMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ - if (!VAR) { \ - __android_log_print(ANDROID_LOG_FATAL, qtTagText(), methodErrorMsgFmt(), METHOD_NAME, METHOD_SIGNATURE); \ - return false; \ - } - -#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ - VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ - if (!VAR) { \ - __android_log_print(ANDROID_LOG_FATAL, qtTagText(), methodErrorMsgFmt(), METHOD_NAME, METHOD_SIGNATURE); \ - return false; \ - } - -#define GET_AND_CHECK_STATIC_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE) \ - VAR = env->GetStaticFieldID(CLASS, FIELD_NAME, FIELD_SIGNATURE); \ - if (!VAR) { \ - __android_log_print(ANDROID_LOG_FATAL, qtTagText(), methodErrorMsgFmt(), FIELD_NAME, FIELD_SIGNATURE); \ - return false; \ - } - - bool registerNatives(JNIEnv *env) - { - jclass appClass = applicationClass(); - - if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { - __android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed"); - return false; - } - - GET_AND_CHECK_STATIC_METHOD(openContextMenuMethodID, appClass, "openContextMenu", "()V"); - GET_AND_CHECK_STATIC_METHOD(closeContextMenuMethodID, appClass, "closeContextMenu", "()V"); - GET_AND_CHECK_STATIC_METHOD(resetOptionsMenuMethodID, appClass, "resetOptionsMenu", "()V"); - - jclass clazz; - FIND_AND_CHECK_CLASS("android/view/Menu"); - GET_AND_CHECK_METHOD(clearMenuMethodID, clazz, "clear", "()V"); - GET_AND_CHECK_METHOD(addMenuItemMethodID, clazz, "add", "(IIILjava/lang/CharSequence;)Landroid/view/MenuItem;"); - jfieldID menuNoneFiledId; - GET_AND_CHECK_STATIC_FIELD(menuNoneFiledId, clazz, "NONE", "I"); - menuNoneValue = env->GetStaticIntField(clazz, menuNoneFiledId); - - FIND_AND_CHECK_CLASS("android/view/ContextMenu"); - GET_AND_CHECK_METHOD(setHeaderTitleContextMenuMethodID, clazz, "setHeaderTitle","(Ljava/lang/CharSequence;)Landroid/view/ContextMenu;"); - - FIND_AND_CHECK_CLASS("android/view/MenuItem"); - GET_AND_CHECK_METHOD(setCheckableMenuItemMethodID, clazz, "setCheckable", "(Z)Landroid/view/MenuItem;"); - GET_AND_CHECK_METHOD(setCheckedMenuItemMethodID, clazz, "setChecked", "(Z)Landroid/view/MenuItem;"); - GET_AND_CHECK_METHOD(setEnabledMenuItemMethodID, clazz, "setEnabled", "(Z)Landroid/view/MenuItem;"); - GET_AND_CHECK_METHOD(setIconMenuItemMethodID, clazz, "setIcon", "(Landroid/graphics/drawable/Drawable;)Landroid/view/MenuItem;"); - GET_AND_CHECK_METHOD(setVisibleMenuItemMethodID, clazz, "setVisible", "(Z)Landroid/view/MenuItem;"); - return true; - } -} diff --git a/src/plugins/platforms/android/src/androidjnimenu.h b/src/plugins/platforms/android/src/androidjnimenu.h deleted file mode 100644 index 7c5422f67b..0000000000 --- a/src/plugins/platforms/android/src/androidjnimenu.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ANDROIDJNIMENU_H -#define ANDROIDJNIMENU_H - -#include - -class QAndroidPlatformMenuBar; -class QAndroidPlatformMenu; -class QAndroidPlatformMenuItem; -class QWindow; - -namespace QtAndroidMenu -{ - // Menu support - void showContextMenu(QAndroidPlatformMenu *menu, JNIEnv *env = 0); - void hideContextMenu(QAndroidPlatformMenu *menu); - void syncMenu(QAndroidPlatformMenu *menu); - void androidPlatformMenuDestroyed(QAndroidPlatformMenu *menu); - - void setMenuBar(QAndroidPlatformMenuBar *menuBar, QWindow *window); - void setActiveTopLevelWindow(QWindow *window); - void addMenuBar(QAndroidPlatformMenuBar *menuBar); - void removeMenuBar(QAndroidPlatformMenuBar *menuBar); - - // Menu support - bool registerNatives(JNIEnv *env); -} - -#endif // ANDROIDJNIMENU_H diff --git a/src/plugins/platforms/android/src/androidplatformplugin.cpp b/src/plugins/platforms/android/src/androidplatformplugin.cpp deleted file mode 100644 index 2cf5aa1e01..0000000000 --- a/src/plugins/platforms/android/src/androidplatformplugin.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "qandroidplatformintegration.h" - -QT_BEGIN_NAMESPACE - -class QAndroidPlatformIntegrationPlugin: public QPlatformIntegrationPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2" FILE "android.json") -public: - QPlatformIntegration *create(const QString &key, const QStringList ¶mList); -}; - - -QPlatformIntegration *QAndroidPlatformIntegrationPlugin::create(const QString &key, const QStringList ¶mList) -{ - Q_UNUSED(paramList); - if (!key.compare(QLatin1String("android"), Qt::CaseInsensitive)) - return new QAndroidPlatformIntegration(paramList); - return 0; -} - -QT_END_NAMESPACE -#include "androidplatformplugin.moc" - diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglcontext.cpp b/src/plugins/platforms/android/src/opengl/qandroidopenglcontext.cpp deleted file mode 100644 index 6431914812..0000000000 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglcontext.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidopenglcontext.h" -#include "qandroidopenglplatformwindow.h" -#include "qandroidplatformintegration.h" - -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -QAndroidOpenGLContext::QAndroidOpenGLContext(const QAndroidPlatformIntegration *integration, - const QSurfaceFormat &format, - QPlatformOpenGLContext *share, - EGLDisplay display, - EGLenum eglApi) - : QEglFSContext(format, share, display, eglApi) - , m_platformIntegration(integration) -{ -} - -void QAndroidOpenGLContext::swapBuffers(QPlatformSurface *surface) -{ - QEglFSContext::swapBuffers(surface); - - if (surface->surface()->surfaceClass() == QSurface::Window) { - QAndroidOpenGLPlatformWindow *window = static_cast(surface); - window->lock(); - QSize size = window->scheduledResize(); - if (size.isValid()) { - QRect geometry(QPoint(0, 0), size); - window->setGeometry(geometry); - QWindowSystemInterface::handleGeometryChange(window->window(), geometry); - QWindowSystemInterface::handleExposeEvent(window->window(), QRegion(geometry)); - window->scheduleResize(QSize()); - } - window->unlock(); - } -} - -bool QAndroidOpenGLContext::makeCurrent(QPlatformSurface *surface) -{ - bool ret = QEglFSContext::makeCurrent(surface); - - const char *rendererString = reinterpret_cast(glGetString(GL_RENDERER)); - if (rendererString != 0 && qstrncmp(rendererString, "Android Emulator", 16) == 0) { - QOpenGLContextPrivate *ctx_d = QOpenGLContextPrivate::get(context()); - ctx_d->workaround_missingPrecisionQualifiers = true; - } - - return ret; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglcontext.h b/src/plugins/platforms/android/src/opengl/qandroidopenglcontext.h deleted file mode 100644 index c419ae8392..0000000000 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglcontext.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDOPENGLCONTEXT_H -#define QANDROIDOPENGLCONTEXT_H - -#include -#include "qeglfscontext.h" - -QT_BEGIN_NAMESPACE - -class QAndroidPlatformIntegration; -class QAndroidOpenGLContext : public QEglFSContext -{ -public: - QAndroidOpenGLContext(const QAndroidPlatformIntegration *integration, - const QSurfaceFormat &format, - QPlatformOpenGLContext *share, - EGLDisplay display, - EGLenum eglApi = EGL_OPENGL_ES_API); - - void swapBuffers(QPlatformSurface *surface); - bool makeCurrent(QPlatformSurface *surface); - -private: - const QAndroidPlatformIntegration *m_platformIntegration; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDOPENGLCONTEXT_H diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.cpp b/src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.cpp deleted file mode 100644 index de4075feff..0000000000 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidopenglplatformscreen.h" -#include "qandroidopenglplatformwindow.h" -#include "androidjnimenu.h" - -QT_BEGIN_NAMESPACE - -QAndroidOpenGLPlatformScreen::QAndroidOpenGLPlatformScreen(EGLDisplay display) - : QEglFSScreen(display) -{ -} - -void QAndroidOpenGLPlatformScreen::topWindowChanged(QPlatformWindow *window) -{ - QtAndroidMenu::setActiveTopLevelWindow(window->window()); - QAndroidOpenGLPlatformWindow *platformWindow = static_cast(window); - if (platformWindow != 0) - platformWindow->updateStatusBarVisibility(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.h b/src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.h deleted file mode 100644 index e9251592aa..0000000000 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDOPENGLPLATFORMSCREEN_H -#define QANDROIDOPENGLPLATFORMSCREEN_H - -#include "qeglfsscreen.h" - -QT_BEGIN_NAMESPACE - -class QAndroidOpenGLPlatformScreen : public QEglFSScreen -{ -public: - QAndroidOpenGLPlatformScreen(EGLDisplay display); - -protected: - void topWindowChanged(QPlatformWindow *window); -}; - -QT_END_NAMESPACE - -#endif // QANDROIDOPENGLPLATFORMSCREEN_H diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp b/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp deleted file mode 100644 index 6ed805174b..0000000000 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidopenglplatformwindow.h" -#include "androidjnimain.h" -#include "qandroidplatformintegration.h" -#include - -QT_BEGIN_NAMESPACE - -EGLSurface QAndroidOpenGLPlatformWindow::m_staticSurface = 0; -EGLNativeWindowType QAndroidOpenGLPlatformWindow::m_staticNativeWindow = 0; -QReadWriteLock QAndroidOpenGLPlatformWindow::m_staticSurfaceLock; -QBasicAtomicInt QAndroidOpenGLPlatformWindow::m_referenceCount = Q_BASIC_ATOMIC_INITIALIZER(0); - -QAndroidOpenGLPlatformWindow::QAndroidOpenGLPlatformWindow(QWindow *window) - : QEglFSWindow(window) - , m_state(Qt::WindowNoState) -{ -} - -QAndroidOpenGLPlatformWindow::~QAndroidOpenGLPlatformWindow() -{ - destroy(); -} - -bool QAndroidOpenGLPlatformWindow::isExposed() const -{ - return QtAndroid::nativeWindow(false) != 0 && QEglFSWindow::isExposed(); -} - -void QAndroidOpenGLPlatformWindow::invalidateSurface() -{ - QWindowSystemInterface::handleExposeEvent(window(), QRegion()); // Obscure event - QWindowSystemInterface::flushWindowSystemEvents(); - - m_window = 0; - m_surface = 0; - - if (!m_referenceCount.deref()){ - QWriteLocker locker(&m_staticSurfaceLock); - - EGLDisplay display = (static_cast(window()->screen()->handle()))->display(); - eglDestroySurface(display, m_staticSurface); - - m_staticSurface = 0; - m_staticNativeWindow = 0; - } -} - -void QAndroidOpenGLPlatformWindow::updateStaticNativeWindow() -{ - QWriteLocker locker(&m_staticSurfaceLock); - m_staticNativeWindow = QtAndroid::nativeWindow(false); -} - -void QAndroidOpenGLPlatformWindow::resetSurface() -{ - // Only add a reference if we're not already holding one, otherwise we're just updating - // the native window pointer - if (m_window == 0) - m_referenceCount.ref(); - - if (m_staticSurface == 0) { - QWriteLocker locker(&m_staticSurfaceLock); - QEglFSWindow::resetSurface(); - m_staticSurface = m_surface; - m_staticNativeWindow = m_window; - } else { - QReadLocker locker(&m_staticSurfaceLock); - m_window = m_staticNativeWindow; - m_surface = m_staticSurface; - } - - { - lock(); - // Use the desktop size. - // On some devices, the getters for the native window size gives wrong values - scheduleResize(QAndroidPlatformIntegration::defaultDesktopSize()); - QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); // Expose event - unlock(); - } - - QWindowSystemInterface::flushWindowSystemEvents(); -} - -void QAndroidOpenGLPlatformWindow::destroy() -{ - if (!m_referenceCount.deref()) { - QEglFSWindow::destroy(); - } else { - m_window = 0; - m_surface = 0; - } -} - -void QAndroidOpenGLPlatformWindow::updateStatusBarVisibility() -{ - Qt::WindowFlags flags = window()->flags(); - bool isNonRegularWindow = flags & (Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window; - if (!isNonRegularWindow) { - if (m_state & Qt::WindowFullScreen) - QtAndroid::hideStatusBar(); - else if (m_state & Qt::WindowMaximized) - QtAndroid::showStatusBar(); - } -} - -void QAndroidOpenGLPlatformWindow::raise() -{ - updateStatusBarVisibility(); -} - -void QAndroidOpenGLPlatformWindow::setWindowState(Qt::WindowState state) -{ - if (m_state == state) - return; - - m_state = state; - if (window()->isVisible()) - updateStatusBarVisibility(); -} - -void QAndroidOpenGLPlatformWindow::setVisible(bool visible) -{ - if (visible) - updateStatusBarVisibility(); - - QEglFSWindow::setVisible(visible); - - // The Android Activity is activated before Qt is initialized, causing the application state to - // never be set to 'active'. We explicitly set this state when the first window becomes visible. - if (visible) - QtAndroid::setApplicationActive(); - - QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); // Expose event - QWindowSystemInterface::flushWindowSystemEvents(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.h b/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.h deleted file mode 100644 index e4ff0444d4..0000000000 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDOPENGLPLATFORMWINDOW_H -#define QANDROIDOPENGLPLATFORMWINDOW_H - -#include "qeglfswindow.h" -#include -#include - -QT_BEGIN_NAMESPACE - -class QAndroidOpenGLPlatformWindow : public QEglFSWindow -{ -public: - QAndroidOpenGLPlatformWindow(QWindow *window); - ~QAndroidOpenGLPlatformWindow(); - - QSize scheduledResize() const { return m_scheduledResize; } - void scheduleResize(const QSize &size) { m_scheduledResize = size; } - - void lock() { m_lock.lock(); } - void unlock() { m_lock.unlock(); } - - bool isExposed() const; - - void raise(); - - void invalidateSurface(); - void resetSurface(); - void setWindowState(Qt::WindowState state); - - void setVisible(bool visible); - - void destroy(); - - static void updateStaticNativeWindow(); - void updateStatusBarVisibility(); - -private: - QSize m_scheduledResize; - QMutex m_lock; - Qt::WindowState m_state; - - static QReadWriteLock m_staticSurfaceLock; - static EGLSurface m_staticSurface; - static EGLNativeWindowType m_staticNativeWindow; - static QBasicAtomicInt m_referenceCount; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDOPENGLPLATFORMWINDOW_H diff --git a/src/plugins/platforms/android/src/opengl/qeglfshooks_android.cpp b/src/plugins/platforms/android/src/opengl/qeglfshooks_android.cpp deleted file mode 100644 index 278cd553f4..0000000000 --- a/src/plugins/platforms/android/src/opengl/qeglfshooks_android.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qeglfshooks.h" -#include "androidjnimain.h" -#include "qandroidplatformintegration.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -class QEglFSAndroidHooks: public QEglFSHooks -{ -public: - void platformInit(); - void platformDestroy(); - EGLNativeDisplayType platformDisplay() const; - QSize screenSize() const; - QSizeF physicalScreenSize() const; - QDpi logicalDpi() const; - Qt::ScreenOrientation orientation() const; - Qt::ScreenOrientation nativeOrientation() const; - int screenDepth() const; - QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &inputFormat) const; - EGLNativeWindowType createNativeWindow(QPlatformWindow *platformWindow, const QSize &size, const QSurfaceFormat &format); - void destroyNativeWindow(EGLNativeWindowType window); - bool hasCapability(QPlatformIntegration::Capability cap) const; - QEglFSCursor *createCursor(QEglFSScreen *screen) const; -}; - -void QEglFSAndroidHooks::platformInit() -{ -} - -void QEglFSAndroidHooks::platformDestroy() -{ -} - -EGLNativeDisplayType QEglFSAndroidHooks::platformDisplay() const -{ - return EGL_DEFAULT_DISPLAY; -} - -QSize QEglFSAndroidHooks::screenSize() const -{ - return QAndroidPlatformIntegration::defaultDesktopSize(); -} - -QSizeF QEglFSAndroidHooks::physicalScreenSize() const -{ - return QSizeF(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth, QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight); -} - -QDpi QEglFSAndroidHooks::logicalDpi() const -{ - qreal lDpi = QtAndroid::scaledDensity() * 72; - return QDpi(lDpi, lDpi); -} - -Qt::ScreenOrientation QEglFSAndroidHooks::orientation() const -{ - return QAndroidPlatformIntegration::m_orientation; -} - -Qt::ScreenOrientation QEglFSAndroidHooks::nativeOrientation() const -{ - return QAndroidPlatformIntegration::m_nativeOrientation; -} - -EGLNativeWindowType QEglFSAndroidHooks::createNativeWindow(QPlatformWindow *platformWindow, const QSize &size, const QSurfaceFormat &format) -{ - Q_UNUSED(platformWindow); - Q_UNUSED(size); - Q_UNUSED(format); - ANativeWindow *window = QtAndroid::nativeWindow(); - if (window != 0) - ANativeWindow_acquire(window); - - return window; -} - -void QEglFSAndroidHooks::destroyNativeWindow(EGLNativeWindowType window) -{ - if (window != 0) - ANativeWindow_release(window); -} - -bool QEglFSAndroidHooks::hasCapability(QPlatformIntegration::Capability capability) const -{ - switch (capability) { - case QPlatformIntegration::OpenGL: return true; - case QPlatformIntegration::ThreadedOpenGL: return true; - default: return false; - }; -} - -int QEglFSAndroidHooks::screenDepth() const -{ - // ### Hardcoded - return 32; -} - -QSurfaceFormat QEglFSAndroidHooks::surfaceFormatFor(const QSurfaceFormat &inputFormat) const -{ - QSurfaceFormat ret(inputFormat); - ret.setAlphaBufferSize(8); - ret.setRedBufferSize(8); - ret.setGreenBufferSize(8); - ret.setBlueBufferSize(8); - return ret; -} - -QEglFSCursor *QEglFSAndroidHooks::createCursor(QEglFSScreen *screen) const -{ - Q_UNUSED(screen); - return 0; -} - -static QEglFSAndroidHooks eglFSAndroidHooks; -QEglFSHooks *platformHooks = &eglFSAndroidHooks; - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/src/qandroidassetsfileenginehandler.cpp deleted file mode 100644 index 95844fc649..0000000000 --- a/src/plugins/platforms/android/src/qandroidassetsfileenginehandler.cpp +++ /dev/null @@ -1,309 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidassetsfileenginehandler.h" -#include "androidjnimain.h" - -#include -#include - -typedef QVector FilesList; - -struct AndroidAssetDir -{ - AndroidAssetDir(AAssetDir* ad) - { - const char *fileName; - while ((fileName = AAssetDir_getNextFileName(ad))) - m_items.push_back(QString::fromUtf8(fileName)); - AAssetDir_close(ad); - } - FilesList m_items; -}; - -class AndroidAbstractFileEngineIterator: public QAbstractFileEngineIterator -{ -public: - AndroidAbstractFileEngineIterator(QDir::Filters filters, - const QStringList &nameFilters, - QSharedPointer asset, - const QString &path) - : QAbstractFileEngineIterator(filters, nameFilters) - { - m_items = asset->m_items; - m_index = -1; - m_path = path; - } - - virtual QFileInfo currentFileInfo() const - { - return QFileInfo(currentFilePath()); - } - - virtual QString currentFileName() const - { - if (m_index < 0 || m_index >= m_items.size()) - return QString(); - return m_items[m_index]; - } - - virtual QString currentFilePath() const - { - return m_path + currentFileName(); - } - - virtual bool hasNext() const - { - return m_items.size() && (m_index < m_items.size() - 1); - } - - virtual QString next() - { - if (!hasNext()) - return QString(); - m_index++; - return currentFileName(); - } - -private: - QString m_path; - FilesList m_items; - int m_index; -}; - -class AndroidAbstractFileEngine: public QAbstractFileEngine -{ -public: - explicit AndroidAbstractFileEngine(AAsset *asset, const QString &fileName) - { - m_assetFile = asset; - m_fileName = fileName; - } - - explicit AndroidAbstractFileEngine(QSharedPointer asset, const QString &fileName) - { - m_assetFile = 0; - m_assetDir = asset; - m_fileName = fileName; - if (!m_fileName.endsWith(QChar(QLatin1Char('/')))) - m_fileName += "/"; - } - - ~AndroidAbstractFileEngine() - { - close(); - } - - virtual bool open(QIODevice::OpenMode openMode) - { - if (m_assetFile) - return openMode & QIODevice::ReadOnly; - return false; - } - - virtual bool close() - { - if (m_assetFile) { - AAsset_close(m_assetFile); - m_assetFile = 0; - return true; - } - return false; - } - - virtual qint64 size() const - { - if (m_assetFile) - return AAsset_getLength(m_assetFile); - return -1; - } - - virtual qint64 pos() const - { - if (m_assetFile) - return AAsset_seek(m_assetFile, 0, SEEK_CUR); - return -1; - } - - virtual bool seek(qint64 pos) - { - if (m_assetFile) - return pos == AAsset_seek(m_assetFile, pos, SEEK_SET); - return false; - } - - virtual qint64 read(char *data, qint64 maxlen) - { - if (m_assetFile) - return AAsset_read(m_assetFile, data, maxlen); - return -1; - } - - virtual bool isSequential() const - { - return false; - } - - virtual bool caseSensitive() const - { - return true; - } - - virtual bool isRelativePath() const - { - return false; - } - - virtual FileFlags fileFlags(FileFlags type = FileInfoAll) const - { - FileFlags flags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm|ExistsFlag); - if (m_assetFile) - flags |= FileType; - if (!m_assetDir.isNull()) - flags |= DirectoryType; - - return type & flags; - } - - virtual QString fileName(FileName file = DefaultName) const - { - int pos; - switch (file) { - case DefaultName: - case AbsoluteName: - case CanonicalName: - return m_fileName; - case BaseName: - if ((pos = m_fileName.lastIndexOf(QChar(QLatin1Char('/')))) != -1) - return m_fileName.mid(pos); - else - return m_fileName; - case PathName: - case AbsolutePathName: - case CanonicalPathName: - if ((pos = m_fileName.lastIndexOf(QChar(QLatin1Char('/')))) != -1) - return m_fileName.left(pos); - else - return m_fileName; - default: - return QString(); - } - } - - virtual void setFileName(const QString &file) - { - if (file == m_fileName) - return; - - m_fileName = file; - if (!m_fileName.endsWith(QChar(QLatin1Char('/')))) - m_fileName += "/"; - - close(); - } - - virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) - { - if (!m_assetDir.isNull()) - return new AndroidAbstractFileEngineIterator(filters, filterNames, m_assetDir, m_fileName); - return 0; - } - -private: - AAsset *m_assetFile; - QSharedPointer m_assetDir; - QString m_fileName; -}; - - -AndroidAssetsFileEngineHandler::AndroidAssetsFileEngineHandler():m_assetsCache(std::max(5, qgetenv("QT_ANDROID_MAX_ASSETS_CACHE_SIZE").toInt())) -{ - m_assetManager = QtAndroid::assetManager(); -} - -AndroidAssetsFileEngineHandler::~AndroidAssetsFileEngineHandler() -{ -} - -QAbstractFileEngine * AndroidAssetsFileEngineHandler::create(const QString &fileName) const -{ - if (fileName.isEmpty()) - return 0; - - if (!fileName.startsWith(QLatin1String("assets:/"))) - return 0; - - int prefixSize=8; - - QByteArray path; - if (!fileName.endsWith(QLatin1Char('/'))) { - path = fileName.toUtf8(); - AAsset *asset = AAssetManager_open(m_assetManager, - path.constData() + prefixSize, - AASSET_MODE_BUFFER); - if (asset) - return new AndroidAbstractFileEngine(asset, fileName); - } - - if (!path.size()) - path = fileName.left(fileName.length() - 1).toUtf8(); - - m_assetsCacheMutext.lock(); - QSharedPointer *aad = m_assetsCache.object(path); - m_assetsCacheMutext.unlock(); - if (!aad) { - AAssetDir *assetDir = AAssetManager_openDir(m_assetManager, path.constData() + prefixSize); - if (assetDir) { - if (AAssetDir_getNextFileName(assetDir)) { - aad = new QSharedPointer(new AndroidAssetDir(assetDir)); - m_assetsCacheMutext.lock(); - m_assetsCache.insert(path, aad); - m_assetsCacheMutext.unlock(); - return new AndroidAbstractFileEngine(*aad, fileName); - } else { - AAssetDir_close(assetDir); - } - } - } else { - return new AndroidAbstractFileEngine(*aad, fileName); - } - return 0; -} diff --git a/src/plugins/platforms/android/src/qandroidassetsfileenginehandler.h b/src/plugins/platforms/android/src/qandroidassetsfileenginehandler.h deleted file mode 100644 index 7bd560886c..0000000000 --- a/src/plugins/platforms/android/src/qandroidassetsfileenginehandler.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDASSETSFILEENGINEHANDLER_H -#define QANDROIDASSETSFILEENGINEHANDLER_H - -#include -#include -#include -#include - -#include - -struct AndroidAssetDir; -class AndroidAssetsFileEngineHandler: public QAbstractFileEngineHandler -{ -public: - AndroidAssetsFileEngineHandler(); - virtual ~AndroidAssetsFileEngineHandler(); - QAbstractFileEngine *create(const QString &fileName) const; - -private: - AAssetManager *m_assetManager; - mutable QCache> m_assetsCache; - mutable QMutex m_assetsCacheMutext; -}; - -#endif // QANDROIDASSETSFILEENGINEHANDLER_H diff --git a/src/plugins/platforms/android/src/qandroidinputcontext.cpp b/src/plugins/platforms/android/src/qandroidinputcontext.cpp deleted file mode 100644 index 326972e71e..0000000000 --- a/src/plugins/platforms/android/src/qandroidinputcontext.cpp +++ /dev/null @@ -1,762 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "qandroidinputcontext.h" -#include "androidjnimain.h" -#include "androidjniinput.h" -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -QT_BEGIN_NAMESPACE - -static QAndroidInputContext *m_androidInputContext = 0; -static char const *const QtNativeInputConnectionClassName = "org.qtproject.qt5.android.QtNativeInputConnection"; -static char const *const QtExtractedTextClassName = "org.qtproject.qt5.android.QtExtractedText"; -static jclass m_extractedTextClass = 0; -static jmethodID m_classConstructorMethodID = 0; -static jfieldID m_partialEndOffsetFieldID = 0; -static jfieldID m_partialStartOffsetFieldID = 0; -static jfieldID m_selectionEndFieldID = 0; -static jfieldID m_selectionStartFieldID = 0; -static jfieldID m_startOffsetFieldID = 0; -static jfieldID m_textFieldID = 0; - -static jboolean commitText(JNIEnv *env, jobject /*thiz*/, jstring text, jint newCursorPosition) -{ - if (!m_androidInputContext) - return JNI_FALSE; - - jboolean isCopy; - const jchar *jstr = env->GetStringChars(text, &isCopy); - QString str(reinterpret_cast(jstr), env->GetStringLength(text)); - env->ReleaseStringChars(text, jstr); - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ COMMIT" << str; -#endif - return m_androidInputContext->commitText(str, newCursorPosition); -} - -static jboolean deleteSurroundingText(JNIEnv */*env*/, jobject /*thiz*/, jint leftLength, jint rightLength) -{ - if (!m_androidInputContext) - return JNI_FALSE; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ DELETE" << leftLength << rightLength; -#endif - return m_androidInputContext->deleteSurroundingText(leftLength, rightLength); -} - -static jboolean finishComposingText(JNIEnv */*env*/, jobject /*thiz*/) -{ - if (!m_androidInputContext) - return JNI_FALSE; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ FINISH"; -#endif - return m_androidInputContext->finishComposingText(); -} - -static jint getCursorCapsMode(JNIEnv */*env*/, jobject /*thiz*/, jint reqModes) -{ - if (!m_androidInputContext) - return 0; - - return m_androidInputContext->getCursorCapsMode(reqModes); -} - -static jobject getExtractedText(JNIEnv *env, jobject /*thiz*/, int hintMaxChars, int hintMaxLines, jint flags) -{ - if (!m_androidInputContext) - return 0; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ GETEX"; -#endif - const QAndroidInputContext::ExtractedText &extractedText = - m_androidInputContext->getExtractedText(hintMaxChars, hintMaxLines, flags); - - jobject object = env->NewObject(m_extractedTextClass, m_classConstructorMethodID); - env->SetIntField(object, m_partialStartOffsetFieldID, extractedText.partialStartOffset); - env->SetIntField(object, m_partialEndOffsetFieldID, extractedText.partialEndOffset); - env->SetIntField(object, m_selectionStartFieldID, extractedText.selectionStart); - env->SetIntField(object, m_selectionEndFieldID, extractedText.selectionEnd); - env->SetIntField(object, m_startOffsetFieldID, extractedText.startOffset); - env->SetObjectField(object, - m_textFieldID, - env->NewString(reinterpret_cast(extractedText.text.constData()), - jsize(extractedText.text.length()))); - - return object; -} - -static jstring getSelectedText(JNIEnv *env, jobject /*thiz*/, jint flags) -{ - if (!m_androidInputContext) - return 0; - - const QString &text = m_androidInputContext->getSelectedText(flags); -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ GETSEL" << text; -#endif - return env->NewString(reinterpret_cast(text.constData()), jsize(text.length())); -} - -static jstring getTextAfterCursor(JNIEnv *env, jobject /*thiz*/, jint length, jint flags) -{ - if (!m_androidInputContext) - return 0; - - const QString &text = m_androidInputContext->getTextAfterCursor(length, flags); -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ GET" << length << text; -#endif - return env->NewString(reinterpret_cast(text.constData()), jsize(text.length())); -} - -static jstring getTextBeforeCursor(JNIEnv *env, jobject /*thiz*/, jint length, jint flags) -{ - if (!m_androidInputContext) - return 0; - - const QString &text = m_androidInputContext->getTextBeforeCursor(length, flags); -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ GET" << length << text; -#endif - return env->NewString(reinterpret_cast(text.constData()), jsize(text.length())); -} - -static jboolean setComposingText(JNIEnv *env, jobject /*thiz*/, jstring text, jint newCursorPosition) -{ - if (!m_androidInputContext) - return JNI_FALSE; - - jboolean isCopy; - const jchar *jstr = env->GetStringChars(text, &isCopy); - QString str(reinterpret_cast(jstr), env->GetStringLength(text)); - env->ReleaseStringChars(text, jstr); - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ SET" << str; -#endif - return m_androidInputContext->setComposingText(str, newCursorPosition); -} - -static jboolean setComposingRegion(JNIEnv */*env*/, jobject /*thiz*/, jint start, jint end) -{ - if (!m_androidInputContext) - return JNI_FALSE; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ SETR" << start << end; -#endif - return m_androidInputContext->setComposingRegion(start, end); -} - - -static jboolean setSelection(JNIEnv */*env*/, jobject /*thiz*/, jint start, jint end) -{ - if (!m_androidInputContext) - return JNI_FALSE; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ SETSEL" << start << end; -#endif - return m_androidInputContext->setSelection(start, end); -} - -static jboolean selectAll(JNIEnv */*env*/, jobject /*thiz*/) -{ - if (!m_androidInputContext) - return JNI_FALSE; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@ SELALL"; -#endif - return m_androidInputContext->selectAll(); -} - -static jboolean cut(JNIEnv */*env*/, jobject /*thiz*/) -{ - if (!m_androidInputContext) - return JNI_FALSE; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@"; -#endif - return m_androidInputContext->cut(); -} - -static jboolean copy(JNIEnv */*env*/, jobject /*thiz*/) -{ - if (!m_androidInputContext) - return JNI_FALSE; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@"; -#endif - return m_androidInputContext->copy(); -} - -static jboolean copyURL(JNIEnv */*env*/, jobject /*thiz*/) -{ - if (!m_androidInputContext) - return JNI_FALSE; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@"; -#endif - return m_androidInputContext->copyURL(); -} - -static jboolean paste(JNIEnv */*env*/, jobject /*thiz*/) -{ - if (!m_androidInputContext) - return JNI_FALSE; - -#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL - qDebug() << "@@@"; -#endif - return m_androidInputContext->paste(); -} - - -static JNINativeMethod methods[] = { - {"commitText", "(Ljava/lang/String;I)Z", (void *)commitText}, - {"deleteSurroundingText", "(II)Z", (void *)deleteSurroundingText}, - {"finishComposingText", "()Z", (void *)finishComposingText}, - {"getCursorCapsMode", "(I)I", (void *)getCursorCapsMode}, - {"getExtractedText", "(III)Lorg/qtproject/qt5/android/QtExtractedText;", (void *)getExtractedText}, - {"getSelectedText", "(I)Ljava/lang/String;", (void *)getSelectedText}, - {"getTextAfterCursor", "(II)Ljava/lang/String;", (void *)getTextAfterCursor}, - {"getTextBeforeCursor", "(II)Ljava/lang/String;", (void *)getTextBeforeCursor}, - {"setComposingText", "(Ljava/lang/String;I)Z", (void *)setComposingText}, - {"setComposingRegion", "(II)Z", (void *)setComposingRegion}, - {"setSelection", "(II)Z", (void *)setSelection}, - {"selectAll", "()Z", (void *)selectAll}, - {"cut", "()Z", (void *)cut}, - {"copy", "()Z", (void *)copy}, - {"copyURL", "()Z", (void *)copyURL}, - {"paste", "()Z", (void *)paste} -}; - - -QAndroidInputContext::QAndroidInputContext() - : QPlatformInputContext(), m_blockUpdateSelection(false) -{ - QtAndroid::AttachedJNIEnv env; - if (!env.jniEnv) - return; - - jclass clazz = QtAndroid::findClass(QtNativeInputConnectionClassName, env.jniEnv); - if (clazz == NULL) { - qCritical() << "Native registration unable to find class '" - << QtNativeInputConnectionClassName - << "'"; - return; - } - - if (env.jniEnv->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])) < 0) { - qCritical() << "RegisterNatives failed for '" - << QtNativeInputConnectionClassName - << "'"; - return; - } - - clazz = QtAndroid::findClass(QtExtractedTextClassName, env.jniEnv); - if (clazz == NULL) { - qCritical() << "Native registration unable to find class '" - << QtExtractedTextClassName - << "'"; - return; - } - - m_extractedTextClass = static_cast(env.jniEnv->NewGlobalRef(clazz)); - m_classConstructorMethodID = env.jniEnv->GetMethodID(m_extractedTextClass, "", "()V"); - if (m_classConstructorMethodID == NULL) { - qCritical() << "GetMethodID failed"; - return; - } - - m_partialEndOffsetFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "partialEndOffset", "I"); - if (m_partialEndOffsetFieldID == NULL) { - qCritical() << "Can't find field partialEndOffset"; - return; - } - - m_partialStartOffsetFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "partialStartOffset", "I"); - if (m_partialStartOffsetFieldID == NULL) { - qCritical() << "Can't find field partialStartOffset"; - return; - } - - m_selectionEndFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "selectionEnd", "I"); - if (m_selectionEndFieldID == NULL) { - qCritical() << "Can't find field selectionEnd"; - return; - } - - m_selectionStartFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "selectionStart", "I"); - if (m_selectionStartFieldID == NULL) { - qCritical() << "Can't find field selectionStart"; - return; - } - - m_startOffsetFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "startOffset", "I"); - if (m_startOffsetFieldID == NULL) { - qCritical() << "Can't find field startOffset"; - return; - } - - m_textFieldID = env.jniEnv->GetFieldID(m_extractedTextClass, "text", "Ljava/lang/String;"); - if (m_textFieldID == NULL) { - qCritical() << "Can't find field text"; - return; - } - qRegisterMetaType("QInputMethodEvent*"); - qRegisterMetaType("QInputMethodQueryEvent*"); - m_androidInputContext = this; -} - -QAndroidInputContext::~QAndroidInputContext() -{ - m_androidInputContext = 0; - m_extractedTextClass = 0; - m_partialEndOffsetFieldID = 0; - m_partialStartOffsetFieldID = 0; - m_selectionEndFieldID = 0; - m_selectionStartFieldID = 0; - m_startOffsetFieldID = 0; - m_textFieldID = 0; -} - -QAndroidInputContext *QAndroidInputContext::androidInputContext() -{ - return m_androidInputContext; -} - -void QAndroidInputContext::reset() -{ - clear(); - if (qGuiApp->focusObject()) - QtAndroidInput::resetSoftwareKeyboard(); - else - QtAndroidInput::hideSoftwareKeyboard(); -} - -void QAndroidInputContext::commit() -{ - finishComposingText(); -} - -void QAndroidInputContext::updateCursorPosition() -{ - QSharedPointer query = focusObjectInputMethodQuery(); - if (!query.isNull() && !m_blockUpdateSelection) { - const int cursorPos = query->value(Qt::ImCursorPosition).toInt(); - QtAndroidInput::updateSelection(cursorPos, cursorPos, -1, -1); //selection empty and no pre-edit text - } -} - -void QAndroidInputContext::update(Qt::InputMethodQueries queries) -{ - QSharedPointer query = focusObjectInputMethodQuery(queries); - if (query.isNull()) - return; -#warning TODO extract the needed data from query -} - -void QAndroidInputContext::invokeAction(QInputMethod::Action action, int cursorPosition) -{ -#warning TODO Handle at least QInputMethod::ContextMenu action - Q_UNUSED(action) - Q_UNUSED(cursorPosition) - - if (action == QInputMethod::Click) - commit(); -} - -QRectF QAndroidInputContext::keyboardRect() const -{ - return QPlatformInputContext::keyboardRect(); -} - -bool QAndroidInputContext::isAnimating() const -{ - return false; -} - -void QAndroidInputContext::showInputPanel() -{ - QSharedPointer query = focusObjectInputMethodQuery(); - if (query.isNull()) - return; - - disconnect(m_updateCursorPosConnection); - if (qGuiApp->focusObject()->metaObject()->indexOfSignal("cursorPositionChanged(int,int)") >= 0) // QLineEdit breaks the pattern - m_updateCursorPosConnection = connect(qGuiApp->focusObject(), SIGNAL(cursorPositionChanged(int,int)), this, SLOT(updateCursorPosition())); - else - m_updateCursorPosConnection = connect(qGuiApp->focusObject(), SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition())); - QRectF itemRect = qGuiApp->inputMethod()->inputItemRectangle(); - QRect rect = qGuiApp->inputMethod()->inputItemTransform().mapRect(itemRect).toRect(); - QWindow *window = qGuiApp->focusWindow(); - if (window) - rect = QRect(window->mapToGlobal(rect.topLeft()), rect.size()); - - QtAndroidInput::showSoftwareKeyboard(rect.left(), - rect.top(), - rect.width(), - rect.height(), - query->value(Qt::ImHints).toUInt()); -} - -void QAndroidInputContext::hideInputPanel() -{ - QtAndroidInput::hideSoftwareKeyboard(); -} - -bool QAndroidInputContext::isInputPanelVisible() const -{ - return QtAndroidInput::isSoftwareKeyboardVisible(); -} - -bool QAndroidInputContext::isComposing() const -{ - return m_composingText.length(); -} - -void QAndroidInputContext::clear() -{ - m_composingText.clear(); - m_extractedText.clear(); -} - -void QAndroidInputContext::sendEvent(QObject *receiver, QInputMethodEvent *event) -{ - QCoreApplication::sendEvent(receiver, event); -} - -void QAndroidInputContext::sendEvent(QObject *receiver, QInputMethodQueryEvent *event) -{ - QCoreApplication::sendEvent(receiver, event); -} - -jboolean QAndroidInputContext::commitText(const QString &text, jint /*newCursorPosition*/) -{ - m_composingText = text; - return finishComposingText(); -} - -jboolean QAndroidInputContext::deleteSurroundingText(jint leftLength, jint rightLength) -{ - QSharedPointer query = focusObjectInputMethodQuery(); - if (query.isNull()) - return JNI_TRUE; - - m_composingText.clear(); - - QInputMethodEvent event; - event.setCommitString(QString(), -leftLength, leftLength+rightLength); - sendInputMethodEvent(&event); - clear(); - - return JNI_TRUE; -} - -jboolean QAndroidInputContext::finishComposingText() -{ - QInputMethodEvent event; - event.setCommitString(m_composingText); - sendInputMethodEvent(&event); - clear(); - - return JNI_TRUE; -} - -jint QAndroidInputContext::getCursorCapsMode(jint /*reqModes*/) -{ - jint res = 0; - QSharedPointer query = focusObjectInputMethodQuery(); - if (query.isNull()) - return res; - - const uint qtInputMethodHints = query->value(Qt::ImHints).toUInt(); - - if (qtInputMethodHints & Qt::ImhPreferUppercase) - res = CAP_MODE_SENTENCES; - - if (qtInputMethodHints & Qt::ImhUppercaseOnly) - res = CAP_MODE_CHARACTERS; - - return res; -} - -const QAndroidInputContext::ExtractedText &QAndroidInputContext::getExtractedText(jint hintMaxChars, jint /*hintMaxLines*/, jint /*flags*/) -{ - QSharedPointer query = focusObjectInputMethodQuery(); - if (query.isNull()) - return m_extractedText; - - if (hintMaxChars) - m_extractedText.text = query->value(Qt::ImSurroundingText).toString().right(hintMaxChars); - - m_extractedText.startOffset = query->value(Qt::ImCursorPosition).toInt(); - const QString &selection = query->value(Qt::ImCurrentSelection).toString(); - const int selLen = selection.length(); - if (selLen) { - m_extractedText.selectionStart = query->value(Qt::ImAnchorPosition).toInt(); - m_extractedText.selectionEnd = m_extractedText.startOffset; - } - - return m_extractedText; -} - -QString QAndroidInputContext::getSelectedText(jint /*flags*/) -{ - QSharedPointer query = focusObjectInputMethodQuery(); - if (query.isNull()) - return QString(); - - return query->value(Qt::ImCurrentSelection).toString(); -} - -QString QAndroidInputContext::getTextAfterCursor(jint length, jint /*flags*/) -{ - QSharedPointer query = focusObjectInputMethodQuery(); - if (query.isNull()) - return QString(); - - QString text = query->value(Qt::ImSurroundingText).toString(); - if (!text.length()) - return text; - - int cursorPos = query->value(Qt::ImCursorPosition).toInt(); - return text.mid(cursorPos, length); -} - -QString QAndroidInputContext::getTextBeforeCursor(jint length, jint /*flags*/) -{ - QSharedPointer query = focusObjectInputMethodQuery(); - if (query.isNull()) - return QString(); - - QString text = query->value(Qt::ImSurroundingText).toString(); - if (!text.length()) - return text; - - int cursorPos = query->value(Qt::ImCursorPosition).toInt(); - const int wordLeftPos = cursorPos - length; - return text.mid(wordLeftPos > 0 ? wordLeftPos : 0, cursorPos); -} - -jboolean QAndroidInputContext::setComposingText(const QString &text, jint newCursorPosition) -{ - if (newCursorPosition > 0) - newCursorPosition += text.length() - 1; - m_composingText = text; - QList attributes; - attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, - newCursorPosition, - 1, - QVariant())); - // Show compose text underlined - QTextCharFormat underlined; - underlined.setFontUnderline(true); - attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,0, text.length(), - QVariant(underlined))); - - QInputMethodEvent event(m_composingText, attributes); - sendInputMethodEvent(&event); - - QSharedPointer query = focusObjectInputMethodQuery(); - if (!query.isNull() && !m_blockUpdateSelection) { - int cursorPos = query->value(Qt::ImCursorPosition).toInt(); - int preeditLength = text.length(); - QtAndroidInput::updateSelection(cursorPos+preeditLength, cursorPos+preeditLength, cursorPos, cursorPos+preeditLength); - } - - return JNI_TRUE; -} - -// Android docs say: -// * start may be after end, same meaning as if swapped -// * this function must not trigger updateSelection -// * if start == end then we should stop composing -jboolean QAndroidInputContext::setComposingRegion(jint start, jint end) -{ - QSharedPointer query = focusObjectInputMethodQuery(); - if (query.isNull()) - return JNI_FALSE; - - if (start > end) - qSwap(start, end); - - /* - start and end are cursor positions, not character positions, - i.e. selecting the first character is done by start == 0 and end == 1, - and start == end means no character selected - - Therefore, the length of the region is end - start - */ - int length = end - start; - - bool updateSelectionWasBlocked = m_blockUpdateSelection; - m_blockUpdateSelection = true; - - QString text = query->value(Qt::ImSurroundingText).toString(); - m_composingText = text.mid(start, length); - - //in the Qt text controls, cursor pos is the start of the preedit - int cursorPos = query->value(Qt::ImCursorPosition).toInt(); - int relativeStart = start - cursorPos; - - QList attributes; - - // Show compose text underlined - QTextCharFormat underlined; - underlined.setFontUnderline(true); - attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,0, length, - QVariant(underlined))); - - QInputMethodEvent event(m_composingText, attributes); - event.setCommitString(QString(), relativeStart, length); - sendInputMethodEvent(&event); - - m_blockUpdateSelection = updateSelectionWasBlocked; - return JNI_TRUE; -} - -jboolean QAndroidInputContext::setSelection(jint start, jint end) -{ - QList attributes; - attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, - start, - end - start, - QVariant())); - - QInputMethodEvent event(QString(), attributes); - sendInputMethodEvent(&event); - return JNI_TRUE; -} - -jboolean QAndroidInputContext::selectAll() -{ -#warning TODO - return JNI_FALSE; -} - -jboolean QAndroidInputContext::cut() -{ -#warning TODO - return JNI_FALSE; -} - -jboolean QAndroidInputContext::copy() -{ -#warning TODO - return JNI_FALSE; -} - -jboolean QAndroidInputContext::copyURL() -{ -#warning TODO - return JNI_FALSE; -} - -jboolean QAndroidInputContext::paste() -{ -#warning TODO - return JNI_FALSE; -} - -QSharedPointer QAndroidInputContext::focusObjectInputMethodQuery(Qt::InputMethodQueries queries) -{ -#warning TODO make qGuiApp->focusObject() thread safe !!! - QObject *focusObject = qGuiApp->focusObject(); - if (!focusObject) - return QSharedPointer(); - - QSharedPointer ret = QSharedPointer(new QInputMethodQueryEvent(queries)); - if (qGuiApp->thread()==QThread::currentThread()) { - QCoreApplication::sendEvent(focusObject, ret.data()); - } else { - QMetaObject::invokeMethod(this, - "sendEvent", - Qt::BlockingQueuedConnection, - Q_ARG(QObject*, focusObject), - Q_ARG(QInputMethodQueryEvent*, ret.data())); - } - - return ret; -} - -void QAndroidInputContext::sendInputMethodEvent(QInputMethodEvent *event) -{ -#warning TODO make qGuiApp->focusObject() thread safe !!! - QObject *focusObject = qGuiApp->focusObject(); - if (!focusObject) - return; - - if (qGuiApp->thread() == QThread::currentThread()) { - QCoreApplication::sendEvent(focusObject, event); - } else { - QMetaObject::invokeMethod(this, - "sendEvent", - Qt::BlockingQueuedConnection, - Q_ARG(QObject*, focusObject), - Q_ARG(QInputMethodEvent*, event)); - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/qandroidinputcontext.h b/src/plugins/platforms/android/src/qandroidinputcontext.h deleted file mode 100644 index 041bd0dc49..0000000000 --- a/src/plugins/platforms/android/src/qandroidinputcontext.h +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ANDROIDINPUTCONTEXT_H -#define ANDROIDINPUTCONTEXT_H - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QAndroidInputContext: public QPlatformInputContext -{ - Q_OBJECT - enum CapsMode - { - CAP_MODE_CHARACTERS = 0x00001000, - CAP_MODE_SENTENCES = 0x00004000, - CAP_MODE_WORDS = 0x00002000 - }; - -public: - struct ExtractedText - { - ExtractedText() { clear(); } - - void clear() - { - partialEndOffset = partialStartOffset = selectionEnd = selectionStart = startOffset = -1; - text.clear(); - } - - int partialEndOffset; - int partialStartOffset; - int selectionEnd; - int selectionStart; - int startOffset; - QString text; - }; - -public: - QAndroidInputContext(); - ~QAndroidInputContext(); - static QAndroidInputContext * androidInputContext(); - bool isValid() const { return true; } - - void reset(); - void commit(); - void update(Qt::InputMethodQueries queries); - void invokeAction(QInputMethod::Action action, int cursorPosition); - QRectF keyboardRect() const; - bool isAnimating() const; - void showInputPanel(); - void hideInputPanel(); - bool isInputPanelVisible() const; - - bool isComposing() const; - void clear(); - - //---------------// - jboolean commitText(const QString &text, jint newCursorPosition); - jboolean deleteSurroundingText(jint leftLength, jint rightLength); - jboolean finishComposingText(); - jint getCursorCapsMode(jint reqModes); - const ExtractedText &getExtractedText(jint hintMaxChars, jint hintMaxLines, jint flags); - QString getSelectedText(jint flags); - QString getTextAfterCursor(jint length, jint flags); - QString getTextBeforeCursor(jint length, jint flags); - jboolean setComposingText(const QString &text, jint newCursorPosition); - jboolean setComposingRegion(jint start, jint end); - jboolean setSelection(jint start, jint end); - jboolean selectAll(); - jboolean cut(); - jboolean copy(); - jboolean copyURL(); - jboolean paste(); - -private: - QSharedPointer focusObjectInputMethodQuery(Qt::InputMethodQueries queries = Qt::ImQueryAll); - void sendInputMethodEvent(QInputMethodEvent *event); - -private slots: - virtual void sendEvent(QObject *receiver, QInputMethodEvent *event); - virtual void sendEvent(QObject *receiver, QInputMethodQueryEvent *event); - void updateCursorPosition(); - -private: - ExtractedText m_extractedText; - QString m_composingText; - QMetaObject::Connection m_updateCursorPosConnection; - bool m_blockUpdateSelection; -}; - -QT_END_NAMESPACE - -#endif // ANDROIDINPUTCONTEXT_H diff --git a/src/plugins/platforms/android/src/qandroidplatformaccessibility.cpp b/src/plugins/platforms/android/src/qandroidplatformaccessibility.cpp deleted file mode 100644 index 229368345b..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformaccessibility.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qandroidplatformaccessibility.h" - -QT_BEGIN_NAMESPACE - -QAndroidPlatformAccessibility::QAndroidPlatformAccessibility() -{} - -QAndroidPlatformAccessibility::~QAndroidPlatformAccessibility() -{} - -void QAndroidPlatformAccessibility::notifyAccessibilityUpdate(QAccessibleEvent */*event*/) -{ - // FIXME send events -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/qandroidplatformaccessibility.h b/src/plugins/platforms/android/src/qandroidplatformaccessibility.h deleted file mode 100644 index 1b87f11919..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformaccessibility.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QANDROIDPLATFORMACCESSIBILITY_H -#define QANDROIDPLATFORMACCESSIBILITY_H - -#include - -QT_BEGIN_NAMESPACE - -class QAndroidPlatformAccessibility: public QPlatformAccessibility -{ -public: - QAndroidPlatformAccessibility(); - ~QAndroidPlatformAccessibility(); - - virtual void notifyAccessibilityUpdate(QAccessibleEvent *event); -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/platforms/android/src/qandroidplatformclipboard.cpp b/src/plugins/platforms/android/src/qandroidplatformclipboard.cpp deleted file mode 100644 index bc48b4935b..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformclipboard.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidplatformclipboard.h" -#include "androidjniclipboard.h" -#ifndef QT_NO_CLIPBOARD -#include - -QT_BEGIN_NAMESPACE - -QAndroidPlatformClipboard::QAndroidPlatformClipboard() -{ - QtAndroidClipboard::setClipboardListener(this); -} - -QMimeData *QAndroidPlatformClipboard::mimeData(QClipboard::Mode mode) -{ - if (QClipboard::Clipboard != mode || !QtAndroidClipboard::hasClipboardText()) - return 0; - - QMimeData *mimeData = new QMimeData(); - mimeData->setText(QtAndroidClipboard::clipboardText()); - return mimeData; -} - -void QAndroidPlatformClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) -{ - if (!data || !data->hasText() || QClipboard::Clipboard != mode) - return; - - QtAndroidClipboard::setClipboardText(data->text()); -} - -bool QAndroidPlatformClipboard::supportsMode(QClipboard::Mode mode) const -{ - return QClipboard::Clipboard == mode; -} - -QT_END_NAMESPACE - -#endif // QT_NO_CLIPBOARD diff --git a/src/plugins/platforms/android/src/qandroidplatformclipboard.h b/src/plugins/platforms/android/src/qandroidplatformclipboard.h deleted file mode 100644 index 644f326934..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformclipboard.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDPLATFORMCLIPBOARD_H -#define QANDROIDPLATFORMCLIPBOARD_H - -#include - -#ifndef QT_NO_CLIPBOARD -QT_BEGIN_NAMESPACE - -class QAndroidPlatformClipboard: public QPlatformClipboard -{ -public: - QAndroidPlatformClipboard(); - - virtual QMimeData *mimeData(QClipboard::Mode mode = QClipboard::Clipboard); - virtual void setMimeData(QMimeData *data, QClipboard::Mode mode = QClipboard::Clipboard); - virtual bool supportsMode(QClipboard::Mode mode) const; -}; - -QT_END_NAMESPACE -#endif // QT_NO_CLIPBOARD - -#endif // QANDROIDPLATFORMCLIPBOARD_H diff --git a/src/plugins/platforms/android/src/qandroidplatformdialoghelpers.cpp b/src/plugins/platforms/android/src/qandroidplatformdialoghelpers.cpp deleted file mode 100644 index 4c91e76e0f..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformdialoghelpers.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include "qandroidplatformdialoghelpers.h" -#include "androidjnimain.h" - -namespace QtAndroidDialogHelpers { -static jclass g_messageDialogHelperClass = 0; - -QAndroidPlatformMessageDialogHelper::QAndroidPlatformMessageDialogHelper() - :m_buttonId(-1) - ,m_javaMessageDialog(g_messageDialogHelperClass, "(Landroid/app/Activity;)V", QtAndroid::activity()) - ,m_shown(false) -{ -} - -void QAndroidPlatformMessageDialogHelper::exec() -{ - if (!m_shown) - show(Qt::Dialog, Qt::ApplicationModal, 0); - m_loop.exec(); -} - -static QString standardButtonText(int sbutton) -{ - switch (sbutton) { - case QMessageDialogOptions::Ok: - return QAndroidPlatformMessageDialogHelper::tr("OK"); - case QMessageDialogOptions::Save: - return QAndroidPlatformMessageDialogHelper::tr("Save"); - case QMessageDialogOptions::Open: - return QAndroidPlatformMessageDialogHelper::tr("Open"); - case QMessageDialogOptions::Cancel: - return QAndroidPlatformMessageDialogHelper::tr("Cancel"); - case QMessageDialogOptions::Close: - return QAndroidPlatformMessageDialogHelper::tr("Close"); - case QMessageDialogOptions::Apply: - return QAndroidPlatformMessageDialogHelper::tr("Apply"); - case QMessageDialogOptions::Reset: - return QAndroidPlatformMessageDialogHelper::tr("Reset"); - case QMessageDialogOptions::Help: - return QAndroidPlatformMessageDialogHelper::tr("Help"); - case QMessageDialogOptions::Discard: - return QAndroidPlatformMessageDialogHelper::tr("Discard"); - case QMessageDialogOptions::Yes: - return QAndroidPlatformMessageDialogHelper::tr("Yes"); - case QMessageDialogOptions::YesToAll: - return QAndroidPlatformMessageDialogHelper::tr("Yes to All"); - case QMessageDialogOptions::No: - return QAndroidPlatformMessageDialogHelper::tr("No"); - case QMessageDialogOptions::NoToAll: - return QAndroidPlatformMessageDialogHelper::tr("No to All"); - case QMessageDialogOptions::SaveAll: - return QAndroidPlatformMessageDialogHelper::tr("Save All"); - case QMessageDialogOptions::Abort: - return QAndroidPlatformMessageDialogHelper::tr("Abort"); - case QMessageDialogOptions::Retry: - return QAndroidPlatformMessageDialogHelper::tr("Retry"); - case QMessageDialogOptions::Ignore: - return QAndroidPlatformMessageDialogHelper::tr("Ignore"); - case QMessageDialogOptions::RestoreDefaults: - return QAndroidPlatformMessageDialogHelper::tr("Restore Defaults"); - } // switch - return QString(); -} - -bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags - , Qt::WindowModality windowModality - , QWindow *parent) -{ - Q_UNUSED(windowFlags) - Q_UNUSED(windowModality) - Q_UNUSED(parent) - QSharedPointer opt = options(); - if (!opt.data()) - return false; - - m_javaMessageDialog.callMethod("setIcon", "(I)V", opt->icon()); - - QString str = opt->windowTitle(); - if (!str.isEmpty()) - m_javaMessageDialog.callMethod("setTile", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object()); - - str = opt->text(); - if (!str.isEmpty()) - m_javaMessageDialog.callMethod("setText", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object()); - - str = opt->informativeText(); - if (!str.isEmpty()) - m_javaMessageDialog.callMethod("setInformativeText", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object()); - - str = opt->detailedText(); - if (!str.isEmpty()) - m_javaMessageDialog.callMethod("setDetailedText", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object()); - - for (int i = QMessageDialogOptions::FirstButton; i < QMessageDialogOptions::LastButton; i<<=1) { - if ( opt->standardButtons() & i ) - m_javaMessageDialog.callMethod("addButton", "(ILjava/lang/String;)V", i, QJNIObjectPrivate::fromString(standardButtonText(i)).object()); - } - - m_javaMessageDialog.callMethod("show", "(J)V", jlong(static_cast(this))); - m_shown = true; - return true; -} - -void QAndroidPlatformMessageDialogHelper::hide() -{ - m_javaMessageDialog.callMethod("hide", "()V"); - m_shown = false; -} - -void QAndroidPlatformMessageDialogHelper::dialogResult(int buttonID) -{ - m_buttonId = buttonID; - if (m_loop.isRunning()) - m_loop.exit(); - if (m_buttonId < 0) { - emit reject(); - return; - } - - QMessageDialogOptions::StandardButton standardButton = static_cast(buttonID); - QMessageDialogOptions::ButtonRole role = QMessageDialogOptions::buttonRole(standardButton); - emit clicked(standardButton, role); -} - -static void dialogResult(JNIEnv * /*env*/, jobject /*thiz*/, jlong handler, int buttonID) -{ - QObject *object = reinterpret_cast(handler); - QMetaObject::invokeMethod(object, "dialogResult", Qt::QueuedConnection, Q_ARG(int, buttonID)); -} - -static JNINativeMethod methods[] = { - {"dialogResult", "(JI)V", (void *)dialogResult} -}; - - -#define FIND_AND_CHECK_CLASS(CLASS_NAME) \ - clazz = env->FindClass(CLASS_NAME); \ - if (!clazz) { \ - __android_log_print(ANDROID_LOG_FATAL, QtAndroid::qtTagText(), QtAndroid::classErrorMsgFmt(), CLASS_NAME); \ - return false; \ - } - -bool registerNatives(JNIEnv *env) -{ - jclass clazz = QtAndroid::findClass("org.qtproject.qt5.android.QtMessageDialogHelper", env); - if (!clazz) { - __android_log_print(ANDROID_LOG_FATAL, QtAndroid::qtTagText(), QtAndroid::classErrorMsgFmt() - , "org/qtproject/qt5/android/QtMessageDialogHelper"); - return false; - } - g_messageDialogHelperClass = static_cast(env->NewGlobalRef(clazz)); - FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/QtNativeDialogHelper"); - jclass appClass = static_cast(env->NewGlobalRef(clazz)); - - if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { - __android_log_print(ANDROID_LOG_FATAL, "Qt", "RegisterNatives failed"); - return false; - } - - return true; -} -} diff --git a/src/plugins/platforms/android/src/qandroidplatformdialoghelpers.h b/src/plugins/platforms/android/src/qandroidplatformdialoghelpers.h deleted file mode 100644 index 88ec91d936..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformdialoghelpers.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDPLATFORMDIALOGHELPERS_H -#define QANDROIDPLATFORMDIALOGHELPERS_H -#include -#include -#include -#include - -namespace QtAndroidDialogHelpers { - -class QAndroidPlatformMessageDialogHelper: public QPlatformMessageDialogHelper -{ - Q_OBJECT -public: - QAndroidPlatformMessageDialogHelper(); - void exec(); - bool show(Qt::WindowFlags windowFlags, - Qt::WindowModality windowModality, - QWindow *parent); - void hide(); - -public slots: - void dialogResult(int buttonID); - -private: - int m_buttonId; - QEventLoop m_loop; - QJNIObjectPrivate m_javaMessageDialog; - bool m_shown; -}; - - -bool registerNatives(JNIEnv *env); - -} - -#endif // QANDROIDPLATFORMDIALOGHELPERS_H diff --git a/src/plugins/platforms/android/src/qandroidplatformfontdatabase.cpp b/src/plugins/platforms/android/src/qandroidplatformfontdatabase.cpp deleted file mode 100644 index 7f68b44ed8..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformfontdatabase.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "qandroidplatformfontdatabase.h" - -QString QAndroidPlatformFontDatabase::fontDir() const -{ - return QLatin1String("/system/fonts"); -} - -void QAndroidPlatformFontDatabase::populateFontDatabase() -{ - QString fontpath = fontDir(); - - if (!QFile::exists(fontpath)) { - qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?", - qPrintable(fontpath)); - } - - QDir dir(fontpath, QLatin1String("*.ttf")); - for (int i = 0; i < int(dir.count()); ++i) { - const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); - addTTFile(QByteArray(), file); - } -} - -QStringList QAndroidPlatformFontDatabase::fallbacksForFamily(const QString &family, - QFont::Style style, - QFont::StyleHint styleHint, - QChar::Script script) const -{ - Q_UNUSED(family); - Q_UNUSED(style); - Q_UNUSED(script); - if (styleHint == QFont::Monospace) - return QString(qgetenv("QT_ANDROID_FONTS_MONOSPACE")).split(";"); - - return QString(qgetenv("QT_ANDROID_FONTS")).split(";"); -} diff --git a/src/plugins/platforms/android/src/qandroidplatformfontdatabase.h b/src/plugins/platforms/android/src/qandroidplatformfontdatabase.h deleted file mode 100644 index 3cbfe95d36..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformfontdatabase.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDPLATFORMFONTDATABASE_H -#define QANDROIDPLATFORMFONTDATABASE_H - -#include - -class QAndroidPlatformFontDatabase: public QBasicFontDatabase -{ -public: - QString fontDir() const; - void populateFontDatabase(); - QStringList fallbacksForFamily(const QString &family, - QFont::Style style, - QFont::StyleHint styleHint, - QChar::Script script) const; -}; - -#endif // QANDROIDPLATFORMFONTDATABASE_H diff --git a/src/plugins/platforms/android/src/qandroidplatformintegration.cpp b/src/plugins/platforms/android/src/qandroidplatformintegration.cpp deleted file mode 100644 index ae3e257d3c..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformintegration.cpp +++ /dev/null @@ -1,343 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidplatformintegration.h" -#include "qabstracteventdispatcher.h" -#include "androidjnimain.h" -#include -#include -#include -#include -#include "qandroidplatformservices.h" -#include "qandroidplatformfontdatabase.h" -#include "qandroidplatformclipboard.h" -#include "qandroidplatformaccessibility.h" -#include - -#ifndef ANDROID_PLUGIN_OPENGL -# include "qandroidplatformscreen.h" -# include "qandroidplatformwindow.h" -# include -#else -# include "qeglfswindow.h" -# include "androidjnimenu.h" -# include "qandroidopenglcontext.h" -# include "qandroidopenglplatformwindow.h" -# include "qandroidopenglplatformscreen.h" -# include "qeglfshooks.h" -# include -#endif - -#include "qandroidplatformtheme.h" -#include "qandroidsystemlocale.h" - -QT_BEGIN_NAMESPACE - -int QAndroidPlatformIntegration::m_defaultGeometryWidth = 320; -int QAndroidPlatformIntegration::m_defaultGeometryHeight = 455; -int QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth = 50; -int QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight = 71; - -Qt::ScreenOrientation QAndroidPlatformIntegration::m_orientation = Qt::PrimaryOrientation; -Qt::ScreenOrientation QAndroidPlatformIntegration::m_nativeOrientation = Qt::PrimaryOrientation; - -void *QAndroidPlatformNativeInterface::nativeResourceForIntegration(const QByteArray &resource) -{ - if (resource=="JavaVM") - return QtAndroid::javaVM(); - if (resource == "QtActivity") - return QtAndroid::activity(); - if (resource == "AndroidStylePalettes") - return &m_palettes; - if (resource == "AndroidStyleFonts") - return &m_fonts; - return 0; -} - -QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶mList) - : m_touchDevice(0) -#ifndef QT_NO_ACCESSIBILITY - , m_accessibility(0) -#endif -{ - Q_UNUSED(paramList); - - m_androidPlatformNativeInterface = new QAndroidPlatformNativeInterface(); - -#ifndef ANDROID_PLUGIN_OPENGL - m_primaryScreen = new QAndroidPlatformScreen(); - screenAdded(m_primaryScreen); - m_primaryScreen->setPhysicalSize(QSize(m_defaultPhysicalSizeWidth, m_defaultPhysicalSizeHeight)); - m_primaryScreen->setGeometry(QRect(0, 0, m_defaultGeometryWidth, m_defaultGeometryHeight)); -#endif - - m_mainThread = QThread::currentThread(); - QtAndroid::setAndroidPlatformIntegration(this); - - m_androidFDB = new QAndroidPlatformFontDatabase(); - m_androidPlatformServices = new QAndroidPlatformServices(); - m_androidPlatformClipboard = new QAndroidPlatformClipboard(); - - m_androidSystemLocale = new QAndroidSystemLocale; -} - -bool QAndroidPlatformIntegration::hasCapability(Capability cap) const -{ - switch (cap) { - case ThreadedPixmaps: return true; - case ApplicationState: return true; - case NativeWidgets: return false; - default: -#ifndef ANDROID_PLUGIN_OPENGL - return QPlatformIntegration::hasCapability(cap); -#else - return QEglFSIntegration::hasCapability(cap); -#endif - } -} - -#ifndef ANDROID_PLUGIN_OPENGL -QPlatformBackingStore *QAndroidPlatformIntegration::createPlatformBackingStore(QWindow *window) const -{ - return new QFbBackingStore(window); -} - -QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const -{ - QAndroidPlatformWindow *platformWindow = new QAndroidPlatformWindow(window); - platformWindow->setWindowState(window->windowState()); - - return platformWindow; -} - -QAbstractEventDispatcher *QAndroidPlatformIntegration::createEventDispatcher() const -{ - return createUnixEventDispatcher(); -} -#else // !ANDROID_PLUGIN_OPENGL -QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const -{ - QAndroidOpenGLPlatformWindow *platformWindow = new QAndroidOpenGLPlatformWindow(window); - platformWindow->create(); - platformWindow->requestActivateWindow(); - platformWindow->setWindowState(window->windowState()); - QtAndroidMenu::setActiveTopLevelWindow(window); - - return platformWindow; -} - -void QAndroidPlatformIntegration::invalidateNativeSurface() -{ - foreach (QWindow *w, QGuiApplication::topLevelWindows()) { - QAndroidOpenGLPlatformWindow *window = - static_cast(w->handle()); - if (window != 0) - window->invalidateSurface(); - } -} - -void QAndroidPlatformIntegration::surfaceChanged() -{ - QAndroidOpenGLPlatformWindow::updateStaticNativeWindow(); - foreach (QWindow *w, QGuiApplication::topLevelWindows()) { - QAndroidOpenGLPlatformWindow *window = - static_cast(w->handle()); - if (window != 0) - window->resetSurface(); - } -} - -QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const -{ - return new QAndroidOpenGLContext(this, - QEglFSHooks::hooks()->surfaceFormatFor(context->format()), - context->shareHandle(), - display()); -} -#endif // ANDROID_PLUGIN_OPENGL - -QAndroidPlatformIntegration::~QAndroidPlatformIntegration() -{ - delete m_androidPlatformNativeInterface; - delete m_androidFDB; - delete m_androidSystemLocale; - QtAndroid::setAndroidPlatformIntegration(NULL); -} -QPlatformFontDatabase *QAndroidPlatformIntegration::fontDatabase() const -{ - return m_androidFDB; -} - -#ifndef QT_NO_CLIPBOARD -QPlatformClipboard *QAndroidPlatformIntegration::clipboard() const -{ -static QAndroidPlatformClipboard *clipboard = 0; - if (!clipboard) - clipboard = new QAndroidPlatformClipboard; - - return clipboard; -} -#endif - -QPlatformInputContext *QAndroidPlatformIntegration::inputContext() const -{ - return &m_platformInputContext; -} - -QPlatformNativeInterface *QAndroidPlatformIntegration::nativeInterface() const -{ - return m_androidPlatformNativeInterface; -} - -QPlatformServices *QAndroidPlatformIntegration::services() const -{ - return m_androidPlatformServices; -} - -QVariant QAndroidPlatformIntegration::styleHint(StyleHint hint) const -{ - switch (hint) { - case ShowIsMaximized: - return true; - default: - return QPlatformIntegration::styleHint(hint); - } -} - -Qt::WindowState QAndroidPlatformIntegration::defaultWindowState(Qt::WindowFlags flags) const -{ - // Don't maximize dialogs on Android - if (flags & Qt::Dialog & ~Qt::Window) - return Qt::WindowNoState; - - return QPlatformIntegration::defaultWindowState(flags); -} - -static const QLatin1String androidThemeName("android"); -QStringList QAndroidPlatformIntegration::themeNames() const -{ - return QStringList(QString(androidThemeName)); -} - -QPlatformTheme *QAndroidPlatformIntegration::createPlatformTheme(const QString &name) const -{ - if (androidThemeName == name) - return new QAndroidPlatformTheme(m_androidPlatformNativeInterface); - - return 0; -} - -void QAndroidPlatformIntegration::setDefaultDisplayMetrics(int gw, int gh, int sw, int sh) -{ - m_defaultGeometryWidth = gw; - m_defaultGeometryHeight = gh; - m_defaultPhysicalSizeWidth = sw; - m_defaultPhysicalSizeHeight = sh; -} - -void QAndroidPlatformIntegration::setDefaultDesktopSize(int gw, int gh) -{ - m_defaultGeometryWidth = gw; - m_defaultGeometryHeight = gh; -} - -void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation currentOrientation, - Qt::ScreenOrientation nativeOrientation) -{ - m_orientation = currentOrientation; - m_nativeOrientation = nativeOrientation; -} - -#ifndef QT_NO_ACCESSIBILITY -QPlatformAccessibility *QAndroidPlatformIntegration::accessibility() const -{ - if (!m_accessibility) - m_accessibility = new QAndroidPlatformAccessibility(); - return m_accessibility; -} -#endif - - -#ifndef ANDROID_PLUGIN_OPENGL -void QAndroidPlatformIntegration::setDesktopSize(int width, int height) -{ - if (m_primaryScreen) - QMetaObject::invokeMethod(m_primaryScreen, "setGeometry", Qt::AutoConnection, Q_ARG(QRect, QRect(0,0,width, height))); -} - -void QAndroidPlatformIntegration::setDisplayMetrics(int width, int height) -{ - if (m_primaryScreen) - QMetaObject::invokeMethod(m_primaryScreen, "setPhysicalSize", Qt::AutoConnection, Q_ARG(QSize, QSize(width, height))); -} -#else -void QAndroidPlatformIntegration::setDesktopSize(int width, int height) -{ - m_defaultGeometryWidth = width; - m_defaultGeometryHeight = height; -} - -void QAndroidPlatformIntegration::setDisplayMetrics(int width, int height) -{ - m_defaultPhysicalSizeWidth = width; - m_defaultPhysicalSizeHeight = height; -} - -QEglFSScreen *QAndroidPlatformIntegration::createScreen() const -{ - return new QAndroidOpenGLPlatformScreen(display()); -} - -#endif - -void QAndroidPlatformIntegration::pauseApp() -{ - if (QAbstractEventDispatcher::instance(m_mainThread)) - QAbstractEventDispatcher::instance(m_mainThread)->interrupt(); -} - -void QAndroidPlatformIntegration::resumeApp() -{ - if (QAbstractEventDispatcher::instance(m_mainThread)) - QAbstractEventDispatcher::instance(m_mainThread)->wakeUp(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/qandroidplatformintegration.h b/src/plugins/platforms/android/src/qandroidplatformintegration.h deleted file mode 100644 index bd08ad694c..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformintegration.h +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDPLATFORMINTERATION_H -#define QANDROIDPLATFORMINTERATION_H - -#include -#include -#include -#include - -#include -#include "qandroidinputcontext.h" - -#ifndef ANDROID_PLUGIN_OPENGL -# include "qandroidplatformscreen.h" -#else -# include "qeglfsintegration.h" -#endif - -QT_BEGIN_NAMESPACE - -class QDesktopWidget; -class QAndroidPlatformServices; -class QAndroidSystemLocale; -class QPlatformAccessibility; - -#ifdef ANDROID_PLUGIN_OPENGL -class QAndroidOpenGLPlatformWindow; -#endif - -class QAndroidPlatformNativeInterface: public QPlatformNativeInterface -{ -public: - void *nativeResourceForIntegration(const QByteArray &resource); - QHash m_palettes; - QHash m_fonts; -}; - -class QAndroidPlatformIntegration -#ifndef ANDROID_PLUGIN_OPENGL - : public QPlatformIntegration -#else - : public QEglFSIntegration -#endif -{ - friend class QAndroidPlatformScreen; - -public: - QAndroidPlatformIntegration(const QStringList ¶mList); - ~QAndroidPlatformIntegration(); - - bool hasCapability(QPlatformIntegration::Capability cap) const; - -#ifndef ANDROID_PLUGIN_OPENGL - QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; - QPlatformWindow *createPlatformWindow(QWindow *window) const; - QAbstractEventDispatcher *createEventDispatcher() const; - QAndroidPlatformScreen *screen() { return m_primaryScreen; } -#else - QPlatformWindow *createPlatformWindow(QWindow *window) const; - void invalidateNativeSurface(); - void surfaceChanged(); - QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; -#endif - - virtual void setDesktopSize(int width, int height); - virtual void setDisplayMetrics(int width, int height); - bool isVirtualDesktop() { return true; } - - QPlatformFontDatabase *fontDatabase() const; - -#ifndef QT_NO_CLIPBOARD - QPlatformClipboard *clipboard() const; -#endif - - QPlatformInputContext *inputContext() const; - QPlatformNativeInterface *nativeInterface() const; - QPlatformServices *services() const; - -#ifndef QT_NO_ACCESSIBILITY - virtual QPlatformAccessibility *accessibility() const; -#endif - - QVariant styleHint(StyleHint hint) const; - Qt::WindowState defaultWindowState(Qt::WindowFlags flags) const Q_DECL_OVERRIDE; - - QStringList themeNames() const; - QPlatformTheme *createPlatformTheme(const QString &name) const; - - void pauseApp(); - void resumeApp(); - static void setDefaultDisplayMetrics(int gw, int gh, int sw, int sh); - static void setDefaultDesktopSize(int gw, int gh); - static void setScreenOrientation(Qt::ScreenOrientation currentOrientation, - Qt::ScreenOrientation nativeOrientation); - - static QSize defaultDesktopSize() - { - return QSize(m_defaultGeometryWidth, m_defaultGeometryHeight); - } - - QTouchDevice *touchDevice() const { return m_touchDevice; } - void setTouchDevice(QTouchDevice *touchDevice) { m_touchDevice = touchDevice; } - -#ifdef ANDROID_PLUGIN_OPENGL - QEglFSScreen *createScreen() const; -#endif - -private: - - friend class QEglFSAndroidHooks; - - QTouchDevice *m_touchDevice; - -#ifndef ANDROID_PLUGIN_OPENGL - QAndroidPlatformScreen *m_primaryScreen; -#endif - - QThread *m_mainThread; - - static int m_defaultGeometryWidth; - static int m_defaultGeometryHeight; - static int m_defaultPhysicalSizeWidth; - static int m_defaultPhysicalSizeHeight; - - static Qt::ScreenOrientation m_orientation; - static Qt::ScreenOrientation m_nativeOrientation; - - QPlatformFontDatabase *m_androidFDB; - QImage *m_FbScreenImage; - QPainter *m_compositePainter; - QAndroidPlatformNativeInterface *m_androidPlatformNativeInterface; - QAndroidPlatformServices *m_androidPlatformServices; - QPlatformClipboard *m_androidPlatformClipboard; - QAndroidSystemLocale *m_androidSystemLocale; -#ifndef QT_NO_ACCESSIBILITY - mutable QPlatformAccessibility *m_accessibility; -#endif - - mutable QAndroidInputContext m_platformInputContext; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/platforms/android/src/qandroidplatformmenu.cpp b/src/plugins/platforms/android/src/qandroidplatformmenu.cpp deleted file mode 100644 index 1ecabb25e2..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformmenu.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidplatformmenu.h" -#include "qandroidplatformmenuitem.h" -#include "androidjnimenu.h" - -QAndroidPlatformMenu::QAndroidPlatformMenu() -{ - m_tag = reinterpret_cast(this); // QMenu will overwrite this later, but we need a unique ID for QtQuick - m_enabled = true; - m_isVisible = true; -} - -QAndroidPlatformMenu::~QAndroidPlatformMenu() -{ - QtAndroidMenu::androidPlatformMenuDestroyed(this); -} - -void QAndroidPlatformMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) -{ - QMutexLocker lock(&m_menuItemsMutex); - m_menuItems.insert(qFind(m_menuItems.begin(), - m_menuItems.end(), - static_cast(before)), - static_cast(menuItem)); -} - -void QAndroidPlatformMenu::removeMenuItem(QPlatformMenuItem *menuItem) -{ - QMutexLocker lock(&m_menuItemsMutex); - PlatformMenuItemsType::iterator it = qFind(m_menuItems.begin(), - m_menuItems.end(), - static_cast(menuItem)); - if (it != m_menuItems.end()) - m_menuItems.erase(it); -} - -void QAndroidPlatformMenu::syncMenuItem(QPlatformMenuItem *menuItem) -{ - PlatformMenuItemsType::iterator it; - for (it = m_menuItems.begin(); it != m_menuItems.end(); ++it) { - if ((*it)->tag() == menuItem->tag()) - break; - } - - if (it != m_menuItems.end()) - QtAndroidMenu::syncMenu(this); -} - -void QAndroidPlatformMenu::syncSeparatorsCollapsible(bool enable) -{ - Q_UNUSED(enable) -} - -void QAndroidPlatformMenu::setTag(quintptr tag) -{ - m_tag = tag; -} - -quintptr QAndroidPlatformMenu::tag() const -{ - return m_tag; -} - -void QAndroidPlatformMenu::setText(const QString &text) -{ - m_text = text; -} - -QString QAndroidPlatformMenu::text() const -{ - return m_text; -} - -void QAndroidPlatformMenu::setIcon(const QIcon &icon) -{ - m_icon = icon; -} - -QIcon QAndroidPlatformMenu::icon() const -{ - return m_icon; -} - -void QAndroidPlatformMenu::setEnabled(bool enabled) -{ - m_enabled = enabled; -} - -bool QAndroidPlatformMenu::isEnabled() const -{ - return m_enabled; -} - -void QAndroidPlatformMenu::setVisible(bool visible) -{ - m_isVisible = visible; -} - -bool QAndroidPlatformMenu::isVisible() const -{ - return m_isVisible; -} - -void QAndroidPlatformMenu::showPopup(const QWindow *parentWindow, QPoint pos, const QPlatformMenuItem *item) -{ - Q_UNUSED(parentWindow); - Q_UNUSED(pos); - Q_UNUSED(item); - setVisible(true); - QtAndroidMenu::showContextMenu(this); -} - -QPlatformMenuItem *QAndroidPlatformMenu::menuItemAt(int position) const -{ - if (position < m_menuItems.size()) - return m_menuItems[position]; - return 0; -} - -QPlatformMenuItem *QAndroidPlatformMenu::menuItemForTag(quintptr tag) const -{ - foreach (QPlatformMenuItem *menuItem, m_menuItems) { - if (menuItem->tag() == tag) - return menuItem; - } - return 0; -} - -QAndroidPlatformMenu::PlatformMenuItemsType QAndroidPlatformMenu::menuItems() const -{ - return m_menuItems; -} - -QMutex *QAndroidPlatformMenu::menuItemsMutex() -{ - return &m_menuItemsMutex; -} diff --git a/src/plugins/platforms/android/src/qandroidplatformmenu.h b/src/plugins/platforms/android/src/qandroidplatformmenu.h deleted file mode 100644 index 305b64168a..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformmenu.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDPLATFORMMENU_H -#define QANDROIDPLATFORMMENU_H - -#include -#include -#include - -class QAndroidPlatformMenuItem; -class QAndroidPlatformMenu: public QPlatformMenu -{ -public: - typedef QVector PlatformMenuItemsType; - -public: - QAndroidPlatformMenu(); - ~QAndroidPlatformMenu(); - - void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before); - void removeMenuItem(QPlatformMenuItem *menuItem); - void syncMenuItem(QPlatformMenuItem *menuItem); - void syncSeparatorsCollapsible(bool enable); - - void setTag(quintptr tag); - quintptr tag() const; - void setText(const QString &text); - QString text() const; - void setIcon(const QIcon &icon); - QIcon icon() const; - void setEnabled(bool enabled); - bool isEnabled() const; - void setVisible(bool visible); - bool isVisible() const; - void showPopup(const QWindow *parentWindow, QPoint pos, const QPlatformMenuItem *item); - - QPlatformMenuItem *menuItemAt(int position) const; - QPlatformMenuItem *menuItemForTag(quintptr tag) const; - - PlatformMenuItemsType menuItems() const; - QMutex *menuItemsMutex(); - -private: - PlatformMenuItemsType m_menuItems; - quintptr m_tag; - QString m_text; - QIcon m_icon; - bool m_enabled; - bool m_isVisible; - QMutex m_menuItemsMutex; -}; - -#endif // QANDROIDPLATFORMMENU_H diff --git a/src/plugins/platforms/android/src/qandroidplatformmenubar.cpp b/src/plugins/platforms/android/src/qandroidplatformmenubar.cpp deleted file mode 100644 index 134062fb32..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformmenubar.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidplatformmenubar.h" -#include "qandroidplatformmenu.h" -#include "androidjnimenu.h" - - -QAndroidPlatformMenuBar::QAndroidPlatformMenuBar() -{ - m_parentWindow = 0; - QtAndroidMenu::addMenuBar(this); -} - -QAndroidPlatformMenuBar::~QAndroidPlatformMenuBar() -{ - QtAndroidMenu::removeMenuBar(this); -} - -void QAndroidPlatformMenuBar::insertMenu(QPlatformMenu *menu, QPlatformMenu *before) -{ - QMutexLocker lock(&m_menusListMutex); - m_menus.insert(qFind(m_menus.begin(), - m_menus.end(), - static_cast(before)), - static_cast(menu)); -} - -void QAndroidPlatformMenuBar::removeMenu(QPlatformMenu *menu) -{ - QMutexLocker lock(&m_menusListMutex); - m_menus.erase(qFind(m_menus.begin(), - m_menus.end(), - static_cast(menu))); -} - -void QAndroidPlatformMenuBar::syncMenu(QPlatformMenu *menu) -{ - QtAndroidMenu::syncMenu(static_cast(menu)); -} - -void QAndroidPlatformMenuBar::handleReparent(QWindow *newParentWindow) -{ - if (m_parentWindow == newParentWindow) - return; - m_parentWindow = newParentWindow; - QtAndroidMenu::setMenuBar(this, newParentWindow); -} - -QPlatformMenu *QAndroidPlatformMenuBar::menuForTag(quintptr tag) const -{ - foreach (QPlatformMenu *menu, m_menus) { - if (menu->tag() == tag) - return menu; - } - - return 0; -} - -QWindow *QAndroidPlatformMenuBar::parentWindow() const -{ - return m_parentWindow; -} - -QAndroidPlatformMenuBar::PlatformMenusType QAndroidPlatformMenuBar::menus() const -{ - return m_menus; -} - -QMutex *QAndroidPlatformMenuBar::menusListMutex() -{ - return &m_menusListMutex; -} diff --git a/src/plugins/platforms/android/src/qandroidplatformmenubar.h b/src/plugins/platforms/android/src/qandroidplatformmenubar.h deleted file mode 100644 index 56915335c2..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformmenubar.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDPLATFORMMENUBAR_H -#define QANDROIDPLATFORMMENUBAR_H - -#include -#include -#include - -class QAndroidPlatformMenu; -class QAndroidPlatformMenuBar: public QPlatformMenuBar -{ -public: - typedef QVector PlatformMenusType; -public: - QAndroidPlatformMenuBar(); - ~QAndroidPlatformMenuBar(); - - void insertMenu(QPlatformMenu *menu, QPlatformMenu *before); - void removeMenu(QPlatformMenu *menu); - void syncMenu(QPlatformMenu *menu); - void handleReparent(QWindow *newParentWindow); - QPlatformMenu *menuForTag(quintptr tag) const; - - QWindow *parentWindow() const; - PlatformMenusType menus() const; - QMutex *menusListMutex(); - -private: - PlatformMenusType m_menus; - QWindow *m_parentWindow; - QMutex m_menusListMutex; -}; - -#endif // QANDROIDPLATFORMMENUBAR_H diff --git a/src/plugins/platforms/android/src/qandroidplatformmenuitem.cpp b/src/plugins/platforms/android/src/qandroidplatformmenuitem.cpp deleted file mode 100644 index bd37834d2a..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformmenuitem.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidplatformmenuitem.h" -#include "qandroidplatformmenu.h" - -QAndroidPlatformMenuItem::QAndroidPlatformMenuItem() -{ - m_tag = reinterpret_cast(this); // QMenu will overwrite this later, but we need a unique ID for QtQuick - m_menu = 0; - m_isVisible = true; - m_isSeparator = false; - m_role = NoRole; - m_isCheckable = false; - m_isChecked = false; - m_isEnabled = true; -} - -void QAndroidPlatformMenuItem::setTag(quintptr tag) -{ - m_tag = tag; -} - -quintptr QAndroidPlatformMenuItem::tag() const -{ - return m_tag; -} - -void QAndroidPlatformMenuItem::setText(const QString &text) -{ - m_text = text; - if (m_menu) - m_menu->setText(m_text); -} - -QString QAndroidPlatformMenuItem::text() const -{ - return m_text; -} - -void QAndroidPlatformMenuItem::setIcon(const QIcon &icon) -{ - m_icon = icon; - if (m_menu) - m_menu->setIcon(m_icon); -} - -QIcon QAndroidPlatformMenuItem::icon() const -{ - return m_icon; -} - -void QAndroidPlatformMenuItem::setMenu(QPlatformMenu *menu) -{ - m_menu = static_cast(menu); - if (!m_menu) - return; - - m_menu->setText(m_text); - m_menu->setIcon(m_icon); - m_menu->setVisible(m_isVisible); - m_menu->setEnabled(m_isEnabled); -} - -QAndroidPlatformMenu *QAndroidPlatformMenuItem::menu() const -{ - return m_menu; -} - -void QAndroidPlatformMenuItem::setVisible(bool isVisible) -{ - m_isVisible = isVisible; - if (m_menu) - m_menu->setVisible(m_isVisible); -} - -bool QAndroidPlatformMenuItem::isVisible() const -{ - return m_isVisible; -} - -void QAndroidPlatformMenuItem::setIsSeparator(bool isSeparator) -{ - m_isSeparator = isSeparator; -} - -bool QAndroidPlatformMenuItem::isSeparator() const -{ - return m_isSeparator; -} - -void QAndroidPlatformMenuItem::setFont(const QFont &font) -{ - Q_UNUSED(font) -} - -void QAndroidPlatformMenuItem::setRole(QPlatformMenuItem::MenuRole role) -{ - m_role = role; -} - -QPlatformMenuItem::MenuRole QAndroidPlatformMenuItem::role() const -{ - return m_role; -} - -void QAndroidPlatformMenuItem::setCheckable(bool checkable) -{ - m_isCheckable = checkable; -} - -bool QAndroidPlatformMenuItem::isCheckable() const -{ - return m_isCheckable; -} - -void QAndroidPlatformMenuItem::setChecked(bool isChecked) -{ - m_isChecked = isChecked; -} - -bool QAndroidPlatformMenuItem::isChecked() const -{ - return m_isChecked; -} - -void QAndroidPlatformMenuItem::setShortcut(const QKeySequence &shortcut) -{ - Q_UNUSED(shortcut) -} - -void QAndroidPlatformMenuItem::setEnabled(bool enabled) -{ - m_isEnabled = enabled; - if (m_menu) - m_menu->setEnabled(m_isEnabled); -} - -bool QAndroidPlatformMenuItem::isEnabled() const -{ - return m_isEnabled; -} diff --git a/src/plugins/platforms/android/src/qandroidplatformmenuitem.h b/src/plugins/platforms/android/src/qandroidplatformmenuitem.h deleted file mode 100644 index 5861e8e195..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformmenuitem.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDPLATFORMMENUITEM_H -#define QANDROIDPLATFORMMENUITEM_H -#include - -class QAndroidPlatformMenu; - -class QAndroidPlatformMenuItem: public QPlatformMenuItem -{ -public: - QAndroidPlatformMenuItem(); - void setTag(quintptr tag); - quintptr tag() const; - - void setText(const QString &text); - QString text() const; - - void setIcon(const QIcon &icon); - QIcon icon() const; - - void setMenu(QPlatformMenu *menu); - QAndroidPlatformMenu *menu() const; - - void setVisible(bool isVisible); - bool isVisible() const; - - void setIsSeparator(bool isSeparator); - bool isSeparator() const; - - void setFont(const QFont &font); - - void setRole(MenuRole role); - MenuRole role() const; - - void setCheckable(bool checkable); - bool isCheckable() const; - - void setChecked(bool isChecked); - bool isChecked() const; - - void setShortcut(const QKeySequence &shortcut); - - void setEnabled(bool enabled); - bool isEnabled() const; - -private: - quintptr m_tag; - QString m_text; - QIcon m_icon; - QAndroidPlatformMenu *m_menu; - bool m_isVisible; - bool m_isSeparator; - MenuRole m_role; - bool m_isCheckable; - bool m_isChecked; - bool m_isEnabled; -}; - -#endif // QANDROIDPLATFORMMENUITEM_H diff --git a/src/plugins/platforms/android/src/qandroidplatformservices.cpp b/src/plugins/platforms/android/src/qandroidplatformservices.cpp deleted file mode 100644 index 0df882f1f0..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformservices.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidplatformservices.h" -#include -#include -#include - -QAndroidPlatformServices::QAndroidPlatformServices() -{ - QtAndroid::AttachedJNIEnv env; - if (!env.jniEnv) - return; - - m_openURIMethodID = env.jniEnv->GetStaticMethodID(QtAndroid::applicationClass(), - "openURL", - "(Ljava/lang/String;)V"); -} - -bool QAndroidPlatformServices::openUrl(const QUrl &url) -{ - QtAndroid::AttachedJNIEnv env; - if (!env.jniEnv) - return false; - - jstring string = env.jniEnv->NewString(reinterpret_cast(url.toString().constData()), - url.toString().length()); - env.jniEnv->CallStaticVoidMethod(QtAndroid::applicationClass(), m_openURIMethodID, string); - env.jniEnv->DeleteLocalRef(string); - return true; -} - -bool QAndroidPlatformServices::openDocument(const QUrl &url) -{ - return openUrl(url); -} - -QByteArray QAndroidPlatformServices::desktopEnvironment() const -{ - return QByteArray("Android"); -} diff --git a/src/plugins/platforms/android/src/qandroidplatformservices.h b/src/plugins/platforms/android/src/qandroidplatformservices.h deleted file mode 100644 index 8368b19043..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformservices.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ANDROIDPLATFORMDESKTOPSERVICE_H -#define ANDROIDPLATFORMDESKTOPSERVICE_H - -#include -#include "androidjnimain.h" -#include - -class QAndroidPlatformServices: public QPlatformServices -{ -public: - QAndroidPlatformServices(); - bool openUrl(const QUrl &url); - bool openDocument(const QUrl &url); - QByteArray desktopEnvironment() const; -private: - jmethodID m_openURIMethodID; - -}; - -#endif // ANDROIDPLATFORMDESKTOPSERVICE_H diff --git a/src/plugins/platforms/android/src/qandroidplatformtheme.cpp b/src/plugins/platforms/android/src/qandroidplatformtheme.cpp deleted file mode 100644 index 308bb70faf..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformtheme.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidplatformtheme.h" -#include "qandroidplatformmenubar.h" -#include "qandroidplatformmenu.h" -#include "qandroidplatformmenuitem.h" -#include "qandroidplatformdialoghelpers.h" -#include -#include -#include - -QAndroidPlatformTheme::QAndroidPlatformTheme(QAndroidPlatformNativeInterface *androidPlatformNativeInterface) -{ - m_androidPlatformNativeInterface = androidPlatformNativeInterface; -} - -QPlatformMenuBar *QAndroidPlatformTheme::createPlatformMenuBar() const -{ - return new QAndroidPlatformMenuBar; -} - -QPlatformMenu *QAndroidPlatformTheme::createPlatformMenu() const -{ - return new QAndroidPlatformMenu; -} - -QPlatformMenuItem *QAndroidPlatformTheme::createPlatformMenuItem() const -{ - return new QAndroidPlatformMenuItem; -} - -static inline int paletteType(QPlatformTheme::Palette type) -{ - switch (type) { - case QPlatformTheme::ToolButtonPalette: - case QPlatformTheme::ButtonPalette: - return QPlatformTheme::ButtonPalette; - - case QPlatformTheme::CheckBoxPalette: - return QPlatformTheme::CheckBoxPalette; - - case QPlatformTheme::RadioButtonPalette: - return QPlatformTheme::RadioButtonPalette; - - case QPlatformTheme::ComboBoxPalette: - return QPlatformTheme::ComboBoxPalette; - - case QPlatformTheme::TextEditPalette: - case QPlatformTheme::TextLineEditPalette: - return QPlatformTheme::TextLineEditPalette; - - case QPlatformTheme::ItemViewPalette: - return QPlatformTheme::ItemViewPalette; - - default: - return QPlatformTheme::SystemPalette; - } -} - -const QPalette *QAndroidPlatformTheme::palette(Palette type) const -{ - QHash::const_iterator it = m_androidPlatformNativeInterface->m_palettes.find(paletteType(type)); - if (it != m_androidPlatformNativeInterface->m_palettes.end()) - return &(it.value()); - return 0; -} - -static inline int fontType(QPlatformTheme::Font type) -{ - switch (type) { - case QPlatformTheme::LabelFont: - return QPlatformTheme::SystemFont; - - case QPlatformTheme::ToolButtonFont: - return QPlatformTheme::PushButtonFont; - - default: - return type; - } -} - -const QFont *QAndroidPlatformTheme::font(Font type) const -{ - QHash::const_iterator it = m_androidPlatformNativeInterface->m_fonts.find(fontType(type)); - if (it != m_androidPlatformNativeInterface->m_fonts.end()) - return &(it.value()); - - // default in case the style has not set a font - static QFont systemFont("Roboto", 14.0 * 100 / 72); // keep default size the same after changing from 100 dpi to 72 dpi - if (type == QPlatformTheme::SystemFont) - return &systemFont; - return 0; -} - -static const QLatin1String STYLES_PATH("/data/data/org.kde.necessitas.ministro/files/dl/style/"); -static const QLatin1String STYLE_FILE("/style.json"); - -QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const -{ - switch (hint) { - case StyleNames: - if (qgetenv("QT_USE_ANDROID_NATIVE_STYLE").toInt() - && (!qgetenv("MINISTRO_ANDROID_STYLE_PATH").isEmpty() - || QFileInfo(STYLES_PATH - + QLatin1String(qgetenv("QT_ANDROID_THEME_DISPLAY_DPI")) - + STYLE_FILE).exists())) { - return QStringList("android"); - } - return QStringList("fusion"); - break; - default: - return QPlatformTheme::themeHint(hint); - } -} - -bool QAndroidPlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const -{ - if (type == MessageDialog) - return qgetenv("QT_USE_ANDROID_NATIVE_DIALOGS").toInt() == 1; - return false; -} - -QPlatformDialogHelper *QAndroidPlatformTheme::createPlatformDialogHelper(QPlatformTheme::DialogType type) const -{ - switch (type) { - case MessageDialog: - return new QtAndroidDialogHelpers::QAndroidPlatformMessageDialogHelper; - default: - return 0; - } -} diff --git a/src/plugins/platforms/android/src/qandroidplatformtheme.h b/src/plugins/platforms/android/src/qandroidplatformtheme.h deleted file mode 100644 index ec259a9b0a..0000000000 --- a/src/plugins/platforms/android/src/qandroidplatformtheme.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDPLATFORMTHEME_H -#define QANDROIDPLATFORMTHEME_H - -#include -class QAndroidPlatformNativeInterface; -class QAndroidPlatformTheme: public QPlatformTheme -{ -public: - QAndroidPlatformTheme(QAndroidPlatformNativeInterface * androidPlatformNativeInterface); - virtual QPlatformMenuBar *createPlatformMenuBar() const; - virtual QPlatformMenu *createPlatformMenu() const; - virtual QPlatformMenuItem *createPlatformMenuItem() const; - virtual const QPalette *palette(Palette type = SystemPalette) const; - virtual const QFont *font(Font type = SystemFont) const; - virtual QVariant themeHint(ThemeHint hint) const; - virtual bool usePlatformNativeDialog(DialogType type) const; - virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const; - - -private: - QAndroidPlatformNativeInterface * m_androidPlatformNativeInterface; -}; - -#endif // QANDROIDPLATFORMTHEME_H diff --git a/src/plugins/platforms/android/src/qandroidsystemlocale.cpp b/src/plugins/platforms/android/src/qandroidsystemlocale.cpp deleted file mode 100644 index a20f970a44..0000000000 --- a/src/plugins/platforms/android/src/qandroidsystemlocale.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidsystemlocale.h" -#include "androidjnimain.h" -#include -#include "qdatetime.h" -#include "qstringlist.h" -#include "qvariant.h" - -QT_BEGIN_NAMESPACE - -QAndroidSystemLocale::QAndroidSystemLocale() : m_locale(QLocale::C) -{ -} - -void QAndroidSystemLocale::getLocaleFromJava() const -{ - QWriteLocker locker(&m_lock); - - QJNIObjectPrivate javaLocaleObject; - QJNIObjectPrivate javaActivity(QtAndroid::activity()); - if (javaActivity.isValid()) { - QJNIObjectPrivate resources = javaActivity.callObjectMethod("getResources", "()Landroid/content/res/Resources;"); - QJNIObjectPrivate configuration = resources.callObjectMethod("getConfiguration", "()Landroid/content/res/Configuration;"); - - javaLocaleObject = configuration.getObjectField("locale", "Ljava/util/Locale;"); - } else { - javaLocaleObject = QJNIObjectPrivate::callStaticObjectMethod("java/util/Locale", "getDefault", "()Ljava/util/Locale;"); - } - - QString languageCode = javaLocaleObject.callObjectMethod("getLanguage", "()Ljava/lang/String;").toString(); - QString countryCode = javaLocaleObject.callObjectMethod("getCountry", "()Ljava/lang/String;").toString(); - - m_locale = QLocale(languageCode + QLatin1Char('_') + countryCode); -} - -QVariant QAndroidSystemLocale::query(QueryType type, QVariant in) const -{ - if (type == LocaleChanged) { - getLocaleFromJava(); - return QVariant(); - } - - QReadLocker locker(&m_lock); - - switch (type) { - case DecimalPoint: - return m_locale.decimalPoint(); - case GroupSeparator: - return m_locale.groupSeparator(); - case ZeroDigit: - return m_locale.zeroDigit(); - case NegativeSign: - return m_locale.negativeSign(); - case DateFormatLong: - return m_locale.dateFormat(QLocale::LongFormat); - case DateFormatShort: - return m_locale.dateFormat(QLocale::ShortFormat); - case TimeFormatLong: - return m_locale.timeFormat(QLocale::LongFormat); - case TimeFormatShort: - return m_locale.timeFormat(QLocale::ShortFormat); - case DayNameLong: - return m_locale.dayName(in.toInt(), QLocale::LongFormat); - case DayNameShort: - return m_locale.dayName(in.toInt(), QLocale::ShortFormat); - case MonthNameLong: - return m_locale.monthName(in.toInt(), QLocale::LongFormat); - case MonthNameShort: - return m_locale.monthName(in.toInt(), QLocale::ShortFormat); - case StandaloneMonthNameLong: - return m_locale.standaloneMonthName(in.toInt(), QLocale::LongFormat); - case StandaloneMonthNameShort: - return m_locale.standaloneMonthName(in.toInt(), QLocale::ShortFormat); - case DateToStringLong: - return m_locale.toString(in.toDate(), QLocale::LongFormat); - case DateToStringShort: - return m_locale.toString(in.toDate(), QLocale::ShortFormat); - case TimeToStringLong: - return m_locale.toString(in.toTime(), QLocale::LongFormat); - case TimeToStringShort: - return m_locale.toString(in.toTime(), QLocale::ShortFormat); - case DateTimeFormatLong: - return m_locale.dateTimeFormat(QLocale::LongFormat); - case DateTimeFormatShort: - return m_locale.dateTimeFormat(QLocale::ShortFormat); - case DateTimeToStringLong: - return m_locale.toString(in.toDateTime(), QLocale::LongFormat); - case DateTimeToStringShort: - return m_locale.toString(in.toDateTime(), QLocale::ShortFormat); - case PositiveSign: - return m_locale.positiveSign(); - case AMText: - return m_locale.amText(); - case PMText: - return m_locale.pmText(); - case FirstDayOfWeek: - return m_locale.firstDayOfWeek(); - case CurrencySymbol: - return m_locale .currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt())); - case CurrencyToString: { - switch (in.type()) { - case QVariant::Int: - return m_locale .toCurrencyString(in.toInt()); - case QVariant::UInt: - return m_locale .toCurrencyString(in.toUInt()); - case QVariant::Double: - return m_locale .toCurrencyString(in.toDouble()); - case QVariant::LongLong: - return m_locale .toCurrencyString(in.toLongLong()); - case QVariant::ULongLong: - return m_locale .toCurrencyString(in.toULongLong()); - default: - break; - } - return QString(); - } - case StringToStandardQuotation: - return m_locale.quoteString(in.value()); - case StringToAlternateQuotation: - return m_locale.quoteString(in.value(), QLocale::AlternateQuotation); - case ListToSeparatedString: - return m_locale.createSeparatedList(in.value()); - case LocaleChanged: - Q_ASSERT_X(false, Q_FUNC_INFO, "This can't happen."); - default: - break; - } - return QVariant(); -} - -QLocale QAndroidSystemLocale::fallbackUiLocale() const -{ - QReadLocker locker(&m_lock); - return m_locale; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/qandroidsystemlocale.h b/src/plugins/platforms/android/src/qandroidsystemlocale.h deleted file mode 100644 index fc2f6fad98..0000000000 --- a/src/plugins/platforms/android/src/qandroidsystemlocale.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDSYSTEMLOCALE_H -#define QANDROIDSYSTEMLOCALE_H - -#include "private/qlocale_p.h" -#include - -QT_BEGIN_NAMESPACE - -class QAndroidSystemLocale : public QSystemLocale -{ -public: - QAndroidSystemLocale(); - - virtual QVariant query(QueryType type, QVariant in) const; - virtual QLocale fallbackUiLocale() const; - -private: - void getLocaleFromJava() const; - - mutable QLocale m_locale; - mutable QReadWriteLock m_lock; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDSYSTEMLOCALE_H diff --git a/src/plugins/platforms/android/src/raster/qandroidplatformscreen.cpp b/src/plugins/platforms/android/src/raster/qandroidplatformscreen.cpp deleted file mode 100644 index 2e59c307c3..0000000000 --- a/src/plugins/platforms/android/src/raster/qandroidplatformscreen.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidplatformscreen.h" -#include "qandroidplatformintegration.h" -#include "androidjnimain.h" -#include "androidjnimenu.h" -#include "qandroidplatformwindow.h" - -QAndroidPlatformScreen::QAndroidPlatformScreen():QFbScreen() -{ - mGeometry = QRect(0, 0, QAndroidPlatformIntegration::m_defaultGeometryWidth, QAndroidPlatformIntegration::m_defaultGeometryHeight); - mFormat = QImage::Format_RGB16; - mDepth = 16; - mPhysicalSize.setHeight(QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight); - mPhysicalSize.setWidth(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth); - initializeCompositor(); -} - -void QAndroidPlatformScreen::topWindowChanged(QWindow *w) -{ - QtAndroidMenu::setActiveTopLevelWindow(w); - - if (w != 0) { - QAndroidPlatformWindow *platformWindow = static_cast(w->handle()); - if (platformWindow != 0) - platformWindow->updateStatusBarVisibility(); - } -} - -QRegion QAndroidPlatformScreen::doRedraw() -{ - QRegion touched; - touched = QFbScreen::doRedraw(); - if (touched.isEmpty()) - return touched; - - QtAndroid::flushImage(mGeometry.topLeft(), *mScreenImage, touched.boundingRect()); - return touched; -} - -QDpi QAndroidPlatformScreen::logicalDpi() const -{ - qreal lDpi = QtAndroid::scaledDensity() * 72; - return QDpi(lDpi, lDpi); -} - -Qt::ScreenOrientation QAndroidPlatformScreen::orientation() const -{ - return QAndroidPlatformIntegration::m_orientation; -} - -Qt::ScreenOrientation QAndroidPlatformScreen::nativeOrientation() const -{ - return QAndroidPlatformIntegration::m_nativeOrientation; -} diff --git a/src/plugins/platforms/android/src/raster/qandroidplatformscreen.h b/src/plugins/platforms/android/src/raster/qandroidplatformscreen.h deleted file mode 100644 index 9f8807b995..0000000000 --- a/src/plugins/platforms/android/src/raster/qandroidplatformscreen.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDPLATFORMSCREEN_H -#define QANDROIDPLATFORMSCREEN_H - -#include - -class QAndroidPlatformScreen: public QFbScreen -{ - Q_OBJECT -public: - QAndroidPlatformScreen(); - void topWindowChanged(QWindow *w); - QDpi logicalDpi() const; - Qt::ScreenOrientation orientation() const; - Qt::ScreenOrientation nativeOrientation() const; - -public slots: - QRegion doRedraw(); - -}; - -#endif diff --git a/src/plugins/platforms/android/src/raster/qandroidplatformwindow.cpp b/src/plugins/platforms/android/src/raster/qandroidplatformwindow.cpp deleted file mode 100644 index 7ff18526d9..0000000000 --- a/src/plugins/platforms/android/src/raster/qandroidplatformwindow.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidplatformwindow.h" - -#include "androidjnimain.h" -#include - -QAndroidPlatformWindow::QAndroidPlatformWindow(QWindow *window) - : QFbWindow(window) -{ -} - -void QAndroidPlatformWindow::setGeometry(const QRect &rect) -{ - QFbWindow::setGeometry(rect); -} - -void QAndroidPlatformWindow::propagateSizeHints() -{ - //shut up warning from default implementation -} - -void QAndroidPlatformWindow::updateStatusBarVisibility() -{ - Qt::WindowFlags flags = window()->flags(); - bool isNonRegularWindow = flags & (Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window; - if (!isNonRegularWindow) { - if (mWindowState & Qt::WindowFullScreen) - QtAndroid::hideStatusBar(); - else if (mWindowState & Qt::WindowMaximized) - QtAndroid::showStatusBar(); - } -} - -void QAndroidPlatformWindow::raise() -{ - updateStatusBarVisibility(); - QFbWindow::raise(); -} - -void QAndroidPlatformWindow::setWindowState(Qt::WindowState state) -{ - if (mWindowState == state) - return; - - if (window()->isVisible()) - updateStatusBarVisibility(); - - QFbWindow::setWindowState(state); -} - -void QAndroidPlatformWindow::setVisible(bool visible) -{ - if (visible) - updateStatusBarVisibility(); - - QFbWindow::setVisible(visible); - - // The Android Activity is activated before Qt is initialized, causing the application state to - // never be set to 'active'. We explicitly set this state when the first window becomes visible. - if (visible) - QtAndroid::setApplicationActive(); -} diff --git a/src/plugins/platforms/android/src/raster/qandroidplatformwindow.h b/src/plugins/platforms/android/src/raster/qandroidplatformwindow.h deleted file mode 100644 index 9e3f203201..0000000000 --- a/src/plugins/platforms/android/src/raster/qandroidplatformwindow.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ANDROIDPLATFORMWINDOW_H -#define ANDROIDPLATFORMWINDOW_H -#include -#include - -class QAndroidPlatformWindow: public QObject, public QFbWindow -{ - Q_OBJECT -public: - explicit QAndroidPlatformWindow(QWindow *window); - - void propagateSizeHints(); - - void raise(); - void setWindowState(Qt::WindowState state); - void setVisible(bool visible); - void updateStatusBarVisibility(); - -public slots: - void setGeometry(const QRect &rect); -}; - -#endif // ANDROIDPLATFORMWINDOW_H diff --git a/src/plugins/platforms/android/src/raster/raster.pri b/src/plugins/platforms/android/src/raster/raster.pri deleted file mode 100644 index 86e5aa235f..0000000000 --- a/src/plugins/platforms/android/src/raster/raster.pri +++ /dev/null @@ -1,7 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += $$PWD/qandroidplatformscreen.cpp \ - $$PWD/qandroidplatformwindow.cpp - -HEADERS += $$PWD/qandroidplatformscreen.h \ - $$PWD/qandroidplatformwindow.h diff --git a/src/plugins/platforms/android/src/src.pri b/src/plugins/platforms/android/src/src.pri deleted file mode 100644 index 9b64e846f7..0000000000 --- a/src/plugins/platforms/android/src/src.pri +++ /dev/null @@ -1,55 +0,0 @@ -load(qt_plugin) - -QT += core-private gui-private platformsupport-private - -CONFIG += qpa/genericunixfontdatabase - -OTHER_FILES += $$PWD/android.json - -INCLUDEPATH += $$PWD -INCLUDEPATH += $$PWD/../../../../3rdparty/android/src - -SOURCES += $$PWD/androidplatformplugin.cpp \ - $$PWD/androidjnimain.cpp \ - $$PWD/androidjniaccessibility.cpp \ - $$PWD/androidjniinput.cpp \ - $$PWD/androidjnimenu.cpp \ - $$PWD/androidjniclipboard.cpp \ - $$PWD/qandroidplatformintegration.cpp \ - $$PWD/qandroidplatformservices.cpp \ - $$PWD/qandroidassetsfileenginehandler.cpp \ - $$PWD/qandroidinputcontext.cpp \ - $$PWD/qandroidplatformaccessibility.cpp \ - $$PWD/qandroidplatformfontdatabase.cpp \ - $$PWD/qandroidplatformdialoghelpers.cpp \ - $$PWD/qandroidplatformclipboard.cpp \ - $$PWD/qandroidplatformtheme.cpp \ - $$PWD/qandroidplatformmenubar.cpp \ - $$PWD/qandroidplatformmenu.cpp \ - $$PWD/qandroidplatformmenuitem.cpp \ - $$PWD/qandroidsystemlocale.cpp - - -HEADERS += $$PWD/qandroidplatformintegration.h \ - $$PWD/androidjnimain.h \ - $$PWD/androidjniaccessibility.h \ - $$PWD/androidjniinput.h \ - $$PWD/androidjnimenu.h \ - $$PWD/androidjniclipboard.h \ - $$PWD/qandroidplatformservices.h \ - $$PWD/qandroidassetsfileenginehandler.h \ - $$PWD/qandroidinputcontext.h \ - $$PWD/qandroidplatformaccessibility.h \ - $$PWD/qandroidplatformfontdatabase.h \ - $$PWD/qandroidplatformclipboard.h \ - $$PWD/qandroidplatformdialoghelpers.h \ - $$PWD/qandroidplatformtheme.h \ - $$PWD/qandroidplatformmenubar.h \ - $$PWD/qandroidplatformmenu.h \ - $$PWD/qandroidplatformmenuitem.h \ - $$PWD/qandroidsystemlocale.h - - -#Non-standard install directory, QTBUG-29859 -DESTDIR = $$DESTDIR/android -target.path = $${target.path}/android -- cgit v1.2.3