Sha256: caea098c391a0e9994e9d6b19aac27821c0da7e5ecbbc00200184aabf6f38ea0

Contents?: true

Size: 1.32 KB

Versions: 22

Compression:

Stored size: 1.32 KB

Contents

package com.rhomobile.rhodes.util;

import com.rhomobile.rhodes.Logger;
import com.rhomobile.rhodes.RhodesActivity;

public class PerformOnUiThread implements Runnable {
	
	private static final String TAG = PerformOnUiThread.class.getSimpleName();
	
	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 {
			RhodesActivity ra = RhodesActivity.getInstance();
			ra.post(r, delay);
		}
		catch (Exception e) {
			Logger.E(TAG, "exec failed: " + e.getMessage());
		}
	}
	
	public static void exec(Runnable r, boolean wait) {
		try {
			RhodesActivity ra = RhodesActivity.getInstance();
			if (!wait) {
				ra.post(r);
			}
			else {
				long thrId = Thread.currentThread().getId();
				if (ra.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) {
						ra.post(new PerformOnUiThread(r));
						r.wait();
					}
				}
			}
		}
		catch (Exception e) {
			Logger.E(TAG, "exec failed: " + e.getMessage());
		}
	}
};

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rhodes-3.0.0 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-3.0.0.beta.7 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-3.0.0.beta.6 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-3.0.0.beta.5 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-3.0.0.beta.4 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-3.0.0.beta.3 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-3.0.0.beta.2 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-3.0.0.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.4.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.4.1.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.4.0 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.4.0.beta.2 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.4.0.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.3.2 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.3.2.beta.2 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.3.2.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.3.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.3.1.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.3.0 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.3.0.beta.3 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java