Android: avoid reflection with ClipData addItem
Task-number: QTBUG-81687 Change-Id: If07fff6f371d2c05cb61a1a7695c96219d0260d2 Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Andy Shaw <andy.shaw@qt.io> (cherry picked from commit 27dbb3ee5477dbfed5fa96a688683744e13cc9cb) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
32aeba4e38
commit
20124ebf2c
@ -43,6 +43,7 @@ package org.qtproject.qt.android;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@ -113,7 +114,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 Method m_addItemMethod = null;
|
||||
private static HashMap<String, Uri> m_cachedUris = new HashMap<String, Uri>();
|
||||
private static ArrayList<String> m_knownDirs = new ArrayList<String>();
|
||||
|
||||
@ -963,9 +963,8 @@ public class QtNative
|
||||
|
||||
private static void clearClipData()
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= 28 && m_clipboardManager != null && m_usePrimaryClip)
|
||||
if (Build.VERSION.SDK_INT >= 28 && m_clipboardManager != null)
|
||||
m_clipboardManager.clearPrimaryClip();
|
||||
m_usePrimaryClip = false;
|
||||
}
|
||||
private static void setClipboardText(String text)
|
||||
{
|
||||
@ -1011,25 +1010,9 @@ public class QtNative
|
||||
if (m_usePrimaryClip) {
|
||||
ClipData clip = m_clipboardManager.getPrimaryClip();
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
if (m_addItemMethod == null) {
|
||||
Class[] cArg = new Class[2];
|
||||
cArg[0] = ContentResolver.class;
|
||||
cArg[1] = ClipData.Item.class;
|
||||
try {
|
||||
m_addItemMethod = m_clipboardManager.getClass().getMethod("addItem", cArg);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_addItemMethod != null) {
|
||||
try {
|
||||
m_addItemMethod.invoke(m_activity.getContentResolver(), clipData.getItemAt(0));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Objects.requireNonNull(clip).addItem(m_activity.getContentResolver(), clipData.getItemAt(0));
|
||||
} else {
|
||||
clip.addItem(clipData.getItemAt(0));
|
||||
Objects.requireNonNull(clip).addItem(clipData.getItemAt(0));
|
||||
}
|
||||
m_clipboardManager.setPrimaryClip(clip);
|
||||
} else {
|
||||
@ -1054,7 +1037,7 @@ public class QtNative
|
||||
try {
|
||||
if (m_clipboardManager != null && m_clipboardManager.hasPrimaryClip()) {
|
||||
ClipData primaryClip = m_clipboardManager.getPrimaryClip();
|
||||
for (int i = 0; i < primaryClip.getItemCount(); ++i)
|
||||
for (int i = 0; i < Objects.requireNonNull(primaryClip).getItemCount(); ++i)
|
||||
if (primaryClip.getItemAt(i).getHtmlText() != null)
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user