()
| 1169 | |
| 1170 | /// Implementation of the event dispatch loop content |
| 1171 | void edtLoopImpl() { |
| 1172 | try { |
| 1173 | // transitions shouldn't be bound by framerate |
| 1174 | if (animationQueue == null || animationQueue.isEmpty()) { |
| 1175 | // prevents us from waking up the EDT too much and |
| 1176 | // thus exhausting the systems resources. The + 1 |
| 1177 | // prevents us from ever waiting 0 milliseconds which |
| 1178 | // is the same as waiting with no time limit |
| 1179 | if (!noSleep) { |
| 1180 | synchronized (lock) { |
| 1181 | impl.edtIdle(true); |
| 1182 | long waitTime = Math.max(1, framerateLock - (time)); |
| 1183 | long end = System.currentTimeMillis() + waitTime; |
| 1184 | while (true) { |
| 1185 | long remaining = end - System.currentTimeMillis(); |
| 1186 | if (remaining <= 0) { |
| 1187 | break; |
| 1188 | } |
| 1189 | try { |
| 1190 | lock.wait(remaining); |
| 1191 | break; |
| 1192 | } catch (InterruptedException ie) { |
| 1193 | Thread.currentThread().interrupt(); |
| 1194 | break; |
| 1195 | } |
| 1196 | } |
| 1197 | impl.edtIdle(false); |
| 1198 | } |
| 1199 | } |
| 1200 | } else { |
| 1201 | // paint transition or intro animations and don't do anything else if such |
| 1202 | // animations are in progress... |
| 1203 | paintTransitionAnimation(); |
| 1204 | return; |
| 1205 | } |
| 1206 | } catch (RuntimeException ignor) { |
| 1207 | Log.e(ignor); |
| 1208 | } |
| 1209 | long currentTime = System.currentTimeMillis(); |
| 1210 | |
| 1211 | // minimal amount of sync, just flipping the stack pointers |
| 1212 | synchronized (lock) { |
| 1213 | inputEventStackPointerTmp = inputEventStackPointer; |
| 1214 | inputEventStackPointer = 0; |
| 1215 | lastDragOffset = -1; |
| 1216 | int[] qt = inputEventStackTmp; |
| 1217 | inputEventStackTmp = inputEventStack; |
| 1218 | |
| 1219 | // We have a special flag here for a case where the input event stack might still be processing this can |
| 1220 | // happen if an event callback calls something like invokeAndBlock while processing and might reach |
| 1221 | // this code again |
| 1222 | if (qt[qt.length - 1] == Integer.MAX_VALUE) { |
| 1223 | inputEventStack = new int[qt.length]; |
| 1224 | } else { |
| 1225 | inputEventStack = qt; |
| 1226 | qt[qt.length - 1] = 0; |
| 1227 | } |
| 1228 | } |
no test coverage detected