├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── README_AgentWeb-ENGLISH.md ├── README_AgentWeb.md ├── agentweb-core ├── .gitignore ├── build.gradle ├── libs │ └── alipaySdk-15.6.8-20191021122514.aar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── just │ │ └── agentweb │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── just │ │ │ └── agentweb │ │ │ ├── AbsAgentWebSettings.java │ │ │ ├── AbsAgentWebUIController.java │ │ │ ├── Action.java │ │ │ ├── ActionActivity.java │ │ │ ├── AgentWeb.java │ │ │ ├── AgentWebConfig.java │ │ │ ├── AgentWebFileProvider.java │ │ │ ├── AgentWebJsInterfaceCompat.java │ │ │ ├── AgentWebPermissions.java │ │ │ ├── AgentWebSettingsImpl.java │ │ │ ├── AgentWebUIControllerImplBase.java │ │ │ ├── AgentWebUtils.java │ │ │ ├── AgentWebView.java │ │ │ ├── BaseIndicatorSpec.java │ │ │ ├── BaseIndicatorView.java │ │ │ ├── BaseJsAccessEntrace.java │ │ │ ├── DefaultChromeClient.java │ │ │ ├── DefaultDesignUIController.java │ │ │ ├── DefaultDownloadImpl.java │ │ │ ├── DefaultUIController.java │ │ │ ├── DefaultWebClient.java │ │ │ ├── DefaultWebCreator.java │ │ │ ├── DefaultWebLifeCycleImpl.java │ │ │ ├── EventHandlerImpl.java │ │ │ ├── EventInterceptor.java │ │ │ ├── HookManager.java │ │ │ ├── HttpHeaders.java │ │ │ ├── IAgentWebSettings.java │ │ │ ├── IEventHandler.java │ │ │ ├── IUrlLoader.java │ │ │ ├── IVideo.java │ │ │ ├── IWebIndicator.java │ │ │ ├── IWebLayout.java │ │ │ ├── IndicatorController.java │ │ │ ├── IndicatorHandler.java │ │ │ ├── JsAccessEntrace.java │ │ │ ├── JsAccessEntraceImpl.java │ │ │ ├── JsBaseInterfaceHolder.java │ │ │ ├── JsCallJava.java │ │ │ ├── JsCallback.java │ │ │ ├── JsInterfaceHolder.java │ │ │ ├── JsInterfaceHolderImpl.java │ │ │ ├── JsInterfaceObjectException.java │ │ │ ├── LayoutParamsOffer.java │ │ │ ├── LogUtils.java │ │ │ ├── LollipopFixedWebView.java │ │ │ ├── MiddlewareWebChromeBase.java │ │ │ ├── MiddlewareWebClientBase.java │ │ │ ├── NestedScrollAgentWebView.java │ │ │ ├── PermissionInterceptor.java │ │ │ ├── ProcessUtils.java │ │ │ ├── Provider.java │ │ │ ├── QuickCallJs.java │ │ │ ├── UrlCommonException.java │ │ │ ├── UrlLoaderImpl.java │ │ │ ├── VideoImpl.java │ │ │ ├── WebChromeClient.java │ │ │ ├── WebChromeClientDelegate.java │ │ │ ├── WebCreator.java │ │ │ ├── WebIndicator.java │ │ │ ├── WebLifeCycle.java │ │ │ ├── WebListenerManager.java │ │ │ ├── WebParentLayout.java │ │ │ ├── WebSecurityCheckLogic.java │ │ │ ├── WebSecurityController.java │ │ │ ├── WebSecurityControllerImpl.java │ │ │ ├── WebSecurityLogicImpl.java │ │ │ ├── WebViewClient.java │ │ │ └── WebViewClientDelegate.java │ ├── jniLibs │ │ └── armeabi │ │ │ └── libtbs.so │ └── res │ │ ├── layout │ │ └── agentweb_error_page.xml │ │ ├── values-zh │ │ └── strings.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── ids.xml │ │ ├── strings.xml │ │ └── style.xml │ │ └── xml │ │ └── web_files_public.xml │ └── test │ └── java │ └── com │ └── just │ └── agentweb │ └── ExampleUnitTest.java ├── agentweb-filechooser ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── just │ │ └── agentweb │ │ └── filechooser │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── just │ │ │ └── agentweb │ │ │ └── filechooser │ │ │ ├── FileChooser.java │ │ │ └── FileParcel.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── just │ └── agentweb │ └── filechooser │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img ├── agentweb结构.png ├── alipay.jpg ├── alipay.png ├── custom setting.png ├── img-bounce.png ├── img-download.png ├── img-function-list.png ├── img-permission.png ├── img-scheme.png ├── img-sonic.png ├── jd.png ├── js.png ├── logo.png ├── upload.png ├── video.png ├── wechat pay.png └── wechat_pay.jpg ├── jsbridge_x5 ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── lzyzsd │ │ └── jsbridge_x5 │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── WebViewJavascriptBridge.js │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── lzyzsd │ │ │ └── jsbridge │ │ │ ├── BridgeHandler.java │ │ │ ├── BridgeUtil.java │ │ │ ├── BridgeWebView.java │ │ │ ├── BridgeWebViewClient.java │ │ │ ├── CallBackFunction.java │ │ │ ├── DefaultHandler.java │ │ │ ├── Message.java │ │ │ └── WebViewJavascriptBridge.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── github │ └── lzyzsd │ └── jsbridge_x5 │ └── ExampleUnitTest.java ├── releasenote.md ├── sample ├── .gitignore ├── build.gradle ├── keystore.jks ├── keystore │ └── keystore.jks ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── just │ │ └── agentweb │ │ └── sample │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ ├── js_interaction │ │ │ ├── button.css │ │ │ └── hello.html │ │ ├── jsbridge │ │ │ └── demo.html │ │ ├── sms │ │ │ └── sms.html │ │ ├── upload_file │ │ │ ├── event.js │ │ │ ├── id.png │ │ │ ├── jsuploadfile.html │ │ │ ├── upload.css │ │ │ └── uploadfile.html │ │ └── webpage │ │ │ ├── fileChooser.html │ │ │ ├── fullscreenVideo.html │ │ │ ├── hitTestResult.html │ │ │ ├── sdd.html │ │ │ └── websocket.html │ ├── java │ │ └── com │ │ │ └── just │ │ │ └── agentweb │ │ │ └── sample │ │ │ ├── activity │ │ │ ├── AutoHidenToolbarActivity.java │ │ │ ├── BaseWebActivity.java │ │ │ ├── CommonActivity.java │ │ │ ├── ContainerActivity.java │ │ │ ├── EasyWebActivity.java │ │ │ ├── ExternalActivity.java │ │ │ ├── FullScreenActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── NativeDownloadActivity.java │ │ │ ├── TestJsBridgeX5Activity.java │ │ │ ├── WebActivity.java │ │ │ └── utils │ │ │ │ ├── WebViewJavaScriptFunction.java │ │ │ │ └── X5WebView.java │ │ │ ├── app │ │ │ └── App.java │ │ │ ├── base │ │ │ ├── BaseAgentWebActivity.java │ │ │ ├── BaseAgentWebFragment.java │ │ │ └── FragmentKeyDown.java │ │ │ ├── behavior │ │ │ └── BottomNavigationViewBehavior.java │ │ │ ├── client │ │ │ ├── MiddlewareChromeClient.java │ │ │ ├── MiddlewareWebViewClient.java │ │ │ └── SonicWebViewClient.java │ │ │ ├── common │ │ │ ├── AndroidInterface.java │ │ │ ├── CommonWebChromeClient.java │ │ │ ├── CustomSettings.java │ │ │ ├── FragmentKeyDown.java │ │ │ ├── GuideItemEntity.java │ │ │ └── UIController.java │ │ │ ├── fragment │ │ │ ├── AgentWebFragment.java │ │ │ ├── BounceWebFragment.java │ │ │ ├── CustomIndicatorFragment.java │ │ │ ├── CustomSettingsFragment.java │ │ │ ├── CustomWebViewFragment.java │ │ │ ├── EasyWebFragment.java │ │ │ ├── JsAgentWebFragment.java │ │ │ ├── JsbridgeWebFragment.java │ │ │ ├── SmartRefreshWebFragment.java │ │ │ └── VasSonicFragment.java │ │ │ ├── sonic │ │ │ ├── DefaultSonicRuntimeImpl.java │ │ │ ├── SonicImpl.java │ │ │ ├── SonicJavaScriptInterface.java │ │ │ ├── SonicSessionClientImpl.java │ │ │ └── SonicWebViewClient.java │ │ │ └── widget │ │ │ ├── CommonIndicator.java │ │ │ ├── CoolIndicatorLayout.java │ │ │ ├── MarkdownView.java │ │ │ ├── SmartRefreshWebLayout.java │ │ │ └── WebLayout.java │ └── res │ │ ├── drawable-v21 │ │ ├── ripple_for_btn.xml │ │ └── selector_drawable_for_btn.xml │ │ ├── drawable │ │ ├── btn_shape.xml │ │ ├── btn_shape_s.xml │ │ ├── indicator_shape.xml │ │ ├── iv_back_selector.xml │ │ └── selector_drawable_for_btn.xml │ │ ├── layout │ │ ├── activity_auto_hiden_toolbar.xml │ │ ├── activity_common.xml │ │ ├── activity_main.xml │ │ ├── activity_native_download.xml │ │ ├── activity_test_jsbridge_x5.xml │ │ ├── activity_web.xml │ │ ├── filechooser_layout.xml │ │ ├── fragment_agentweb.xml │ │ ├── fragment_js.xml │ │ ├── fragment_srl_web.xml │ │ ├── fragment_twk_web.xml │ │ ├── listview_main.xml │ │ ├── markdown_view.xml │ │ ├── recyclerview_item_download.xml │ │ └── toorbar_main.xml │ │ ├── menu │ │ └── toolbar_menu.xml │ │ ├── mipmap-xhdpi │ │ └── app_logo.png │ │ ├── mipmap-xxhdpi │ │ └── app_logo.png │ │ ├── mipmap-xxxhdpi │ │ ├── app_logo.png │ │ ├── back.png │ │ ├── cha.png │ │ └── more.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── just │ └── agentweb │ └── sample │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # ---> Android 2 | # Built application files 3 | *.apk 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # IntelliJ 38 | *.iml 39 | .idea/workspace.xml 40 | .idea/tasks.xml 41 | .idea/gradle.xml 42 | .idea/assetWizardSettings.xml 43 | .idea/dictionaries 44 | .idea/libraries 45 | .idea/caches 46 | 47 | # Keystore files 48 | # Uncomment the following lines if you do not want to check your keystore files in. 49 | #*.jks 50 | #*.keystore 51 | 52 | # External native build folder generated in Android Studio 2.2 and later 53 | .externalNativeBuild 54 | 55 | # Google Services (e.g. APIs or Firebase) 56 | google-services.json 57 | 58 | # Freeline 59 | freeline.py 60 | freeline/ 61 | freeline_project_description.json 62 | 63 | # fastlane 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | fastlane/readme.md 69 | 70 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AgentWebX5-JsBridge 2 | AgentWeb替换X5内核+JsBridge替换X5内核 3 | 4 | AgentWeb用法与原来相同:https://github.com/Justson/AgentWeb 5 | 6 | JsBridge用法与原来相同:https://github.com/lzyzsd/JsBridge 7 | 8 | 9 | -------------------------------------------------------------------------------- /agentweb-core/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /agentweb-core/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 21 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | } 14 | 15 | repositories { 16 | flatDir { 17 | dirs 'libs' 18 | } 19 | } 20 | 21 | dependencies { 22 | compileOnly fileTree(include: ['*.jar', '*.aar'], dir: 'libs') 23 | compileOnly 'com.google.android.material:material:1.0.0' 24 | api 'com.download.library:Downloader:4.1.2' 25 | api 'com.tencent.tbs.tbssdk:sdk:43697' 26 | } 27 | -------------------------------------------------------------------------------- /agentweb-core/libs/alipaySdk-15.6.8-20191021122514.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/agentweb-core/libs/alipaySdk-15.6.8-20191021122514.aar -------------------------------------------------------------------------------- /agentweb-core/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/cenxiaozhong/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.create.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /agentweb-core/src/androidTest/java/com/just/agentweb/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.just.agentweb; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.InstrumentationRegistry; 6 | import androidx.test.runner.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | 13 | /** 14 | * Instrumentation test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() throws Exception { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getTargetContext(); 24 | 25 | assertEquals("com.just.library.test", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /agentweb-core/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 11 | 14 | 15 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/Action.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; 18 | 19 | import android.os.Parcel; 20 | import android.os.Parcelable; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Arrays; 24 | import java.util.List; 25 | 26 | 27 | /** 28 | * @author cenxiaozhong 29 | * @since 2.0.0 30 | */ 31 | public class Action implements Parcelable { 32 | 33 | public transient static final int ACTION_PERMISSION = 1; 34 | public transient static final int ACTION_FILE = 2; 35 | public transient static final int ACTION_CAMERA = 3; 36 | public transient static final int ACTION_VIDEO = 4; 37 | private ArrayList mPermissions = new ArrayList(); 38 | private int mAction; 39 | private int mFromIntention; 40 | 41 | public Action() { 42 | } 43 | 44 | public ArrayList getPermissions() { 45 | return mPermissions; 46 | } 47 | 48 | public void setPermissions(ArrayList permissions) { 49 | this.mPermissions = permissions; 50 | } 51 | 52 | public void setPermissions(String[] permissions) { 53 | this.mPermissions = new ArrayList<>(Arrays.asList(permissions)); 54 | } 55 | 56 | public int getAction() { 57 | return mAction; 58 | } 59 | 60 | public void setAction(int action) { 61 | this.mAction = action; 62 | } 63 | 64 | protected Action(Parcel in) { 65 | mPermissions = in.createStringArrayList(); 66 | mAction = in.readInt(); 67 | mFromIntention = in.readInt(); 68 | } 69 | 70 | @Override 71 | public void writeToParcel(Parcel dest, int flags) { 72 | dest.writeStringList(mPermissions); 73 | dest.writeInt(mAction); 74 | dest.writeInt(mFromIntention); 75 | } 76 | 77 | @Override 78 | public int describeContents() { 79 | return 0; 80 | } 81 | 82 | public static final Creator CREATOR = new Creator() { 83 | @Override 84 | public Action createFromParcel(Parcel in) { 85 | return new Action(in); 86 | } 87 | 88 | @Override 89 | public Action[] newArray(int size) { 90 | return new Action[size]; 91 | } 92 | }; 93 | 94 | public int getFromIntention() { 95 | return mFromIntention; 96 | } 97 | 98 | public static Action createPermissionsAction(String[] permissions) { 99 | Action mAction = new Action(); 100 | mAction.setAction(Action.ACTION_PERMISSION); 101 | List mList = Arrays.asList(permissions); 102 | mAction.setPermissions(new ArrayList(mList)); 103 | return mAction; 104 | } 105 | 106 | public Action setFromIntention(int fromIntention) { 107 | this.mFromIntention = fromIntention; 108 | return this; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/AgentWebFileProvider.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; 18 | 19 | import android.content.Context; 20 | import android.content.pm.ProviderInfo; 21 | 22 | import androidx.annotation.NonNull; 23 | import androidx.core.content.FileProvider; 24 | 25 | /** 26 | * @since 2.0.0 27 | * @author cenxiaozhong 28 | */ 29 | public class AgentWebFileProvider extends FileProvider { 30 | 31 | @Override 32 | public void attachInfo(@NonNull Context context, @NonNull ProviderInfo info) { 33 | super.attachInfo(context, info); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/AgentWebJsInterfaceCompat.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; 18 | 19 | import android.app.Activity; 20 | import android.os.Handler; 21 | import android.os.Message; 22 | import android.webkit.JavascriptInterface; 23 | 24 | import java.lang.ref.WeakReference; 25 | 26 | /** 27 | * @author cenxiaozhong 28 | * @since 1.0.0 29 | */ 30 | public class AgentWebJsInterfaceCompat { 31 | 32 | private WeakReference mReference = null; 33 | private WeakReference mActivityWeakReference = null; 34 | private String TAG = this.getClass().getSimpleName(); 35 | 36 | AgentWebJsInterfaceCompat(AgentWeb agentWeb, Activity activity) { 37 | mReference = new WeakReference(agentWeb); 38 | mActivityWeakReference = new WeakReference(activity); 39 | } 40 | 41 | @JavascriptInterface 42 | public void uploadFile() { 43 | uploadFile("*/*"); 44 | } 45 | 46 | @JavascriptInterface 47 | public void uploadFile(String acceptType) { 48 | LogUtils.i(TAG, acceptType + " " + mActivityWeakReference.get() + " " + mReference.get()); 49 | if (mActivityWeakReference.get() != null && mReference.get() != null) { 50 | AgentWebUtils.showFileChooserCompat(mActivityWeakReference.get(), 51 | mReference.get().getWebCreator().getWebView(), 52 | null, 53 | null, 54 | mReference.get().getPermissionInterceptor(), 55 | null, 56 | acceptType, 57 | new Handler.Callback() { 58 | @Override 59 | public boolean handleMessage(Message msg) { 60 | if (mReference.get() != null) { 61 | mReference.get().getJsAccessEntrace() 62 | .quickCallJs("uploadFileResult", 63 | msg.obj instanceof String ? (String) msg.obj : null); 64 | } 65 | return true; 66 | } 67 | } 68 | ); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/AgentWebPermissions.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; 18 | 19 | import android.Manifest; 20 | 21 | 22 | /** 23 | * @author cenxiaozhong 24 | * @since 1.0.0 25 | */ 26 | public class AgentWebPermissions { 27 | public static final String[] CAMERA; 28 | public static final String[] LOCATION; 29 | public static final String[] STORAGE; 30 | public static final String ACTION_CAMERA = "Camera"; 31 | public static final String ACTION_LOCATION = "Location"; 32 | public static final String ACTION_STORAGE = "Storage"; 33 | static { 34 | CAMERA = new String[]{ 35 | Manifest.permission.CAMERA}; 36 | LOCATION = new String[]{ 37 | Manifest.permission.ACCESS_FINE_LOCATION, 38 | Manifest.permission.ACCESS_COARSE_LOCATION}; 39 | STORAGE = new String[]{ 40 | Manifest.permission.READ_EXTERNAL_STORAGE, 41 | Manifest.permission.WRITE_EXTERNAL_STORAGE}; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/AgentWebSettingsImpl.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; 18 | 19 | import android.app.Activity; 20 | import android.content.Context; 21 | import android.content.ContextWrapper; 22 | import android.os.Build; 23 | import android.view.View; 24 | import android.view.ViewGroup; 25 | 26 | import com.tencent.smtt.sdk.DownloadListener; 27 | import com.tencent.smtt.sdk.WebView; 28 | 29 | 30 | /** 31 | * @author cenxiaozhong 32 | * @since 1.0.0 33 | */ 34 | public class AgentWebSettingsImpl extends AbsAgentWebSettings { 35 | private AgentWeb mAgentWeb; 36 | 37 | @Override 38 | protected void bindAgentWebSupport(AgentWeb agentWeb) { 39 | this.mAgentWeb = agentWeb; 40 | } 41 | 42 | @Override 43 | public WebListenerManager setDownloader(WebView webView, DownloadListener downloadListener) { 44 | // Fix Android 5.1 crashing: 45 | // ClassCastException: android.app.ContextImpl cannot be cast to android.app.Activity 46 | if (downloadListener == null) { 47 | Activity activity = getActivityByContext(webView.getContext()); 48 | if (null == activity) { 49 | if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) { 50 | activity = getActivityByContext(((ViewGroup) webView.getParent()).getContext()); 51 | } 52 | } 53 | downloadListener = DefaultDownloadImpl.create(activity, webView, mAgentWeb.getPermissionInterceptor()); 54 | } 55 | return super.setDownloader(webView, downloadListener); 56 | } 57 | 58 | /** 59 | * Copy from com.blankj.utilcode.util.ActivityUtils#getActivityByView 60 | */ 61 | private Activity getActivityByContext(Context context) { 62 | if (context instanceof Activity) return (Activity) context; 63 | while (context instanceof ContextWrapper) { 64 | if (context instanceof Activity) { 65 | return (Activity) context; 66 | } 67 | context = ((ContextWrapper) context).getBaseContext(); 68 | } 69 | return null; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/AgentWebUIControllerImplBase.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; 18 | 19 | import android.app.Activity; 20 | import android.os.Handler; 21 | 22 | import com.tencent.smtt.export.external.interfaces.JsPromptResult; 23 | import com.tencent.smtt.export.external.interfaces.JsResult; 24 | import com.tencent.smtt.sdk.WebView; 25 | 26 | 27 | /** 28 | * @author cenxiaozhong 29 | * @date 2017/12/6 30 | * @since 3.0.0 31 | */ 32 | public class AgentWebUIControllerImplBase extends AbsAgentWebUIController { 33 | 34 | public static AbsAgentWebUIController build() { 35 | return new AgentWebUIControllerImplBase(); 36 | } 37 | 38 | @Override 39 | public void onJsAlert(WebView view, String url, String message) { 40 | getDelegate().onJsAlert(view, url, message); 41 | } 42 | 43 | @Override 44 | public void onOpenPagePrompt(WebView view, String url, Handler.Callback callback) { 45 | getDelegate().onOpenPagePrompt(view, url, callback); 46 | } 47 | 48 | @Override 49 | public void onJsConfirm(WebView view, String url, String message, JsResult jsResult) { 50 | getDelegate().onJsConfirm(view, url, message, jsResult); 51 | } 52 | 53 | @Override 54 | public void onSelectItemsPrompt(WebView view, String url, String[] ways, Handler.Callback callback) { 55 | getDelegate().onSelectItemsPrompt(view, url, ways, callback); 56 | } 57 | 58 | @Override 59 | public void onForceDownloadAlert(String url, Handler.Callback callback) { 60 | getDelegate().onForceDownloadAlert(url, callback); 61 | } 62 | 63 | @Override 64 | public void onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult jsPromptResult) { 65 | getDelegate().onJsPrompt(view, url, message, defaultValue, jsPromptResult); 66 | } 67 | 68 | @Override 69 | public void onMainFrameError(WebView view, int errorCode, String description, String failingUrl) { 70 | getDelegate().onMainFrameError(view, errorCode, description, failingUrl); 71 | } 72 | 73 | @Override 74 | public void onShowMainFrame() { 75 | getDelegate().onShowMainFrame(); 76 | } 77 | 78 | @Override 79 | public void onLoading(String msg) { 80 | getDelegate().onLoading(msg); 81 | } 82 | 83 | @Override 84 | public void onCancelLoading() { 85 | getDelegate().onCancelLoading(); 86 | } 87 | 88 | 89 | @Override 90 | public void onShowMessage(String message, String from) { 91 | getDelegate().onShowMessage(message, from); 92 | } 93 | 94 | @Override 95 | public void onPermissionsDeny(String[] permissions, String permissionType, String action) { 96 | getDelegate().onPermissionsDeny(permissions, permissionType, action); 97 | } 98 | 99 | @Override 100 | protected void bindSupportWebParent(WebParentLayout webParentLayout, Activity activity) { 101 | getDelegate().bindSupportWebParent(webParentLayout, activity); 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/BaseIndicatorSpec.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; 18 | 19 | 20 | 21 | /** 22 | * @author cenxiaozhong 23 | * @since 1.0.0 24 | */ 25 | public interface BaseIndicatorSpec { 26 | 27 | void show(); 28 | 29 | void hide(); 30 | 31 | void reset(); 32 | 33 | void setProgress(int newProgress); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/BaseIndicatorView.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; 18 | 19 | import android.content.Context; 20 | import android.util.AttributeSet; 21 | import android.widget.FrameLayout; 22 | 23 | import androidx.annotation.Nullable; 24 | 25 | 26 | /** 27 | * @author cenxiaozhong 28 | * @date 2017/5/12 29 | * @since 1.0.0 30 | */ 31 | public abstract class BaseIndicatorView extends FrameLayout implements BaseIndicatorSpec,LayoutParamsOffer{ 32 | public BaseIndicatorView(Context context) { 33 | super(context); 34 | } 35 | 36 | public BaseIndicatorView(Context context, @Nullable AttributeSet attrs) { 37 | super(context, attrs); 38 | } 39 | 40 | public BaseIndicatorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 41 | super(context, attrs, defStyleAttr); 42 | } 43 | 44 | @Override 45 | public void reset() { 46 | } 47 | 48 | @Override 49 | public void setProgress(int newProgress) { 50 | } 51 | 52 | @Override 53 | public void show() { 54 | } 55 | 56 | @Override 57 | public void hide() { 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/BaseJsAccessEntrace.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; 18 | 19 | import android.os.Build; 20 | import com.tencent.smtt.sdk.ValueCallback; 21 | import com.tencent.smtt.sdk.WebView; 22 | 23 | /** 24 | * @author cenxiaozhong 25 | * @date 2017/5/26 26 | * @since 1.0.0 27 | */ 28 | public abstract class BaseJsAccessEntrace implements JsAccessEntrace { 29 | private WebView mWebView; 30 | public static final String TAG=BaseJsAccessEntrace.class.getSimpleName(); 31 | BaseJsAccessEntrace(WebView webView){ 32 | this.mWebView=webView; 33 | } 34 | @Override 35 | public void callJs(String js, final ValueCallback callback) { 36 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 37 | this.evaluateJs(js, callback); 38 | } else { 39 | this.loadJs(js); 40 | } 41 | } 42 | @Override 43 | public void callJs(String js) { 44 | this.callJs(js, null); 45 | } 46 | 47 | private void loadJs(String js) { 48 | mWebView.loadUrl(js); 49 | } 50 | private void evaluateJs(String js, final ValueCallbackcallback){ 51 | mWebView.evaluateJavascript(js, new ValueCallback() { 52 | @Override 53 | public void onReceiveValue(String value) { 54 | if (callback != null){ 55 | callback.onReceiveValue(value); 56 | } 57 | } 58 | }); 59 | } 60 | 61 | 62 | @Override 63 | public void quickCallJs(String method, ValueCallback callback, String... params) { 64 | StringBuilder sb=new StringBuilder(); 65 | sb.append("javascript:"+method); 66 | if(params==null||params.length==0){ 67 | sb.append("()"); 68 | }else{ 69 | sb.append("(").append(concat(params)).append(")"); 70 | } 71 | callJs(sb.toString(),callback); 72 | } 73 | 74 | private String concat(String...params){ 75 | StringBuilder mStringBuilder=new StringBuilder(); 76 | for(int i=0;i= 11){ 37 | this.mWebView.onResume(); 38 | } 39 | this.mWebView.resumeTimers(); 40 | } 41 | } 42 | 43 | @Override 44 | public void onPause() { 45 | if (this.mWebView != null) { 46 | if (Build.VERSION.SDK_INT >= 11){ 47 | this.mWebView.onPause(); 48 | } 49 | this.mWebView.pauseTimers(); 50 | } 51 | } 52 | 53 | @Override 54 | public void onDestroy() { 55 | if(this.mWebView!=null){ 56 | this.mWebView.resumeTimers(); 57 | } 58 | AgentWebUtils.clearWebView(this.mWebView); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/EventHandlerImpl.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; 18 | 19 | import android.view.KeyEvent; 20 | import com.tencent.smtt.sdk.WebView; 21 | 22 | /** 23 | * IEventHandler 对事件的处理,主要是针对 24 | * 视屏状态进行了处理 , 如果当前状态为 视频状态 25 | * 则先退出视频。 26 | * 27 | * @author cenxiaozhong 28 | * @date 2017/6/3 29 | * @since 2.0.0 30 | */ 31 | public class EventHandlerImpl implements IEventHandler { 32 | private WebView mWebView; 33 | private EventInterceptor mEventInterceptor; 34 | 35 | public static final EventHandlerImpl getInstantce(WebView view, EventInterceptor eventInterceptor) { 36 | return new EventHandlerImpl(view, eventInterceptor); 37 | } 38 | 39 | public EventHandlerImpl(WebView webView, EventInterceptor eventInterceptor) { 40 | this.mWebView = webView; 41 | this.mEventInterceptor = eventInterceptor; 42 | } 43 | 44 | @Override 45 | public boolean onKeyDown(int keyCode, KeyEvent event) { 46 | if (keyCode == KeyEvent.KEYCODE_BACK) { 47 | return back(); 48 | } 49 | return false; 50 | } 51 | 52 | @Override 53 | public boolean back() { 54 | if (this.mEventInterceptor != null && this.mEventInterceptor.event()) { 55 | return true; 56 | } 57 | if (mWebView != null && mWebView.canGoBack()) { 58 | mWebView.goBack(); 59 | return true; 60 | } 61 | return false; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/EventInterceptor.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; 18 | 19 | /** 20 | * @author cenxiaozhong 21 | * @date 2017/6/3 22 | * @since 1.0.0 23 | */ 24 | public interface EventInterceptor { 25 | boolean event(); 26 | } 27 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/HookManager.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; 18 | 19 | 20 | /** 21 | * @author cenxiaozhong 22 | * @since 1.0.0 23 | */ 24 | public class HookManager { 25 | 26 | public static AgentWeb hookAgentWeb(AgentWeb agentWeb, AgentWeb.AgentBuilder agentBuilder) { 27 | return agentWeb; 28 | } 29 | 30 | public static boolean permissionHook(String url,String[]permissions){ 31 | return true; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/IAgentWebSettings.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; 18 | 19 | 20 | import com.tencent.smtt.sdk.WebSettings; 21 | import com.tencent.smtt.sdk.WebView; 22 | 23 | /** 24 | * @author cenxiaozhong 25 | * @since 1.0.0 26 | */ 27 | 28 | public interface IAgentWebSettings { 29 | 30 | IAgentWebSettings toSetting(WebView webView); 31 | 32 | T getWebSettings(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/IEventHandler.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; 18 | 19 | import android.view.KeyEvent; 20 | 21 | /** 22 | * @author cenxiaozhong 23 | * @since 1.0.0 24 | */ 25 | public interface IEventHandler { 26 | 27 | boolean onKeyDown(int keyCode, KeyEvent event); 28 | 29 | boolean back(); 30 | } 31 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/IUrlLoader.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; 18 | 19 | import java.util.Map; 20 | 21 | /** 22 | * @author cenxiaozhong 23 | * @date 2017/6/3 24 | * @update 4.0.0 25 | * @since 2.0.0 26 | */ 27 | public interface IUrlLoader { 28 | 29 | 30 | void loadUrl(String url); 31 | 32 | void loadUrl(String url, Map headers); 33 | 34 | void reload(); 35 | 36 | void loadData(String data, String mimeType, String encoding); 37 | 38 | void stopLoading(); 39 | 40 | void loadDataWithBaseURL(String baseUrl, String data, 41 | String mimeType, String encoding, String historyUrl); 42 | 43 | void postUrl(String url, byte[] params); 44 | 45 | HttpHeaders getHttpHeaders(); 46 | } 47 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/IVideo.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; 18 | 19 | import android.view.View; 20 | 21 | import com.tencent.smtt.export.external.interfaces.IX5WebChromeClient; 22 | 23 | 24 | /** 25 | * @author cenxiaozhong 26 | * @date 2017/6/10 27 | * @since 2.0.0 28 | */ 29 | public interface IVideo { 30 | 31 | 32 | void onShowCustomView(View view, IX5WebChromeClient.CustomViewCallback callback); 33 | 34 | 35 | void onHideCustomView(); 36 | 37 | 38 | boolean isVideoState(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/IWebIndicator.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; 18 | 19 | /** 20 | * @author cenxiaozhong 21 | * @since 1.0.0 22 | */ 23 | 24 | 25 | public interface IWebIndicator { 26 | 27 | 28 | T offer(); 29 | } 30 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/IWebLayout.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; 18 | 19 | import android.view.ViewGroup; 20 | 21 | import androidx.annotation.NonNull; 22 | import androidx.annotation.Nullable; 23 | 24 | import com.tencent.smtt.sdk.WebView; 25 | 26 | /** 27 | * Created by cenxiaozhong on 2017/7/1. 28 | */ 29 | 30 | /** 31 | * @author cenxiaozhong 32 | * @date 2017/7/1 33 | * @update 4.0.0 34 | * @since 1.0.0 35 | */ 36 | public interface IWebLayout { 37 | 38 | /** 39 | * @return WebView 的父控件 40 | */ 41 | @NonNull 42 | V getLayout(); 43 | 44 | /** 45 | * @return 返回 WebView 或 WebView 的子View ,返回null AgentWeb 内部会创建适当 WebView 46 | */ 47 | @Nullable 48 | T getWebView(); 49 | } 50 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/IndicatorController.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; 18 | 19 | import com.tencent.smtt.sdk.WebView; 20 | /** 21 | * @author cenxiaozhong 22 | * @update 4.0.0 23 | * @since 1.0.0 24 | */ 25 | 26 | public interface IndicatorController { 27 | 28 | void progress(WebView v, int newProgress); 29 | 30 | BaseIndicatorSpec offerIndicator(); 31 | 32 | void showIndicator(); 33 | 34 | void setProgress(int newProgress); 35 | 36 | void finish(); 37 | } 38 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/IndicatorHandler.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; 18 | 19 | import com.tencent.smtt.sdk.WebView; 20 | 21 | 22 | /** 23 | * @author cenxiaozhong 24 | * @since 1.0.0 25 | */ 26 | public class IndicatorHandler implements IndicatorController { 27 | private BaseIndicatorSpec mBaseIndicatorSpec; 28 | 29 | @Override 30 | public void progress(WebView v, int newProgress) { 31 | 32 | if (newProgress == 0) { 33 | reset(); 34 | } else if (newProgress > 0 && newProgress <= 10) { 35 | showIndicator(); 36 | } else if (newProgress > 10 && newProgress < 95) { 37 | setProgress(newProgress); 38 | } else { 39 | setProgress(newProgress); 40 | finish(); 41 | } 42 | 43 | } 44 | 45 | @Override 46 | public BaseIndicatorSpec offerIndicator() { 47 | return this.mBaseIndicatorSpec; 48 | } 49 | 50 | public void reset() { 51 | 52 | if (mBaseIndicatorSpec != null) { 53 | mBaseIndicatorSpec.reset(); 54 | } 55 | } 56 | 57 | @Override 58 | public void finish() { 59 | if (mBaseIndicatorSpec != null) { 60 | mBaseIndicatorSpec.hide(); 61 | } 62 | } 63 | 64 | @Override 65 | public void setProgress(int n) { 66 | if (mBaseIndicatorSpec != null) { 67 | mBaseIndicatorSpec.setProgress(n); 68 | } 69 | } 70 | 71 | @Override 72 | public void showIndicator() { 73 | 74 | if (mBaseIndicatorSpec != null) { 75 | mBaseIndicatorSpec.show(); 76 | } 77 | } 78 | 79 | static IndicatorHandler getInstance() { 80 | return new IndicatorHandler(); 81 | } 82 | 83 | 84 | IndicatorHandler inJectIndicator(BaseIndicatorSpec baseIndicatorSpec) { 85 | this.mBaseIndicatorSpec = baseIndicatorSpec; 86 | return this; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/JsAccessEntrace.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; 18 | 19 | import com.tencent.smtt.sdk.ValueCallback; 20 | 21 | /** 22 | * @author cenxiaozhong 23 | * @date 2017/5/14 24 | * @since 1.0.0 25 | */ 26 | public interface JsAccessEntrace extends QuickCallJs { 27 | 28 | 29 | void callJs(String js, ValueCallback callback); 30 | 31 | void callJs(String js); 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/JsAccessEntraceImpl.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; 18 | 19 | import android.os.Handler; 20 | import android.os.Looper; 21 | import com.tencent.smtt.sdk.ValueCallback; 22 | import com.tencent.smtt.sdk.WebView; 23 | 24 | 25 | /** 26 | * @author cenxiaozhong 27 | * @date 2017/6/3 28 | * @since 1.0.0 29 | */ 30 | public class JsAccessEntraceImpl extends BaseJsAccessEntrace { 31 | 32 | private WebView mWebView; 33 | private Handler mHandler = new Handler(Looper.getMainLooper()); 34 | 35 | public static JsAccessEntraceImpl getInstance(WebView webView) { 36 | return new JsAccessEntraceImpl(webView); 37 | } 38 | 39 | private JsAccessEntraceImpl(WebView webView) { 40 | super(webView); 41 | this.mWebView = webView; 42 | } 43 | 44 | private void safeCallJs(final String s, final ValueCallback valueCallback) { 45 | mHandler.post(new Runnable() { 46 | @Override 47 | public void run() { 48 | callJs(s, valueCallback); 49 | } 50 | }); 51 | } 52 | 53 | @Override 54 | public void callJs(String params, final ValueCallback callback) { 55 | if (Thread.currentThread() != Looper.getMainLooper().getThread()) { 56 | safeCallJs(params, callback); 57 | return; 58 | } 59 | super.callJs(params,callback); 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/JsBaseInterfaceHolder.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; 18 | 19 | import android.os.Build; 20 | import android.webkit.JavascriptInterface; 21 | 22 | import java.lang.annotation.Annotation; 23 | import java.lang.reflect.Method; 24 | 25 | /** 26 | * @author cenxiaozhong 27 | * @date 2017/5/13 28 | * @since 1.0.0 29 | */ 30 | public abstract class JsBaseInterfaceHolder implements JsInterfaceHolder { 31 | 32 | private AgentWeb.SecurityType mSecurityType; 33 | 34 | protected JsBaseInterfaceHolder(AgentWeb.SecurityType securityType) { 35 | this.mSecurityType = securityType; 36 | } 37 | 38 | @Override 39 | public boolean checkObject(Object v) { 40 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { 41 | return true; 42 | } 43 | if (AgentWebConfig.WEBVIEW_TYPE == AgentWebConfig.WEBVIEW_AGENTWEB_SAFE_TYPE) { 44 | return true; 45 | } 46 | boolean tag = false; 47 | Class clazz = v.getClass(); 48 | Method[] mMethods = clazz.getMethods(); 49 | for (Method mMethod : mMethods) { 50 | Annotation[] mAnnotations = mMethod.getAnnotations(); 51 | for (Annotation mAnnotation : mAnnotations) { 52 | if (mAnnotation instanceof JavascriptInterface) { 53 | tag = true; 54 | break; 55 | } 56 | } 57 | if (tag) { 58 | break; 59 | } 60 | } 61 | return tag; 62 | } 63 | 64 | protected boolean checkSecurity() { 65 | return mSecurityType != AgentWeb.SecurityType.STRICT_CHECK 66 | ? true : AgentWebConfig.WEBVIEW_TYPE == AgentWebConfig.WEBVIEW_AGENTWEB_SAFE_TYPE 67 | ? true : Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/JsInterfaceHolder.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; 18 | 19 | import java.util.Map; 20 | 21 | /** 22 | * @author cenxiaozhong 23 | * @date 2017/5/13 24 | * @since 1.0.0 25 | */ 26 | public interface JsInterfaceHolder { 27 | 28 | JsInterfaceHolder addJavaObjects(Map maps); 29 | 30 | JsInterfaceHolder addJavaObject(String k, Object v); 31 | 32 | boolean checkObject(Object v); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/JsInterfaceHolderImpl.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; 18 | 19 | import com.tencent.smtt.sdk.WebView; 20 | 21 | import java.util.Map; 22 | import java.util.Set; 23 | 24 | /** 25 | * @author cenxiaozhong 26 | * @date 2017/5/13 27 | * @since 1.0.0 28 | */ 29 | public class JsInterfaceHolderImpl extends JsBaseInterfaceHolder { 30 | 31 | private static final String TAG = JsInterfaceHolderImpl.class.getSimpleName(); 32 | private WebView mWebView; 33 | private AgentWeb.SecurityType mSecurityType; 34 | 35 | static JsInterfaceHolderImpl getJsInterfaceHolder(WebView webView, AgentWeb.SecurityType securityType) { 36 | return new JsInterfaceHolderImpl(webView, securityType); 37 | } 38 | 39 | JsInterfaceHolderImpl(WebView webView, AgentWeb.SecurityType securityType) { 40 | super(securityType); 41 | this.mWebView = webView; 42 | this.mSecurityType = securityType; 43 | } 44 | 45 | @Override 46 | public JsInterfaceHolder addJavaObjects(Map maps) { 47 | if (!checkSecurity()) { 48 | LogUtils.e(TAG, "The injected object is not safe, give up injection"); 49 | return this; 50 | } 51 | Set> sets = maps.entrySet(); 52 | for (Map.Entry mEntry : sets) { 53 | Object v = mEntry.getValue(); 54 | boolean t = checkObject(v); 55 | if (!t) { 56 | throw new JsInterfaceObjectException("This object has not offer method javascript to call ,please check addJavascriptInterface annotation was be added"); 57 | } else { 58 | addJavaObjectDirect(mEntry.getKey(), v); 59 | } 60 | } 61 | return this; 62 | } 63 | 64 | @Override 65 | public JsInterfaceHolder addJavaObject(String k, Object v) { 66 | if (!checkSecurity()) { 67 | return this; 68 | } 69 | boolean t = checkObject(v); 70 | if (!t) { 71 | throw new JsInterfaceObjectException("this object has not offer method javascript to call , please check addJavascriptInterface annotation was be added"); 72 | } else { 73 | addJavaObjectDirect(k, v); 74 | } 75 | return this; 76 | } 77 | 78 | private JsInterfaceHolder addJavaObjectDirect(String k, Object v) { 79 | LogUtils.i(TAG, "k:" + k + " v:" + v); 80 | this.mWebView.addJavascriptInterface(v, k); 81 | return this; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/JsInterfaceObjectException.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; 18 | 19 | 20 | /** 21 | * @author cenxiaozhong 22 | * @date 2017/5/13 23 | * @since 1.0.0 24 | */ 25 | public class JsInterfaceObjectException extends RuntimeException { 26 | JsInterfaceObjectException(String msg){ 27 | super(msg); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/LayoutParamsOffer.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; 18 | 19 | import android.widget.FrameLayout; 20 | 21 | /** 22 | * @author cenxiaozhong 23 | * @date 2017/5/12 24 | * @since 1.0.0 25 | */ 26 | public interface LayoutParamsOffer { 27 | 28 | T offerLayoutParams(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/LogUtils.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; 18 | 19 | import android.util.Log; 20 | 21 | /** 22 | * @author cenxiaozhong 23 | * @date 2017/5/28 24 | * @since 1.0.0 25 | */ 26 | public class LogUtils { 27 | 28 | private static final String PREFIX = " agentweb - "; 29 | 30 | public static boolean isDebug() { 31 | return AgentWebConfig.DEBUG; 32 | } 33 | 34 | public static void i(String tag, String message) { 35 | 36 | if (isDebug()){ 37 | Log.i(PREFIX.concat(tag), message); 38 | } 39 | } 40 | 41 | public static void v(String tag, String message) { 42 | 43 | if (isDebug()){ 44 | Log.v(PREFIX.concat(tag), message); 45 | } 46 | 47 | } 48 | 49 | public static void safeCheckCrash(String tag, String msg, Throwable tr) { 50 | if (isDebug()) { 51 | throw new RuntimeException(PREFIX.concat(tag) + " " + msg, tr); 52 | } else { 53 | Log.e(PREFIX.concat(tag), msg, tr); 54 | } 55 | } 56 | 57 | public static void e(String tag, String msg, Throwable tr) { 58 | Log.e(tag, msg, tr); 59 | } 60 | 61 | public static void e(String tag, String message) { 62 | 63 | if (isDebug()){ 64 | Log.e(PREFIX.concat(tag), message); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/LollipopFixedWebView.java: -------------------------------------------------------------------------------- 1 | package com.just.agentweb; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.tencent.smtt.sdk.WebView; 7 | 8 | /** 9 | * 修复 Android 5.0 & 5.1 打开 WebView 闪退问题: 10 | * 参阅 https://stackoverflow.com/questions/41025200/android-view-inflateexception-error-inflating-class-android-webkit-webview 11 | */ 12 | @SuppressWarnings("unused") 13 | public class LollipopFixedWebView extends WebView { 14 | public LollipopFixedWebView(Context context) { 15 | super(getFixedContext(context)); 16 | } 17 | 18 | public LollipopFixedWebView(Context context, AttributeSet attrs) { 19 | super(getFixedContext(context), attrs); 20 | } 21 | 22 | public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) { 23 | super(getFixedContext(context), attrs, defStyleAttr); 24 | } 25 | 26 | /** 27 | * X5 没有此构造函数 28 | */ 29 | // @TargetApi(Build.VERSION_CODES.LOLLIPOP) 30 | // public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 31 | // super(getFixedContext(context), attrs, defStyleAttr, true); 32 | // } 33 | public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) { 34 | super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing); 35 | } 36 | 37 | /** 38 | * 不能使用此方式处理Android L中 WebView Resources$NotFoundException 的问题, 39 | * 因为X5 内部会直接获取context转Activity, 此方式处理后context 变为 ContextImpl 了. 40 | * @param context 41 | * @return 42 | */ 43 | public static Context getFixedContext(Context context) { 44 | // if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) { 45 | // // Avoid crashing on Android 5 and 6 (API level 21 to 23) 46 | // return context.createConfigurationContext(new Configuration()); 47 | // } 48 | return context; 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/MiddlewareWebChromeBase.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; 18 | 19 | import com.tencent.smtt.sdk.WebChromeClient; 20 | 21 | /** 22 | * @author cenxiaozhong 23 | * @date 2017/12/16 24 | * @since 3.0.0 25 | */ 26 | public class MiddlewareWebChromeBase extends WebChromeClientDelegate { 27 | 28 | private MiddlewareWebChromeBase mMiddlewareWebChromeBase; 29 | 30 | protected MiddlewareWebChromeBase(WebChromeClient webChromeClient) { 31 | super(webChromeClient); 32 | } 33 | 34 | protected MiddlewareWebChromeBase() { 35 | super(null); 36 | } 37 | 38 | @Override 39 | final void setDelegate(WebChromeClient delegate) { 40 | super.setDelegate(delegate); 41 | } 42 | 43 | final MiddlewareWebChromeBase enq(MiddlewareWebChromeBase middlewareWebChromeBase) { 44 | setDelegate(middlewareWebChromeBase); 45 | this.mMiddlewareWebChromeBase = middlewareWebChromeBase; 46 | return this.mMiddlewareWebChromeBase; 47 | } 48 | 49 | 50 | final MiddlewareWebChromeBase next() { 51 | return this.mMiddlewareWebChromeBase; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/MiddlewareWebClientBase.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; 18 | 19 | import com.tencent.smtt.sdk.WebViewClient; 20 | 21 | /** 22 | * @author cenxiaozhong 23 | * @date 2017/12/15 24 | * @since 3.0.0 25 | */ 26 | public class MiddlewareWebClientBase extends WebViewClientDelegate { 27 | private MiddlewareWebClientBase mMiddleWrareWebClientBase; 28 | private static String TAG = MiddlewareWebClientBase.class.getSimpleName(); 29 | 30 | MiddlewareWebClientBase(MiddlewareWebClientBase client) { 31 | super(client); 32 | this.mMiddleWrareWebClientBase = client; 33 | } 34 | 35 | protected MiddlewareWebClientBase(WebViewClient client) { 36 | super(client); 37 | } 38 | 39 | protected MiddlewareWebClientBase() { 40 | super(null); 41 | } 42 | 43 | final MiddlewareWebClientBase next() { 44 | return this.mMiddleWrareWebClientBase; 45 | } 46 | 47 | @Override 48 | final void setDelegate(com.tencent.smtt.sdk.WebViewClient delegate) { 49 | super.setDelegate(delegate); 50 | 51 | } 52 | 53 | final MiddlewareWebClientBase enq(MiddlewareWebClientBase middleWrareWebClientBase) { 54 | setDelegate(middleWrareWebClientBase); 55 | this.mMiddleWrareWebClientBase = middleWrareWebClientBase; 56 | return middleWrareWebClientBase; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/PermissionInterceptor.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; 18 | 19 | /** 20 | * @author cenxiaozhong 21 | * @since 3.0.0 22 | */ 23 | public interface PermissionInterceptor { 24 | boolean intercept(String url, String[] permissions, String action); 25 | } 26 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/ProcessUtils.java: -------------------------------------------------------------------------------- 1 | package com.just.agentweb; 2 | 3 | import android.app.ActivityManager; 4 | import android.app.Application; 5 | import android.content.Context; 6 | import android.text.TextUtils; 7 | 8 | import java.io.BufferedReader; 9 | import java.io.File; 10 | import java.io.FileReader; 11 | import java.lang.reflect.Field; 12 | import java.lang.reflect.Method; 13 | import java.util.List; 14 | 15 | /** 16 | * Adapted from com.blankj.utilcode.util.ProcessUtils#getCurrentProcessName 17 | */ 18 | class ProcessUtils { 19 | 20 | static String getCurrentProcessName(Context context) { 21 | String name = getCurrentProcessNameByFile(); 22 | if (!TextUtils.isEmpty(name)) return name; 23 | name = getCurrentProcessNameByAms(context); 24 | if (!TextUtils.isEmpty(name)) return name; 25 | name = getCurrentProcessNameByReflect(context); 26 | return name; 27 | } 28 | 29 | private static String getCurrentProcessNameByFile() { 30 | try { 31 | File file = new File("/proc/" + android.os.Process.myPid() + "/" + "cmdline"); 32 | BufferedReader mBufferedReader = new BufferedReader(new FileReader(file)); 33 | String processName = mBufferedReader.readLine().trim(); 34 | mBufferedReader.close(); 35 | return processName; 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | return ""; 39 | } 40 | } 41 | 42 | private static String getCurrentProcessNameByAms(Context context) { 43 | ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 44 | if (am == null) return ""; 45 | List info = am.getRunningAppProcesses(); 46 | if (info == null || info.size() == 0) return ""; 47 | int pid = android.os.Process.myPid(); 48 | for (ActivityManager.RunningAppProcessInfo aInfo : info) { 49 | if (aInfo.pid == pid) { 50 | if (aInfo.processName != null) { 51 | return aInfo.processName; 52 | } 53 | } 54 | } 55 | return ""; 56 | } 57 | 58 | private static String getCurrentProcessNameByReflect(Context context) { 59 | String processName = ""; 60 | try { 61 | Application app = (Application) context.getApplicationContext(); 62 | Field loadedApkField = app.getClass().getField("mLoadedApk"); 63 | loadedApkField.setAccessible(true); 64 | Object loadedApk = loadedApkField.get(app); 65 | 66 | Field activityThreadField = loadedApk.getClass().getDeclaredField("mActivityThread"); 67 | activityThreadField.setAccessible(true); 68 | Object activityThread = activityThreadField.get(loadedApk); 69 | 70 | Method getProcessName = activityThread.getClass().getDeclaredMethod("getProcessName"); 71 | processName = (String) getProcessName.invoke(activityThread); 72 | } catch (Exception e) { 73 | e.printStackTrace(); 74 | } 75 | return processName; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/Provider.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; 18 | 19 | /** 20 | * @author cenxiaozhong 21 | * @date 2017/7/5 22 | * @since 1.0.0 23 | */ 24 | public interface Provider { 25 | T provide(); 26 | } 27 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/QuickCallJs.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; 18 | 19 | import android.os.Build; 20 | import com.tencent.smtt.sdk.ValueCallback; 21 | 22 | import androidx.annotation.RequiresApi; 23 | 24 | 25 | /** 26 | * @author cenxiaozhong 27 | * @date 2017/5/29 28 | * @since 1.0.0 29 | */ 30 | public interface QuickCallJs { 31 | @RequiresApi(Build.VERSION_CODES.KITKAT) 32 | void quickCallJs(String method, ValueCallback callback, String... params); 33 | 34 | void quickCallJs(String method, String... params); 35 | 36 | void quickCallJs(String method); 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/UrlCommonException.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; 18 | /** 19 | * @author cenxiaozhong 20 | * @since 1.0.0 21 | */ 22 | public class UrlCommonException extends RuntimeException { 23 | 24 | public UrlCommonException() { 25 | } 26 | 27 | public UrlCommonException(String msg) { 28 | super(msg); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/WebChromeClient.java: -------------------------------------------------------------------------------- 1 | package com.just.agentweb; 2 | 3 | /** 4 | * @author cenxiaozhong 5 | * @date 2019/4/13 6 | * @since 1.0.0 7 | */ 8 | public class WebChromeClient extends MiddlewareWebChromeBase{ 9 | public WebChromeClient() { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/WebCreator.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; 18 | 19 | import com.tencent.smtt.sdk.WebView; 20 | 21 | import android.widget.FrameLayout; 22 | 23 | /** 24 | * @author cenxiaozhong 25 | * @since 1.0.0 26 | */ 27 | public interface WebCreator extends IWebIndicator { 28 | WebCreator create(); 29 | 30 | WebView getWebView(); 31 | 32 | FrameLayout getWebParentLayout(); 33 | } 34 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/WebLifeCycle.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; 18 | 19 | /** 20 | * @author cenxiaozhong 21 | * @date 2017/5/30 22 | * @since 1.0.0 23 | */ 24 | public interface WebLifeCycle { 25 | void onResume(); 26 | void onPause(); 27 | void onDestroy(); 28 | } 29 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/WebListenerManager.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; 18 | 19 | 20 | import com.tencent.smtt.sdk.DownloadListener; 21 | import com.tencent.smtt.sdk.WebChromeClient; 22 | import com.tencent.smtt.sdk.WebView; 23 | import com.tencent.smtt.sdk.WebViewClient; 24 | 25 | /** 26 | * @author cenxiaozhong 27 | * @date 2017/5/13 28 | * @since 1.0.0 29 | */ 30 | public interface WebListenerManager { 31 | WebListenerManager setWebChromeClient(WebView webview, WebChromeClient webChromeClient); 32 | WebListenerManager setWebViewClient(WebView webView, WebViewClient webViewClient); 33 | WebListenerManager setDownloader(WebView webView, DownloadListener downloadListener); 34 | } 35 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/WebSecurityCheckLogic.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; 18 | 19 | import com.tencent.smtt.sdk.WebView; 20 | 21 | import androidx.collection.ArrayMap; 22 | 23 | 24 | /** 25 | * @author cenxiaozhong 26 | */ 27 | public interface WebSecurityCheckLogic { 28 | void dealHoneyComb(WebView view); 29 | void dealJsInterface(ArrayMap objects, AgentWeb.SecurityType securityType); 30 | } 31 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/WebSecurityController.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; 18 | 19 | /** 20 | * @author cenxiaozhong 21 | */ 22 | public interface WebSecurityController { 23 | void check(T t); 24 | } 25 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/WebSecurityControllerImpl.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; 18 | 19 | import android.os.Build; 20 | import com.tencent.smtt.sdk.WebView; 21 | 22 | import androidx.collection.ArrayMap; 23 | 24 | 25 | /** 26 | * @author cenxiaozhong 27 | */ 28 | public class WebSecurityControllerImpl implements WebSecurityController { 29 | 30 | private WebView mWebView; 31 | private ArrayMap mMap; 32 | private AgentWeb.SecurityType mSecurityType; 33 | 34 | public WebSecurityControllerImpl(WebView view, ArrayMap map, AgentWeb.SecurityType securityType) { 35 | this.mWebView = view; 36 | this.mMap = map; 37 | this.mSecurityType = securityType; 38 | } 39 | 40 | @Override 41 | public void check(WebSecurityCheckLogic webSecurityCheckLogic) { 42 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { 43 | webSecurityCheckLogic.dealHoneyComb(mWebView); 44 | } 45 | if (mMap != null && mSecurityType == AgentWeb.SecurityType.STRICT_CHECK && !mMap.isEmpty()) { 46 | webSecurityCheckLogic.dealJsInterface(mMap, mSecurityType); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/WebSecurityLogicImpl.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; 18 | 19 | import android.annotation.TargetApi; 20 | import android.os.Build; 21 | import com.tencent.smtt.sdk.WebView; 22 | 23 | import androidx.collection.ArrayMap; 24 | 25 | 26 | /** 27 | * @author cenxiaozhong 28 | */ 29 | public class WebSecurityLogicImpl implements WebSecurityCheckLogic { 30 | private String TAG=this.getClass().getSimpleName(); 31 | public static WebSecurityLogicImpl getInstance() { 32 | return new WebSecurityLogicImpl(); 33 | } 34 | 35 | public WebSecurityLogicImpl(){} 36 | 37 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 38 | @Override 39 | public void dealHoneyComb(WebView view) { 40 | if (Build.VERSION_CODES.HONEYCOMB > Build.VERSION.SDK_INT || Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1){ 41 | return; 42 | } 43 | view.removeJavascriptInterface("searchBoxJavaBridge_"); 44 | view.removeJavascriptInterface("accessibility"); 45 | view.removeJavascriptInterface("accessibilityTraversal"); 46 | } 47 | 48 | @Override 49 | public void dealJsInterface(ArrayMap objects, AgentWeb.SecurityType securityType) { 50 | if (securityType== AgentWeb.SecurityType.STRICT_CHECK 51 | &&AgentWebConfig.WEBVIEW_TYPE!=AgentWebConfig.WEBVIEW_AGENTWEB_SAFE_TYPE 52 | &&Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { 53 | LogUtils.e(TAG,"Give up all inject objects"); 54 | objects.clear(); 55 | objects = null; 56 | System.gc(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /agentweb-core/src/main/java/com/just/agentweb/WebViewClient.java: -------------------------------------------------------------------------------- 1 | package com.just.agentweb; 2 | 3 | /** 4 | * @author cenxiaozhong 5 | * @date 2019/4/13 6 | * @since 1.0.0 7 | */ 8 | public class WebViewClient extends MiddlewareWebClientBase { 9 | public WebViewClient() { 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /agentweb-core/src/main/jniLibs/armeabi/libtbs.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/agentweb-core/src/main/jniLibs/armeabi/libtbs.so -------------------------------------------------------------------------------- /agentweb-core/src/main/res/layout/agentweb_error_page.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /agentweb-core/src/main/res/values-zh/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 该任务已经存在 , 请勿重复点击下载! 3 | 提示 4 | 您正在使用手机流量 , 继续下载该文件吗? 5 | 下载 6 | 取消 7 | 下载失败! 8 | 当前进度:%s 9 | 已下载:%s 10 | 您有一条新通知 11 | 文件下载 12 | 点击打开 13 | 即将开始下载文件 14 | 相机 15 | 文件 16 | 加载中 ... 17 | 您需要离开%s前往其他应用吗? 18 | 离开 19 | 选择的文件不能大于%sMB 20 | 出错啦! 点击空白处刷新 ~ 21 | 22 | -------------------------------------------------------------------------------- /agentweb-core/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #000000 4 | #ffffff 5 | #2e2e32 6 | -------------------------------------------------------------------------------- /agentweb-core/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /agentweb-core/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | The task already exists, do not repeat click to download! 3 | Note 4 | Wi-Fi disconnected. Continue the download via mobile data network? 5 | Download 6 | Cancel 7 | Download failed! 8 | Downloading:%s 9 | downloaded:%s 10 | You have a new notice 11 | Download 12 | Tap to continue 13 | Coming soon to download the file 14 | Camera 15 | Files 16 | Loading ... 17 | leaving %s and opening another app? 18 | Go away 19 | The selected file can not be larger than %s MB 20 | error~ 21 | 22 | -------------------------------------------------------------------------------- /agentweb-core/src/main/res/values/style.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /agentweb-core/src/main/res/xml/web_files_public.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /agentweb-core/src/test/java/com/just/agentweb/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.just.agentweb; 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 | } -------------------------------------------------------------------------------- /agentweb-filechooser/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /agentweb-filechooser/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 21 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | } 14 | 15 | dependencies { 16 | implementation fileTree(include: ['*.jar'], dir: 'libs') 17 | compileOnly 'androidx.annotation:annotation:1.1.0' 18 | api project(':agentweb-core') 19 | } 20 | -------------------------------------------------------------------------------- /agentweb-filechooser/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /agentweb-filechooser/src/androidTest/java/com/just/agentweb/filechooser/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.just.agentweb.filechooser; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.InstrumentationRegistry; 6 | import androidx.test.runner.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() throws Exception { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getTargetContext(); 24 | 25 | assertEquals("com.just.agentweb.filechooser.test", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /agentweb-filechooser/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /agentweb-filechooser/src/main/java/com/just/agentweb/filechooser/FileParcel.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.filechooser; 18 | 19 | import android.os.Parcel; 20 | import android.os.Parcelable; 21 | 22 | /** 23 | * @author cenxiaozhong 24 | * @date 2017/5/24 25 | */ 26 | public class FileParcel implements Parcelable { 27 | 28 | private int mId; 29 | private String mContentPath; 30 | private String mFileBase64; 31 | 32 | protected FileParcel(Parcel in) { 33 | mId = in.readInt(); 34 | mContentPath = in.readString(); 35 | mFileBase64 = in.readString(); 36 | } 37 | 38 | public FileParcel(int id, String contentPath, String fileBase64) { 39 | this.mId = id; 40 | this.mContentPath = contentPath; 41 | this.mFileBase64 = fileBase64; 42 | 43 | } 44 | 45 | public static final Creator CREATOR = new Creator() { 46 | @Override 47 | public FileParcel createFromParcel(Parcel in) { 48 | return new FileParcel(in); 49 | } 50 | 51 | @Override 52 | public FileParcel[] newArray(int size) { 53 | return new FileParcel[size]; 54 | } 55 | }; 56 | 57 | public int getId() { 58 | return mId; 59 | } 60 | 61 | public void setId(int id) { 62 | this.mId = id; 63 | } 64 | 65 | public String getContentPath() { 66 | return mContentPath; 67 | } 68 | 69 | public void setContentPath(String contentPath) { 70 | this.mContentPath = contentPath; 71 | } 72 | 73 | public String getFileBase64() { 74 | return mFileBase64; 75 | } 76 | 77 | public void setFileBase64(String fileBase64) { 78 | this.mFileBase64 = fileBase64; 79 | } 80 | 81 | @Override 82 | public int describeContents() { 83 | return 0; 84 | } 85 | 86 | @Override 87 | public void writeToParcel(Parcel dest, int flags) { 88 | dest.writeInt(mId); 89 | dest.writeString(mContentPath); 90 | dest.writeString(mFileBase64); 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | return "FileParcel{" + 96 | "mId=" + mId + 97 | ", mContentPath='" + mContentPath + '\'' + 98 | ", mFileBase64='" + mFileBase64 + '\'' + 99 | '}'; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /agentweb-filechooser/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /agentweb-filechooser/src/test/java/com/just/agentweb/filechooser/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.just.agentweb.filechooser; 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 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public' } 6 | maven { url 'https://maven.aliyun.com/repository/google' } 7 | maven { url 'https://maven.aliyun.com/repository/jcenter' } 8 | maven { url 'https://jitpack.io' } 9 | jcenter() { url 'http://jcenter.bintray.com' } 10 | } 11 | dependencies { 12 | classpath 'com.android.tools.build:gradle:3.6.0' 13 | classpath 'com.novoda:bintray-release:0.9.1' 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public' } 20 | maven { url 'https://maven.aliyun.com/repository/google' } 21 | maven { url 'https://maven.aliyun.com/repository/jcenter' } 22 | maven { url 'https://jitpack.io' } 23 | jcenter() { url 'http://jcenter.bintray.com' } 24 | flatDir { 25 | dirs 'libs' 26 | } 27 | } 28 | 29 | } 30 | tasks.withType(Javadoc) { 31 | options.addStringOption('Xdoclint:none', '-quiet') 32 | options.addStringOption('encoding', 'UTF-8') 33 | } 34 | task clean(type: Delete) { 35 | delete rootProject.buildDir 36 | } 37 | //tasks.getByPath(":agentweb-core:mavenAndroidJavadocs").enabled = false 38 | //tasks.getByPath(":agentweb-download:mavenAndroidJavadocs").enabled = false 39 | //tasks.getByPath(":agentweb-filechooser:mavenAndroidJavadocs").enabled = false 40 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | COMPILE_SDK_VERSION=29 14 | BUILD_TOOL_VERSION=29.0.2 15 | SUPPORT_LIB_VERSION=28.0.0 16 | TARGET_SDK_VERSION=27 17 | # When configured, Gradle will run in incubating parallel mode. 18 | # This option should only be used with decoupled projects. More details, visit 19 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 20 | # org.gradle.parallel=true 21 | 22 | android.useAndroidX=true 23 | android.enableJetifier=true 24 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun May 12 10:39:24 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /img/agentweb结构.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/agentweb结构.png -------------------------------------------------------------------------------- /img/alipay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/alipay.jpg -------------------------------------------------------------------------------- /img/alipay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/alipay.png -------------------------------------------------------------------------------- /img/custom setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/custom setting.png -------------------------------------------------------------------------------- /img/img-bounce.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/img-bounce.png -------------------------------------------------------------------------------- /img/img-download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/img-download.png -------------------------------------------------------------------------------- /img/img-function-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/img-function-list.png -------------------------------------------------------------------------------- /img/img-permission.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/img-permission.png -------------------------------------------------------------------------------- /img/img-scheme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/img-scheme.png -------------------------------------------------------------------------------- /img/img-sonic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/img-sonic.png -------------------------------------------------------------------------------- /img/jd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/jd.png -------------------------------------------------------------------------------- /img/js.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/js.png -------------------------------------------------------------------------------- /img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/logo.png -------------------------------------------------------------------------------- /img/upload.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/upload.png -------------------------------------------------------------------------------- /img/video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/video.png -------------------------------------------------------------------------------- /img/wechat pay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/wechat pay.png -------------------------------------------------------------------------------- /img/wechat_pay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/img/wechat_pay.jpg -------------------------------------------------------------------------------- /jsbridge_x5/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /jsbridge_x5/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 21 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | } 14 | 15 | dependencies { 16 | implementation fileTree(dir: 'libs', include: ['*.jar']) 17 | api project(':agentweb-filechooser') 18 | } 19 | -------------------------------------------------------------------------------- /jsbridge_x5/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/jsbridge_x5/consumer-rules.pro -------------------------------------------------------------------------------- /jsbridge_x5/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /jsbridge_x5/src/androidTest/java/com/github/lzyzsd/jsbridge_x5/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.jsbridge_x5; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | 25 | assertEquals("com.github.lzyzsd.jsbridge_x5.test", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jsbridge_x5/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /jsbridge_x5/src/main/java/com/github/lzyzsd/jsbridge/BridgeHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.jsbridge; 2 | 3 | public interface BridgeHandler { 4 | 5 | void handler(String data, CallBackFunction function); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /jsbridge_x5/src/main/java/com/github/lzyzsd/jsbridge/BridgeWebViewClient.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.jsbridge; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | import com.tencent.smtt.sdk.WebView; 6 | import com.tencent.smtt.sdk.WebViewClient; 7 | 8 | import java.io.UnsupportedEncodingException; 9 | import java.net.URLDecoder; 10 | 11 | /** 12 | * Description: 13 | * Author: Lijunhua 14 | * Date: 14:25 2020/1/7 15 | */ 16 | public class BridgeWebViewClient extends WebViewClient { 17 | private BridgeWebView webView; 18 | 19 | public BridgeWebViewClient(BridgeWebView webView) { 20 | this.webView = webView; 21 | } 22 | 23 | @Override 24 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 25 | try { 26 | url = URLDecoder.decode(url, "UTF-8"); 27 | } catch (UnsupportedEncodingException e) { 28 | e.printStackTrace(); 29 | } 30 | 31 | if (url.startsWith(BridgeUtil.YY_RETURN_DATA)) { // 如果是返回数据 32 | webView.handlerReturnData(url); 33 | return true; 34 | } else if (url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) { // 35 | webView.flushMessageQueue(); 36 | return true; 37 | } else { 38 | return super.shouldOverrideUrlLoading(view, url); 39 | } 40 | } 41 | 42 | @Override 43 | public void onPageStarted(WebView view, String url, Bitmap favicon) { 44 | super.onPageStarted(view, url, favicon); 45 | } 46 | 47 | @Override 48 | public void onPageFinished(WebView view, String url) { 49 | super.onPageFinished(view, url); 50 | 51 | if (BridgeWebView.toLoadJs != null) { 52 | BridgeUtil.webViewLoadLocalJs(view, BridgeWebView.toLoadJs); 53 | } 54 | 55 | // 56 | if (webView.getStartupMessage() != null) { 57 | for (Message m : webView.getStartupMessage()) { 58 | webView.dispatchMessage(m); 59 | } 60 | webView.setStartupMessage(null); 61 | } 62 | } 63 | 64 | @Override 65 | public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 66 | super.onReceivedError(view, errorCode, description, failingUrl); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /jsbridge_x5/src/main/java/com/github/lzyzsd/jsbridge/CallBackFunction.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.jsbridge; 2 | 3 | public interface CallBackFunction { 4 | 5 | public void onCallBack(String data); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /jsbridge_x5/src/main/java/com/github/lzyzsd/jsbridge/DefaultHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.jsbridge; 2 | 3 | public class DefaultHandler implements BridgeHandler { 4 | 5 | String TAG = "DefaultHandler"; 6 | 7 | @Override 8 | public void handler(String data, CallBackFunction function) { 9 | if(function != null){ 10 | function.onCallBack("DefaultHandler response data"); 11 | } 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /jsbridge_x5/src/main/java/com/github/lzyzsd/jsbridge/WebViewJavascriptBridge.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.jsbridge; 2 | 3 | 4 | public interface WebViewJavascriptBridge { 5 | 6 | public void send(String data); 7 | public void send(String data, CallBackFunction responseCallback); 8 | 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /jsbridge_x5/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | jsbridge_x5 3 | 4 | -------------------------------------------------------------------------------- /jsbridge_x5/src/test/java/com/github/lzyzsd/jsbridge_x5/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.github.lzyzsd.jsbridge_x5; 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() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /releasenote.md: -------------------------------------------------------------------------------- 1 | * v_4.1.1 更新 2 | * [#587](https://github.com/Justson/AgentWeb/pull/587) input 支持视屏拍摄 3 | * [#614](https://github.com/Justson/AgentWeb/pull/614)修复上传文件选择的兼容性bug 4 | * 重构了Download 5 | * 最小SDK提升到了 14 6 | 7 | * v_4.0.3 更新 8 | * 部分手机下载过程中~声音一直响 [#523](https://github.com/Justson/AgentWeb/issues/523) 9 | * 抽离[Downloader](https://github.com/Justson/Downloader) 10 | * 放弃反射回调WebViewClient#methods,使用洋葱模型的Middleware代替 11 | 12 | * v_4.0.2 更新 13 | * 修复断点续传时进度计算错误 14 | * 修复无法通过`Extra`关闭进度通知 15 | 16 | * v_4.0.0 更新 17 | * `AgentWeb` 拆分出 `AgentWeb-Download` 、 `AgentWeb-FileChooser` 、`AgentWeb-core` 三个库,用户可以按需选择 18 | * 重新设计了 `AgentWeb-Download` 19 | * 删除了 `DownloadListener` 、`DefaultMsgConfig` 以及相关API 20 | * 旧废弃的API,4.0.0 直接删除,不在提供兼容 21 | * 部分类和API重命名 22 | * `Fragment`和`Activity`构建一致。[#227](https://github.com/Justson/AgentWeb/issues/227) 23 | * 从AgentWeb-core删除 `BaseAgentWebFragment`和`BaseAgentWebActivity` ,于Sample形式提供参考 24 | * v_3.1.0 更新 25 | * `WebProgress` 进度条动画更细腻 26 | * 修复部分机型拍照文件大小为0情况 27 | * 更新了`FileUpLoadChooserImpl` 28 | * v_3.0.0 更新 29 | * 加入 `MiddlewareWebChromeBase` 中间件 ,支持多个 `WebChromeClient` 30 | * 加入 `MiddlewareWebClientBase`中间件 , 支持多个 `WebViewClient` 31 | * 加入了默认的错误页,并支持自定义错误页 32 | * 加入 `AgentWebUIController` ,统一控制UI 33 | * 支持拦截未知的页面 34 | * 支持调起其他应用 35 | * v_2.0.1 更新 36 | * 支持并行下载 , 修复 #114 #109 37 | * v_2.0.0 更新 38 | * 加入动态权限 39 | * 拍照 40 | * v_1.2.6 更新 41 | * 修复Android 4.4以下布局错乱 42 | * v_1.2.5 提示信息支持配置 43 | * 提示信息支持配置 44 | * v_1.2.4 更新 45 | * 支持传入 IWebLayout ,支持下拉回弹,下拉刷新效果 46 | * v_1.2.3 更新 47 | * 新增下载结果回调 48 | * v_1.2.2 更新 49 | * 修复已知 Bug 50 | * v_1.2.1 更新 51 | * 支持调起支付宝 , 微信支付 52 | * v_1.2.0 更新 53 | * 全面支持全屏视频 54 | * v_1.1.2 更新 55 | * 完善功能 56 | 57 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | map.txt -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion COMPILE_SDK_VERSION.toInteger() 5 | buildToolsVersion BUILD_TOOL_VERSION 6 | defaultConfig { 7 | applicationId "com.just.agentweb.sample2" 8 | minSdkVersion 21 9 | targetSdkVersion TARGET_SDK_VERSION.toInteger() 10 | versionCode 4 11 | versionName "4.1.2" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | multiDexEnabled true 14 | } 15 | signingConfigs { 16 | release { 17 | storeFile file("./keystore/keystore.jks") 18 | storePassword "admin123" 19 | keyAlias "agentweb" 20 | keyPassword "admin123" 21 | } 22 | } 23 | buildTypes { 24 | release { 25 | signingConfig signingConfigs.release 26 | minifyEnabled true 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | ndk { 29 | abiFilters "armeabi" 30 | } 31 | } 32 | debug { 33 | signingConfig signingConfigs.release 34 | minifyEnabled false 35 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 36 | ndk { 37 | abiFilters "armeabi" 38 | } 39 | } 40 | } 41 | sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } } 42 | lintOptions { 43 | abortOnError false 44 | } 45 | 46 | lintOptions { 47 | abortOnError false 48 | } 49 | 50 | sourceSets { 51 | main { 52 | jniLibs.srcDirs = ['libs'] 53 | } 54 | } 55 | } 56 | 57 | dependencies { 58 | implementation fileTree(include: ['*.jar'], dir: 'libs') 59 | implementation 'androidx.appcompat:appcompat:1.0.2'//只能使用1.0.2版本,否则Android L WebView会报Resources$NotFoundException异常 60 | implementation 'com.google.android.material:material:1.0.0' 61 | 62 | implementation project(':jsbridge_x5') 63 | 64 | 65 | debugImplementation('com.squareup.leakcanary:leakcanary-android:1.6.3') 66 | releaseImplementation('com.squareup.leakcanary:leakcanary-android-no-op:1.6.3') 67 | testImplementation('com.squareup.leakcanary:leakcanary-android-no-op:1.6.3') 68 | implementation('us.feras.mdv:markdownview:1.1.0') 69 | implementation('com.lcodecorex:tkrefreshlayout:1.0.7') 70 | implementation('com.google.code.gson:gson:2.8.6') 71 | implementation('com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-14') 72 | implementation('com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-14') 73 | implementation('com.tencent.sonic:sdk:2.0.0') 74 | implementation('com.coolindicator.sdk:coolindicator:1.0.0-beta') 75 | implementation('com.squareup.picasso:picasso:2.71828') 76 | implementation "androidx.multidex:multidex:2.0.1" 77 | } -------------------------------------------------------------------------------- /sample/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/sample/keystore.jks -------------------------------------------------------------------------------- /sample/keystore/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lijunhuayc/AgentWebX5-JsBridge/748e00d463514b7a2ffe97f9f27a85521b166508/sample/keystore/keystore.jks -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/just/agentweb/sample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.just.agentweb.sample; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.InstrumentationRegistry; 6 | import androidx.test.runner.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | 13 | /** 14 | * Instrumentation test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() throws Exception { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getTargetContext(); 24 | 25 | assertEquals("com.just.library.agentweb", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample/src/main/assets/js_interaction/button.css: -------------------------------------------------------------------------------- 1 | 2 | .button { 3 | color: #666; 4 | background-color: #EEE; 5 | border-color: #EEE; 6 | font-weight: 300; 7 | font-size: 16px; 8 | font-family: "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; 9 | text-decoration: none; 10 | text-align: center; 11 | line-height: 40px; 12 | height: 40px; 13 | padding: 0 40px; 14 | margin: 0; 15 | display: inline-block; 16 | appearance: none; 17 | cursor: pointer; 18 | border: none; 19 | -webkit-box-sizing: border-box; 20 | -moz-box-sizing: border-box; 21 | box-sizing: border-box; 22 | -webkit-transition-property: all; 23 | transition-property: all; 24 | -webkit-transition-duration: .3s; 25 | transition-duration: .3s; 26 | /* 27 | * Disabled State 28 | * 29 | * The disabled state uses the class .disabled, is-disabled, 30 | * and the form attribute disabled="disabled". 31 | * The use of !important is only added because this is a state 32 | * that must be applied to all buttons when in a disabled state. 33 | */ } 34 | 35 | .button-glow { 36 | -webkit-animation-duration: 3s; 37 | animation-duration: 3s; 38 | -webkit-animation-iteration-count: infinite; 39 | animation-iteration-count: infinite; 40 | -webkit-animation-name: glowing; 41 | animation-name: glowing; } 42 | 43 | .button-rounded { 44 | border-radius: 4px; } 45 | 46 | /* 47 | * Base Colors 48 | * 49 | * Create colors for buttons 50 | * (.button-primary, .button-secondary, etc.) 51 | */ 52 | .button-primary, 53 | .button-primary-flat { 54 | background-color: #1B9AF7; 55 | border-color: #1B9AF7; 56 | color: #FFF; } 57 | 58 | /* 59 | * Border Buttons 60 | * 61 | * These buttons have no fill they only have a 62 | * border to define their hit target. 63 | */ 64 | .button-border, .button-border-thin, .button-border-thick { 65 | background: none; 66 | border-width: 2px; 67 | border-style: solid; 68 | line-height: 36px; } 69 | 70 | -------------------------------------------------------------------------------- /sample/src/main/assets/js_interaction/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 17 | 18 | 70 | 71 | 72 | 73 |
75 | 76 | 77 |
78 | 79 | -------------------------------------------------------------------------------- /sample/src/main/assets/sms/sms.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 电话短信邮件 9 | 10 | 32 | 33 | 34 |
35 | 电话短信邮件跳转 36 |
37 |
38 | 39 |
40 |
41 | 42 | 43 | 44 | 45 | 46 | 54 |

电话 55 | 短信 56 | 邮件 57 | 打开应用内部页面 58 | 打开微信 59 |

60 |
61 |
62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /sample/src/main/assets/upload_file/event.js: -------------------------------------------------------------------------------- 1 | // ---------- 事件绑定与删除绑定 ---------- // 2 | function bindEvent(element, eventName, func) { 3 | var events = element['the'+eventName]; //用于保存某个事件序列 4 | if(!events) { //如果不存在一个序列,则创建它,并加入HTML标记当中的onEvent = function(){}形式的绑定 5 | events = element['the'+eventName] = []; 6 | if (element['on'+eventName]) { events.push(element['on'+eventName]); } 7 | } 8 | 9 | //检测是否为重复绑定 10 | for(var i=0; i= events.length) { events.push(func); } 16 | 17 | // 重新定义这个事件的执行方式 18 | element['on'+eventName] = function(event) { 19 | event = event || (function() { //修复IE的事件对象 20 | var e = window.event; 21 | e.preventDefault = function() { e.returnValue = false; } 22 | e.stopPropagation = function() { e.cancelBubble = true; } 23 | //根据需要继续修复 24 | return e; 25 | })(); 26 | //顺序执行这些函数 27 | for(var i=0; i 2 | 3 | 4 | 5 | 6 | file chooser 7 | 15 | 21 | 22 | 23 |
    24 |
  • 25 |
    26 |
    27 |

    28 |
    29 | 30 |
    31 |
  • 32 | 33 |
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 | <h2>请长按一下html元素</h2> 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 |