Sha256: f9e104c3f79de7c6b12d960d4aee01ee9856961d85ac74243d078841444ebbfe

Contents?: true

Size: 1.09 KB

Versions: 13

Compression:

Stored size: 1.09 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, 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

13 entries across 13 versions & 1 rubygems

Version Path
rhodes-2.2.4.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.3 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.3.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.2 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.2.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.1.beta.2 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.1.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.0 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.0.beta.3 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.0.beta.2 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.2.0.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java
rhodes-2.1.0 platform/android/Rhodes/src/com/rhomobile/rhodes/util/PerformOnUiThread.java