Mercurial > dwindows
comparison android/DWindows.kt @ 2514:5f711e86a211
Android: Implement dw_main_sleep() and dw_main_iteration().
Using the sort of hacky exception handler method for now....
since Google doesn't seem to want us to do this in a clean way.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 07 May 2021 19:54:05 +0000 |
parents | f54051c3f2a5 |
children | 211044d98e86 |
comparison
equal
deleted
inserted
replaced
2513:0fa54c340902 | 2514:5f711e86a211 |
---|---|
10 import android.media.AudioManager | 10 import android.media.AudioManager |
11 import android.media.ToneGenerator | 11 import android.media.ToneGenerator |
12 import android.os.Bundle | 12 import android.os.Bundle |
13 import android.os.Handler | 13 import android.os.Handler |
14 import android.os.Looper | 14 import android.os.Looper |
15 import android.os.MessageQueue | |
15 import android.text.InputFilter | 16 import android.text.InputFilter |
16 import android.text.InputFilter.LengthFilter | 17 import android.text.InputFilter.LengthFilter |
17 import android.text.InputType | 18 import android.text.InputType |
18 import android.text.method.PasswordTransformationMethod | 19 import android.text.method.PasswordTransformationMethod |
19 import android.util.Base64 | 20 import android.util.Base64 |
1059 Looper.loop() | 1060 Looper.loop() |
1060 } catch (e2: RuntimeException) { | 1061 } catch (e2: RuntimeException) { |
1061 } | 1062 } |
1062 } | 1063 } |
1063 return retval | 1064 return retval |
1065 } | |
1066 | |
1067 fun mainSleep(milliseconds: Int) | |
1068 { | |
1069 // If we are on the main UI thread... add an idle handler | |
1070 // Then loop until we throw an exception when the time expires | |
1071 // in the idle handler, if we are already thrown... remove the handler | |
1072 if(Looper.getMainLooper() == Looper.myLooper()) { | |
1073 val starttime = System.currentTimeMillis() | |
1074 | |
1075 // Waiting for Idle to make sure Toast gets rendered. | |
1076 Looper.myQueue().addIdleHandler(object : MessageQueue.IdleHandler { | |
1077 var thrown: Boolean = false | |
1078 | |
1079 override fun queueIdle(): Boolean { | |
1080 if(System.currentTimeMillis() - starttime >= milliseconds) { | |
1081 if (thrown == false) { | |
1082 thrown = true | |
1083 throw java.lang.RuntimeException() | |
1084 } | |
1085 return false | |
1086 } | |
1087 return true | |
1088 } | |
1089 }) | |
1090 | |
1091 // loop till a runtime exception is triggered. | |
1092 try { | |
1093 Looper.loop() | |
1094 } catch (e2: RuntimeException) { | |
1095 } | |
1096 } | |
1097 else | |
1098 { | |
1099 // If we are in a different thread just sleep | |
1100 Thread.sleep(milliseconds.toLong()) | |
1101 } | |
1064 } | 1102 } |
1065 | 1103 |
1066 fun dwindowsExit(exitcode: Int) | 1104 fun dwindowsExit(exitcode: Int) |
1067 { | 1105 { |
1068 waitOnUiThread { | 1106 waitOnUiThread { |