Skip to content

Commit

Permalink
Let Android dispatcher use main thread
Browse files Browse the repository at this point in the history
This enables use of the main thread as the dispatcher thread if the calling
thread is not a dispatcher thread.

This closes #2
  • Loading branch information
code77se committed Feb 11, 2016
1 parent 6b708e3 commit 96eb7e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
13 changes: 4 additions & 9 deletions jq/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = '1.0.0' // Change this to match your version number
version = '1.0.1'

android {
compileSdkVersion 23
Expand All @@ -11,14 +11,10 @@ android {
defaultConfig {
minSdkVersion 1
targetSdkVersion 23
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.0.1"
}
buildTypes {
// release {
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// }
}
}

Expand All @@ -45,7 +41,6 @@ task javadoc(type: Javadoc) {
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
// options.encoding = 'UTF-8'
}

artifacts {
Expand All @@ -67,6 +62,6 @@ bintray {
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
//publish = true
publish = true
}
}
3 changes: 2 additions & 1 deletion jq/src/main/java/se/code77/jq/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ protected Config(boolean monitorUnterminated) {
public final boolean monitorUnterminated;

/**
* Create a dispatcher capable of dispatching events to the current thread
* Create a dispatcher capable of dispatching events to the current thread;
* or if the current thread does not implement an event loop, to another thread that does.
* @return Dispatcher
*/
public abstract Dispatcher createDispatcher();
Expand Down
13 changes: 12 additions & 1 deletion jq/src/main/java/se/code77/jq/config/android/AndroidConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import se.code77.jq.config.Config;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

public class AndroidConfig extends Config {
Expand All @@ -11,7 +12,17 @@ public AndroidConfig(boolean monitorUnterminated) {
}

public static class AndroidDispatcher implements Dispatcher {
protected final Handler mHandler = new Handler();
protected final Handler mHandler;

public AndroidDispatcher() {
Looper looper = Looper.myLooper();

if (looper == null) {
looper = Looper.getMainLooper();
}

mHandler = new Handler(looper);
}

@Override
public void dispatch(Runnable r) {
Expand Down

0 comments on commit 96eb7e7

Please sign in to comment.