-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,097 additions
and
581 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Android CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
- name: Build with Gradle | ||
run: ./gradlew build |
Binary file not shown.
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
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
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
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
115 changes: 115 additions & 0 deletions
115
example/src/main/java/com/github/lzyzsd/jsbridge/example/CustomWebView.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.github.lzyzsd.jsbridge.example; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.os.Build; | ||
import android.util.AttributeSet; | ||
import android.webkit.WebView; | ||
import android.webkit.WebViewClient; | ||
|
||
import com.github.lzyzsd.jsbridge.BridgeHandler; | ||
import com.github.lzyzsd.jsbridge.BridgeHelper; | ||
import com.github.lzyzsd.jsbridge.CallBackFunction; | ||
import com.github.lzyzsd.jsbridge.IWebView; | ||
import com.github.lzyzsd.jsbridge.WebViewJavascriptBridge; | ||
|
||
/** | ||
* 采用BridgeHelper集成JsBridge功能示例.定制WebView,可只添加实际需要的JsBridge接口. | ||
* | ||
* @author ZhengAn | ||
* @date 2019-07-07 | ||
*/ | ||
@SuppressLint("SetJavaScriptEnabled") | ||
public class CustomWebView extends WebView implements WebViewJavascriptBridge, IWebView { | ||
|
||
private BridgeHelper bridgeHelper; | ||
|
||
public CustomWebView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
init(); | ||
} | ||
|
||
public CustomWebView(Context context, AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
init(); | ||
} | ||
|
||
public CustomWebView(Context context) { | ||
super(context); | ||
init(); | ||
} | ||
|
||
private void init() { | ||
this.setVerticalScrollBarEnabled(false); | ||
this.setHorizontalScrollBarEnabled(false); | ||
this.getSettings().setJavaScriptEnabled(true); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
WebView.setWebContentsDebuggingEnabled(true); | ||
} | ||
|
||
bridgeHelper = new BridgeHelper(this); | ||
this.setWebViewClient(new WebViewClient() { | ||
@Override | ||
public void onPageFinished(WebView webView, String s) { | ||
bridgeHelper.onPageFinished(); | ||
} | ||
|
||
@Override | ||
public boolean shouldOverrideUrlLoading(WebView webView, String s) { | ||
return bridgeHelper.shouldOverrideUrlLoading(s); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* @param handler default handler,handle messages send by js without assigned handler name, | ||
* if js message has handler name, it will be handled by named handlers registered by native | ||
*/ | ||
public void setDefaultHandler(BridgeHandler handler) { | ||
bridgeHelper.setDefaultHandler(handler); | ||
} | ||
|
||
@Override | ||
public void send(String data) { | ||
send(data, null); | ||
} | ||
|
||
@Override | ||
public void send(String data, CallBackFunction responseCallback) { | ||
bridgeHelper.send(data, responseCallback); | ||
} | ||
|
||
|
||
/** | ||
* register handler,so that javascript can call it | ||
* 注册处理程序,以便javascript调用它 | ||
* | ||
* @param handlerName handlerName | ||
* @param handler BridgeHandler | ||
*/ | ||
public void registerHandler(String handlerName, BridgeHandler handler) { | ||
bridgeHelper.registerHandler(handlerName, handler); | ||
} | ||
|
||
/** | ||
* unregister handler | ||
* | ||
* @param handlerName | ||
*/ | ||
public void unregisterHandler(String handlerName) { | ||
bridgeHelper.unregisterHandler(handlerName); | ||
} | ||
|
||
/** | ||
* call javascript registered handler | ||
* 调用javascript处理程序注册 | ||
* | ||
* @param handlerName handlerName | ||
* @param data data | ||
* @param callBack CallBackFunction | ||
*/ | ||
public void callHandler(String handlerName, String data, CallBackFunction callBack) { | ||
bridgeHelper.callHandler(handlerName, data, callBack); | ||
} | ||
|
||
} |
Oops, something went wrong.