diff options
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt/android/QtNative.java')
-rw-r--r-- | src/android/jar/src/org/qtproject/qt/android/QtNative.java | 219 |
1 files changed, 13 insertions, 206 deletions
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtNative.java b/src/android/jar/src/org/qtproject/qt/android/QtNative.java index 8140a46f11..b4116f3e5b 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtNative.java @@ -10,7 +10,6 @@ import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Objects; import java.util.concurrent.Semaphore; -import java.util.HashMap; import android.app.Activity; import android.app.Service; @@ -80,8 +79,6 @@ public class QtNative private static Boolean m_tabletEventSupported = null; private static boolean m_usePrimaryClip = false; public static QtThread m_qtThread = new QtThread(); - private static HashMap<String, Uri> m_cachedUris = new HashMap<String, Uri>(); - private static ArrayList<String> m_knownDirs = new ArrayList<String>(); private static final int KEYBOARD_HEIGHT_THRESHOLD = 100; private static final String INVALID_OR_NULL_URI_ERROR_MESSAGE = "Received invalid/null Uri"; @@ -214,209 +211,6 @@ public class QtNative } } - public static ParcelFileDescriptor openParcelFdForContentUrl(Context context, String contentUrl, - String openMode) - { - Uri uri = m_cachedUris.get(contentUrl); - if (uri == null) - uri = getUriWithValidPermission(context, contentUrl, openMode); - - if (uri == null) { - Log.e(QtTAG, getCurrentMethodNameLog() + INVALID_OR_NULL_URI_ERROR_MESSAGE); - return null; - } - - try { - final ContentResolver resolver = context.getContentResolver(); - return resolver.openFileDescriptor(uri, openMode); - } catch (FileNotFoundException | IllegalArgumentException | SecurityException e) { - Log.e(QtTAG, getCurrentMethodNameLog() + e.toString()); - } - - return null; - } - - public static FileDescriptor openFdObjectForContentUrl(Context context, String contentUrl, - String openMode) - { - final ParcelFileDescriptor pfd = openParcelFdForContentUrl(context, contentUrl, openMode); - if (pfd != null) - return pfd.getFileDescriptor(); - return null; - } - - public static int openFdForContentUrl(Context context, String contentUrl, String openMode) - { - Uri uri = m_cachedUris.get(contentUrl); - if (uri == null) - uri = getUriWithValidPermission(context, contentUrl, openMode); - - int fileDescriptor = -1; - if (uri == null) { - Log.e(QtTAG, getCurrentMethodNameLog() + INVALID_OR_NULL_URI_ERROR_MESSAGE); - return fileDescriptor; - } - - try { - final ContentResolver resolver = context.getContentResolver(); - fileDescriptor = resolver.openFileDescriptor(uri, openMode).detachFd(); - } catch (IllegalArgumentException | SecurityException | FileNotFoundException e) { - Log.e(QtTAG, getCurrentMethodNameLog() + e.toString()); - } - - return fileDescriptor; - } - - public static long getSize(Context context, String contentUrl) - { - long size = -1; - Uri uri = m_cachedUris.get(contentUrl); - if (uri == null) - uri = getUriWithValidPermission(context, contentUrl, "r"); - - if (uri == null) { - Log.e(QtTAG, getCurrentMethodNameLog() + INVALID_OR_NULL_URI_ERROR_MESSAGE); - return size; - } else if (!m_cachedUris.containsKey(contentUrl)) { - m_cachedUris.put(contentUrl, uri); - } - - try { - ContentResolver resolver = context.getContentResolver(); - Cursor cur = resolver.query(uri, new String[] { - DocumentsContract.Document.COLUMN_SIZE }, - null, null, null); - if (cur != null) { - if (cur.moveToFirst()) - size = cur.getLong(0); - cur.close(); - } - return size; - } catch (IllegalArgumentException | SecurityException | UnsupportedOperationException e) { - Log.e(QtTAG, getCurrentMethodNameLog() + e.toString()); - } - return size; - } - - public static boolean checkFileExists(Context context, String contentUrl) - { - boolean exists = false; - Uri uri = m_cachedUris.get(contentUrl); - if (uri == null) - uri = getUriWithValidPermission(context, contentUrl, "r"); - if (uri == null) { - Log.e(QtTAG, getCurrentMethodNameLog() + INVALID_OR_NULL_URI_ERROR_MESSAGE); - return exists; - } else { - if (!m_cachedUris.containsKey(contentUrl)) - m_cachedUris.put(contentUrl, uri); - } - - try { - ContentResolver resolver = context.getContentResolver(); - Cursor cur = resolver.query(uri, null, null, null, null); - if (cur != null) { - exists = true; - cur.close(); - } - return exists; - } catch (IllegalArgumentException | SecurityException | UnsupportedOperationException e) { - Log.e(QtTAG, getCurrentMethodNameLog() + e.toString()); - } - return exists; - } - - public static boolean checkIfWritable(Context context, String contentUrl) - { - return getUriWithValidPermission(context, contentUrl, "w") != null; - } - - public static boolean checkIfDir(Context context, String contentUrl) - { - boolean isDir = false; - Uri uri = m_cachedUris.get(contentUrl); - if (m_knownDirs.contains(contentUrl)) - return true; - if (uri == null) - uri = getUriWithValidPermission(context, contentUrl, "r"); - - if (uri == null) { - Log.e(QtTAG, getCurrentMethodNameLog() + INVALID_OR_NULL_URI_ERROR_MESSAGE); - return isDir; - } else { - if (!m_cachedUris.containsKey(contentUrl)) - m_cachedUris.put(contentUrl, uri); - } - - try { - final List<String> paths = uri.getPathSegments(); - // getTreeDocumentId will throw an exception if it is not a directory so check manually - if (!paths.get(0).equals("tree")) - return false; - ContentResolver resolver = context.getContentResolver(); - Uri docUri = DocumentsContract.buildDocumentUriUsingTree(uri, - DocumentsContract.getTreeDocumentId(uri)); - if (!docUri.toString().startsWith(uri.toString())) - return false; - Cursor cur = resolver.query(docUri, new String[] { - DocumentsContract.Document.COLUMN_MIME_TYPE }, - null, null, null); - if (cur != null) { - if (cur.moveToFirst()) { - final String dirStr = new String(DocumentsContract.Document.MIME_TYPE_DIR); - isDir = cur.getString(0).equals(dirStr); - if (isDir) - m_knownDirs.add(contentUrl); - } - cur.close(); - } - return isDir; - } catch (IllegalArgumentException | SecurityException | UnsupportedOperationException e) { - Log.e(QtTAG, getCurrentMethodNameLog() + e.toString()); - } - return false; - } - - public static String[] listContentsFromTreeUri(Context context, String contentUrl) - { - Uri treeUri = Uri.parse(contentUrl); - final ArrayList<String> results = new ArrayList<>(); - if (treeUri == null) { - Log.e(QtTAG, getCurrentMethodNameLog() + INVALID_OR_NULL_URI_ERROR_MESSAGE); - return results.toArray(new String[results.size()]); - } - final ContentResolver resolver = context.getContentResolver(); - final Uri docUri = DocumentsContract.buildDocumentUriUsingTree(treeUri, - DocumentsContract.getTreeDocumentId(treeUri)); - final Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(docUri, - DocumentsContract.getDocumentId(docUri)); - Cursor c; - final String dirStr = DocumentsContract.Document.MIME_TYPE_DIR; - try { - c = resolver.query(childrenUri, new String[] { - DocumentsContract.Document.COLUMN_DOCUMENT_ID, - DocumentsContract.Document.COLUMN_DISPLAY_NAME, - DocumentsContract.Document.COLUMN_MIME_TYPE }, - null, null, null); - while (c.moveToNext()) { - final String fileString = c.getString(1); - if (!m_cachedUris.containsKey(contentUrl + "/" + fileString)) { - m_cachedUris.put(contentUrl + "/" + fileString, - DocumentsContract.buildDocumentUriUsingTree(treeUri, - c.getString(0))); - } - results.add(fileString); - if (c.getString(2).equals(dirStr)) - m_knownDirs.add(contentUrl + "/" + fileString); - } - c.close(); - } catch (Exception e) { - Log.w(QtTAG, "Failed query: " + e); - return results.toArray(new String[results.size()]); - } - return results.toArray(new String[results.size()]); - } - // this method loads full path libs public static void loadQtLibraries(final ArrayList<String> libraries) { @@ -985,6 +779,18 @@ public class QtNative }); } + private static void notifyScrolledEvent(final int viewId) + { + runAction(new Runnable() { + @Override + public void run() { + if (m_activityDelegate != null) { + m_activityDelegate.notifyScrolledEvent(viewId); + } + } + }); + } + public static void notifyQtAndroidPluginRunning(final boolean running) { m_activityDelegate.notifyQtAndroidPluginRunning(running); @@ -1392,6 +1198,7 @@ public class QtNative public static native void handleOrientationChanged(int newRotation, int nativeOrientation); public static native void handleRefreshRateChanged(float refreshRate); // screen methods + public static native void handleUiDarkModeChanged(int newUiMode); // pointer methods public static native void mouseDown(int winId, int x, int y); |