Mercurial > dwindows
comparison android/DWindows.kt @ 2595:6b5057dd6b8e
Android: Experimental change for the new file browser... require it be on secondary...
thread, and use condition for the UI thread to trigger execution on result.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 28 May 2021 18:28:15 +0000 |
parents | 2c15b3d41fe4 |
children | 60ec91d23746 |
comparison
equal
deleted
inserted
replaced
2594:2c15b3d41fe4 | 2595:6b5057dd6b8e |
---|---|
740 private var paint = Paint() | 740 private var paint = Paint() |
741 private var bgcolor: Int = 0 | 741 private var bgcolor: Int = 0 |
742 private var menuBar: DWMenu? = null | 742 private var menuBar: DWMenu? = null |
743 private var defaultItem: View? = null | 743 private var defaultItem: View? = null |
744 private var fileURI: Uri? = null | 744 private var fileURI: Uri? = null |
745 private var fileLock = ReentrantLock() | |
746 private var fileCond = threadLock.newCondition() | |
745 | 747 |
746 // Our version of runOnUiThread that waits for execution | 748 // Our version of runOnUiThread that waits for execution |
747 fun waitOnUiThread(runnable: Runnable) | 749 fun waitOnUiThread(runnable: Runnable) |
748 { | 750 { |
749 if(Looper.myLooper() == Looper.getMainLooper()) { | 751 if(Looper.myLooper() == Looper.getMainLooper()) { |
3223 Log.d(null, text) | 3225 Log.d(null, text) |
3224 } | 3226 } |
3225 | 3227 |
3226 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | 3228 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
3227 super.onActivityResult(requestCode, resultCode, data) | 3229 super.onActivityResult(requestCode, resultCode, data) |
3228 if(requestCode == 100 && resultCode == Activity.RESULT_OK) { | 3230 if(requestCode == 100) { |
3229 fileURI = data!!.data | 3231 fileLock.lock() |
3230 throw java.lang.RuntimeException() | 3232 if(resultCode == Activity.RESULT_OK) { |
3233 fileURI = data!!.data | |
3234 } else { | |
3235 fileURI = null | |
3236 } | |
3237 fileCond.signal() | |
3238 fileLock.unlock() | |
3231 } | 3239 } |
3232 } | 3240 } |
3233 | 3241 |
3234 fun fileBrowseNew(title: String, defpath: String?, ext: String?, flags: Int): String? | 3242 fun fileBrowseNew(title: String, defpath: String?, ext: String?, flags: Int): String? |
3235 { | 3243 { |
3236 var retval: String? = null | 3244 var retval: String? = null |
3237 | 3245 |
3238 waitOnUiThread { | 3246 // This can't be called from the main thread |
3239 val fileintent = Intent(Intent.ACTION_GET_CONTENT) | 3247 if(Looper.getMainLooper() != Looper.myLooper()) { |
3240 fileintent.type = "text/plain" | 3248 fileLock.lock() |
3241 fileintent.addCategory(Intent.CATEGORY_OPENABLE) | 3249 waitOnUiThread { |
3242 startActivityForResult(fileintent, 100) | 3250 val fileintent = Intent(Intent.ACTION_GET_CONTENT) |
3243 } | 3251 fileintent.type = "text/plain" |
3244 | 3252 fileintent.addCategory(Intent.CATEGORY_OPENABLE) |
3245 // loop till a runtime exception is triggered. | 3253 startActivityForResult(fileintent, 100) |
3246 try { | 3254 } |
3247 Looper.loop() | 3255 |
3248 } catch (e2: RuntimeException) { | 3256 // Wait until the intent finishes. |
3249 } | 3257 fileCond.await() |
3250 | 3258 fileLock.unlock() |
3251 retval = getUriRealPath(this, fileURI) | 3259 |
3260 if(fileURI != null) { | |
3261 retval = getUriRealPath(this, fileURI) | |
3262 } | |
3263 } | |
3252 return retval | 3264 return retval |
3253 } | 3265 } |
3254 | 3266 |
3255 fun fileBrowse(title: String, defpath: String?, ext: String?, flags: Int): String? | 3267 fun fileBrowse(title: String, defpath: String?, ext: String?, flags: Int): String? |
3256 { | 3268 { |