2 |
3 |
4 |
5 |
6 | file chooser
7 |
15 |
21 |
22 |
23 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/sample/src/main/assets/webpage/fullscreenVideo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
16 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
54 |
--------------------------------------------------------------------------------
/sample/src/main/assets/webpage/hitTestResult.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 请长按一下html元素
7 |
12 |
13 |
14 | 请长按一下html元素
15 | hello world!
16 |
17 | 
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample/src/main/assets/webpage/sdd.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/sample/src/main/assets/webpage/websocket.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | WebSocket 测试
9 |
10 |
11 |
12 |
34 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/activity/ContainerActivity.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.activity;
2 |
3 | import android.os.Bundle;
4 | import androidx.annotation.Nullable;
5 | import androidx.fragment.app.Fragment;
6 | import androidx.appcompat.app.AppCompatActivity;
7 |
8 | import com.just.agentweb.sample.R;
9 | import com.just.agentweb.sample.fragment.EasyWebFragment;
10 |
11 | /**
12 | * Created by cenxiaozhong on 2017/7/22.
13 | */
14 |
15 | public class ContainerActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 |
21 | setContentView(R.layout.activity_common);
22 |
23 | Fragment mFragment=null;
24 | getSupportFragmentManager()
25 | .beginTransaction()
26 | .add(R.id.container_framelayout,mFragment= EasyWebFragment.getInstance(new Bundle()),EasyWebFragment.class.getName())
27 | .show(mFragment)
28 | .commit();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/activity/EasyWebActivity.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.activity;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import androidx.annotation.NonNull;
6 | import androidx.annotation.Nullable;
7 | import androidx.appcompat.widget.Toolbar;
8 | import android.text.TextUtils;
9 | import android.view.KeyEvent;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import com.tencent.smtt.sdk.WebView;
13 | import android.widget.LinearLayout;
14 | import android.widget.TextView;
15 |
16 | import com.just.agentweb.sample.R;
17 | import com.just.agentweb.sample.base.BaseAgentWebActivity;
18 |
19 | /**
20 | * Created by cenxiaozhong on 2017/7/22.
21 | *
22 | */
23 | public class EasyWebActivity extends BaseAgentWebActivity {
24 |
25 | private TextView mTitleTextView;
26 |
27 | @Override
28 | protected void onCreate(@Nullable Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_web);
31 |
32 | LinearLayout mLinearLayout = (LinearLayout) this.findViewById(R.id.container);
33 | Toolbar mToolbar = (Toolbar) this.findViewById(R.id.toolbar);
34 | mToolbar.setTitleTextColor(Color.WHITE);
35 | mToolbar.setTitle("");
36 | mTitleTextView = (TextView) this.findViewById(R.id.toolbar_title);
37 | this.setSupportActionBar(mToolbar);
38 | if (getSupportActionBar() != null) {
39 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
40 | }
41 | mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View v) {
44 | EasyWebActivity.this.finish();
45 | }
46 | });
47 | }
48 |
49 |
50 | @NonNull
51 | @Override
52 | protected ViewGroup getAgentWebParent() {
53 | return (ViewGroup) this.findViewById(R.id.container);
54 | }
55 |
56 | @Override
57 | public boolean onKeyDown(int keyCode, KeyEvent event) {
58 | if (mAgentWeb != null && mAgentWeb.handleKeyEvent(keyCode, event)) {
59 | return true;
60 | }
61 |
62 | return super.onKeyDown(keyCode, event);
63 | }
64 |
65 | @Override
66 | protected int getIndicatorColor() {
67 | return Color.parseColor("#ff0000");
68 | }
69 |
70 | @Override
71 | protected void setTitle(WebView view, String title) {
72 | super.setTitle(view, title);
73 | if (!TextUtils.isEmpty(title)) {
74 | if (title.length() > 10) {
75 | title = title.substring(0, 10).concat("...");
76 | }
77 | }
78 | mTitleTextView.setText(title);
79 | }
80 |
81 | @Override
82 | protected int getIndicatorHeight() {
83 | return 3;
84 | }
85 |
86 | @Nullable
87 | @Override
88 | protected String getUrl() {
89 | return "https://www.baidu.com/";
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/activity/ExternalActivity.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.activity;
2 |
3 | import android.os.Bundle;
4 | import androidx.annotation.Nullable;
5 | import android.util.Log;
6 |
7 | /**
8 | * @author cenxiaozhong
9 | * @date 2019-05-19
10 | * @since 1.0.0
11 | */
12 | public class ExternalActivity extends WebActivity {
13 |
14 | public static final String TAG = ExternalActivity.class.getSimpleName();
15 |
16 | @Override
17 | protected void onCreate(@Nullable Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | }
20 |
21 | @Override
22 | public String getUrl() {
23 | String url = getIntent().getData().getQueryParameter("url");
24 | Log.e(TAG, " url:" + url);
25 | return url;
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/activity/WebActivity.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.activity;
2 |
3 | /**
4 | * Created by cenxiaozhong on 2017/5/22.
5 | *
6 | *
7 | */
8 |
9 | public class WebActivity extends BaseWebActivity {
10 |
11 | @Override
12 | public String getUrl() {
13 | return super.getUrl();
14 | }
15 |
16 | @Override
17 | protected void onStart() {
18 | super.onStart();
19 | }
20 |
21 | @Override
22 | protected void onResume() {
23 | super.onResume();
24 |
25 |
26 |
27 | //测试Cookies
28 | /*try {
29 |
30 | String targetUrl="";
31 | Log.i("Info","cookies:"+ AgentWebConfig.getCookiesByUrl(targetUrl="http://www.jd.com"));
32 | AgentWebConfig.removeAllCookies(new ValueCallback() {
33 | @Override
34 | public void onReceiveValue(Boolean value) {
35 | Log.i("Info","onResume():"+value);
36 | }
37 | });
38 |
39 | String tagInfo=AgentWebConfig.getCookiesByUrl(targetUrl);
40 | Log.i("Info","tag:"+tagInfo);
41 | AgentWebConfig.syncCookie("http://www.jd.com","ID=IDHl3NVU0N3ltZm9OWHhubHVQZW1BRThLdGhLaFc5TnVtQWd1S2g1REcwNVhTS3RXQVFBQEBFDA984906B62C444931EA0");
42 | String tag=AgentWebConfig.getCookiesByUrl(targetUrl);
43 | Log.i("Info","tag:"+tag);
44 | AgentWebConfig.removeSessionCookies();
45 | Log.i("Info","removeSessionCookies:"+AgentWebConfig.getCookiesByUrl(targetUrl));
46 | }catch (Exception e){
47 | e.printStackTrace();
48 | }*/
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/activity/utils/WebViewJavaScriptFunction.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.activity.utils;
2 |
3 | public interface WebViewJavaScriptFunction {
4 |
5 | void onJsFunctionCalled(String tag);
6 | }
7 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/app/App.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.app;
2 |
3 | import android.util.Log;
4 |
5 | import androidx.multidex.MultiDexApplication;
6 |
7 | import com.squareup.leakcanary.LeakCanary;
8 | import com.tencent.smtt.sdk.QbSdk;
9 |
10 | /**
11 | * Created by cenxiaozhong on 2017/5/23.
12 | * source code https://github.com/Justson/AgentWeb
13 | */
14 |
15 | public class App extends MultiDexApplication {
16 |
17 | @Override
18 | public void onCreate() {
19 | super.onCreate();
20 |
21 | /**
22 | * 说明, WebView 初处初始化耗时 250ms 左右。
23 | * 提前初始化WebView ,好处可以提升页面初始化速度,减少白屏时间,
24 | * 坏处,拖慢了App 冷启动速度,如果 WebView 配合 VasSonic 使用,
25 | * 建议不要在此处提前初始化 WebView 。
26 | */
27 | // WebView mWebView=new WebView(new MutableContextWrapper(this));
28 |
29 | if (LeakCanary.isInAnalyzerProcess(this)) {
30 | // This process is dedicated to LeakCanary for heap analysis.
31 | // You should not init your app in this process.
32 | return;
33 | }
34 | LeakCanary.install(this);
35 | // Normal app init code...
36 |
37 | QbSdk.setDownloadWithoutWifi(true);//设置非WIFI也需要主动下载X5内核
38 | // TODO... PS: 等待X5初始化完毕再创建webview, 否则会使用系统内核
39 | QbSdk.setNeedInitX5FirstTime(true);//true表示首次使用时需要先加载X5(避免启动界面广告打开webview时X5还未初始化完毕导致使用系统内核)
40 | // //这个函数内是异步执行所以不会阻塞 App 主线程,这个函数内是轻量级执行所以对 App 启动性能没有影响
41 | QbSdk.initX5Environment(this, new QbSdk.PreInitCallback() {
42 | @Override
43 | public void onCoreInitFinished() {
44 | Log.d("X5LOG", "BrowserSDKCore.initBrowserSDK.onCoreInitFinished: ...");
45 | }
46 |
47 | @Override
48 | public void onViewInitFinished(boolean finished) {
49 | Log.d("X5LOG", "BrowserSDKCore.initBrowserSDK.onViewInitFinished: finished = " + finished);
50 | }
51 | });
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/base/FragmentKeyDown.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.base;
2 |
3 | import android.view.KeyEvent;
4 |
5 | /**
6 | * Created by cenxiaozhong
7 | * source code https://github.com/Justson/AgentWeb
8 | */
9 |
10 | public interface FragmentKeyDown {
11 |
12 | boolean onFragmentKeyDown(int keyCode, KeyEvent event);
13 | }
14 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/behavior/BottomNavigationViewBehavior.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) LeonDevLifeLog(https://github.com/Justson/AgentWeb)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.just.agentweb.sample.behavior;
18 |
19 | import android.content.Context;
20 | import android.util.AttributeSet;
21 | import android.view.View;
22 |
23 | import androidx.coordinatorlayout.widget.CoordinatorLayout;
24 | import androidx.core.view.ViewCompat;
25 |
26 | import com.google.android.material.appbar.AppBarLayout;
27 |
28 | /**
29 | * 与toolbar联动隐藏底部菜单
30 | *
31 | * @author LeonDevLifeLog
32 | * @date 2018-02-24 08:59
33 | * @since V4.0.0
34 | */
35 | public class BottomNavigationViewBehavior extends CoordinatorLayout.Behavior {
36 | public BottomNavigationViewBehavior() {
37 | }
38 |
39 | public BottomNavigationViewBehavior(Context context, AttributeSet attrs) {
40 | super(context, attrs);
41 | }
42 |
43 | @Override
44 | public boolean onLayoutChild(CoordinatorLayout parent, View child, int layoutDirection) {
45 | ((CoordinatorLayout.LayoutParams) child.getLayoutParams()).topMargin = parent
46 | .getMeasuredHeight() - child.getMeasuredHeight();
47 | return super.onLayoutChild(parent, child, layoutDirection);
48 | }
49 |
50 | @Override
51 | public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
52 | return dependency instanceof AppBarLayout;
53 | }
54 |
55 | @Override
56 | public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
57 | //得到依赖View的滑动距离
58 | int top = ((AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) dependency
59 | .getLayoutParams()).getBehavior()).getTopAndBottomOffset();
60 | //因为BottomNavigation的滑动与ToolBar是反向的,所以取负值
61 | ViewCompat.setTranslationY(child, -(top * child.getMeasuredHeight() / dependency.getMeasuredHeight()));
62 | return false;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/client/MiddlewareChromeClient.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.client;
2 |
3 | import android.util.Log;
4 | import com.tencent.smtt.export.external.interfaces.JsResult;
5 | import com.tencent.smtt.sdk.WebView;
6 |
7 | import com.just.agentweb.MiddlewareWebChromeBase;
8 |
9 | /**
10 | * Created by cenxiaozhong on 2017/12/16.
11 | * After agentweb 3.0.0 , allow dev to custom self WebChromeClient's MiddleWare .
12 | */
13 | public class MiddlewareChromeClient extends MiddlewareWebChromeBase {
14 | public MiddlewareChromeClient() {
15 | }
16 | @Override
17 | public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
18 | Log.i("Info","onJsAlert:"+url);
19 | return super.onJsAlert(view, url, message, result);
20 | }
21 |
22 | @Override
23 | public void onProgressChanged(WebView view, int newProgress) {
24 | super.onProgressChanged(view, newProgress);
25 | Log.i("Info","onProgressChanged:");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/client/MiddlewareWebViewClient.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.client;
2 |
3 | import android.util.Log;
4 |
5 | import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
6 | import com.tencent.smtt.sdk.WebView;
7 |
8 | import com.just.agentweb.MiddlewareWebClientBase;
9 |
10 | /**
11 | * Created by cenxiaozhong on 2017/12/16.
12 | *
13 | *
14 | * 方法的执行顺序,例如下面用了7个中间件一个 WebViewClient
15 | *
16 | * .useMiddlewareWebClient(getMiddlewareWebClient()) // 1
17 | * .useMiddlewareWebClient(getMiddlewareWebClient()) // 2
18 | * .useMiddlewareWebClient(getMiddlewareWebClient()) // 3
19 | * .useMiddlewareWebClient(getMiddlewareWebClient()) // 4
20 | * .useMiddlewareWebClient(getMiddlewareWebClient()) // 5
21 | * .useMiddlewareWebClient(getMiddlewareWebClient()) // 6
22 | * .useMiddlewareWebClient(getMiddlewareWebClient()) // 7
23 | * DefaultWebClient // 8
24 | * .setWebViewClient(mWebViewClient) // 9
25 | *
26 | *
27 | * 典型的洋葱模型
28 | * 对象内部的方法执行顺序: 1->2->3->4->5->6->7->8->9->8->7->6->5->4->3->2->1
29 | *
30 | *
31 | * 中断中间件的执行, 删除super.methodName(...) 这行即可
32 | *
33 | */
34 |
35 | public class MiddlewareWebViewClient extends MiddlewareWebClientBase {
36 |
37 | public MiddlewareWebViewClient() {
38 | }
39 |
40 | private static int count = 1;
41 |
42 | @Override
43 | public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
44 | Log.i("Info", "MiddlewareWebViewClient -- > shouldOverrideUrlLoading:" + request.getUrl().toString() + " c:" + (count++));
45 | return super.shouldOverrideUrlLoading(view, request);
46 |
47 | }
48 |
49 | @Override
50 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
51 | Log.i("Info", "MiddlewareWebViewClient -- > shouldOverrideUrlLoading:" + url + " c:" + (count++));
52 | return super.shouldOverrideUrlLoading(view, url);
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/client/SonicWebViewClient.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.client;
2 |
3 | import android.annotation.TargetApi;
4 |
5 | import com.just.agentweb.MiddlewareWebClientBase;
6 | import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
7 | import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
8 | import com.tencent.smtt.sdk.WebView;
9 | import com.tencent.sonic.sdk.SonicSession;
10 |
11 | /**
12 | * Created by cenxiaozhong on 2017/12/17.
13 | */
14 |
15 | public class SonicWebViewClient extends MiddlewareWebClientBase {
16 |
17 | private SonicSession sonicSession;
18 |
19 | public SonicWebViewClient(SonicSession sonicSession) {
20 | this.sonicSession = sonicSession;
21 | }
22 |
23 | @Override
24 | public void onPageFinished(WebView view, String url) {
25 | super.onPageFinished(view, url);
26 | if (sonicSession != null) {
27 | sonicSession.getSessionClient().pageFinish(url);
28 | }
29 | }
30 |
31 | @TargetApi(21)
32 | @Override
33 | public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
34 | return shouldInterceptRequest(view, request.getUrl().toString());
35 | }
36 |
37 | @Override
38 | public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
39 | if (sonicSession != null) {
40 | return (WebResourceResponse) sonicSession.getSessionClient().requestResource(url);
41 | }
42 | return null;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/common/AndroidInterface.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.common;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.os.Looper;
6 | import android.util.Log;
7 | import android.webkit.JavascriptInterface;
8 | import android.widget.Toast;
9 |
10 | import com.just.agentweb.AgentWeb;
11 |
12 | /**
13 | * Created by cenxiaozhong on 2017/5/14.
14 | * source code https://github.com/Justson/AgentWeb
15 | */
16 |
17 | public class AndroidInterface {
18 |
19 | private Handler deliver = new Handler(Looper.getMainLooper());
20 | private AgentWeb agent;
21 | private Context context;
22 |
23 | public AndroidInterface(AgentWeb agent, Context context) {
24 | this.agent = agent;
25 | this.context = context;
26 | }
27 |
28 |
29 |
30 | @JavascriptInterface
31 | public void callAndroid(final String msg) {
32 |
33 |
34 | deliver.post(new Runnable() {
35 | @Override
36 | public void run() {
37 |
38 | Log.i("Info", "main Thread:" + Thread.currentThread());
39 | Toast.makeText(context.getApplicationContext(), "" + msg, Toast.LENGTH_LONG).show();
40 | }
41 | });
42 |
43 |
44 | Log.i("Info", "Thread:" + Thread.currentThread());
45 |
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/common/CommonWebChromeClient.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.common;
2 |
3 | import android.util.Log;
4 | import com.tencent.smtt.sdk.WebView;
5 |
6 | import com.just.agentweb.WebChromeClient;
7 |
8 | /**
9 | * @author cenxiaozhong
10 | * @date 2019/2/19
11 | * @since 1.0.0
12 | */
13 | public class CommonWebChromeClient extends WebChromeClient {
14 | @Override
15 | public void onProgressChanged(WebView view, int newProgress) {
16 | super.onProgressChanged(view, newProgress);
17 | Log.i("CommonWebChromeClient", "onProgressChanged:" + newProgress + " view:" + view);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/common/CustomSettings.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.common;
2 |
3 | import android.app.Activity;
4 | import android.os.Build;
5 | import com.tencent.smtt.sdk.DownloadListener;
6 | import com.tencent.smtt.sdk.WebView;
7 |
8 | import com.just.agentweb.AbsAgentWebSettings;
9 | import com.just.agentweb.AgentWeb;
10 | import com.just.agentweb.DefaultDownloadImpl;
11 | import com.just.agentweb.IAgentWebSettings;
12 | import com.just.agentweb.WebListenerManager;
13 |
14 | /**
15 | * Created by cenxiaozhong on 2017/5/26.
16 | * source code https://github.com/Justson/AgentWeb
17 | */
18 | //WebDefaultSettingsManager 重命名为 AbsAgentWebSettings 并且抽象出bindAgentWebSupport方法
19 | public class CustomSettings extends AbsAgentWebSettings {
20 | public CustomSettings() {
21 | super();
22 | }
23 |
24 | @Override
25 | protected void bindAgentWebSupport(AgentWeb agentWeb) {
26 |
27 | }
28 |
29 |
30 | @Override
31 | public IAgentWebSettings toSetting(WebView webView) {
32 | super.toSetting(webView);
33 |
34 | getWebSettings().setBlockNetworkImage(false);//是否阻塞加载网络图片 协议http or https
35 | getWebSettings().setAllowFileAccess(false); //允许加载本地文件html file协议, 这可能会造成不安全 , 建议重写关闭
36 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
37 | getWebSettings().setAllowFileAccessFromFileURLs(false); //通过 file mUrl 加载的 Javascript 读取其他的本地文件 .建议关闭
38 | getWebSettings().setAllowUniversalAccessFromFileURLs(false);//允许通过 file mUrl 加载的 Javascript 可以访问其他的源,包括其他的文件和 http,https 等其他的源
39 | }
40 | getWebSettings().setNeedInitialFocus(true);
41 | getWebSettings().setDefaultTextEncodingName("gb2312");//设置编码格式
42 | getWebSettings().setDefaultFontSize(16);
43 | getWebSettings().setMinimumFontSize(12);//设置 WebView 支持的最小字体大小,默认为 8
44 | getWebSettings().setGeolocationEnabled(true);
45 | getWebSettings().setUserAgentString(getWebSettings().getUserAgentString().concat("agentweb/3.1.0"));
46 | return this;
47 | }
48 |
49 | @Override
50 | public WebListenerManager setDownloader(WebView webView, DownloadListener downloadListener) {
51 | return super.setDownloader(webView,
52 | DefaultDownloadImpl.create((Activity) webView.getContext()
53 | , webView, mAgentWeb.getPermissionInterceptor()));
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/common/FragmentKeyDown.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.common;
2 |
3 | import android.view.KeyEvent;
4 |
5 | /**
6 | * Created by cenxiaozhong on 2017/5/23.
7 | * source code https://github.com/Justson/AgentWeb
8 | */
9 |
10 | public interface FragmentKeyDown {
11 |
12 | boolean onFragmentKeyDown(int keyCode, KeyEvent event);
13 | }
14 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/common/GuideItemEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) Justson(https://github.com/Justson/AgentWeb)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.just.agentweb.sample.common;
18 |
19 | /**
20 | * @author cenxiaozhong
21 | * @date 2018/7/15
22 | * @since 1.0.0
23 | */
24 | public class GuideItemEntity {
25 |
26 | private String guideTitle;
27 | private int guideDictionary;
28 | private int extra;
29 |
30 | public GuideItemEntity(String guideTitle, int guideDictionary) {
31 | this.guideTitle = guideTitle;
32 | this.guideDictionary = guideDictionary;
33 | }
34 |
35 |
36 | public String getGuideTitle() {
37 | return guideTitle;
38 | }
39 |
40 | public void setGuideTitle(String guideTitle) {
41 | this.guideTitle = guideTitle;
42 | }
43 |
44 | public int getGuideDictionary() {
45 | return guideDictionary;
46 | }
47 |
48 | public void setGuideDictionary(int guideDictionary) {
49 | this.guideDictionary = guideDictionary;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/common/UIController.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.common;
2 |
3 | import android.app.Activity;
4 | import android.os.Handler;
5 | import android.util.Log;
6 | import com.tencent.smtt.sdk.WebView;
7 |
8 | import com.just.agentweb.AgentWebUIControllerImplBase;
9 |
10 | /**
11 | * Created by cenxiaozhong on 2017/12/23.
12 | */
13 |
14 | /**
15 | * 如果你需要修改某一个AgentWeb 内部的某一个弹窗 ,请看下面的例子
16 | * 注意写法一定要参照 DefaultUIController 的写法 ,因为UI自由定制,但是回调的方式是固定的,并且一定要回调。
17 | */
18 | public class UIController extends AgentWebUIControllerImplBase {
19 |
20 | private Activity mActivity;
21 | public UIController(Activity activity){
22 | this.mActivity=activity;
23 | }
24 |
25 | @Override
26 | public void onShowMessage(String message, String from) {
27 | super.onShowMessage(message,from);
28 | Log.i(TAG,"message:"+message);
29 | }
30 |
31 | @Override
32 | public void onSelectItemsPrompt(WebView view, String url, String[] items, Handler.Callback callback) {
33 | super.onSelectItemsPrompt(view,url,items,callback); // 使用默认的UI
34 | }
35 |
36 |
37 | /**
38 | * 修改文件选择的弹窗
39 | */
40 | /* @Override
41 | public void onSelectItemsPrompt(WebView view, String mUrl, String[] ways, final Handler.Callback callback) {
42 | //super.onSelectItemsPrompt(view,mUrl,ways,callback); //这行应该注释或者删除掉
43 | final AlertDialog mAlertDialog = new AlertDialog.Builder(mActivity)//
44 | .setSingleChoiceItems(ways, -1, new DialogInterface.OnClickListener() {
45 | @Override
46 | public void onClick(DialogInterface dialog, int which) {
47 | dialog.dismiss();
48 | if (callback != null) {
49 | Message mMessage = Message.obtain();
50 | mMessage.what = which; //mMessage.what 必须等于ways的index
51 | callback.handleMessage(mMessage); //最后callback一定要回调
52 | }
53 |
54 | }
55 | }).setOnCancelListener(new DialogInterface.OnCancelListener() {
56 | @Override
57 | public void onCancel(DialogInterface dialog) {
58 | dialog.dismiss();
59 | if (callback != null) {
60 | callback.handleMessage(Message.obtain(null, -1)); //-1表示取消 //最后callback一定要回调
61 | }
62 | }
63 | }).create();
64 | mAlertDialog.show();
65 |
66 | }*/
67 | }
68 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/fragment/BounceWebFragment.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import androidx.annotation.Nullable;
6 | import android.view.Gravity;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.FrameLayout;
10 | import android.widget.LinearLayout;
11 | import android.widget.TextView;
12 |
13 | import com.just.agentweb.AgentWeb;
14 | import com.just.agentweb.DefaultWebClient;
15 | import com.just.agentweb.IWebLayout;
16 | import com.just.agentweb.sample.R;
17 | import com.just.agentweb.sample.widget.WebLayout;
18 |
19 | /**
20 | * Created by cenxiaozhong on 2017/7/1.
21 | * source code https://github.com/Justson/AgentWeb
22 | */
23 |
24 | public class BounceWebFragment extends AgentWebFragment {
25 |
26 | public static BounceWebFragment getInstance(Bundle bundle) {
27 | BounceWebFragment mBounceWebFragment = new BounceWebFragment();
28 | if (mBounceWebFragment != null){
29 | mBounceWebFragment.setArguments(bundle);
30 | }
31 | return mBounceWebFragment;
32 | }
33 |
34 |
35 | @Override
36 | public String getUrl() {
37 | return super.getUrl();
38 | }
39 |
40 | @Override
41 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
42 | mAgentWeb = AgentWeb.with(this)
43 | .setAgentWebParent((ViewGroup) view, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
44 | .useDefaultIndicator(-1, 2)
45 | .setAgentWebWebSettings(getSettings())
46 | .setWebViewClient(mWebViewClient)
47 | .setWebChromeClient(mWebChromeClient)
48 | .setWebLayout(getWebLayout())
49 | .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
50 | .interceptUnkownUrl()
51 | .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)
52 | .setMainFrameErrorView(R.layout.agentweb_error_page, -1)
53 | .createAgentWeb()//
54 | .ready()//
55 | .go(getUrl());
56 | // 得到 AgentWeb 最底层的控件
57 | addBGChild((FrameLayout) mAgentWeb.getWebCreator().getWebParentLayout());
58 | initView(view);
59 |
60 |
61 | }
62 |
63 | protected IWebLayout getWebLayout() {
64 | return new WebLayout(getActivity());
65 | }
66 |
67 | protected void addBGChild(FrameLayout frameLayout) {
68 |
69 | TextView mTextView = new TextView(frameLayout.getContext());
70 | mTextView.setText("技术由 AgentWeb 提供");
71 | mTextView.setTextSize(16);
72 | mTextView.setTextColor(Color.parseColor("#727779"));
73 | frameLayout.setBackgroundColor(Color.parseColor("#272b2d"));
74 | FrameLayout.LayoutParams mFlp = new FrameLayout.LayoutParams(-2, -2);
75 | mFlp.gravity = Gravity.CENTER_HORIZONTAL;
76 | final float scale = frameLayout.getContext().getResources().getDisplayMetrics().density;
77 | mFlp.topMargin = (int) (15 * scale + 0.5f);
78 | frameLayout.addView(mTextView, 0, mFlp);
79 | }
80 |
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/fragment/CustomIndicatorFragment.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.fragment;
2 |
3 | import android.os.Bundle;
4 | import androidx.annotation.Nullable;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.LinearLayout;
8 |
9 | import com.just.agentweb.AgentWeb;
10 | import com.just.agentweb.AgentWebSettingsImpl;
11 | import com.just.agentweb.DefaultWebClient;
12 | import com.just.agentweb.sample.widget.CoolIndicatorLayout;
13 |
14 | /**
15 | * Created by cenxiaozhong on 2017/5/26.
16 | * source code https://github.com/Justson/AgentWeb
17 | */
18 |
19 | public class CustomIndicatorFragment extends AgentWebFragment {
20 | public static CustomIndicatorFragment getInstance(Bundle bundle) {
21 | CustomIndicatorFragment mCustomIndicatorFragment = new CustomIndicatorFragment();
22 | if (bundle != null){
23 | mCustomIndicatorFragment.setArguments(bundle);
24 | }
25 | return mCustomIndicatorFragment;
26 | }
27 |
28 | @Override
29 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
30 |
31 | // CommonIndicator mCommonIndicator=new CommonIndicator(this.getActivity());
32 | // FrameLayout.LayoutParams lp=new FrameLayout.LayoutParams(-2,-2);
33 | // lp.gravity= Gravity.CENTER;
34 | // ProgressBar mProgressBar=new ProgressBar(this.getActivity());
35 | // mProgressBar.setBackground(this.getResources().getDrawable(R.drawable.indicator_shape));
36 | // mCommonIndicator.addView(mProgressBar,lp);
37 |
38 |
39 | CoolIndicatorLayout mCoolIndicatorLayout = new CoolIndicatorLayout(this.getActivity());
40 | this.mAgentWeb = AgentWeb.with(this)//
41 | .setAgentWebParent((ViewGroup) view, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
42 | .setCustomIndicator(mCoolIndicatorLayout)
43 | .setAgentWebWebSettings(AgentWebSettingsImpl.getInstance())
44 | .setWebViewClient(mWebViewClient)
45 | .setPermissionInterceptor(mPermissionInterceptor)
46 | .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
47 | .interceptUnkownUrl()
48 | .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)
49 | .createAgentWeb()//
50 | .ready()//
51 | .go(getUrl());
52 |
53 |
54 | initView(view);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/fragment/CustomSettingsFragment.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.fragment;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.just.agentweb.IAgentWebSettings;
6 | import com.just.agentweb.sample.common.CustomSettings;
7 |
8 | /**
9 | * Created by cenxiaozhong on 2017/5/26.
10 | * source code https://github.com/Justson/AgentWeb
11 | */
12 |
13 | public class CustomSettingsFragment extends AgentWebFragment {
14 |
15 | public static AgentWebFragment getInstance(Bundle bundle) {
16 |
17 | CustomSettingsFragment mCustomSettingsFragment = new CustomSettingsFragment();
18 | if (bundle != null){
19 | mCustomSettingsFragment.setArguments(bundle);
20 | }
21 | return mCustomSettingsFragment;
22 |
23 | }
24 |
25 | @Override
26 | public IAgentWebSettings getSettings() {
27 | return new CustomSettings();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/fragment/SmartRefreshWebFragment.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import androidx.annotation.Nullable;
6 | import android.view.View;
7 | import com.tencent.smtt.sdk.WebView;
8 | import android.widget.FrameLayout;
9 |
10 | import com.just.agentweb.IWebLayout;
11 | import com.just.agentweb.sample.widget.SmartRefreshWebLayout;
12 | import com.scwang.smartrefresh.layout.SmartRefreshLayout;
13 | import com.scwang.smartrefresh.layout.api.RefreshLayout;
14 | import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
15 |
16 | /**
17 | * Created by cenxiaozhong on 2017/7/1.
18 | * source code https://github.com/Justson/AgentWeb
19 | */
20 |
21 | public class SmartRefreshWebFragment extends BounceWebFragment {
22 |
23 | public static SmartRefreshWebFragment getInstance(Bundle bundle) {
24 |
25 | SmartRefreshWebFragment mSmartRefreshWebFragment = new SmartRefreshWebFragment();
26 | if (mSmartRefreshWebFragment != null) {
27 | mSmartRefreshWebFragment.setArguments(bundle);
28 | }
29 |
30 | return mSmartRefreshWebFragment;
31 | }
32 |
33 | private SmartRefreshWebLayout mSmartRefreshWebLayout = null;
34 |
35 | @Override
36 | public String getUrl() {
37 | return super.getUrl();
38 | }
39 |
40 |
41 | @Override
42 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
43 | super.onViewCreated(view, savedInstanceState);
44 |
45 | final SmartRefreshLayout mSmartRefreshLayout = (SmartRefreshLayout) this.mSmartRefreshWebLayout.getLayout();
46 |
47 | final WebView mWebView = this.mSmartRefreshWebLayout.getWebView();
48 | mSmartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
49 | @Override
50 | public void onRefresh(RefreshLayout refreshlayout) {
51 | mAgentWeb.getUrlLoader().reload();
52 |
53 | mSmartRefreshLayout.postDelayed(new Runnable() {
54 | @Override
55 | public void run() {
56 | mSmartRefreshLayout.finishRefresh();
57 | }
58 | }, 2000);
59 | }
60 | });
61 | mSmartRefreshLayout.autoRefresh();
62 |
63 |
64 | }
65 |
66 |
67 | @Override
68 | protected IWebLayout getWebLayout() {
69 | return this.mSmartRefreshWebLayout = new SmartRefreshWebLayout(this.getActivity());
70 | }
71 |
72 |
73 | @Override
74 | protected void addBGChild(FrameLayout frameLayout) {
75 |
76 | frameLayout.setBackgroundColor(Color.TRANSPARENT);
77 |
78 | }
79 |
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/fragment/VasSonicFragment.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.fragment;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import androidx.annotation.Nullable;
6 | import android.view.View;
7 |
8 | import com.just.agentweb.MiddlewareWebClientBase;
9 | import com.just.agentweb.sample.sonic.SonicImpl;
10 | import com.just.agentweb.sample.sonic.SonicJavaScriptInterface;
11 |
12 | import static com.just.agentweb.sample.sonic.SonicJavaScriptInterface.PARAM_CLICK_TIME;
13 |
14 | /**
15 | * Created by cenxiaozhong on 2017/12/18.
16 | *
17 | * If you wanna use VasSonic to fast open first page , please
18 | * follow as sample to update your code;
19 | */
20 |
21 | public class VasSonicFragment extends AgentWebFragment {
22 | private SonicImpl mSonicImpl;
23 | public static VasSonicFragment create(Bundle bundle){
24 |
25 | VasSonicFragment mVasSonicFragment =new VasSonicFragment();
26 | if(bundle!=null){
27 | mVasSonicFragment.setArguments(bundle);
28 | }
29 | return mVasSonicFragment;
30 | }
31 |
32 |
33 | @Override
34 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
35 |
36 | // 1. 首先创建SonicImpl
37 | mSonicImpl = new SonicImpl(this.getArguments().getString(URL_KEY), this.getContext());
38 | // 2. 调用 onCreateSession
39 | mSonicImpl.onCreateSession();
40 | //3. 创建AgentWeb ,注意创建AgentWeb的时候应该使用加入SonicWebViewClient中间件
41 | super.onViewCreated(view, savedInstanceState); // 创建 AgentWeb 注意的 go("") 传入的 mUrl 应该null 或者""
42 | //4. 注入 JavaScriptInterface
43 | mAgentWeb.getJsInterfaceHolder().addJavaObject("sonic", new SonicJavaScriptInterface(mSonicImpl.getSonicSessionClient(), new Intent().putExtra(PARAM_CLICK_TIME,getArguments().getLong(PARAM_CLICK_TIME)).putExtra("loadUrlTime", System.currentTimeMillis())));
44 | //5. 最后绑定AgentWeb
45 | mSonicImpl.bindAgentWeb(mAgentWeb);
46 |
47 | }
48 |
49 | //在步骤3的时候应该传入给AgentWeb
50 | @Override
51 | public MiddlewareWebClientBase getMiddlewareWebClient() {
52 | return mSonicImpl.createSonicClientMiddleWare();
53 | }
54 |
55 | //getUrl 应该为null
56 | @Override
57 | public String getUrl() {
58 | return null;
59 | }
60 |
61 | @Override
62 | public void onDestroyView() {
63 | super.onDestroyView();
64 | //销毁SonicSession
65 | if(mSonicImpl !=null){
66 | mSonicImpl.destrory();
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/sonic/SonicImpl.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.sonic;
2 |
3 | import android.content.Context;
4 |
5 | import com.just.agentweb.AgentWeb;
6 | import com.just.agentweb.MiddlewareWebClientBase;
7 | import com.tencent.sonic.sdk.SonicConfig;
8 | import com.tencent.sonic.sdk.SonicEngine;
9 | import com.tencent.sonic.sdk.SonicSession;
10 | import com.tencent.sonic.sdk.SonicSessionConfig;
11 |
12 | /**
13 | * Created by cenxiaozhong on 2017/12/17.
14 | */
15 |
16 | public class SonicImpl {
17 |
18 | private SonicSession sonicSession;
19 | private Context mContext;
20 | private String url;
21 | private SonicSessionClientImpl sonicSessionClient;
22 | public SonicImpl(String url , Context context){
23 | this.url=url;
24 | this.mContext=context;
25 |
26 | }
27 |
28 | /**
29 | */
30 | public void onCreateSession() {
31 |
32 | SonicSessionConfig.Builder sessionConfigBuilder = new SonicSessionConfig.Builder();
33 | sessionConfigBuilder.setSupportLocalServer(true);
34 | SonicEngine.createInstance(new DefaultSonicRuntimeImpl(mContext.getApplicationContext()), new SonicConfig.Builder().build());
35 | // create sonic session and run sonic flow
36 | sonicSession = SonicEngine.getInstance().createSession(url, sessionConfigBuilder.build());
37 | if (null != sonicSession) {
38 | sonicSession.bindClient(sonicSessionClient = new SonicSessionClientImpl());
39 | } else {
40 | // throw new UnknownError("create session fail!");
41 | // Toast.makeText(this, "create sonic session fail!", Toast.LENGTH_LONG).show();
42 | }
43 | }
44 |
45 | public SonicSessionClientImpl getSonicSessionClient(){
46 | return this.sonicSessionClient;
47 | }
48 |
49 | /**
50 | * 不使用中间件,使用普通的 WebViewClient 也是可以的。
51 | * @return MiddlewareWebClientBase
52 | */
53 | public MiddlewareWebClientBase createSonicClientMiddleWare(){
54 | return new SonicWebViewClient(sonicSession);
55 | }
56 |
57 | public void bindAgentWeb(AgentWeb agentWeb){
58 | if (sonicSessionClient != null) {
59 | sonicSessionClient.bindWebView(agentWeb);
60 | sonicSessionClient.clientReady();
61 | } else { // default mode
62 | agentWeb.getUrlLoader().loadUrl(url);
63 | }
64 | }
65 |
66 | public void destrory(){
67 | if(sonicSession!=null){
68 | sonicSession.destroy();
69 | }
70 | }
71 |
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/sonic/SonicSessionClientImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Tencent is pleased to support the open source community by making VasSonic available.
3 | *
4 | * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
5 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * https://opensource.org/licenses/BSD-3-Clause
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
10 | *
11 | *
12 | */
13 |
14 | package com.just.agentweb.sample.sonic;
15 |
16 | import android.os.Bundle;
17 | import com.tencent.smtt.sdk.WebView;
18 |
19 | import com.just.agentweb.AgentWeb;
20 | import com.tencent.sonic.sdk.SonicSessionClient;
21 |
22 | import java.util.HashMap;
23 |
24 | /**
25 | * a implement of SonicSessionClient which need to connect webview and content data.
26 | */
27 |
28 | public class SonicSessionClientImpl extends SonicSessionClient {
29 |
30 |
31 | private AgentWeb mAgentWeb;
32 | public void bindWebView(AgentWeb agentWeb) {
33 | this.mAgentWeb = agentWeb;
34 | }
35 |
36 | public WebView getWebView() {
37 | return this.mAgentWeb.getWebCreator().getWebView();
38 | }
39 |
40 | @Override
41 | public void loadUrl(String url, Bundle extraData) {
42 | this.mAgentWeb.getUrlLoader().loadUrl(url);
43 |
44 | }
45 |
46 | @Override
47 | public void loadDataWithBaseUrl(String baseUrl, String data, String mimeType, String encoding, String historyUrl) {
48 | this.mAgentWeb.getUrlLoader().loadDataWithBaseURL(baseUrl,data,mimeType,encoding,historyUrl);
49 |
50 | }
51 |
52 |
53 | @Override
54 | public void loadDataWithBaseUrlAndHeader(String baseUrl, String data, String mimeType, String encoding, String historyUrl, HashMap headers) {
55 | loadDataWithBaseUrl(baseUrl, data, mimeType, encoding, historyUrl);
56 | }
57 |
58 |
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/sonic/SonicWebViewClient.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.sonic;
2 |
3 | import android.annotation.TargetApi;
4 |
5 | import com.just.agentweb.MiddlewareWebClientBase;
6 | import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
7 | import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
8 | import com.tencent.smtt.sdk.WebView;
9 | import com.tencent.sonic.sdk.SonicSession;
10 |
11 | /**
12 | * Created by cenxiaozhong on 2017/12/17.
13 | */
14 |
15 | public class SonicWebViewClient extends MiddlewareWebClientBase {
16 |
17 | private SonicSession sonicSession;
18 |
19 | public SonicWebViewClient(SonicSession sonicSession) {
20 | this.sonicSession = sonicSession;
21 | }
22 |
23 | @Override
24 | public void onPageFinished(WebView view, String url) {
25 | super.onPageFinished(view, url);
26 | if (sonicSession != null) {
27 | sonicSession.getSessionClient().pageFinish(url);
28 | }
29 | }
30 |
31 | @TargetApi(21)
32 | @Override
33 | public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
34 | return shouldInterceptRequest(view, request.getUrl().toString());
35 | }
36 |
37 | @Override
38 | public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
39 | if (sonicSession != null) {
40 | return (WebResourceResponse) sonicSession.getSessionClient().requestResource(url);
41 | }
42 | return null;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/widget/CommonIndicator.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.widget;
2 |
3 | import android.content.Context;
4 | import androidx.annotation.Nullable;
5 | import android.util.AttributeSet;
6 | import android.view.View;
7 | import android.widget.FrameLayout;
8 |
9 | import com.just.agentweb.BaseIndicatorView;
10 |
11 | /**
12 | * Created by cenxiaozhong on 2017/5/26.
13 | * source code https://github.com/Justson/AgentWeb
14 | */
15 |
16 | public class CommonIndicator extends BaseIndicatorView {
17 | public CommonIndicator(Context context) {
18 | super(context);
19 | }
20 |
21 | public CommonIndicator(Context context, @Nullable AttributeSet attrs) {
22 | super(context, attrs);
23 | }
24 |
25 | public CommonIndicator(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 | }
28 |
29 |
30 | @Override
31 | public void show() {
32 | this.setVisibility(View.VISIBLE);
33 | }
34 |
35 | @Override
36 | public void hide() {
37 | this.setVisibility(View.GONE);
38 | }
39 |
40 |
41 | @Override
42 | public LayoutParams offerLayoutParams() {
43 | return new FrameLayout.LayoutParams(-1, -1);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/widget/CoolIndicatorLayout.java:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Copyright (C) Justson(https://github.com/Justson/AgentWeb)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.just.agentweb.sample.widget;
19 |
20 | import android.app.Activity;
21 | import android.content.Context;
22 | import android.os.Build;
23 | import androidx.annotation.Nullable;
24 | import android.util.AttributeSet;
25 | import android.view.View;
26 | import android.widget.FrameLayout;
27 |
28 | import com.coolindicator.sdk.CoolIndicator;
29 | import com.just.agentweb.AgentWebUtils;
30 | import com.just.agentweb.BaseIndicatorView;
31 |
32 | /**
33 | * @author cenxiaozhong
34 | * @date 2018/2/23
35 | * @since 1.0.0
36 | */
37 | public class CoolIndicatorLayout extends BaseIndicatorView {
38 |
39 |
40 | private static final String TAG = CoolIndicatorLayout.class.getSimpleName();
41 | private CoolIndicator mCoolIndicator = null;
42 |
43 |
44 | public CoolIndicatorLayout(Context context) {
45 | this(context, null);
46 | }
47 |
48 | public CoolIndicatorLayout(Context context, @Nullable AttributeSet attrs) {
49 | this(context, attrs, -1);
50 | }
51 |
52 | public CoolIndicatorLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
53 | super(context, attrs, defStyleAttr);
54 | mCoolIndicator = CoolIndicator.create((Activity) context);
55 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
56 | mCoolIndicator.setProgressDrawable(context.getResources().getDrawable(com.coolindicator.sdk.R.drawable.default_drawable_indicator, context.getTheme()));
57 | } else {
58 | mCoolIndicator.setProgressDrawable(context.getResources().getDrawable(com.coolindicator.sdk.R.drawable.default_drawable_indicator));
59 | }
60 |
61 | this.addView(mCoolIndicator, offerLayoutParams());
62 |
63 | }
64 |
65 | @Override
66 | public void show() {
67 | this.setVisibility(View.VISIBLE);
68 | mCoolIndicator.start();
69 | }
70 |
71 | @Override
72 | public void setProgress(int newProgress) {
73 | }
74 |
75 | @Override
76 | public void hide() {
77 | mCoolIndicator.complete();
78 | }
79 |
80 | @Override
81 | public LayoutParams offerLayoutParams() {
82 | return new FrameLayout.LayoutParams(-1, AgentWebUtils.dp2px(getContext(), 3));
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/widget/SmartRefreshWebLayout.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.widget;
2 |
3 | import android.app.Activity;
4 | import androidx.annotation.NonNull;
5 | import androidx.annotation.Nullable;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import com.tencent.smtt.sdk.WebView;
9 |
10 | import com.just.agentweb.IWebLayout;
11 | import com.just.agentweb.sample.R;
12 | import com.scwang.smartrefresh.layout.SmartRefreshLayout;
13 |
14 | /**
15 | * Created by cenxiaozhong on 2017/8/14.
16 | */
17 |
18 | public class SmartRefreshWebLayout implements IWebLayout {
19 |
20 | private final SmartRefreshLayout mSmartRefreshLayout;
21 | private final WebView mWebView;
22 |
23 | public SmartRefreshWebLayout(Activity activity){
24 |
25 | View mView=activity.getLayoutInflater().inflate(R.layout.fragment_srl_web,null);
26 | View smarkView = mView.findViewById(R.id.smarkLayout);
27 | mSmartRefreshLayout = (SmartRefreshLayout) smarkView;
28 | mWebView = (WebView) mSmartRefreshLayout.findViewById(R.id.webView);
29 |
30 | }
31 |
32 | @NonNull
33 | @Override
34 | public ViewGroup getLayout() {
35 | return mSmartRefreshLayout;
36 | }
37 |
38 | @Nullable
39 | @Override
40 | public WebView getWebView() {
41 | return mWebView;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/just/agentweb/sample/widget/WebLayout.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample.widget;
2 |
3 | import android.app.Activity;
4 | import android.view.LayoutInflater;
5 | import android.view.ViewGroup;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.annotation.Nullable;
9 |
10 | import com.just.agentweb.IWebLayout;
11 | import com.just.agentweb.sample.R;
12 | import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
13 | import com.tencent.smtt.sdk.WebView;
14 |
15 | /**
16 | * Created by cenxiaozhong on 2017/7/1.
17 | * source code https://github.com/Justson/AgentWeb
18 | */
19 |
20 | public class WebLayout implements IWebLayout {
21 |
22 | private Activity mActivity;
23 | private final TwinklingRefreshLayout mTwinklingRefreshLayout;
24 | // private WebView mWebView = null;
25 | private WebView mWebView = null;
26 |
27 | public WebLayout(Activity activity) {
28 | this.mActivity = activity;
29 | mTwinklingRefreshLayout = (TwinklingRefreshLayout) LayoutInflater.from(activity).inflate(R.layout.fragment_twk_web, null);
30 | mTwinklingRefreshLayout.setPureScrollModeOn();
31 | mWebView = mTwinklingRefreshLayout.findViewById(R.id.webView);
32 | }
33 |
34 | @NonNull
35 | @Override
36 | public ViewGroup getLayout() {
37 | return mTwinklingRefreshLayout;
38 | }
39 |
40 | @Nullable
41 | @Override
42 | public WebView getWebView() {
43 | return mWebView;
44 | }
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-v21/ripple_for_btn.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-v21/selector_drawable_for_btn.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/btn_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/btn_shape_s.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/indicator_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/iv_back_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/selector_drawable_for_btn.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_auto_hiden_toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
19 |
20 |
21 |
29 |
30 |
38 |
39 |
47 |
48 |
56 |
57 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_common.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
19 |
27 |
28 |
29 |
30 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_native_download.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
19 |
27 |
28 |
29 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_test_jsbridge_x5.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
14 |
15 |
16 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_web.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
21 |
22 |
23 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/filechooser_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
15 |
16 |
21 |
22 |
27 |
28 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/fragment_agentweb.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/fragment_js.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
21 |
22 |
34 |
47 |
48 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/fragment_srl_web.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
17 |
22 |
23 |
29 |
30 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/fragment_twk_web.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/listview_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/markdown_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/recyclerview_item_download.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
18 |
26 |
27 |
35 |
36 |
46 |
47 |
48 |
49 |
57 |
58 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/toorbar_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
17 |
18 |
28 |
37 |
46 |
47 |
55 |
56 |
57 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/toolbar_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/app_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/sample/src/main/res/mipmap-xhdpi/app_logo.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/app_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/sample/src/main/res/mipmap-xxhdpi/app_logo.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/app_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/sample/src/main/res/mipmap-xxxhdpi/app_logo.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/sample/src/main/res/mipmap-xxxhdpi/back.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/cha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/sample/src/main/res/mipmap-xxxhdpi/cha.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/sample/src/main/res/mipmap-xxxhdpi/more.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #393a3f
4 | #303135
5 | #1aad19
6 |
7 | #1B9AF7
8 | #58b2f2
9 |
10 | #7b393a3f
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AgentWebX5
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
14 |
18 |
19 |
25 |
26 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/sample/src/test/java/com/just/agentweb/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.just.agentweb.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':agentweb-core', ':agentweb-filechooser', ':jsbridge_x5'
2 |
--------------------------------------------------------------------------------