| 147 | } |
| 148 | |
| 149 | public void run() { |
| 150 | try { |
| 151 | if (LOG_ENGINE_TASKS) |
| 152 | log.i("running task.work() " |
| 153 | + task.getClass().getName()); |
| 154 | if (!initialized) |
| 155 | throw new IllegalStateException("Engine not initialized"); |
| 156 | // run task |
| 157 | task.work(); |
| 158 | if (LOG_ENGINE_TASKS) |
| 159 | log.i("exited task.work() " |
| 160 | + task.getClass().getName()); |
| 161 | // post success callback |
| 162 | mBackgroundThread.postGUI(new Runnable() { |
| 163 | public void run() { |
| 164 | if (LOG_ENGINE_TASKS) |
| 165 | log.i("running task.done() " |
| 166 | + task.getClass().getName() |
| 167 | + " in gui thread"); |
| 168 | task.done(); |
| 169 | } |
| 170 | }); |
| 171 | // } catch ( final FatalError e ) { |
| 172 | // TODO: |
| 173 | // Handler h = view.getHandler(); |
| 174 | // |
| 175 | // if ( h==null ) { |
| 176 | // View root = view.getRootView(); |
| 177 | // h = root.getHandler(); |
| 178 | // } |
| 179 | // if ( h==null ) { |
| 180 | // // |
| 181 | // e.handle(); |
| 182 | // } else { |
| 183 | // h.postAtFrontOfQueue(new Runnable() { |
| 184 | // public void run() { |
| 185 | // e.handle(); |
| 186 | // } |
| 187 | // }); |
| 188 | // } |
| 189 | } catch (final Exception e) { |
| 190 | log.e("exception while running task " |
| 191 | + task.getClass().getName(), e); |
| 192 | // post error callback |
| 193 | mBackgroundThread.postGUI(new Runnable() { |
| 194 | public void run() { |
| 195 | log.e("running task.fail(" + e.getMessage() |
| 196 | + ") " + task.getClass().getSimpleName() |
| 197 | + " in gui thread "); |
| 198 | task.fail(e); |
| 199 | } |
| 200 | }); |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /** |