
com.flipboard.goldengate.JavaScriptBridge Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compiler Show documentation
Show all versions of compiler Show documentation
Generate type safe java bridge into webview javascript code
The newest version!
package com.flipboard.goldengate;
import android.webkit.WebView;
import java.util.Random;
/**
* Base class with a couple helper methods for the generated bridges
*/
public abstract class JavaScriptBridge {
private static JsonSerializer defaultJsonSerializer;
private final Random random = new Random();
protected final WebView webView;
private final JsonSerializer jsonSerializer;
public JavaScriptBridge(WebView webView) {
this(webView, defaultJsonSerializer != null ? defaultJsonSerializer : new GsonJsonSerializer());
}
public JavaScriptBridge(WebView webView, JsonSerializer jsonSerializer) {
this.webView = webView;
this.jsonSerializer = jsonSerializer;
}
protected String toJson(T stuff) {
return jsonSerializer.toJson(stuff);
}
protected T fromJson(String json, Class type) {
return jsonSerializer.fromJson(json, type);
}
public static void setJsonSerializer(JsonSerializer serializer) {
defaultJsonSerializer = serializer;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy