@@ -38,7 +38,6 @@ import android.content.pm.PackageManager
3838import android.content.res.Configuration
3939import android.content.res.Resources
4040import android.graphics.Color
41- import android.graphics.Rect
4241import android.hardware.Sensor
4342import android.hardware.SensorManager
4443import android.os.*
@@ -79,6 +78,8 @@ import java.io.FileInputStream
7978import java.io.InputStream
8079import java.security.MessageDigest
8180import java.util.*
81+ import java.util.concurrent.Callable
82+ import java.util.concurrent.FutureTask
8283import java.util.concurrent.atomic.AtomicBoolean
8384import java.util.concurrent.atomic.AtomicReference
8485
@@ -136,6 +137,16 @@ class Godot private constructor(val context: Context) {
136137 val netUtils = GodotNetUtils (context)
137138 private val godotInputHandler = GodotInputHandler (context, this )
138139
140+ private val hasClipboardCallable = Callable {
141+ mClipboard?.hasPrimaryClip() == true
142+ }
143+
144+ private val getClipboardCallable = Callable {
145+ val clipData = mClipboard?.primaryClip
146+ val text = clipData?.getItemAt(0 )?.text
147+ text?.toString() ? : " "
148+ }
149+
139150 /* *
140151 * Task to run when the engine terminates.
141152 */
@@ -934,19 +945,31 @@ class Godot private constructor(val context: Context) {
934945
935946 @Keep
936947 fun hasClipboard (): Boolean {
937- return mClipboard?.hasPrimaryClip() == true
948+ return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P || Looper .getMainLooper().thread == Thread .currentThread()) {
949+ hasClipboardCallable.call()
950+ } else {
951+ val task = FutureTask (hasClipboardCallable)
952+ runOnHostThread(task)
953+ task.get()
954+ }
938955 }
939956
940957 @Keep
941958 fun getClipboard (): String {
942- val clipData = mClipboard?.primaryClip ? : return " "
943- val text = clipData.getItemAt(0 ).text ? : return " "
944- return text.toString()
959+ return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P || Looper .getMainLooper().thread == Thread .currentThread()) {
960+ getClipboardCallable.call()
961+ } else {
962+ val task = FutureTask (getClipboardCallable)
963+ runOnHostThread(task)
964+ task.get()
965+ }
945966 }
946967
947968 @Keep
948969 fun setClipboard (text : String? ) {
949- mClipboard?.setPrimaryClip(ClipData .newPlainText(" myLabel" , text))
970+ runOnHostThread {
971+ mClipboard?.setPrimaryClip(ClipData .newPlainText(" myLabel" , text))
972+ }
950973 }
951974
952975 @Keep
0 commit comments