Sha256: 318e6a70539b37cdd8a68c60fef7e466cf9247aa5a2405af7cfb57231b6e46f4
Contents?: true
Size: 1.32 KB
Versions: 6
Compression:
Stored size: 1.32 KB
Contents
package com.rhomobile.rhodes.util; import com.rhomobile.rhodes.Logger; import com.rhomobile.rhodes.RhodesService; public class PerformOnUiThread implements Runnable { private static final String TAG = "PerformOnUiThread"; private Runnable runnable; public PerformOnUiThread(Runnable r) { runnable = r; } public void run() { try { runnable.run(); } catch (Exception e) { Logger.E(TAG, "Operation failed: " + e.getMessage()); } finally { synchronized (runnable) { runnable.notify(); } } } public static void exec(Runnable r, int delay) { try { RhodesService rhodes = RhodesService.getInstance(); rhodes.post(r, delay); } catch (Exception e) { Logger.E(TAG, "exec failed: " + e.getMessage()); } } public static void exec(Runnable r, boolean wait) { try { RhodesService rhodes = RhodesService.getInstance(); if (!wait) { rhodes.post(r); } else { long thrId = Thread.currentThread().getId(); if (rhodes.getUiThreadId() == thrId) { // We are already in UI thread r.run(); } else { // Post request to UI thread and wait when it would be done synchronized (r) { rhodes.post(new PerformOnUiThread(r)); r.wait(); } } } } catch (Exception e) { Logger.E(TAG, "exec failed: " + e.getMessage()); } } };
Version data entries
6 entries across 6 versions & 1 rubygems