Created
October 27, 2018 11:15
-
-
Save AppWerft/6af630b79223321427c0f81118cf1cf8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.appwerft.disto; | |
import org.appcelerator.kroll.KrollDict; | |
import org.appcelerator.kroll.KrollFunction; | |
import org.appcelerator.kroll.KrollProxy; | |
import org.appcelerator.kroll.annotations.Kroll; | |
import android.os.AsyncTask; | |
@Kroll.proxy(creatableInModule = TidistoModule.class, propertyAccessors = { | |
"then", "error" }) | |
public class TestProxy extends KrollProxy { | |
public TestProxy() { | |
super(); | |
} | |
/* JS_ | |
* var test = Module.createTest(); | |
* test.doIt().then(function(e){s}); | |
* */ | |
@Kroll.method | |
public TestProxy doIt(String message) { | |
new LongOperation().execute(); | |
return this; | |
} | |
private void dispatchThen(KrollDict payload) { | |
KrollFunction Then = (KrollFunction) getProperty("then"); | |
if (Then != null) { | |
Object res = Then.call(getKrollObject(), payload); | |
} | |
} | |
private class LongOperation extends AsyncTask<Void, Void, Void> { | |
@Override | |
protected Void doInBackground(Void... params) { | |
try { | |
Thread.sleep(5000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
@Override | |
protected void onPostExecute(Void Param) { | |
dispatchThen(new KrollDict()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment