├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── snc │ │ └── sample │ │ └── webview │ │ └── ExampleInstrumentedTest.java │ ├── debug │ └── res │ │ └── values │ │ └── strings.xml │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── www │ │ │ ├── common │ │ │ ├── css │ │ │ │ ├── anim.css │ │ │ │ ├── components.css │ │ │ │ ├── extends.css │ │ │ │ └── reset.css │ │ │ ├── img │ │ │ │ └── 202205091737430060.jpg │ │ │ └── js │ │ │ │ ├── nativeBridge.js │ │ │ │ └── progress.js │ │ │ ├── dist │ │ │ └── vendor │ │ │ │ ├── css │ │ │ │ ├── normalize.css │ │ │ │ └── reset.css │ │ │ │ └── js │ │ │ │ └── JavaScript-Load-Image │ │ │ │ ├── load-image-helper.js │ │ │ │ └── load-image.js │ │ │ └── docs │ │ │ ├── image-provider │ │ │ ├── image-provider.css │ │ │ ├── image-provider.html │ │ │ └── image-provider.js │ │ │ ├── qrcode-reader │ │ │ ├── dist │ │ │ │ ├── audio │ │ │ │ │ └── beep.mp3 │ │ │ │ ├── css │ │ │ │ │ └── qrcode-reader.css │ │ │ │ └── js │ │ │ │ │ ├── jsQR │ │ │ │ │ ├── LICENSE │ │ │ │ │ ├── README.md │ │ │ │ │ ├── jsQR.js │ │ │ │ │ └── jsQR.min.js │ │ │ │ │ └── qrcode-reader.js │ │ │ └── index.html │ │ │ └── sample │ │ │ ├── image.html │ │ │ ├── sample.css │ │ │ ├── sample.html │ │ │ └── sample.js │ ├── java │ │ └── com │ │ │ └── snc │ │ │ ├── sample │ │ │ └── webview │ │ │ │ ├── activity │ │ │ │ └── WebViewActivity.java │ │ │ │ ├── bridge │ │ │ │ ├── AndroidBridge.java │ │ │ │ ├── AndroidBridgePlugin.java │ │ │ │ └── plugin │ │ │ │ │ ├── PluginAPI.java │ │ │ │ │ ├── PluginCamera.java │ │ │ │ │ └── interfaces │ │ │ │ │ └── Plugin.java │ │ │ │ ├── network │ │ │ │ ├── DynamicUrlService.java │ │ │ │ └── RetrofitDynamicUrlClient.java │ │ │ │ └── webview │ │ │ │ └── WebViewHelper.java │ │ │ └── zero │ │ │ ├── activity │ │ │ └── BaseActivity.java │ │ │ ├── application │ │ │ └── SNCApplication.java │ │ │ ├── dialog │ │ │ ├── DialogBuilder.java │ │ │ └── DialogHelper.java │ │ │ ├── download │ │ │ └── CSDownloadManager.java │ │ │ ├── imageprocess │ │ │ └── ImageProcess.java │ │ │ ├── json │ │ │ └── JSONHelper.java │ │ │ ├── keyevent │ │ │ └── BackKeyShutdown.java │ │ │ ├── media │ │ │ ├── ImageProvider.java │ │ │ └── MediaStoreProvider.java │ │ │ ├── mimetype │ │ │ └── MimeType.java │ │ │ ├── permission │ │ │ ├── RPermission.java │ │ │ └── RPermissionListener.java │ │ │ ├── reflect │ │ │ └── ReflectHelper.java │ │ │ ├── requetcode │ │ │ └── RequestCode.java │ │ │ ├── util │ │ │ ├── AssetUtil.java │ │ │ ├── BitmapUtil.java │ │ │ ├── DateTimeFormat.java │ │ │ ├── EnvUtil.java │ │ │ ├── FileUtil.java │ │ │ ├── IOUtil.java │ │ │ ├── IntentUtil.java │ │ │ ├── MediaUtil.java │ │ │ ├── PackageUtil.java │ │ │ ├── StringUtil.java │ │ │ └── UriUtil.java │ │ │ └── webview │ │ │ ├── CSDownloadListener.java │ │ │ ├── CSFileChooserListener.java │ │ │ ├── CSWebChromeClient.java │ │ │ ├── CSWebViewClient.java │ │ │ └── listener │ │ │ └── FileChooserListener.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ ├── icon_no_image.png │ │ └── progress_horizontal.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ ├── app_backup_rules.xml │ │ ├── app_extraction_rules.xml │ │ └── file_provider_paths.xml │ └── test │ └── java │ └── com │ └── snc │ └── sample │ └── webview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | /*.iml 3 | .gradle 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | /captures 10 | /.idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # What is sample-webview? 3 | This project is a sample for developing android applications using webview. 4 | 5 | 6 | # Release Note 7 | | Date | Comment | 8 | |------------|-------------------| 9 | | 2021-01-07 | Refactoring. | 10 | | 2020-12-19 | Migrating apps to Android 11 (API 30). | 11 | | 2020-12-17 | MediaStore and DownloadManager have been added for Android 10 (API 29). | 12 | | 2020-11-16 | The version of targetSdkVersion has been changed. [targetSdkVersion 28(9.0) -> 29(10.0)] | 13 | | 2020-07-15 | Added file download function in webview. (setDownloadListener()) | 14 | | 2019-08-02 | Added support for the "audio / video recording" feature. | 15 | | 2019-06-14 | Added support for the "multiple windows" features. | 16 | | 2019-06-12 | Added Full-screen video playback on the web. | 17 | | 2019-04-12 | The first commit. | 18 | 19 | 20 | # Support Features 21 | 1. File Chooser 22 | ```code 23 | 24 | 25 | 26 | 27 | ``` 28 | 29 | 2. Camera 30 | ```code 31 | 48 | ``` 49 | 50 | 3. Geolocation 51 | ```code 52 | 57 | ``` 58 | 59 | 4. Full-screen video playback 60 | ```code 61 | 62 | 63 | 64 | Your browser does not support the video tag. 65 | 66 | ``` 67 | 68 | 5. Native Interface 69 | ```code 70 | 114 | ``` 115 | 116 | 117 | # License 118 | ```code 119 | Copyright (C) 2018 Aaron Jo (mcharima5@gmail.com) 120 | 121 | Licensed under the Apache License, Version 2.0 (the "License"); 122 | you may not use this file except in compliance with the License. 123 | You may obtain a copy of the License at 124 | 125 | http://www.apache.org/licenses/LICENSE-2.0 126 | 127 | Unless required by applicable law or agreed to in writing, software 128 | distributed under the License is distributed on an "AS IS" BASIS, 129 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130 | See the License for the specific language governing permissions and 131 | limitations under the License. 132 | ``` 133 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.iml 3 | /*.iml 4 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 33 5 | defaultConfig { 6 | applicationId "com.snc.sample.webview" 7 | minSdkVersion 16 8 | targetSdkVersion 33 9 | versionCode 1 10 | versionName "1.0" 11 | multiDexEnabled true 12 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 13 | 14 | //++ for Android 10 (API 29) 15 | buildConfigField "boolean", "FEATURE_EXTERNAL_STORAGE_DIR", "false" 16 | //-- 17 | 18 | //++ for Android 11 (API 30) 19 | buildConfigField "boolean", "FEATURE_WEBVIEW_ASSET_LOADER", "true" 20 | 21 | buildConfigField "String", "ASSET_BASE_DOMAIN", "\"assets.snc.com\"" 22 | buildConfigField "String", "ASSET_PATH", "\"/assets/\"" 23 | buildConfigField "String", "RES_PATH", "\"/res/\"" 24 | buildConfigField "String", "INTERNAL_PATH", "\"/public/\"" 25 | //-- 26 | 27 | buildConfigField "boolean", "FEATURE_WEBVIEW_BRIDGE_PLUGIN", "true" 28 | } 29 | signingConfigs { 30 | storeFile { 31 | //storeFile file('./keystore/upload_keystore.jks') 32 | //storePassword '' 33 | //keyAlias '' 34 | //keyPassword '' 35 | 36 | v1SigningEnabled true 37 | v2SigningEnabled true 38 | } 39 | } 40 | buildTypes { 41 | release { 42 | //signingConfig signingConfigs.storeFile 43 | minifyEnabled true 44 | shrinkResources true 45 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 46 | } 47 | debug { 48 | //signingConfig signingConfigs.storeFile 49 | } 50 | } 51 | flavorDimensions "version" 52 | productFlavors { 53 | free { 54 | dimension "version" 55 | manifestPlaceholders = [ applicationLabel: "@string/app_name" ] 56 | } 57 | } 58 | sourceSets { 59 | main { 60 | res.srcDirs = ['src/main/res'] 61 | assets.srcDirs = ['src/main/assets'] 62 | } 63 | } 64 | compileOptions { 65 | sourceCompatibility JavaVersion.VERSION_11 66 | targetCompatibility JavaVersion.VERSION_11 67 | } 68 | packagingOptions { 69 | jniLibs { 70 | keepDebugSymbols += ['*/armeabi/*.so', '*/armeabi-v7a/*.so', '*/arm64-v8a/*.so', '*/mips/*.so', '*/mips64/*.so', '*/x86/*.so', '*/x86_64/*.so'] 71 | } 72 | resources { 73 | excludes += ['META-INF/DEPENDENCIES.txt', 'META-INF/DEPENDENCIES', 'META-INF/LICENSE', 'META-INF/LICENSE.txt', 'META-INF/MANIFEST.MF', 'META-INF/NOTICE', 'META-INF/NOTICE.txt', 'META-INF/ASL2.0'] 74 | } 75 | } 76 | lint { 77 | abortOnError false 78 | checkReleaseBuilds false 79 | } 80 | namespace 'com.snc.sample.webview' 81 | } 82 | 83 | dependencies { 84 | implementation fileTree(dir: 'libs', include: ['*.jar']) 85 | 86 | implementation "androidx.multidex:multidex:2.0.1" 87 | 88 | implementation 'androidx.appcompat:appcompat:1.6.1' 89 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 90 | testImplementation 'junit:junit:4.13.2' 91 | //noinspection GradleCompatible 92 | androidTestImplementation 'androidx.test.ext:junit:1.1.5' 93 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 94 | 95 | implementation 'com.jakewharton.timber:timber:4.7.1' 96 | 97 | // runtime permission library 98 | implementation 'io.github.ParkSangGwon:tedpermission:3.3.0' 99 | implementation 'io.github.ParkSangGwon:tedpermission-normal:3.3.0' 100 | 101 | // retrofit 102 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' 103 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0' 104 | implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.7' 105 | implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.7' 106 | 107 | // androidx.webkit.WebViewAssetLoader 108 | implementation "androidx.webkit:webkit:1.7.0" 109 | } 110 | 111 | android.applicationVariants.all { variant -> 112 | variant.outputs.all { output -> 113 | def flavor = variant.productFlavors[0] 114 | def newApkName = variant.applicationId 115 | newApkName += "_" + flavor.name 116 | newApkName += "_" + variant.buildType.name 117 | newApkName += "_v" + variant.versionName 118 | newApkName += "_r" + variant.versionCode 119 | newApkName += "_" + "${getDate()}" + ".apk" 120 | 121 | outputFileName = new File(newApkName) 122 | 123 | println '' 124 | println '' 125 | println 'Rename outputFile : ' + newApkName 126 | println '' 127 | println '' 128 | } 129 | } 130 | 131 | static def getDate() { 132 | return new Date().format('yyyyMMdd_HHmm') 133 | } 134 | 135 | android.applicationVariants.all { variant -> 136 | variant.assembleProvider.configure { 137 | doLast { 138 | println "\n\n" 139 | println "###########################################" 140 | println "# #" 141 | println "# ###### ## # ###### #" 142 | println "# # # # # # #" 143 | println "# ####### # # # # #" 144 | println "# # # # # # #" 145 | println "# ###### # ## ###### #" 146 | println "# #" 147 | println "# Copyright (c) 2016 Aaron Jo. #" 148 | println "# #" 149 | println "# mcharima5@gmail.com #" 150 | println "# #" 151 | println "###########################################" 152 | println "\n\n" 153 | 154 | variant.outputs.all { output -> 155 | println "============================================================" 156 | println "project id: $variant.applicationId" 157 | println "project version : $variant.versionName" 158 | println "project revision : $variant.versionCode" 159 | println "build name: ${variant.name}" 160 | println "build type: ${variant.buildType.name}" 161 | println "output dir : " + variant.packageApplicationProvider.get().outputDirectory 162 | println "output file : $output.outputFileName" 163 | println "============================================================" 164 | println "\n" 165 | } 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /app/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 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/snc/sample/webview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.test.ext.junit.runners.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | //noinspection deprecation 23 | Context appContext = InstrumentationRegistry.getTargetContext(); 24 | 25 | assertEquals("com.snc.sample.webview", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/debug/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SAMPLE WEBVIEW (DEBUG) 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 46 | 47 | 48 | 49 | 50 | 64 | 65 | 66 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 89 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /app/src/main/assets/www/common/css/anim.css: -------------------------------------------------------------------------------- 1 | /**! 2 | * Cascading Style Sheet 3 | */ 4 | @charset "utf-8"; 5 | 6 | .anim-progress-layer { 7 | position: fixed; 8 | left: 50%; top: 50%; 9 | z-index: 99999; 10 | /* width: 60px; height: 60px; margin: -55px 0 0 -40px; */ 11 | width: 70px; height: 70px; margin: -55px 0 0 -40px; 12 | /* width: 100px; height: 100px; margin: -65px 0 0 -56px; */ 13 | border: 7px solid #f3f3f3; 14 | border-top: 7px solid #3498db; 15 | border-radius: 50%; 16 | -webkit-animation: spin 1.5s linear infinite; 17 | animation: spin 1.5s linear infinite; 18 | } 19 | @-webkit-keyframes spin { 20 | 0% { -webkit-transform: rotate(0deg); } 21 | 100% { -webkit-transform: rotate(360deg); } 22 | } 23 | @keyframes spin { 24 | 0% { -webkit-transform: rotate(0deg); } 25 | 100% { -webkit-transform: rotate(360deg); } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/assets/www/common/css/components.css: -------------------------------------------------------------------------------- 1 | /**! 2 | * Cascading Style Sheet 3 | */ 4 | @charset "utf-8"; 5 | 6 | .btn { 7 | display:inline-block; 8 | -webkit-user-select:none; 9 | -moz-user-select:none; 10 | -ms-user-select:none; 11 | user-select:none; 12 | box-sizing:border-box; 13 | cursor:pointer; 14 | padding:5px 7px; 15 | border-width:.5px; 16 | border-radius:2px; 17 | font-size:14px; 18 | font-weight:700; 19 | line-height:1.4; 20 | text-decoration:none; 21 | border-color:rgba(0,0,0,.2); 22 | background-color:hsla(0,0%,100%,.9); 23 | color:#001935 !important; 24 | } 25 | .btn:focus { background-color:hsla(0,0%,100%,.8); } 26 | .btn:active { background-color:hsla(0,0%,100%,.8); } 27 | 28 | .btn-primary { border:.5px solid rgba(0,0,0,.2); background-color:#00b8ff; color:#fff } 29 | .btn-primary:focus { border-color:rgba(0,0,0,.2); background-color:#00b1f5; color:hsla(0,0%,100%,.9) } 30 | .btn-primary:active { border-color:rgba(0,0,0,.2); background-color:#00a9eb; color:hsla(0,0%,100%,.8) } -------------------------------------------------------------------------------- /app/src/main/assets/www/common/css/extends.css: -------------------------------------------------------------------------------- 1 | /**! 2 | * Cascading Style Sheet 3 | */ 4 | @charset "utf-8"; 5 | 6 | .hidden { display:none !important; } 7 | 8 | .center { text-align:center; } 9 | 10 | .mT5 { margin-top: 5px; } 11 | .mT10 { margin-top: 10px; } 12 | .mT20 { margin-top: 20px; } 13 | .mT30 { margin-top: 30px; } 14 | .mT40 { margin-top: 40px; } 15 | .mT50 { margin-top: 50px; } 16 | 17 | .word-break { word-break:break-all; white-space:normal; } 18 | -------------------------------------------------------------------------------- /app/src/main/assets/www/common/css/reset.css: -------------------------------------------------------------------------------- 1 | /**! 2 | * Cascading Style Sheet 3 | */ 4 | @charset "utf-8"; 5 | 6 | /*@import "../../vendor/css/reset.css";*/ 7 | @import "../../vendor/css/normalize.css"; 8 | 9 | a:link, 10 | a:visited, 11 | a:active, 12 | a:hover { text-decoration: none; color:#989da3; } 13 | 14 | input[type="button"], 15 | input[type="reset"], 16 | input[type="submit"], 17 | input[type="file"], 18 | button { 19 | outline: none !important; 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/assets/www/common/img/202205091737430060.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/assets/www/common/img/202205091737430060.jpg -------------------------------------------------------------------------------- /app/src/main/assets/www/common/js/nativeBridge.js: -------------------------------------------------------------------------------- 1 | /**! 2 | * native bridge Javascript 3 | */ 4 | 5 | !(function (window) { 6 | 7 | const _callbackMap = {}; 8 | 9 | function _createUUID () { 10 | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { 11 | var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8); 12 | return v.toString(16); 13 | }); 14 | } 15 | 16 | function _pushCallback (successCallback, errorCallback) { 17 | var _cbId = _createUUID(); 18 | _callbackMap[_cbId] = { 19 | "successCallback": successCallback, 20 | "errorCallback": errorCallback 21 | }; 22 | return _cbId; 23 | } 24 | 25 | function _popCallback (cbId) { 26 | var _callback = _callbackMap[cbId]; 27 | delete _callbackMap[cbId]; 28 | return _callback; 29 | } 30 | 31 | const NativeBridge = { 32 | 33 | // request (Web --> Native) 34 | callToNative: function (plugin, method, args, successCallback, errorCallback) { 35 | var cbId = _pushCallback(successCallback, errorCallback); 36 | 37 | let jsonObject = { 38 | "plugin": plugin, 39 | "method": method, 40 | "args": args, 41 | "cbId": cbId 42 | }; 43 | 44 | let query = btoa(encodeURIComponent(JSON.stringify(jsonObject))); 45 | 46 | if (window.AndroidBridge) { 47 | AndroidBridge.callNativeMethod("native://callToNative?" + query); 48 | } else if (/iPhone|iPod|iPad/i.test(navigator.userAgent)) { 49 | if (window.webkit && window.webkit.callbackHandler) { 50 | window.webkit.messageHandlers.callbackHandler.postMessage("callToNative?" + query); 51 | } else { 52 | window.location.href = "native://callToNative?" + query; 53 | } 54 | } else { 55 | console.warn("Native calls are not supported."); 56 | hideProgress(); 57 | } 58 | }, 59 | 60 | // request (Native --> Web) 61 | callFromNative: function (cbId, resultCode, jsonString) { 62 | var cb = _popCallback(cbId); 63 | if ("00000" == resultCode) { 64 | var fn = cb['successCallback']; 65 | if ("function" == typeof fn) { 66 | fn.apply(window, [ JSON.parse(jsonString) ]); 67 | } else if ("string" == typeof fn) { 68 | eval(fn + "(" + jsonString + ")"); 69 | } 70 | } else { 71 | var fn = cb['errorCallback']; 72 | if ("function" == typeof fn) { 73 | fn.apply(window, [ JSON.parse(jsonString) ]); 74 | } else if ("string" == typeof fn) { 75 | eval(fn + "(" + jsonString + ")"); 76 | } 77 | } 78 | } 79 | 80 | }; 81 | 82 | window.NativeBridge = NativeBridge; 83 | })(window); -------------------------------------------------------------------------------- /app/src/main/assets/www/common/js/progress.js: -------------------------------------------------------------------------------- 1 | /**! 2 | * progress Javascript 3 | * @import [anim.css] 4 | */ 5 | 6 | const Progress = { 7 | 8 | show : function () { 9 | this.hide(); 10 | 11 | var e = document.createElement('div'); 12 | e.className = "anim-progress-layer"; 13 | 14 | var elem = document.getElementsByTagName('body')[0]; 15 | elem.parentNode.appendChild(e); 16 | }, 17 | 18 | hide : function () { 19 | let els = document.querySelectorAll(".anim-progress-layer"); 20 | Array.prototype.forEach.call(els, function(node) { 21 | if (node) { 22 | node.parentNode.removeChild(node); 23 | } 24 | }); 25 | } 26 | 27 | }; -------------------------------------------------------------------------------- /app/src/main/assets/www/dist/vendor/css/normalize.css: -------------------------------------------------------------------------------- 1 | /* 브라우저별 공통 분모는 건드리지 않고 차이를 보이는 부분만 일관성있게 바꿔준다. */ 2 | /* https://necolas.github.io/normalize.css */ 3 | /* cdn: https://cdnjs.com/libraries/normalize */ 4 | 5 | 6 | /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */ 7 | 8 | /* Document 9 | ========================================================================== */ 10 | 11 | /** 12 | * 1. Correct the line height in all browsers. 13 | * 2. Prevent adjustments of font size after orientation changes in iOS. 14 | */ 15 | 16 | html { 17 | line-height: 1.15; /* 1 */ 18 | -webkit-text-size-adjust: 100%; /* 2 */ 19 | } 20 | 21 | /* Sections 22 | ========================================================================== */ 23 | 24 | /** 25 | * Remove the margin in all browsers. 26 | */ 27 | 28 | body { 29 | margin: 0; 30 | } 31 | 32 | /** 33 | * Render the `main` element consistently in IE. 34 | */ 35 | 36 | main { 37 | display: block; 38 | } 39 | 40 | /** 41 | * Correct the font size and margin on `h1` elements within `section` and 42 | * `article` contexts in Chrome, Firefox, and Safari. 43 | */ 44 | 45 | h1 { 46 | font-size: 2em; 47 | margin: 0.67em 0; 48 | } 49 | 50 | /* Grouping content 51 | ========================================================================== */ 52 | 53 | /** 54 | * 1. Add the correct box sizing in Firefox. 55 | * 2. Show the overflow in Edge and IE. 56 | */ 57 | 58 | hr { 59 | box-sizing: content-box; /* 1 */ 60 | height: 0; /* 1 */ 61 | overflow: visible; /* 2 */ 62 | } 63 | 64 | /** 65 | * 1. Correct the inheritance and scaling of font size in all browsers. 66 | * 2. Correct the odd `em` font sizing in all browsers. 67 | */ 68 | 69 | pre { 70 | font-family: monospace, monospace; /* 1 */ 71 | font-size: 1em; /* 2 */ 72 | } 73 | 74 | /* Text-level semantics 75 | ========================================================================== */ 76 | 77 | /** 78 | * Remove the gray background on active links in IE 10. 79 | */ 80 | 81 | a { 82 | background-color: transparent; 83 | } 84 | 85 | /** 86 | * 1. Remove the bottom border in Chrome 57- 87 | * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. 88 | */ 89 | 90 | abbr[title] { 91 | border-bottom: none; /* 1 */ 92 | text-decoration: underline; /* 2 */ 93 | text-decoration: underline dotted; /* 2 */ 94 | } 95 | 96 | /** 97 | * Add the correct font weight in Chrome, Edge, and Safari. 98 | */ 99 | 100 | b, 101 | strong { 102 | font-weight: bolder; 103 | } 104 | 105 | /** 106 | * 1. Correct the inheritance and scaling of font size in all browsers. 107 | * 2. Correct the odd `em` font sizing in all browsers. 108 | */ 109 | 110 | code, 111 | kbd, 112 | samp { 113 | font-family: monospace, monospace; /* 1 */ 114 | font-size: 1em; /* 2 */ 115 | } 116 | 117 | /** 118 | * Add the correct font size in all browsers. 119 | */ 120 | 121 | small { 122 | font-size: 80%; 123 | } 124 | 125 | /** 126 | * Prevent `sub` and `sup` elements from affecting the line height in 127 | * all browsers. 128 | */ 129 | 130 | sub, 131 | sup { 132 | font-size: 75%; 133 | line-height: 0; 134 | position: relative; 135 | vertical-align: baseline; 136 | } 137 | 138 | sub { 139 | bottom: -0.25em; 140 | } 141 | 142 | sup { 143 | top: -0.5em; 144 | } 145 | 146 | /* Embedded content 147 | ========================================================================== */ 148 | 149 | /** 150 | * Remove the border on images inside links in IE 10. 151 | */ 152 | 153 | img { 154 | border-style: none; 155 | } 156 | 157 | /* Forms 158 | ========================================================================== */ 159 | 160 | /** 161 | * 1. Change the font styles in all browsers. 162 | * 2. Remove the margin in Firefox and Safari. 163 | */ 164 | 165 | button, 166 | input, 167 | optgroup, 168 | select, 169 | textarea { 170 | font-family: inherit; /* 1 */ 171 | font-size: 100%; /* 1 */ 172 | line-height: 1.15; /* 1 */ 173 | margin: 0; /* 2 */ 174 | } 175 | 176 | /** 177 | * Show the overflow in IE. 178 | * 1. Show the overflow in Edge. 179 | */ 180 | 181 | button, 182 | input { /* 1 */ 183 | overflow: visible; 184 | } 185 | 186 | /** 187 | * Remove the inheritance of text transform in Edge, Firefox, and IE. 188 | * 1. Remove the inheritance of text transform in Firefox. 189 | */ 190 | 191 | button, 192 | select { /* 1 */ 193 | text-transform: none; 194 | } 195 | 196 | /** 197 | * Correct the inability to style clickable types in iOS and Safari. 198 | */ 199 | 200 | button, 201 | [type="button"], 202 | [type="reset"], 203 | [type="submit"] { 204 | -webkit-appearance: button; 205 | } 206 | 207 | /** 208 | * Remove the inner border and padding in Firefox. 209 | */ 210 | 211 | button::-moz-focus-inner, 212 | [type="button"]::-moz-focus-inner, 213 | [type="reset"]::-moz-focus-inner, 214 | [type="submit"]::-moz-focus-inner { 215 | border-style: none; 216 | padding: 0; 217 | } 218 | 219 | /** 220 | * Restore the focus styles unset by the previous rule. 221 | */ 222 | 223 | button:-moz-focusring, 224 | [type="button"]:-moz-focusring, 225 | [type="reset"]:-moz-focusring, 226 | [type="submit"]:-moz-focusring { 227 | outline: 1px dotted ButtonText; 228 | } 229 | 230 | /** 231 | * Correct the padding in Firefox. 232 | */ 233 | 234 | fieldset { 235 | padding: 0.35em 0.75em 0.625em; 236 | } 237 | 238 | /** 239 | * 1. Correct the text wrapping in Edge and IE. 240 | * 2. Correct the color inheritance from `fieldset` elements in IE. 241 | * 3. Remove the padding so developers are not caught out when they zero out 242 | * `fieldset` elements in all browsers. 243 | */ 244 | 245 | legend { 246 | box-sizing: border-box; /* 1 */ 247 | color: inherit; /* 2 */ 248 | display: table; /* 1 */ 249 | max-width: 100%; /* 1 */ 250 | padding: 0; /* 3 */ 251 | white-space: normal; /* 1 */ 252 | } 253 | 254 | /** 255 | * Add the correct vertical alignment in Chrome, Firefox, and Opera. 256 | */ 257 | 258 | progress { 259 | vertical-align: baseline; 260 | } 261 | 262 | /** 263 | * Remove the default vertical scrollbar in IE 10+. 264 | */ 265 | 266 | textarea { 267 | overflow: auto; 268 | } 269 | 270 | /** 271 | * 1. Add the correct box sizing in IE 10. 272 | * 2. Remove the padding in IE 10. 273 | */ 274 | 275 | [type="checkbox"], 276 | [type="radio"] { 277 | box-sizing: border-box; /* 1 */ 278 | padding: 0; /* 2 */ 279 | } 280 | 281 | /** 282 | * Correct the cursor style of increment and decrement buttons in Chrome. 283 | */ 284 | 285 | [type="number"]::-webkit-inner-spin-button, 286 | [type="number"]::-webkit-outer-spin-button { 287 | height: auto; 288 | } 289 | 290 | /** 291 | * 1. Correct the odd appearance in Chrome and Safari. 292 | * 2. Correct the outline style in Safari. 293 | */ 294 | 295 | [type="search"] { 296 | -webkit-appearance: textfield; /* 1 */ 297 | outline-offset: -2px; /* 2 */ 298 | } 299 | 300 | /** 301 | * Remove the inner padding in Chrome and Safari on macOS. 302 | */ 303 | 304 | [type="search"]::-webkit-search-decoration { 305 | -webkit-appearance: none; 306 | } 307 | 308 | /** 309 | * 1. Correct the inability to style clickable types in iOS and Safari. 310 | * 2. Change font properties to `inherit` in Safari. 311 | */ 312 | 313 | ::-webkit-file-upload-button { 314 | -webkit-appearance: button; /* 1 */ 315 | font: inherit; /* 2 */ 316 | } 317 | 318 | /* Interactive 319 | ========================================================================== */ 320 | 321 | /* 322 | * Add the correct display in Edge, IE 10+, and Firefox. 323 | */ 324 | 325 | details { 326 | display: block; 327 | } 328 | 329 | /* 330 | * Add the correct display in all browsers. 331 | */ 332 | 333 | summary { 334 | display: list-item; 335 | } 336 | 337 | /* Misc 338 | ========================================================================== */ 339 | 340 | /** 341 | * Add the correct display in IE 10+. 342 | */ 343 | 344 | template { 345 | display: none; 346 | } 347 | 348 | /** 349 | * Add the correct display in IE 10. 350 | */ 351 | 352 | [hidden] { 353 | display: none; 354 | } 355 | -------------------------------------------------------------------------------- /app/src/main/assets/www/dist/vendor/css/reset.css: -------------------------------------------------------------------------------- 1 | /* http://meyerweb.com/eric/tools/css/reset/ 2 | v2.0 | 20110126 3 | License: none (public domain) 4 | */ 5 | 6 | html, body, div, span, applet, object, iframe, 7 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 8 | a, abbr, acronym, address, big, cite, code, 9 | del, dfn, em, img, ins, kbd, q, s, samp, 10 | small, strike, strong, sub, sup, tt, var, 11 | b, u, i, center, 12 | dl, dt, dd, ol, ul, li, 13 | fieldset, form, label, legend, 14 | table, caption, tbody, tfoot, thead, tr, th, td, 15 | article, aside, canvas, details, embed, 16 | figure, figcaption, footer, header, hgroup, 17 | menu, nav, output, ruby, section, summary, 18 | time, mark, audio, video { 19 | margin: 0; 20 | padding: 0; 21 | border: 0; 22 | font-size: 100%; 23 | font: inherit; 24 | vertical-align: baseline; 25 | } 26 | /* HTML5 display-role reset for older browsers */ 27 | article, aside, details, figcaption, figure, 28 | footer, header, hgroup, menu, nav, section { 29 | display: block; 30 | } 31 | body { 32 | line-height: 1; 33 | } 34 | ol, ul { 35 | list-style: none; 36 | } 37 | blockquote, q { 38 | quotes: none; 39 | } 40 | blockquote:before, blockquote:after, 41 | q:before, q:after { 42 | content: ''; 43 | content: none; 44 | } 45 | table { 46 | border-collapse: collapse; 47 | border-spacing: 0; 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/assets/www/dist/vendor/js/JavaScript-Load-Image/load-image-helper.js: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | * 3 | * JavaScript-Load-Image Helper 4 | * https://github.com/blueimp/JavaScript-Load-Image 5 | * 6 | * Copyright (c) 2019 Aaron Jo. All rights reserved. 7 | * 8 | *****************************************************************/ 9 | 10 | !(function() { 11 | 12 | var LoadImageHelper = {}; 13 | 14 | LoadImageHelper.loadImage = function (fileOrBlobOrUrl, callback, options) { 15 | options = options || {}; 16 | 17 | var loadingImage = loadImage( 18 | fileOrBlobOrUrl, // Source 19 | function (img, data) { 20 | if (img.type === "error") { 21 | console.error("Error loading image " + target); 22 | if ("function" === typeof callback) { 23 | callback(false, img, data); 24 | } 25 | return; 26 | } 27 | 28 | if ("function" === typeof callback) { 29 | var base64String; 30 | if (img instanceof HTMLCanvasElement) { 31 | base64String = img.toDataURL('image/jpg', 1); 32 | } 33 | callback(true, img, data, base64String); 34 | } 35 | }, 36 | { // Options 37 | orientation: true, 38 | //canvas: true, 39 | meta: true, 40 | minWidth: options.minWidth || 160, 41 | minHeight: options.minHeight || 120, 42 | maxWidth: options.maxWidth || 320 43 | } 44 | ); 45 | }; 46 | 47 | window.LoadImageHelper = window.LoadImageHelper || {}; 48 | 49 | for (var m in LoadImageHelper) { 50 | if (typeof LoadImageHelper[m] === "function") { 51 | window.LoadImageHelper[m] = LoadImageHelper[m]; 52 | } 53 | } 54 | 55 | if ( typeof define === "function" && define.amd ) { 56 | define( "LoadImageHelper", [], function () { 57 | return LoadImageHelper; 58 | } ); 59 | } 60 | 61 | })(); 62 | -------------------------------------------------------------------------------- /app/src/main/assets/www/dist/vendor/js/JavaScript-Load-Image/load-image.js: -------------------------------------------------------------------------------- 1 | /* 2 | * JavaScript Load Image 3 | * https://github.com/blueimp/JavaScript-Load-Image 4 | * 5 | * Copyright 2011, Sebastian Tschan 6 | * https://blueimp.net 7 | * 8 | * Licensed under the MIT license: 9 | * https://opensource.org/licenses/MIT 10 | */ 11 | 12 | /* global define, webkitURL, module */ 13 | 14 | ;(function($) { 15 | 'use strict' 16 | 17 | /** 18 | * Loads an image for a given File object. 19 | * Invokes the callback with an img or optional canvas element 20 | * (if supported by the browser) as parameter:. 21 | * 22 | * @param {File|Blob|string} file File or Blob object or image URL 23 | * @param {Function} [callback] Image load event callback 24 | * @param {object} [options] Options object 25 | * @returns {HTMLImageElement|HTMLCanvasElement|FileReader} image object 26 | */ 27 | function loadImage(file, callback, options) { 28 | var img = document.createElement('img') 29 | var url 30 | img.onerror = function(event) { 31 | return loadImage.onerror(img, event, file, callback, options) 32 | } 33 | img.onload = function(event) { 34 | return loadImage.onload(img, event, file, callback, options) 35 | } 36 | if (typeof file === 'string') { 37 | loadImage.fetchBlob( 38 | file, 39 | function(blob) { 40 | if (blob && loadImage.isInstanceOf('Blob', blob)) { 41 | // eslint-disable-next-line no-param-reassign 42 | file = blob 43 | url = loadImage.createObjectURL(file) 44 | } else { 45 | url = file 46 | if (options && options.crossOrigin) { 47 | img.crossOrigin = options.crossOrigin 48 | } 49 | } 50 | img.src = url 51 | }, 52 | options 53 | ) 54 | return img 55 | } else if ( 56 | loadImage.isInstanceOf('Blob', file) || 57 | // Files are also Blob instances, but some browsers 58 | // (Firefox 3.6) support the File API but not Blobs: 59 | loadImage.isInstanceOf('File', file) 60 | ) { 61 | url = img._objectURL = loadImage.createObjectURL(file) 62 | if (url) { 63 | img.src = url 64 | return img 65 | } 66 | return loadImage.readFile(file, function(e) { 67 | var target = e.target 68 | if (target && target.result) { 69 | img.src = target.result 70 | } else if (callback) { 71 | callback(e) 72 | } 73 | }) 74 | } 75 | } 76 | // The check for URL.revokeObjectURL fixes an issue with Opera 12, 77 | // which provides URL.createObjectURL but doesn't properly implement it: 78 | var urlAPI = 79 | ($.createObjectURL && $) || 80 | ($.URL && URL.revokeObjectURL && URL) || 81 | ($.webkitURL && webkitURL) 82 | 83 | /** 84 | * Helper function to revoke an object URL 85 | * 86 | * @param {HTMLImageElement} img Image element 87 | * @param {object} [options] Options object 88 | */ 89 | function revokeHelper(img, options) { 90 | if (img._objectURL && !(options && options.noRevoke)) { 91 | loadImage.revokeObjectURL(img._objectURL) 92 | delete img._objectURL 93 | } 94 | } 95 | 96 | // If the callback given to this function returns a blob, it is used as image 97 | // source instead of the original url and overrides the file argument used in 98 | // the onload and onerror event callbacks: 99 | loadImage.fetchBlob = function(url, callback) { 100 | callback() 101 | } 102 | 103 | loadImage.isInstanceOf = function(type, obj) { 104 | // Cross-frame instanceof check 105 | return Object.prototype.toString.call(obj) === '[object ' + type + ']' 106 | } 107 | 108 | loadImage.transform = function(img, options, callback, file, data) { 109 | callback(img, data) 110 | } 111 | 112 | loadImage.onerror = function(img, event, file, callback, options) { 113 | revokeHelper(img, options) 114 | if (callback) { 115 | callback.call(img, event) 116 | } 117 | } 118 | 119 | loadImage.onload = function(img, event, file, callback, options) { 120 | revokeHelper(img, options) 121 | if (callback) { 122 | loadImage.transform(img, options, callback, file, { 123 | originalWidth: img.naturalWidth || img.width, 124 | originalHeight: img.naturalHeight || img.height 125 | }) 126 | } 127 | } 128 | 129 | loadImage.createObjectURL = function(file) { 130 | return urlAPI ? urlAPI.createObjectURL(file) : false 131 | } 132 | 133 | loadImage.revokeObjectURL = function(url) { 134 | return urlAPI ? urlAPI.revokeObjectURL(url) : false 135 | } 136 | 137 | // Loads a given File object via FileReader interface, 138 | // invokes the callback with the event object (load or error). 139 | // The result can be read via event.target.result: 140 | loadImage.readFile = function(file, callback, method) { 141 | if ($.FileReader) { 142 | var fileReader = new FileReader() 143 | fileReader.onload = fileReader.onerror = callback 144 | // eslint-disable-next-line no-param-reassign 145 | method = method || 'readAsDataURL' 146 | if (fileReader[method]) { 147 | fileReader[method](file) 148 | return fileReader 149 | } 150 | } 151 | return false 152 | } 153 | 154 | if (typeof define === 'function' && define.amd) { 155 | define(function() { 156 | return loadImage 157 | }) 158 | } else if (typeof module === 'object' && module.exports) { 159 | module.exports = loadImage 160 | } else { 161 | $.loadImage = loadImage 162 | } 163 | })((typeof window !== 'undefined' && window) || this) 164 | -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/image-provider/image-provider.css: -------------------------------------------------------------------------------- 1 | /**! 2 | * Cascading Style Sheet 3 | */ 4 | @charset "utf-8"; 5 | 6 | @import "../../dist/vendor/css/reset.css"; 7 | /*@import "../../dist/vendor/css/normalize.css";*/ 8 | @import "../../common/css/components.css"; 9 | @import "../../common/css/extends.css"; 10 | @import "../../common/css/anim.css"; 11 | 12 | a { color: #989da3; text-decoration: none } 13 | a:hover, 14 | a:focus, 15 | a:active { color: #989da3; text-decoration: none; } 16 | 17 | .identity { background-color:#001935; color:#fefefe; } 18 | 19 | .l-header-container { margin-top:calc(100% - 80%); } 20 | .l-header {} 21 | .l-header h1,h2,h3,h4,h5,h6 { color:#fff; text-align:center; } 22 | .l-header h1 { font-size:3.5em; } 23 | 24 | .l-content-container { margin-top:150px; } 25 | .l-content {} 26 | .l-content h1,h2,h3,h4,h5,h6 { color:#fff; text-align:center; } 27 | 28 | .l-footer-container { margin-top:150px; } 29 | .l-footer {} 30 | .l-footer h1 { color:#fff; font-size:1em; text-align:center; } 31 | .l-footer { color:#989da3; padding:15px 10px 20px 10px; } 32 | .l-footer { text-align:center; } 33 | .l-footer { width:calc(100% - 10%); margin:0 auto; } 34 | .l-footer > p { margin-bottom:8px; font-size:0.8em; } 35 | -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/image-provider/image-provider.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Image Provider Test Page 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 39 | 40 | 41 | Your browser does not support JavaScript! 42 | 43 | 44 | 45 | 46 | 47 | 48 | ImageProvider 49 | 50 | 51 | 52 | 53 | 54 | Image Preview 55 | 56 | 57 | 58 | 59 | 60 | 61 | accept="image/*" 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/image-provider/image-provider.js: -------------------------------------------------------------------------------- 1 | /**! 2 | * Page Javascript 3 | */ 4 | 5 | ///////////////////////////////////////////////// 6 | // Utilities 7 | ///////////////////////////////////////////////// 8 | 9 | function removeAllChild ($el) { 10 | if ($el.children.length > 0) { 11 | while ($el.firstChild) { 12 | $el.removeChild($el.firstChild); 13 | } 14 | } 15 | } 16 | 17 | 18 | ///////////////////////////////////////////////// 19 | // Global 20 | ///////////////////////////////////////////////// 21 | 22 | // response (Native --> Web) 23 | function callbackTakePicture(data, base64String) { 24 | console.log("callbackTakePicture(): data = " + data); 25 | 26 | var $preview = document.querySelector('#img-preview'); 27 | removeAllChild($preview); 28 | 29 | var $img = document.createElement('img'); 30 | $img.src = 'data:image/png;base64,' + base64String; 31 | $img.width = '320'; 32 | 33 | $preview.appendChild($img); 34 | } 35 | 36 | 37 | ///////////////////////////////////////////////// 38 | // Document Ready 39 | ///////////////////////////////////////////////// 40 | 41 | $(document).ready(function() { 42 | console.info('document.ready ...'); 43 | 44 | $('#native-take-a-picture').on('click', function () { 45 | NativeBridge.call("apiTakePicture", { a:"A", b:1, c:false, d:{ d1:"d1", d2:2 } }, "callbackTakePicture"); 46 | }); 47 | 48 | $('#file-chooser-image').on('change', function (e) { 49 | var $preview = document.querySelector('#img-preview'); 50 | removeAllChild($preview); 51 | 52 | var file = e.target.files[0]; 53 | LoadImageHelper.loadImage(file, function (result, img, data, base64String) { 54 | if (result) { 55 | img.width = '320'; 56 | $preview.appendChild(img); 57 | } 58 | }); 59 | }); 60 | 61 | }); 62 | -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/qrcode-reader/dist/audio/beep.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/assets/www/docs/qrcode-reader/dist/audio/beep.mp3 -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/qrcode-reader/dist/css/qrcode-reader.css: -------------------------------------------------------------------------------- 1 | #qrr-overlay { 2 | position: fixed; 3 | top: 0; 4 | left: 0; 5 | background: black; 6 | opacity: 0.6; 7 | width: 100%; 8 | height: 100%; 9 | display: none; 10 | z-index: 20000; 11 | } 12 | 13 | #qrr-container { 14 | font-family: sans-serif; 15 | position: fixed; 16 | top: 0; 17 | left: 0; 18 | right: 0; 19 | bottom: 0; 20 | background: white; 21 | padding: 10px; 22 | width: 90%; 23 | height: 90%; 24 | margin: auto; 25 | display: none; 26 | z-index: 20001; 27 | border-radius: 10px; 28 | } 29 | 30 | #qrr-container h1 { 31 | margin-top: 0; 32 | } 33 | 34 | #qrr-close { 35 | position: absolute; 36 | right: 0; 37 | top: 0; 38 | margin-right: 10px; 39 | margin-top: -5px; 40 | font-size: 3em; 41 | cursor: pointer; 42 | color: #808080; 43 | 44 | } 45 | 46 | #qrr-loading-message { 47 | text-align: center; 48 | padding: 15px; 49 | background-color: #eee; 50 | width: 90%; 51 | margin: 30px auto 0; 52 | } 53 | 54 | #qrr-canvas { 55 | display: block; 56 | height: 65%; 57 | max-width: 90%; 58 | overflow-x: scroll; 59 | cursor: pointer; 60 | margin: 30px auto 10px; 61 | } 62 | 63 | #qrr-canvas.hidden { 64 | display: none; 65 | } 66 | 67 | #qrr-output { 68 | width: 90%; 69 | max-height: 15%; 70 | margin: 20px auto 10px; 71 | background: #eee; 72 | padding: 10px; 73 | overflow-y: auto; 74 | } 75 | 76 | #qrr-ok { 77 | display: none; 78 | position: absolute; 79 | right: 10px; 80 | bottom: 10px; 81 | padding: 10px 50px; 82 | cursor: pointer; 83 | font-weight: bold; 84 | text-decoration: none; 85 | background-color: green; 86 | color: white; 87 | border-radius: 10px; 88 | } 89 | 90 | #qrr-output-data { 91 | display: none; 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/qrcode-reader/dist/js/jsQR/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/assets/www/docs/qrcode-reader/dist/js/jsQR/README.md -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/qrcode-reader/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | qrcode-reader usage example 7 | 8 | 9 | 14 | 15 | 16 | 17 | 18 | QRCode reader plugin examples 19 | 20 | 21 | 22 | Single input (settings in data attributes: no audio, regexp to match URLs): 23 | 24 | Read QRCode 28 | 29 | 30 | 31 | Single input (rebound click, depending on target input's content): 32 | 33 | Read or follow QRCode 36 | 37 | 38 | 39 | Multiple input (settings in data attributes: exclude duplicates, disable repeat timeout): 40 | 41 | 42 | Read QRCodes 47 | 48 | 49 | 50 | Multiple input 2 (include duplicates, settings in runtime call): 51 | 52 | 53 | Read QRCodes 54 | 55 | 56 | 57 | Multiple input 3 (settings in data attributes overridden in runtime call): 58 | 59 | 60 | Read QRCodes 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/sample/image.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Image Test Page 15 | 16 | 17 | 18 | 19 | 20 | Your browser does not support JavaScript! 21 | 22 | 23 | 24 | 25 | 26 | 27 | Image 28 | 29 | 30 | 31 | 32 | 33 | 34 | Local Files 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/sample/sample.css: -------------------------------------------------------------------------------- 1 | /**! 2 | * Cascading Style Sheet 3 | */ 4 | @charset "utf-8"; 5 | 6 | @import "../../dist/vendor/css/reset.css"; 7 | /*@import "../../dist/vendor/css/normalize.css";*/ 8 | @import "../../common/css/components.css"; 9 | @import "../../common/css/extends.css"; 10 | @import "../../common/css/anim.css"; 11 | 12 | a { color: #989da3; text-decoration: none } 13 | a:hover, 14 | a:focus, 15 | a:active { color: #989da3; text-decoration: none; } 16 | 17 | .identity { background-color:#001935; color:#fefefe; } 18 | 19 | .l-header-container { margin-top:calc(100% - 80%); } 20 | .l-header {} 21 | .l-header h1,h2,h3,h4,h5,h6 { color:#fff; text-align:center; } 22 | .l-header h1 { font-size:3.5em; } 23 | 24 | .l-content-container { margin-top:150px; } 25 | .l-content {} 26 | .l-content h1,h2,h3,h4,h5,h6 { color:#fff; text-align:center; } 27 | 28 | .l-footer-container { margin-top:150px; } 29 | .l-footer {} 30 | .l-footer h1 { color:#fff; font-size:1em; text-align:center; } 31 | .l-footer { color:#989da3; padding:15px 10px 20px 10px; } 32 | .l-footer { text-align:center; } 33 | .l-footer { width:calc(100% - 10%); margin:0 auto; } 34 | .l-footer > p { margin-bottom:8px; font-size:0.8em; } 35 | -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/sample/sample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Sample Page 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | Your browser does not support JavaScript! 28 | 29 | 30 | 31 | 32 | 33 | 34 | Welcome 35 | 36 | 37 | 38 | 39 | 40 | Image 41 | 42 | 43 | android_res/ 44 | 45 | http:// 46 | 47 | https:// 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | Content 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | Google Maps 69 | 70 | 71 | 72 | accept="image/*" 73 | accept="audio/*" 74 | accept="video/*" 75 | accept="*/*" 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | Video 84 | 85 | 86 | 87 | 88 | Your browser does not support the video tag. 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | Permission 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | Your browser does not support the video tag. 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | Capture 113 | 114 | 115 | 116 | 117 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /app/src/main/assets/www/docs/sample/sample.js: -------------------------------------------------------------------------------- 1 | /**! 2 | * Page Javascript 3 | */ 4 | 5 | ///////////////////////////////////////////////// 6 | // Immediately 7 | ///////////////////////////////////////////////// 8 | (function() { 9 | window.onerror = function (err) { 10 | //console.log(arguments); 11 | console.log(err); 12 | for (var i=0; i < arguments.length; i++) { 13 | console.log("[" + i + "] : " + arguments[i]); 14 | } 15 | }; 16 | 17 | var ro = new ResizeObserver(function (entries) { 18 | entries[0].target.classList.add('big'); 19 | }); 20 | 21 | if (ro && "function" === typeof ro.observe ) { 22 | ro.observe(window.video); 23 | } 24 | })(); 25 | 26 | 27 | ///////////////////////////////////////////////// 28 | // Document Ready 29 | ///////////////////////////////////////////////// 30 | $(document).ready(function() { 31 | console.info('document.ready ...'); 32 | 33 | $('#call-android-methods-recommended-1').on('click', function () { 34 | Progress.show(); 35 | 36 | NativeBridge.callToNative( 37 | "api", 38 | "recommended", 39 | { a:"A", b:1, c:false, d:{ d1:"d1", d2:2 } }, 40 | function(data) { 41 | console.log("response..." + JSON.stringify(data)); 42 | alert(JSON.stringify(data)); 43 | Progress.hide(); 44 | }, 45 | function(err) { 46 | console.error("error..." + err); 47 | alert(err); 48 | Progress.hide(); 49 | } 50 | ); 51 | }); 52 | 53 | $('#call-android-methods-recommended-2').on('click', function () { 54 | Progress.show(); 55 | 56 | // response (Native --> Web) 57 | function callbackNativeResponse (data) { 58 | console.log("callbackNativeResponse(): data = " + JSON.stringify(data)); 59 | alert(JSON.stringify(data)); 60 | Progress.hide(); 61 | } 62 | window['callbackNativeResponse'] = callbackNativeResponse; 63 | 64 | NativeBridge.callToNative( 65 | "api", 66 | "recommended", 67 | { a:"A", b:1, c:false, d:{ d1:"d1", d2:2 } }, 68 | "callbackNativeResponse" 69 | ); 70 | }); 71 | 72 | $('#native-take-a-picture').on('click', function () { 73 | NativeBridge.callToNative( 74 | "camera", 75 | "takePicture", 76 | { a:"A", b:1, c:false, d:{ d1:"d1", d2:2 } }, 77 | function (data) { 78 | console.log("callback : data = " + data); 79 | alert(data); 80 | } 81 | ); 82 | }); 83 | 84 | $('#req-microphone').on('click', function () { 85 | //navigator.mediaDevices.getUserMedia("microphone") 86 | navigator.mediaDevices.getUserMedia({ 87 | audio: true 88 | }) 89 | .then(function (mediaStream) { 90 | console.log('request: then...', mediaStream); 91 | }) 92 | .catch(function (err) { 93 | console.error('request: error: ' + err.toString(), err); 94 | alert(err); 95 | }); 96 | }); 97 | 98 | // https://www.html5rocks.com/en/tutorials/getusermedia/intro/ 99 | $('#req-camera').on('click', function () { 100 | var constraints = navigator.mediaDevices.getSupportedConstraints(); 101 | console.log(constraints); 102 | 103 | navigator.mediaDevices.getUserMedia({ 104 | audio: false, 105 | video: { 106 | facingMode: { exact: "environment" }, 107 | zoom: true, 108 | }, 109 | }) 110 | .then(function (mediaStream) { 111 | console.log('request: then...', mediaStream); 112 | 113 | var $video = document.querySelector('#media-device-video'); 114 | if ($video) { 115 | $video.srcObject = mediaStream; 116 | $video.onloadedmetadata = function(e) { 117 | $video.play(); 118 | }; 119 | } 120 | }) 121 | .catch(function (err) { 122 | console.error('request: error: ' + err.toString(), err); 123 | alert(err); 124 | }); 125 | }); 126 | 127 | 128 | var $video = document.querySelector('#media-device-video'); 129 | var $canvas = document.querySelector('#canvas'); 130 | var $img = document.querySelector('#captured-img'); 131 | 132 | $('#media-device-video').on('click', function() { 133 | const $canvas = document.createElement("canvas"); 134 | $canvas.width = $video.videoWidth; 135 | $canvas.height = $video.videoHeight; 136 | $canvas.getContext("2d").drawImage($video, 0, 0); 137 | // Other browsers will fall back to image/png 138 | var src = $canvas.toDataURL("image/webp"); 139 | $img.src = src; 140 | }); 141 | 142 | $('#btn-capture').on('click', function() { 143 | $canvas.width = $video.videoWidth; 144 | $canvas.height = $video.videoHeight; 145 | $canvas.getContext("2d").drawImage($video, 0, 0); 146 | // Other browsers will fall back to image/png 147 | var src = $canvas.toDataURL("image/webp"); 148 | $img.src = src; 149 | }); 150 | 151 | }); 152 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/sample/webview/activity/WebViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview.activity; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Intent; 5 | import android.content.pm.PackageManager; 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | import android.view.KeyEvent; 9 | import android.view.ViewGroup; 10 | import android.webkit.WebView; 11 | 12 | import com.snc.sample.webview.BuildConfig; 13 | import com.snc.sample.webview.R; 14 | import com.snc.sample.webview.bridge.AndroidBridge; 15 | import com.snc.sample.webview.bridge.plugin.PluginCamera; 16 | import com.snc.sample.webview.webview.WebViewHelper; 17 | import com.snc.zero.activity.BaseActivity; 18 | import com.snc.zero.dialog.DialogBuilder; 19 | import com.snc.zero.keyevent.BackKeyShutdown; 20 | import com.snc.zero.requetcode.RequestCode; 21 | import com.snc.zero.util.AssetUtil; 22 | import com.snc.zero.util.EnvUtil; 23 | import com.snc.zero.util.PackageUtil; 24 | import com.snc.zero.util.StringUtil; 25 | import com.snc.zero.webview.CSDownloadListener; 26 | import com.snc.zero.webview.CSFileChooserListener; 27 | import com.snc.zero.webview.CSWebChromeClient; 28 | import com.snc.zero.webview.CSWebViewClient; 29 | 30 | import java.io.File; 31 | 32 | import timber.log.Timber; 33 | 34 | /** 35 | * WebView Activity 36 | * 37 | * @author mcharima5@gmail.com 38 | * @since 2018 39 | */ 40 | public class WebViewActivity extends BaseActivity { 41 | private WebView webview; 42 | private CSWebChromeClient webChromeClient; 43 | private CSFileChooserListener webviewFileChooser; 44 | 45 | @Override 46 | protected void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.activity_main); 49 | 50 | if (BuildConfig.DEBUG) { 51 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 52 | WebView.setWebContentsDebuggingEnabled(true); 53 | } 54 | } 55 | 56 | if (!new File(EnvUtil.getInternalFilesDir(getContext(), "public"), "202205091737430060.jpg").exists()) { 57 | AssetUtil.copyAssetToFile(getContext(), 58 | "www/common/img/202205091737430060.jpg", 59 | EnvUtil.getInternalFilesDir(getContext(), "public")); 60 | } 61 | 62 | init(); 63 | } 64 | 65 | @SuppressLint("AddJavascriptInterface") 66 | private void init() { 67 | ViewGroup contentView = findViewById(R.id.contentView); 68 | if (null == contentView) { 69 | DialogBuilder.with(getActivity()) 70 | .setMessage("The contentView does not exist.") 71 | .setPositiveButton(android.R.string.ok, (dialog, which) -> finish()) 72 | .show(); 73 | return; 74 | } 75 | 76 | // add webview 77 | this.webview = WebViewHelper.addWebView(getContext(), contentView); 78 | 79 | // options 80 | //this.webview.getSettings().setSupportMultipleWindows(true); 81 | 82 | // set user-agent 83 | try { 84 | String ua = this.webview.getSettings().getUserAgentString(); 85 | if (!ua.endsWith(" ")) { 86 | ua += " "; 87 | } 88 | ua += PackageUtil.getApplicationName(this); 89 | ua += "/" + PackageUtil.getPackageVersionName(this); 90 | ua += "." + PackageUtil.getPackageVersionCode(this); 91 | this.webview.getSettings().setUserAgentString(ua); 92 | } catch (PackageManager.NameNotFoundException e) { 93 | Timber.e(e); 94 | } 95 | 96 | // set webViewClient 97 | CSWebViewClient webviewClient = new CSWebViewClient(getContext()); 98 | this.webview.setWebViewClient(webviewClient); 99 | 100 | // set webChromeClient 101 | this.webChromeClient = new CSWebChromeClient(getContext()); 102 | this.webview.setWebChromeClient(this.webChromeClient); 103 | 104 | // set fileChooser 105 | this.webviewFileChooser = new CSFileChooserListener(getContext()); 106 | this.webChromeClient.setFileChooserListener(this.webviewFileChooser); 107 | 108 | // add interface 109 | this.webview.addJavascriptInterface(new AndroidBridge(webview), "AndroidBridge"); 110 | 111 | // add download listener 112 | this.webview.setDownloadListener(new CSDownloadListener(getActivity())); 113 | 114 | // load url 115 | //WebViewHelper.loadUrl(this.webview, WebViewHelper.getLocalBaseUrl("assets") + "/www/docs/sample/sample.html"); 116 | //WebViewHelper.loadUrl(this.webview, WebViewHelper.getLocalBaseUrl("assets") + "/www/docs/sample/image.html"); 117 | //WebViewHelper.loadUrl(this.webview, WebViewHelper.getLocalBaseUrl("assets") + "/www/docs/image-provider/image-provider.html"); 118 | //WebViewHelper.loadUrl(this.webview, WebViewHelper.getLocalBaseUrl("assets") + "/www/docs/qrcode-reader/index.html"); 119 | WebViewHelper.loadUrl(this.webview, "https://www.google.com"); 120 | } 121 | 122 | @Override 123 | protected void onDestroy() { 124 | WebViewHelper.removeWebView(this.webview); 125 | this.webview = null; 126 | super.onDestroy(); 127 | } 128 | 129 | @Override 130 | public boolean onKeyDown(int keyCode, KeyEvent event) { 131 | if (KeyEvent.KEYCODE_BACK == keyCode) { 132 | Timber.i("[ACTIVITY] onKeyDown(): WebView isVideoPlayingInFullscreen = %s", this.webChromeClient.isVideoPlayingInFullscreen()); 133 | if (this.webChromeClient.isVideoPlayingInFullscreen()) { 134 | return false; 135 | } 136 | 137 | // multiple windows go back 138 | if (null != this.webChromeClient.getNewWebView()) { 139 | Timber.i("[ACTIVITY] onKeyDown(): NewWebView canGoBack = %s", this.webChromeClient.getNewWebView().canGoBack()); 140 | if (this.webChromeClient.getNewWebView().canGoBack()) { 141 | this.webChromeClient.getNewWebView().goBack(); 142 | return true; 143 | } else { 144 | this.webChromeClient.closeNewWebView(); 145 | } 146 | return true; 147 | } 148 | 149 | Timber.i("[ACTIVITY] onKeyDown(): WebView canGoBack = %s", this.webview.canGoBack()); 150 | // go back 151 | if (this.webview.canGoBack()) { 152 | this.webview.goBack(); 153 | return true; 154 | } 155 | 156 | if (BackKeyShutdown.isFirstBackKeyPress(keyCode, event)) { 157 | DialogBuilder.with(getContext()) 158 | .setMessage(getString(R.string.one_more_press_back_button)) 159 | .toast(); 160 | return true; 161 | } 162 | } 163 | return super.onKeyDown(keyCode, event); 164 | } 165 | 166 | @Override 167 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 168 | if (null == data) { 169 | Timber.i("[ACTIVITY] onActivityResult(): requestCode[" + requestCode + "], resultCode[" + resultCode + "], data[null]"); 170 | } else { 171 | Timber.i("[ACTIVITY] onActivityResult(): requestCode[" + requestCode + "], resultCode[" + resultCode + "], data[" + 172 | "\n action = " + data.getAction() + 173 | "\n scheme = " + data.getScheme() + 174 | "\n data = " + data.getData() + 175 | "\n type = " + data.getType() + 176 | "\n extras = " + StringUtil.toString(data.getExtras()) + 177 | "\n]"); 178 | } 179 | 180 | //++ [[START] File Chooser] 181 | if (RequestCode.REQUEST_FILE_CHOOSER_NORMAL == requestCode) { 182 | Timber.i("[ACTIVITY] onActivityResult(): REQUEST_FILE_CHOOSER_NORMAL"); 183 | this.webviewFileChooser.onActivityResultFileChooserNormal(requestCode, resultCode, data); 184 | } 185 | else if (RequestCode.REQUEST_FILE_CHOOSER_LOLLIPOP == requestCode) { 186 | Timber.i("[ACTIVITY] onActivityResult(): REQUEST_FILE_CHOOSER_LOLLIPOP"); 187 | this.webviewFileChooser.onActivityResultFileChooserLollipop(requestCode, resultCode, data); 188 | } 189 | //-- [[E N D] File Chooser] 190 | 191 | //++ [[START] Take a picture] 192 | if (RequestCode.REQUEST_TAKE_A_PICTURE == requestCode) { 193 | Timber.i("[ACTIVITY] onActivityResult(): REQUEST_TAKE_A_PICTURE"); 194 | PluginCamera.onActivityResultTakePicture(this.webview, requestCode, resultCode, data); 195 | //AndroidBridgeProcessActivityResult.onActivityResultTakePicture(this.webview, requestCode, resultCode, data); 196 | } 197 | //++ [[E N D] Take a picture] 198 | 199 | super.onActivityResult(requestCode, resultCode, data); 200 | } 201 | 202 | } 203 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/sample/webview/bridge/AndroidBridge.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview.bridge; 2 | 3 | import android.net.Uri; 4 | import android.os.Build; 5 | import android.util.Base64; 6 | import android.webkit.JavascriptInterface; 7 | import android.webkit.WebView; 8 | 9 | import com.snc.zero.dialog.DialogBuilder; 10 | import com.snc.zero.json.JSONHelper; 11 | import com.snc.zero.util.StringUtil; 12 | 13 | import org.json.JSONObject; 14 | 15 | import java.io.File; 16 | import java.io.IOException; 17 | import java.net.URLDecoder; 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | import timber.log.Timber; 22 | 23 | /** 24 | * WebView JavaScript Interface Bridge 25 | * 26 | * @author mcharima5@gmail.com 27 | * @since 2018 28 | */ 29 | public class AndroidBridge { 30 | private static final String SCHEME_BRIDGE = "native"; 31 | 32 | // Web -> Native 33 | private static final String HOST_COMMAND = "callToNative"; 34 | 35 | private static final String SCHEME_JAVASCRIPT = "javascript:"; 36 | 37 | private final WebView webView; 38 | 39 | private static final Map callbackFunctionNames = new HashMap<>(); 40 | private static File extraOutput; 41 | 42 | // constructor 43 | public AndroidBridge(WebView webView) { 44 | this.webView = webView; 45 | } 46 | 47 | 48 | //++ [START] call Web --> Native 49 | 50 | // ex) "native://callToNative?" + btoa(encodeURIComponent(JSON.stringify({ command:\"apiSample\", args{max:1,min:1}, callback:\"callbackNativeResponse\" }))) 51 | @JavascriptInterface 52 | public boolean callNativeMethod(String urlString) { 53 | Timber.i("[WEBVIEW] callNativeMethod: %s", urlString); 54 | try { 55 | Uri uri = Uri.parse(urlString); 56 | JSONObject jsonObject = parse(uri); 57 | //jsonObject.put("hostCommand", uri.getHost()); 58 | 59 | String pluginName = JSONHelper.getString(jsonObject, "plugin", ""); 60 | 61 | if (StringUtil.isEmpty(pluginName)) { 62 | DialogBuilder.with(webView.getContext()) 63 | .setMessage("Plugin not exist") 64 | .show(); 65 | return false; 66 | } 67 | 68 | return AndroidBridgePlugin.execute(this.webView, jsonObject); 69 | 70 | } catch (Exception e) { 71 | Timber.e(e); 72 | 73 | DialogBuilder.with(webView.getContext()) 74 | .setMessage(e.toString()) 75 | .show(); 76 | } 77 | return false; 78 | } 79 | 80 | private JSONObject parse(Uri uri) throws IOException { 81 | Timber.i("[WEBVIEW] callNativeMethod: parse() : uri = %s", uri); 82 | 83 | if (!SCHEME_BRIDGE.equals(uri.getScheme())) { 84 | throw new IOException("\"" + uri.getScheme() + "\" scheme is not supported."); 85 | } 86 | if (!HOST_COMMAND.equals(uri.getHost())) { 87 | throw new IOException("\"" + uri.getHost() + "\" host is not supported."); 88 | } 89 | 90 | String query = uri.getEncodedQuery(); 91 | try { 92 | query = new String(Base64.decode(query, Base64.DEFAULT)); 93 | query = URLDecoder.decode(query, "utf-8"); 94 | 95 | return new JSONObject(query); 96 | } catch (Exception e) { 97 | throw new IOException("\"" + query + "\" is not JSONObject."); 98 | } 99 | } 100 | //-- [E N D] call Web --> Native 101 | 102 | 103 | //++ [START] call Native --> Web 104 | 105 | public static void callFromNative(WebView webView, String cbId, String resultCode, String jsonString) { 106 | String param = "'" + cbId + "', '" + resultCode + "', '" + jsonString + "'"; 107 | 108 | String buff = "!(function() {\n" + 109 | " try {\n" + 110 | " NativeBridge.callFromNative(" + param + ");\n" + 111 | " } catch(e) {\n" + 112 | " return '[JS Error] ' + e.message;\n" + 113 | " }\n" + 114 | "})(window);"; 115 | webView.post(() -> evaluateJavascript(webView, buff)); 116 | } 117 | 118 | public static void callJSFunction(final WebView webView, String functionName, String... params) { 119 | if (functionName.startsWith("function") 120 | || functionName.startsWith("(")) { 121 | String buff = "!(\n" + 122 | functionName + 123 | ")(" + makeParam(params) + ");"; 124 | webView.post(() -> evaluateJavascript(webView, buff)); 125 | } else { 126 | String js = makeJavascript(functionName, params); 127 | String buff = "!(function() {\n" + 128 | " try {\n" + 129 | " " + js + "\n" + 130 | " } catch(e) {\n" + 131 | " return '[JS Error] ' + e.message;\n" + 132 | " }\n" + 133 | "})(window);"; 134 | webView.post(() -> evaluateJavascript(webView, buff)); 135 | } 136 | } 137 | 138 | public static String makeJavascript(String functionName, String... params) { 139 | return functionName + "(" + makeParam(params) + ");"; 140 | } 141 | 142 | public static String makeParam(String... params) { 143 | final StringBuilder buff = new StringBuilder(); 144 | for (int i = 0; i < params.length; i++) { 145 | Object param = params[i]; 146 | 147 | // 데이터 설정 148 | if (null != param) { 149 | buff.append("'").append(param).append("'"); 150 | } else { 151 | buff.append("''"); 152 | } 153 | 154 | if (i < params.length - 1) { 155 | buff.append(", "); 156 | } 157 | } 158 | return buff.toString(); 159 | } 160 | 161 | private static void evaluateJavascript(final WebView webView, final String javascriptString) { 162 | String jsString = javascriptString; 163 | 164 | if (jsString.startsWith(SCHEME_JAVASCRIPT)) { 165 | jsString = jsString.substring(SCHEME_JAVASCRIPT.length()); 166 | } 167 | 168 | jsString = jsString.replaceAll("\t", " "); 169 | 170 | // Android 4.4 (KitKat, 19) or higher 171 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 172 | webView.evaluateJavascript(jsString, value -> Timber.i("[WEBVIEW] onReceiveValue: " + value)); 173 | } 174 | // Android 4.3 or lower (Jelly Bean, 18) 175 | else { 176 | webView.loadUrl(SCHEME_JAVASCRIPT + jsString); 177 | } 178 | } 179 | 180 | //-- [E N D] call Native --> Web 181 | 182 | 183 | //++ [[START] for JS Callback] 184 | 185 | public static void setCallbackJSFunctionName(int requestCode, String functionName) { 186 | callbackFunctionNames.put(String.valueOf(requestCode), functionName); 187 | } 188 | 189 | public static String getCallbackJSFunctionName(int requestCode) { 190 | return callbackFunctionNames.remove(String.valueOf(requestCode)); 191 | } 192 | 193 | public static File getExtraOutput(boolean pop) { 194 | if (pop) { 195 | File file = extraOutput; 196 | extraOutput = null; 197 | return file; 198 | } 199 | return extraOutput; 200 | } 201 | 202 | public static void setExtraOutput(File file) { 203 | extraOutput = file; 204 | } 205 | //-- [[E N D] for JS Callback] 206 | 207 | } 208 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/sample/webview/bridge/AndroidBridgePlugin.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview.bridge; 2 | 3 | import android.webkit.WebView; 4 | 5 | import com.snc.sample.webview.bridge.plugin.PluginAPI; 6 | import com.snc.sample.webview.bridge.plugin.PluginCamera; 7 | import com.snc.sample.webview.bridge.plugin.interfaces.Plugin; 8 | import com.snc.zero.dialog.DialogBuilder; 9 | import com.snc.zero.json.JSONHelper; 10 | import com.snc.zero.reflect.ReflectHelper; 11 | 12 | import org.json.JSONObject; 13 | 14 | import java.lang.reflect.Method; 15 | 16 | import timber.log.Timber; 17 | 18 | /** 19 | * WebView JavaScript Interface Process 20 | * 21 | * @author mcharima5@gmail.com 22 | * @since 2022 23 | */ 24 | public class AndroidBridgePlugin { 25 | 26 | ///////////////////////////////////////////////// 27 | // Plugins 28 | 29 | private static final String PLUGIN_API = "api"; 30 | private static final String PLUGIN_CAMERA = "camera"; 31 | 32 | 33 | ///////////////////////////////////////////////// 34 | // Method 35 | 36 | public static boolean execute(WebView webView, JSONObject jsonObject) { 37 | //final String hostCommand = JSONHelper.getString(jsonObject, "hostCommand", ""); 38 | final String pluginName = JSONHelper.getString(jsonObject, "plugin", ""); 39 | final String methodName = JSONHelper.getString(jsonObject, "method", ""); 40 | final JSONObject args = JSONHelper.getJSONObject(jsonObject, "args", new JSONObject()); 41 | final String callback = JSONHelper.getString(jsonObject, "callback", ""); 42 | final String cbId = JSONHelper.getString(jsonObject, "cbId", ""); 43 | 44 | Timber.i("[WEBVIEW] callNativeMethod: execute() : plugin = " + pluginName + ", method = " + methodName + ", args = " + args + ", callback = " + callback); 45 | 46 | try { 47 | Plugin plugin = null; 48 | if (PLUGIN_API.equals(pluginName)) { 49 | plugin = (Plugin) PluginAPI.getInstance(); 50 | } 51 | else if (PLUGIN_CAMERA.equals(pluginName)) { 52 | plugin = (Plugin) PluginCamera.getInstance(); 53 | } 54 | 55 | if (null == plugin) { 56 | Timber.e("[WEBVIEW] plugin is null"); 57 | throw new Exception("plugin is null"); 58 | } 59 | 60 | Method method = ReflectHelper.getMethod(plugin, methodName); 61 | if (null == method) { 62 | Timber.e("[WEBVIEW] method is null"); 63 | throw new Exception("method is null"); 64 | } 65 | 66 | ReflectHelper.invoke(plugin, method, webView, args, cbId); 67 | return true; 68 | 69 | } catch (Exception e) { 70 | Timber.e(e); 71 | DialogBuilder.with(webView.getContext()) 72 | .setMessage(e.toString()) 73 | .show(); 74 | } 75 | return false; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/sample/webview/bridge/plugin/PluginAPI.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview.bridge.plugin; 2 | 3 | import android.webkit.WebView; 4 | 5 | import com.snc.sample.webview.bridge.AndroidBridge; 6 | import com.snc.sample.webview.bridge.plugin.interfaces.Plugin; 7 | import com.snc.zero.json.JSONHelper; 8 | 9 | import org.json.JSONObject; 10 | 11 | import timber.log.Timber; 12 | 13 | /** 14 | * Plugin 15 | * 16 | * @author mcharima5@gmail.com 17 | * @since 2022 18 | */ 19 | @SuppressWarnings({"InstantiationOfUtilityClass", "unused", "RedundantSuppression"}) 20 | public class PluginAPI implements Plugin { 21 | private static final PluginAPI mInstance = new PluginAPI(); 22 | public static PluginAPI getInstance() { 23 | return mInstance; 24 | } 25 | 26 | ///////////////////////////////////////////////// 27 | 28 | public static void recommended(final WebView webview, final JSONObject args, final String cbId) { 29 | Timber.i("[WEBVIEW] recommended : args[" + args + "], cbId[" + cbId + "]"); 30 | 31 | new Thread(() -> { 32 | 33 | // test code... 34 | try { 35 | Thread.sleep(1000); 36 | } catch (Exception e) { 37 | Timber.e(e); 38 | } 39 | //-- 40 | 41 | JSONObject jsonObject = new JSONObject(); 42 | JSONHelper.put(jsonObject, "result", "success"); 43 | 44 | // send result 45 | AndroidBridge.callFromNative(webview, cbId, "00000", jsonObject.toString()); 46 | }).start(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/sample/webview/bridge/plugin/PluginCamera.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview.bridge.plugin; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.graphics.Bitmap; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | import android.os.Bundle; 10 | import android.webkit.WebView; 11 | 12 | import com.snc.sample.webview.bridge.AndroidBridge; 13 | import com.snc.sample.webview.bridge.plugin.interfaces.Plugin; 14 | import com.snc.zero.dialog.DialogBuilder; 15 | import com.snc.zero.imageprocess.ImageProcess; 16 | import com.snc.zero.media.ImageProvider; 17 | import com.snc.zero.permission.RPermission; 18 | import com.snc.zero.permission.RPermissionListener; 19 | import com.snc.zero.requetcode.RequestCode; 20 | import com.snc.zero.util.BitmapUtil; 21 | import com.snc.zero.util.EnvUtil; 22 | import com.snc.zero.util.FileUtil; 23 | import com.snc.zero.util.IntentUtil; 24 | import com.snc.zero.util.StringUtil; 25 | import com.snc.zero.util.UriUtil; 26 | 27 | import org.json.JSONObject; 28 | 29 | import java.io.File; 30 | import java.io.FileNotFoundException; 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | 34 | import timber.log.Timber; 35 | 36 | @SuppressWarnings({"InstantiationOfUtilityClass", "unused", "RedundantSuppression"}) 37 | public class PluginCamera implements Plugin { 38 | private static final String TAG = PluginCamera.class.getSimpleName(); 39 | 40 | private static final PluginCamera mInstance = new PluginCamera(); 41 | public static PluginCamera getInstance() { 42 | return mInstance; 43 | } 44 | 45 | ///////////////////////////////////////////////// 46 | // Method 47 | 48 | public static void takePicture(WebView webview, JSONObject args, String cbId) { 49 | Timber.i("[WEBVIEW] takePicture : args[" + args + "], cbId[" + cbId + "]"); 50 | List permissions = new ArrayList<>(); 51 | permissions.add(Manifest.permission.CAMERA); 52 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { 53 | permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE); 54 | } 55 | permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); 56 | 57 | // check permission 58 | RPermission.with(webview.getContext()) 59 | .setPermissions(permissions) 60 | .setPermissionListener(new RPermissionListener() { 61 | @Override 62 | public void onPermissionGranted() { 63 | Timber.i("[WEBVIEW] onPermissionGranted()"); 64 | try { 65 | AndroidBridge.setCallbackJSFunctionName(RequestCode.REQUEST_TAKE_A_PICTURE, cbId); 66 | 67 | File storageDir = EnvUtil.getMediaDir(webview.getContext(), "image"); 68 | String filename = FileUtil.newFilename("jpg"); 69 | File file = FileUtil.createFile(storageDir, filename); 70 | if (null == file) { 71 | throw new NullPointerException(); 72 | } 73 | 74 | Uri output = UriUtil.fromFile(webview.getContext(), file); 75 | 76 | if (!FileUtil.delete(file)) { 77 | Timber.e("[WEBVIEW] delete failed..."); 78 | } 79 | 80 | AndroidBridge.setExtraOutput(file); 81 | IntentUtil.imageCaptureWithExtraOutput(webview.getContext(), RequestCode.REQUEST_TAKE_A_PICTURE, output); 82 | 83 | } catch (Exception e) { 84 | Timber.e(e); 85 | DialogBuilder.with(webview.getContext()) 86 | .setMessage(e.toString()) 87 | .show(); 88 | } 89 | } 90 | 91 | @Override 92 | public void onPermissionDenied(List deniedPermissions) { 93 | Timber.w("[WEBVIEW] onPermissionDenied()...%s", deniedPermissions.toString()); 94 | } 95 | 96 | @Override 97 | public void onPermissionRationaleShouldBeShown(List deniedPermissions) { 98 | Timber.e("[WEBVIEW] onPermissionRationaleShouldBeShown()...%s", deniedPermissions.toString()); 99 | } 100 | }) 101 | .check(); 102 | } 103 | 104 | 105 | ///////////////////////////////////////////////// 106 | // Callback 107 | 108 | //++ [[START] Take a picture] 109 | public static void onActivityResultTakePicture(WebView webview, int requestCode, int resultCode, Intent data) { 110 | Timber.i("[WEBVIEW] onActivityResultTakePicture(): requestCode[" + requestCode + "] resultCode[" + resultCode + "] data[" + data + "]"); 111 | if (Activity.RESULT_OK != resultCode) { 112 | return; 113 | } 114 | 115 | try { 116 | if (null != AndroidBridge.getExtraOutput(false)) { 117 | Timber.i("[WEBVIEW] onActivityResultTakePicture(): REQUEST_CODE_TAKE_A_PICTURE (with ExtraOutput)"); 118 | File documentFile = AndroidBridge.getExtraOutput(true); 119 | Uri uri = UriUtil.fromFile(webview.getContext(), documentFile); 120 | 121 | Bitmap bitmap = BitmapUtil.decodeBitmap(webview.getContext(), documentFile, 2048); 122 | DialogBuilder.with(webview.getContext()) 123 | .setBitmap(bitmap) 124 | .show(); 125 | 126 | String base64String = ImageProcess.toBase64String(documentFile); 127 | try { 128 | uri = ImageProvider.insert(webview.getContext(), documentFile); 129 | if (EnvUtil.isFilesDir(webview.getContext(), documentFile)) { 130 | if (null != uri) { 131 | if (!documentFile.delete()) { 132 | Timber.e("delete failed..."); 133 | } 134 | } 135 | } 136 | } catch (FileNotFoundException e) { 137 | Timber.e(e); 138 | } 139 | 140 | AndroidBridge.callJSFunction(webview, AndroidBridge.getCallbackJSFunctionName(requestCode), StringUtil.nvl(uri, ""), base64String); 141 | } 142 | else if (null != data) { 143 | Timber.i("[WEBVIEW] onActivityResultTakePicture(): REQUEST_CODE_TAKE_A_PICTURE (with Intent)"); 144 | String params = null; 145 | Bitmap bitmap = null; 146 | if ("inline-data".equals(data.getAction())) { 147 | Bundle extras = data.getExtras(); 148 | if (null != extras) { 149 | bitmap = (Bitmap) extras.get("data"); 150 | if (null != bitmap) { 151 | params = bitmap.toString(); 152 | } 153 | } 154 | } else if (null != data.getData()) { 155 | Uri uri = data.getData(); 156 | params = StringUtil.nvl(uri, ""); 157 | } 158 | 159 | AndroidBridge.callJSFunction(webview, AndroidBridge.getCallbackJSFunctionName(requestCode), params); 160 | 161 | if (null != bitmap) { 162 | DialogBuilder.with(webview.getContext()) 163 | .setBitmap(bitmap) 164 | .show(); 165 | } 166 | } 167 | 168 | } catch (Exception e) { 169 | DialogBuilder.with(webview.getContext()) 170 | .setMessage(e.toString()) 171 | .show(); 172 | } 173 | } 174 | //-- [[E N D] Take a picture] 175 | 176 | } 177 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/sample/webview/bridge/plugin/interfaces/Plugin.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview.bridge.plugin.interfaces; 2 | 3 | public interface Plugin { 4 | } 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/sample/webview/network/DynamicUrlService.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview.network; 2 | 3 | import okhttp3.ResponseBody; 4 | import retrofit2.Call; 5 | import retrofit2.http.GET; 6 | import retrofit2.http.Url; 7 | 8 | /** 9 | * Dynamic URLs for Requests 10 | * 11 | * @author mcharima5@gmail.com 12 | * @since 2020 13 | */ 14 | public interface DynamicUrlService { 15 | 16 | @GET 17 | Call get(@Url String url); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/sample/webview/network/RetrofitDynamicUrlClient.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview.network; 2 | 3 | import android.net.Uri; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import okhttp3.ResponseBody; 8 | import retrofit2.Call; 9 | import retrofit2.Callback; 10 | import retrofit2.Response; 11 | import retrofit2.Retrofit; 12 | import timber.log.Timber; 13 | 14 | /** 15 | * Retrofit Client 16 | * 17 | * @author mcharima5@gmail.com 18 | * @since 2020 19 | */ 20 | public class RetrofitDynamicUrlClient { 21 | 22 | public static void get(String urlString, Callback listener) { 23 | Uri uri = Uri.parse(filter(urlString)); 24 | 25 | Retrofit retrofit = new Retrofit.Builder() 26 | .baseUrl(uri.getScheme() + "://" + uri.getAuthority()) // Base URL required. 27 | .build(); 28 | 29 | DynamicUrlService service = retrofit.create(DynamicUrlService.class); 30 | 31 | Timber.i("[Retrofit GET] Request = %s", urlString); 32 | Call call = service.get(urlString); 33 | 34 | callAsync(call, listener); 35 | } 36 | 37 | private static void callAsync(Call call, Callback listener) { 38 | call.enqueue(new Callback() { 39 | @Override 40 | public void onResponse(@NotNull Call call, @NotNull Response response) { 41 | Timber.i("[Retrofit] onResponse() = response code is %s", response.code()); 42 | 43 | if (null != listener) { 44 | listener.onResponse(call, response); 45 | } 46 | } 47 | 48 | @Override 49 | public void onFailure(@NotNull Call call, @NotNull Throwable t) { 50 | Timber.e(t); 51 | 52 | if (null != listener) { 53 | listener.onFailure(call, t); 54 | } 55 | } 56 | }); 57 | } 58 | 59 | private static String filter(String urlString) { 60 | Uri uri = Uri.parse(urlString); 61 | return uri.getScheme().replaceAll("[^a-zA-Z:/]", "") + "://" + 62 | uri.getAuthority() + 63 | uri.getPath() + 64 | ((null != uri.getQuery()) ? "?" + uri.getQuery() : "") + 65 | ((null != uri.getFragment()) ? "?" + uri.getFragment() : ""); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/sample/webview/webview/WebViewHelper.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview.webview; 2 | 3 | import android.Manifest; 4 | import android.annotation.SuppressLint; 5 | import android.content.Context; 6 | import android.content.pm.PackageManager; 7 | import android.os.Build; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.webkit.WebSettings; 11 | import android.webkit.WebView; 12 | 13 | import com.snc.sample.webview.BuildConfig; 14 | import com.snc.zero.permission.RPermissionListener; 15 | import com.snc.zero.permission.RPermission; 16 | import com.snc.zero.util.PackageUtil; 17 | 18 | import java.util.ArrayList; 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | import timber.log.Timber; 24 | 25 | /** 26 | * WebView Helper 27 | * 28 | * @author mcharima5@gmail.com 29 | * @since 2018 30 | */ 31 | public class WebViewHelper { 32 | private static final String SCHEME_HTTP = "http://"; 33 | private static final String SCHEME_HTTPS = "https://"; 34 | private static final String SCHEME_FILE = "file://"; 35 | private static final String SCHEME_ASSET = "file:///android_asset"; 36 | private static final String SCHEME_ASSET_API30 = SCHEME_HTTPS + BuildConfig.ASSET_BASE_DOMAIN + BuildConfig.ASSET_PATH; 37 | private static final String SCHEME_RES = "file:///android_res"; 38 | private static final String SCHEME_RES_API30 = SCHEME_HTTPS + BuildConfig.ASSET_BASE_DOMAIN + BuildConfig.RES_PATH; 39 | 40 | public static WebView addWebView(Context context, ViewGroup parentView) { 41 | WebView webView = newWebView(context); 42 | parentView.addView(webView); 43 | return webView; 44 | } 45 | 46 | public static void removeWebView(WebView webView) { 47 | if (null != webView) { 48 | webView.setWebChromeClient(null); 49 | webView.setWebViewClient(null); 50 | webView.destroy(); 51 | } 52 | } 53 | 54 | private static WebView newWebView(Context context) { 55 | WebView webView = new WebView(context); 56 | ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( 57 | ViewGroup.LayoutParams.MATCH_PARENT, 58 | ViewGroup.LayoutParams.MATCH_PARENT); 59 | webView.setLayoutParams(params); 60 | //webView.setBackgroundColor(Color.TRANSPARENT); 61 | //webView.setBackgroundResource(android.R.color.white); 62 | 63 | // setup 64 | setup(webView); 65 | 66 | return webView; 67 | } 68 | 69 | @SuppressLint({"SetJavaScriptEnabled", "JavascriptInterface", "AddJavascriptInterface"}) 70 | private static void setup(WebView webView) { 71 | WebSettings settings = webView.getSettings(); 72 | 73 | webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); 74 | webView.setInitialScale(0); // 75 | webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); 76 | webView.setScrollbarFadingEnabled(true); 77 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 78 | webView.setRendererPriorityPolicy(WebView.RENDERER_PRIORITY_BOUND, true); 79 | } 80 | settings.setAllowFileAccess(true); 81 | settings.setAllowContentAccess(true); 82 | settings.setAllowFileAccessFromFileURLs(true); 83 | settings.setAllowUniversalAccessFromFileURLs(true); 84 | settings.setBlockNetworkImage(false); 85 | settings.setBlockNetworkLoads(false); 86 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 87 | settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); 88 | } 89 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 90 | settings.setSafeBrowsingEnabled(false); 91 | } 92 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 93 | settings.setDisabledActionModeMenuItems(WebSettings.MENU_ITEM_NONE); 94 | } 95 | settings.setJavaScriptEnabled(true); 96 | settings.setJavaScriptCanOpenWindowsAutomatically(false); 97 | settings.setCacheMode(WebSettings.LOAD_NO_CACHE); 98 | settings.setDatabaseEnabled(true); 99 | settings.setDomStorageEnabled(true); 100 | settings.setLoadsImagesAutomatically(true); 101 | settings.setLoadWithOverviewMode(false); 102 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 103 | settings.setOffscreenPreRaster(false); 104 | } 105 | settings.setSupportMultipleWindows(true); 106 | settings.setUseWideViewPort(true); 107 | settings.setSupportZoom(true); 108 | settings.setBuiltInZoomControls(true); 109 | settings.setDisplayZoomControls(false); 110 | //settings.setTextZoom(100); 111 | settings.setGeolocationEnabled(true); 112 | settings.setDefaultTextEncodingName("utf-8"); 113 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 114 | settings.setMediaPlaybackRequiresUserGesture(true); // The default is true. Added in API level 17 115 | } 116 | settings.setNeedInitialFocus(true); 117 | settings.setUserAgentString(makeUserAgent(webView)); 118 | } 119 | 120 | public static String makeUserAgent(WebView webView) { 121 | String ua = webView.getSettings().getUserAgentString(); 122 | try { 123 | ua += !ua.endsWith(" ") ? " " : ""; 124 | ua += PackageUtil.getApplicationName(webView.getContext()); 125 | ua += "/" + PackageUtil.getPackageVersionName(webView.getContext()); 126 | ua += "." + PackageUtil.getPackageVersionCode(webView.getContext()); 127 | return ua; 128 | } catch (PackageManager.NameNotFoundException e) { 129 | Timber.e(e); 130 | } 131 | return ua; 132 | } 133 | 134 | public static String getLocalBaseUrl(String type) { 135 | if ("assets".equals(type)) { 136 | if (BuildConfig.FEATURE_WEBVIEW_ASSET_LOADER) { 137 | return SCHEME_ASSET_API30; 138 | } 139 | return SCHEME_ASSET; 140 | } 141 | else if ("res".equals(type)) { 142 | if (BuildConfig.FEATURE_WEBVIEW_ASSET_LOADER) { 143 | return SCHEME_RES_API30; 144 | } 145 | return SCHEME_RES; 146 | } 147 | return ""; 148 | } 149 | 150 | public static void loadUrl(final WebView webView, final String uriString) { 151 | final Map extraHeaders = new HashMap<>(); 152 | //extraHeaders.put("Platform", "A"); 153 | 154 | if (uriString.startsWith(SCHEME_HTTP) || uriString.startsWith(SCHEME_HTTPS) 155 | || uriString.startsWith(SCHEME_ASSET) || uriString.startsWith(SCHEME_ASSET_API30)) { 156 | webView.loadUrl(uriString, extraHeaders); 157 | } 158 | else if (uriString.startsWith(SCHEME_FILE)) { 159 | List permissions = new ArrayList<>(); 160 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { 161 | // Dangerous Permission 162 | permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE); 163 | } 164 | 165 | RPermission.with(webView.getContext()) 166 | .setPermissions(permissions) 167 | .setPermissionListener(new RPermissionListener() { 168 | @Override 169 | public void onPermissionGranted() { 170 | Timber.i("[WEBVIEW] onPermissionGranted()"); 171 | webView.loadUrl(uriString, extraHeaders); 172 | } 173 | 174 | @Override 175 | public void onPermissionDenied(List deniedPermissions) { 176 | Timber.w("[WEBVIEW] onPermissionDenied()...%s", deniedPermissions.toString()); 177 | } 178 | 179 | @Override 180 | public void onPermissionRationaleShouldBeShown(List deniedPermissions) { 181 | Timber.w("[WEBVIEW] onPermissionRationaleShouldBeShown()...%s", deniedPermissions.toString()); 182 | } 183 | }) 184 | .check(); 185 | } 186 | } 187 | 188 | } 189 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/activity/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.activity; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import androidx.appcompat.app.AppCompatActivity; 6 | 7 | /** 8 | * Abstract base activity 9 | * 10 | * @author mcharima5@gmail.com 11 | * @since 2018 12 | */ 13 | public abstract class BaseActivity extends AppCompatActivity { 14 | 15 | protected Context getContext() { 16 | return this; 17 | } 18 | 19 | protected Activity getActivity() { 20 | return this; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/application/SNCApplication.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.application; 2 | 3 | import android.content.Context; 4 | 5 | import com.snc.sample.webview.BuildConfig; 6 | 7 | import androidx.multidex.MultiDexApplication; 8 | import timber.log.Timber; 9 | 10 | /** 11 | * Application 12 | * 13 | * @author mcharima5@gmail.com 14 | * @since 2018 15 | */ 16 | public class SNCApplication extends MultiDexApplication { 17 | private static final String TAG = SNCApplication.class.getSimpleName(); 18 | 19 | @Override 20 | protected void attachBaseContext(Context base) { 21 | Timber.plant(new Timber.DebugTree()); 22 | super.attachBaseContext(base); 23 | } 24 | 25 | @Override 26 | public void onCreate() { 27 | Timber.i(TAG, ">>>>>>>>>> onCreate <<<<<<<<<<"); 28 | super.onCreate(); 29 | } 30 | 31 | @Override 32 | public void onLowMemory() { 33 | Timber.i(">>>>>>>>>> onLowMemory <<<<<<<<<<"); 34 | super.onLowMemory(); 35 | } 36 | 37 | @Override 38 | public void onTrimMemory(int level) { 39 | Timber.i(">>>>>>>>>> onTrimMemory(" + level + ") <<<<<<<<<<"); 40 | super.onTrimMemory(level); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/dialog/DialogBuilder.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.dialog; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.app.Dialog; 6 | import android.content.Context; 7 | import android.content.DialogInterface; 8 | import android.graphics.Bitmap; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.ImageView; 12 | import android.widget.Toast; 13 | 14 | import com.snc.zero.util.StringUtil; 15 | 16 | import timber.log.Timber; 17 | 18 | /** 19 | * Dialog Helper 20 | * 21 | * @author mcharima5@gmail.com 22 | * @since 2019 23 | */ 24 | public class DialogBuilder { 25 | public static DialogBuilder with(Context context) { 26 | return new DialogBuilder((Activity) context); 27 | } 28 | 29 | public static DialogBuilder with(Activity activity) { 30 | return new DialogBuilder(activity); 31 | } 32 | 33 | private final Activity activity; 34 | private String title; 35 | private String message; 36 | private View view; 37 | private Bitmap bitmap; 38 | private CharSequence positiveButtonText; 39 | private DialogInterface.OnClickListener positiveButtonListener; 40 | private CharSequence negativeButtonText; 41 | private DialogInterface.OnClickListener negativeButtonListener; 42 | private CharSequence neutralButtonText; 43 | private DialogInterface.OnClickListener neutralButtonListener; 44 | 45 | public DialogBuilder(Activity activity) { 46 | this.activity = activity; 47 | } 48 | 49 | public DialogBuilder setTitle(String title) { 50 | this.title = title; 51 | return this; 52 | } 53 | 54 | public DialogBuilder setMessage(String message) { 55 | this.message = message; 56 | return this; 57 | } 58 | 59 | public DialogBuilder setView(View view) { 60 | this.view = view; 61 | return this; 62 | } 63 | 64 | public DialogBuilder setBitmap(Bitmap bitmap) { 65 | this.bitmap = bitmap; 66 | return this; 67 | } 68 | 69 | public DialogBuilder setPositiveButton(CharSequence text, final DialogInterface.OnClickListener listener) { 70 | this.positiveButtonText = text; 71 | this.positiveButtonListener = listener; 72 | return this; 73 | } 74 | public DialogBuilder setPositiveButton(int resId, final DialogInterface.OnClickListener listener) { 75 | return setPositiveButton(activity.getResources().getString(resId), listener); 76 | } 77 | 78 | public DialogBuilder setNegativeButton(CharSequence text, final DialogInterface.OnClickListener listener) { 79 | this.negativeButtonText = text; 80 | this.negativeButtonListener = listener; 81 | return this; 82 | } 83 | public DialogBuilder setNegativeButton(int resId, final DialogInterface.OnClickListener listener) { 84 | return setNegativeButton(activity.getResources().getString(resId), listener); 85 | } 86 | 87 | @SuppressWarnings("UnusedReturnValue") 88 | public DialogBuilder setNeutralButton(CharSequence text, final DialogInterface.OnClickListener listener) { 89 | this.neutralButtonText = text; 90 | this.neutralButtonListener = listener; 91 | return this; 92 | } 93 | public DialogBuilder setNeutralButton(int resId, final DialogInterface.OnClickListener listener) { 94 | return setNeutralButton(activity.getResources().getString(resId), listener); 95 | } 96 | 97 | public void toast() { 98 | try { 99 | Toast toast = Toast.makeText(activity, StringUtil.nvl(message, ""), Toast.LENGTH_SHORT); 100 | toast.show(); 101 | 102 | } catch (Exception e) { 103 | Timber.w(e); 104 | } 105 | } 106 | 107 | public void show() { 108 | try { 109 | if (activity.isFinishing()) { 110 | Timber.e("activity is finished."); 111 | return; 112 | } 113 | 114 | AlertDialog.Builder builder = new AlertDialog.Builder(activity); 115 | if (null != title) { 116 | builder.setTitle(title); 117 | } 118 | if (null != message) { 119 | builder.setMessage(message); 120 | } 121 | if (null != view) { 122 | builder.setView(view); 123 | } 124 | if (null != bitmap) { 125 | ImageView iv = new ImageView(this.activity); 126 | ViewGroup.LayoutParams params = iv.getLayoutParams(); 127 | if (null == params) { 128 | params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 129 | } 130 | iv.setLayoutParams(params); 131 | iv.setImageBitmap(bitmap); 132 | builder.setView(iv); 133 | } 134 | if (null != positiveButtonListener) { 135 | builder.setPositiveButton(positiveButtonText, positiveButtonListener); 136 | } 137 | if (null != negativeButtonListener) { 138 | builder.setNegativeButton(negativeButtonText, negativeButtonListener); 139 | } 140 | if (null != neutralButtonListener) { 141 | builder.setNeutralButton(neutralButtonText, neutralButtonListener); 142 | } 143 | if (null == positiveButtonListener && null == negativeButtonListener && null == neutralButtonListener) { 144 | builder.setNegativeButton(android.R.string.ok, (dialog, which) -> { 145 | 146 | }); 147 | } 148 | 149 | builder.setCancelable(false); 150 | 151 | Dialog dialog = builder.show(); 152 | dialog.setCanceledOnTouchOutside(false); 153 | 154 | } catch (android.view.WindowManager.BadTokenException e) { 155 | Timber.e(e); 156 | } 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/dialog/DialogHelper.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.dialog; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.app.Dialog; 6 | import android.content.Context; 7 | import android.content.DialogInterface; 8 | import android.graphics.Bitmap; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.ImageView; 12 | import android.widget.Toast; 13 | 14 | import timber.log.Timber; 15 | 16 | /** 17 | * Dialog Helper 18 | * 19 | * @author mcharima5@gmail.com 20 | * @since 2018 21 | */ 22 | public class DialogHelper { 23 | 24 | public static void alert(Activity activity, String message) { 25 | alert(activity, "", message, android.R.string.ok, 26 | (dialog, which) -> { 27 | 28 | }); 29 | } 30 | 31 | public static void alert(Activity activity, String title, String message, int resId, DialogInterface.OnClickListener listener) { 32 | try { 33 | AlertDialog.Builder builder = new AlertDialog.Builder(activity); 34 | builder.setTitle(title); 35 | builder.setMessage(message); 36 | builder.setView(null); 37 | builder.setNegativeButton(activity.getResources().getString(resId), listener); 38 | builder.setCancelable(true); 39 | 40 | Dialog dialog = builder.show(); 41 | dialog.setCanceledOnTouchOutside(false); 42 | 43 | } catch (android.view.WindowManager.BadTokenException e) { 44 | Timber.e(e); 45 | } 46 | } 47 | 48 | public static void alert(Activity activity, View view) { 49 | try { 50 | AlertDialog.Builder builder = new AlertDialog.Builder(activity); 51 | builder.setView(view); 52 | builder.setNegativeButton(activity.getResources().getString(android.R.string.ok), (dialog, which) -> { 53 | 54 | }); 55 | builder.setCancelable(true); 56 | 57 | Dialog dialog = builder.show(); 58 | dialog.setCanceledOnTouchOutside(false); 59 | 60 | } catch (android.view.WindowManager.BadTokenException e) { 61 | Timber.e(e); 62 | } 63 | } 64 | 65 | public static void alert(Context context, Bitmap bitmap) { 66 | ImageView iv = new ImageView(context); 67 | ViewGroup.LayoutParams params = iv.getLayoutParams(); 68 | if (null == params) { 69 | params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 70 | } 71 | iv.setLayoutParams(params); 72 | iv.setImageBitmap(bitmap); 73 | 74 | DialogHelper.alert((Activity) context, iv); 75 | } 76 | 77 | public static void toast(Context context, String message) { 78 | try { 79 | if (context instanceof Activity) { 80 | if (((Activity) context).isFinishing()) { 81 | return; 82 | } 83 | } 84 | Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); 85 | toast.show(); 86 | 87 | } catch (Exception e) { 88 | Timber.w(e); 89 | } 90 | } 91 | 92 | } -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/download/CSDownloadManager.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.download; 2 | 3 | import android.Manifest; 4 | import android.app.DownloadManager; 5 | import android.content.BroadcastReceiver; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.content.IntentFilter; 9 | import android.database.Cursor; 10 | import android.net.Uri; 11 | import android.os.Build; 12 | import android.os.Environment; 13 | 14 | import com.snc.zero.dialog.DialogBuilder; 15 | import com.snc.zero.mimetype.MimeType; 16 | import com.snc.zero.permission.RPermissionListener; 17 | import com.snc.zero.permission.RPermission; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import timber.log.Timber; 23 | 24 | /** 25 | * Download Manager 26 | * 27 | * @author mcharima5@gmail.com 28 | * @since 2020 29 | */ 30 | public class CSDownloadManager { 31 | private long mDownloadId; 32 | 33 | public void download(Context context, String urlString) { 34 | List permissions = new ArrayList<>(); 35 | 36 | if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) { 37 | permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); // android:maxSdkVersion="28" 38 | } 39 | 40 | if (RPermission.isGranted(context, permissions)) { 41 | downloadIt(context, urlString); 42 | return; 43 | } 44 | 45 | // check permission 46 | RPermission.with(context) 47 | .setPermissions(permissions) 48 | .setPermissionListener(new RPermissionListener() { 49 | @Override 50 | public void onPermissionGranted() { 51 | Timber.i("[CSDownloadManager] onPermissionGranted()"); 52 | downloadIt(context, urlString); 53 | } 54 | 55 | @Override 56 | public void onPermissionDenied(List deniedPermissions) { 57 | Timber.w("[CSDownloadManager] onPermissionDenied()...%s", deniedPermissions.toString()); 58 | 59 | DialogBuilder.with(context) 60 | .setMessage("Permission denied !!!") 61 | .toast(); 62 | } 63 | 64 | @Override 65 | public void onPermissionRationaleShouldBeShown(List deniedPermissions) { 66 | Timber.w("[WEBVIEW] onPermissionRationaleShouldBeShown()...%s", deniedPermissions.toString()); 67 | } 68 | }) 69 | .check(); 70 | } 71 | 72 | private void downloadIt(Context context, String urlString) { 73 | try { 74 | DownloadManager.Request request = new DownloadManager.Request(Uri.parse(urlString)); 75 | //request.allowScanningByMediaScanner(); // Deprecated 76 | request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 77 | 78 | int lastIdx = urlString.lastIndexOf("/"); 79 | String fileName = urlString.substring(lastIdx); 80 | request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); 81 | request.setMimeType(MimeType.getMimeFromFileName(fileName)); 82 | 83 | registerDownloadReceiver(context); 84 | 85 | DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); 86 | mDownloadId = manager.enqueue(request); 87 | 88 | } catch (Exception e) { 89 | Timber.e(e); 90 | 91 | DialogBuilder.with(context) 92 | .setMessage(e.toString()) 93 | .show(); 94 | } 95 | } 96 | 97 | private void registerDownloadReceiver(Context context) { 98 | try { 99 | DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); 100 | IntentFilter intentFilter = new IntentFilter(); 101 | intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE); 102 | context.registerReceiver(new BroadcastReceiver() { 103 | @Override 104 | public void onReceive(final Context context, final Intent intent) { 105 | if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) { 106 | long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); 107 | if (mDownloadId == id) { 108 | DownloadManager.Query query = new DownloadManager.Query(); 109 | query.setFilterById(id); 110 | Cursor cursor = manager.query(query); 111 | if (!cursor.moveToFirst()) { 112 | return; 113 | } 114 | 115 | int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); 116 | int status = cursor.getInt(columnIndex); 117 | if (status == DownloadManager.STATUS_SUCCESSFUL) { 118 | DialogBuilder.with(context) 119 | .setMessage("download success") 120 | .toast(); 121 | } else if (status == DownloadManager.STATUS_FAILED) { 122 | DialogBuilder.with(context) 123 | .setMessage("download failed") 124 | .toast(); 125 | } 126 | 127 | unregisterDownloadReceiver(context, this); 128 | } 129 | } 130 | } 131 | }, intentFilter); 132 | 133 | } catch (Exception e) { 134 | Timber.e(e); 135 | } 136 | } 137 | 138 | private void unregisterDownloadReceiver(Context context, BroadcastReceiver receiver) { 139 | context.unregisterReceiver(receiver); 140 | } 141 | 142 | } -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/imageprocess/ImageProcess.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.imageprocess; 2 | 3 | import android.os.Build; 4 | 5 | import com.snc.zero.util.IOUtil; 6 | 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.File; 9 | import java.io.FileInputStream; 10 | import java.io.IOException; 11 | import java.util.Base64; 12 | 13 | /** 14 | * Image Process 15 | * @author mcharima5@gmail.com 16 | * @since 2016 17 | */ 18 | public class ImageProcess { 19 | 20 | public static String toBase64String(File file) throws IOException { 21 | ByteArrayOutputStream bos; 22 | FileInputStream fis = null; 23 | try { 24 | fis = new FileInputStream(file); 25 | int fileLength = (int) file.length(); 26 | bos = new ByteArrayOutputStream(fileLength); 27 | 28 | final byte[] buff = new byte[4096]; 29 | while (true) { 30 | int len = fis.read(buff, 0, buff.length); 31 | if (len == -1) { 32 | break; 33 | } 34 | bos.write(buff, 0, buff.length); 35 | } 36 | byte[] bytes = bos.toByteArray(); 37 | 38 | byte[] encode; 39 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 40 | encode = Base64.getEncoder().encode(bytes); 41 | } else { 42 | encode = android.util.Base64.encode(bytes, android.util.Base64.DEFAULT); 43 | } 44 | return new String(encode); 45 | } 46 | catch (Exception e) { 47 | throw new IOException("Exception: " + e); 48 | } 49 | finally { 50 | IOUtil.closeQuietly(fis); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/json/JSONHelper.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.json; 2 | 3 | import android.text.TextUtils; 4 | 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | 8 | import timber.log.Timber; 9 | 10 | /** 11 | * JSONObject Helper 12 | * 13 | * @author mcharima5@gmail.com 14 | * @since 2018 15 | */ 16 | public class JSONHelper { 17 | 18 | public static String getString(JSONObject jsonObject, String key, String defaultValue) { 19 | if (isNull(jsonObject, key) || !has(jsonObject, key)) { 20 | return defaultValue; 21 | } 22 | return jsonObject.optString(key, defaultValue); 23 | } 24 | 25 | public static JSONObject getJSONObject(JSONObject jsonObject, String key, JSONObject defaultValue) { 26 | if (isNull(jsonObject, key) || !has(jsonObject, key)) { 27 | return defaultValue; 28 | } 29 | 30 | return jsonObject.optJSONObject(key); 31 | } 32 | 33 | public static void put(JSONObject jsonObject, String key, String value) { 34 | try { 35 | jsonObject.put(key, value); 36 | } catch (JSONException e) { 37 | Timber.e(e); 38 | } 39 | } 40 | 41 | private static boolean has(JSONObject jsonObject, String key) { 42 | if (null == jsonObject || null == key || key.length() <= 0) { 43 | return true; 44 | } 45 | return jsonObject.has(key); 46 | } 47 | 48 | private static boolean isNull(JSONObject jsonObject, String key) { 49 | if (null == jsonObject || TextUtils.isEmpty(key)) { 50 | return false; 51 | } 52 | return jsonObject.isNull(key); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/keyevent/BackKeyShutdown.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.keyevent; 2 | 3 | import android.os.Handler; 4 | import android.os.Looper; 5 | import android.view.KeyEvent; 6 | 7 | /** 8 | * BackKey 9 | * 10 | * @author mcharima5@gmail.com 11 | * @since 2018 12 | */ 13 | public class BackKeyShutdown { 14 | 15 | private static final int PRESS_BACK_KEY_INTERVAL = 2000; 16 | 17 | private static final Handler handler = new Handler(Looper.getMainLooper()); 18 | 19 | private static int backKeyPressedCount = 0; 20 | private static final Runnable callbackBackKeyCancel = () -> backKeyPressedCount = 0; 21 | 22 | public static boolean isFirstBackKeyPress(int keyCode, KeyEvent event) { 23 | if (KeyEvent.ACTION_DOWN == event.getAction()) { 24 | // press back key 25 | if (KeyEvent.KEYCODE_BACK == keyCode) { 26 | // first time 27 | if (backKeyPressedCount <= 0) { 28 | backKeyPressedCount = 1; 29 | 30 | handler.removeCallbacks(callbackBackKeyCancel); 31 | handler.postDelayed(callbackBackKeyCancel, PRESS_BACK_KEY_INTERVAL); 32 | return true; 33 | } 34 | } 35 | } 36 | return false; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/media/ImageProvider.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.media; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.net.Uri; 6 | import android.os.Build; 7 | import android.provider.MediaStore; 8 | 9 | import com.snc.zero.mimetype.MimeType; 10 | 11 | import java.io.File; 12 | import java.io.FileNotFoundException; 13 | 14 | /** 15 | * Image Provider 16 | * 17 | * @author mcharima5@gmail.com 18 | * @since 2020 19 | */ 20 | public class ImageProvider extends MediaStoreProvider { 21 | 22 | public static Uri insert(Context context, File file) throws FileNotFoundException { 23 | ContentValues values = new ContentValues(); 24 | values.put(MediaStore.Images.Media.DISPLAY_NAME, file.getName()); 25 | values.put(MediaStore.Images.Media.MIME_TYPE, MimeType.getMimeFromFileName(file.getName())); 26 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { 27 | values.put(MediaStore.Images.Media.IS_PENDING, 1); 28 | } 29 | 30 | Uri uri; 31 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { 32 | uri = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY); 33 | } else { 34 | uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 35 | } 36 | 37 | return insert(context, uri, values, file, (contentResolver, values1, item1) -> { 38 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { 39 | values1.clear(); 40 | values1.put(MediaStore.Images.Media.IS_PENDING, 0); 41 | contentResolver.update(item1, values1, null, null); 42 | } 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/media/MediaStoreProvider.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.media; 2 | 3 | import android.content.ContentResolver; 4 | import android.content.ContentValues; 5 | import android.content.Context; 6 | import android.net.Uri; 7 | import android.os.Build; 8 | import android.os.ParcelFileDescriptor; 9 | 10 | import com.snc.zero.util.FileUtil; 11 | import com.snc.zero.util.MediaUtil; 12 | 13 | import java.io.File; 14 | import java.io.FileInputStream; 15 | import java.io.FileNotFoundException; 16 | import java.io.FileOutputStream; 17 | import java.io.IOException; 18 | 19 | /** 20 | * MediaStore Provider 21 | * 22 | * @author mcharima5@gmail.com 23 | * @since 2020 24 | */ 25 | public class MediaStoreProvider { 26 | 27 | public static Uri insert(Context context, Uri contentUri, ContentValues values, File file, MediaInsertListener listener) throws FileNotFoundException { 28 | ContentResolver contentResolver = MediaUtil.getContentResolver(context); 29 | 30 | Uri item = contentResolver.insert(contentUri, values); 31 | 32 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 33 | ParcelFileDescriptor fileDesc = contentResolver.openFileDescriptor(item, "w", null); 34 | 35 | FileInputStream fis = new FileInputStream(file); 36 | FileOutputStream fos = new FileOutputStream(fileDesc.getFileDescriptor()); 37 | try { 38 | FileUtil.write(fis, fos); 39 | } catch (IOException e) { 40 | return null; 41 | } 42 | } 43 | 44 | if (null != listener) { 45 | listener.onAfter(contentResolver, values, item); 46 | } 47 | 48 | return item; 49 | } 50 | 51 | public interface MediaInsertListener { 52 | void onAfter(ContentResolver contentResolver, ContentValues values, Uri item); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/mimetype/MimeType.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.mimetype; 2 | 3 | import android.webkit.MimeTypeMap; 4 | 5 | /** 6 | * MimeType 7 | * 8 | * @author mcharima5@gmail.com 9 | * @since 2020 10 | */ 11 | public class MimeType { 12 | 13 | public static String getMimeFromFileName(String fileName) { 14 | MimeTypeMap map = MimeTypeMap.getSingleton(); 15 | String ext = MimeTypeMap.getFileExtensionFromUrl(fileName); 16 | return map.getMimeTypeFromExtension(ext); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/permission/RPermission.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.permission; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.pm.PackageManager; 6 | 7 | import com.gun0912.tedpermission.PermissionListener; 8 | import com.gun0912.tedpermission.normal.TedPermission; 9 | 10 | import java.util.List; 11 | 12 | import androidx.annotation.NonNull; 13 | import androidx.core.app.ActivityCompat; 14 | import androidx.core.content.ContextCompat; 15 | 16 | public class RPermission { 17 | //private static final String TAG = RPermission.class.getSimpleName(); 18 | 19 | public static RPermission with(Context context) { 20 | return new RPermission(context); 21 | } 22 | 23 | private final Context context; 24 | private String[] permissions; 25 | private RPermissionListener listener; 26 | 27 | public RPermission(Context context) { 28 | this.context = context; 29 | } 30 | 31 | public RPermission setPermissionListener(RPermissionListener listener) { 32 | this.listener = listener; 33 | return this; 34 | } 35 | 36 | public RPermission setPermissions(List permissions) { 37 | this.permissions = permissions.toArray(new String[] {}); 38 | return this; 39 | } 40 | 41 | public RPermission setPermissions(String...permissions) { 42 | this.permissions = permissions; 43 | return this; 44 | } 45 | 46 | public void check() { 47 | TedPermission.create() 48 | .setPermissionListener(new PermissionListener() { 49 | @Override 50 | public void onPermissionGranted() { 51 | if (null != listener) { 52 | listener.onPermissionGranted(); 53 | } 54 | } 55 | 56 | @Override 57 | public void onPermissionDenied(List deniedPermissions) { 58 | if (null != listener) { 59 | if (!shouldShowRequestPermissionRationale(deniedPermissions)) { 60 | listener.onPermissionDenied(deniedPermissions); 61 | } else { 62 | listener.onPermissionDenied(deniedPermissions); 63 | } 64 | } 65 | } 66 | }) 67 | //.setDeniedMessage("If you reject permission,you can not use this service\n\nPlease turn on permissions at [Setting] > [Permission]") 68 | .setPermissions(permissions) 69 | .check(); 70 | } 71 | 72 | public static boolean isGranted(Context context, @NonNull List permissions) { 73 | return isGranted(context, permissions.toArray(new String[] {})); 74 | } 75 | 76 | public static boolean isGranted(Context context, @NonNull String... permissions) { 77 | for (String permission : permissions) { 78 | if (isDenied(context, permission)) { 79 | return false; 80 | } 81 | } 82 | return true; 83 | } 84 | 85 | private static boolean isGranted(Context context, @NonNull String permission) { 86 | return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; 87 | } 88 | 89 | public static boolean isDenied(Context context, @NonNull String permission) { 90 | return ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED; 91 | } 92 | 93 | public boolean shouldShowRequestPermissionRationale(List needPermissions) { 94 | if (null == needPermissions) { 95 | return false; 96 | } 97 | 98 | for (String permission : needPermissions) { 99 | if (!ActivityCompat.shouldShowRequestPermissionRationale((Activity) this.context, permission)) { 100 | return false; 101 | } 102 | } 103 | return true; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/permission/RPermissionListener.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.permission; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * (TedPermission Style) Interface 7 | */ 8 | public interface RPermissionListener { 9 | 10 | void onPermissionGranted(); 11 | 12 | void onPermissionDenied(List deniedPermissions); 13 | 14 | void onPermissionRationaleShouldBeShown(List deniedPermissions); 15 | 16 | } -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/reflect/ReflectHelper.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.reflect; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | 6 | /** 7 | * Reflect Helper 8 | * 9 | * @author mcharima5@gmail.com 10 | * @since 2018 11 | */ 12 | public class ReflectHelper { 13 | 14 | public static Method getMethod(Object instance, String methodName) throws IllegalArgumentException { 15 | Method[] methods = instance.getClass().getDeclaredMethods(); 16 | for (Method method : methods) { 17 | if (methodName.equals(method.getName())) { 18 | return method; 19 | } 20 | } 21 | return null; 22 | } 23 | 24 | public static void invoke(Object instance, Method method, Object...param) throws InvocationTargetException, IllegalAccessException { 25 | if (null == instance) { 26 | return; 27 | } 28 | method.setAccessible(true); 29 | method.invoke(instance, param); 30 | method.setAccessible(false); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/requetcode/RequestCode.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.requetcode; 2 | 3 | /** 4 | * Request Code 5 | * 6 | * @author mcharima5@gmail.com 7 | * @since 2018 8 | */ 9 | public class RequestCode { 10 | // Mask 11 | private static final int REQUEST_CODE_MASK = 0x0000FFFF; 12 | 13 | //++ [[START] File Chooser] 14 | public static final int REQUEST_FILE_CHOOSER_NORMAL = 0xA101 & REQUEST_CODE_MASK; 15 | public static final int REQUEST_FILE_CHOOSER_LOLLIPOP = 0xA102 & REQUEST_CODE_MASK; 16 | //-- [[E N D] File Chooser] 17 | 18 | //++ [[START] Take a picture] 19 | public static final int REQUEST_TAKE_A_PICTURE = 0xA201 & REQUEST_CODE_MASK; 20 | //-- [[E N D] Take a picture] 21 | 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/AssetUtil.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import android.content.Context; 4 | import android.content.res.AssetManager; 5 | import android.util.Log; 6 | 7 | import java.io.File; 8 | import java.io.FileOutputStream; 9 | import java.io.InputStream; 10 | import java.io.OutputStream; 11 | 12 | public class AssetUtil { 13 | private static final String TAG = AssetUtil.class.getSimpleName(); 14 | 15 | public static void copyAssetToFile(Context context, String srcAssetsFilePath, File destFolderFile) { 16 | InputStream is = null; 17 | OutputStream os = null; 18 | try { 19 | AssetManager am = context.getResources().getAssets(); 20 | is = am.open(srcAssetsFilePath); 21 | 22 | if (!destFolderFile.exists()) { 23 | if (!destFolderFile.mkdirs()) { 24 | Log.e(TAG, "[ERROR]] mkdir faiIed !!!!! path = " + destFolderFile); 25 | return; 26 | } 27 | } 28 | 29 | File srcAssetsFile = new File(srcAssetsFilePath); 30 | File destFile = new File(destFolderFile, srcAssetsFile.getName()); 31 | if (destFile.exists()) { 32 | return; 33 | } 34 | os = new FileOutputStream(destFile); 35 | 36 | FileUtil.copyFile(is, os); 37 | } 38 | catch (Exception e) { 39 | Log.e(TAG, "Exception", e); 40 | } 41 | finally { 42 | IOUtil.closeQuietly(is); 43 | IOUtil.closeQuietly(os); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/BitmapUtil.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.ImageDecoder; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | 10 | import java.io.File; 11 | 12 | import timber.log.Timber; 13 | 14 | /** 15 | * Bitmap Utilities 16 | * 17 | * @author mcharima5@gmail.com 18 | * @since 2018 19 | */ 20 | public class BitmapUtil { 21 | private static final String TAG = BitmapUtil.class.getSimpleName(); 22 | 23 | public static Bitmap decodeBitmap(Context context, File file, int maxImageWidth) throws Exception { 24 | return decodeBitmap(context, UriUtil.fromFile(context, file), maxImageWidth); 25 | } 26 | 27 | public static Bitmap decodeBitmap(Context context, Uri uri, int maxImageWidth) throws Exception { 28 | try { 29 | return resizeBitmap(context, uri, true, maxImageWidth); 30 | } catch (Exception e) { 31 | Timber.e(e); 32 | throw e; 33 | } 34 | } 35 | 36 | public static Bitmap resizeBitmap(Context context, Uri uri, boolean resize, int maxImageWidth) throws Exception { 37 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 38 | ImageDecoder.Source source = ImageDecoder.createSource(context.getContentResolver(), uri); 39 | return ImageDecoder.decodeBitmap(source, (decoder, info, source1) -> { 40 | if (maxImageWidth <= 0) { 41 | return; 42 | } 43 | 44 | int sampleSize = getSampleSize(info.getSize().getWidth(), info.getSize().getHeight(), maxImageWidth); 45 | decoder.setTargetSampleSize(sampleSize); 46 | }); 47 | } else { 48 | //++ 49 | BitmapFactory.Options bfo = new BitmapFactory.Options(); 50 | bfo.inJustDecodeBounds = true; 51 | BitmapFactory.decodeStream(MediaUtil.getContentResolver(context).openInputStream(uri), null, bfo); 52 | bfo.inSampleSize = 1; 53 | if (resize) { 54 | bfo.inSampleSize = getSampleSize(bfo.outWidth, bfo.outHeight, maxImageWidth); 55 | } 56 | bfo.inJustDecodeBounds = false; 57 | //bfo.inDither = true; // deprecated 58 | return BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri), null, bfo); 59 | //|| 60 | //return MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri); 61 | //-- 62 | } 63 | } 64 | 65 | public static int getSampleSize(int outWidth, int outHeight, int maxImageWidth) { 66 | int inSampleSize = 1; 67 | if (outHeight > maxImageWidth || outWidth > maxImageWidth) { 68 | inSampleSize = (int) Math.pow(2, 69 | (int) Math.round( 70 | (Math.log(maxImageWidth / (double) Math.max(outHeight, outWidth))) 71 | / Math.log(0.5) 72 | ) 73 | ); 74 | } 75 | return Math.max(inSampleSize, 1); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/DateTimeFormat.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | import java.util.Locale; 6 | 7 | /** 8 | * Data & Time Utilities 9 | * 10 | * @author mcharima5@gmail.com 11 | * @since 2018 12 | */ 13 | public class DateTimeFormat { 14 | 15 | public static String format(Date date, String pattern) { 16 | SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.getDefault()); 17 | return formatter.format(date); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/EnvUtil.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.os.Environment; 6 | 7 | import com.snc.sample.webview.BuildConfig; 8 | 9 | import java.io.File; 10 | 11 | /** 12 | * Environment Utilities 13 | * 14 | * @author mcharima5@gmail.com 15 | * @since 2018 16 | */ 17 | public class EnvUtil { 18 | 19 | @Deprecated 20 | public static File getExternalStorageDirectory() { 21 | return Environment.getExternalStorageDirectory(); 22 | } 23 | 24 | public static File getExternalFilesDir(Context context) { 25 | if (BuildConfig.FEATURE_EXTERNAL_STORAGE_DIR) { 26 | return getExternalStorageDirectory(); 27 | } 28 | return context.getExternalFilesDir(null); 29 | } 30 | 31 | @SuppressLint("SdCardPath") 32 | public static File getInternalFilesDir(Context context, String path) { 33 | return new File(context.getFilesDir(), path); 34 | } 35 | 36 | public static File getInternalFilesDir(Context context) { 37 | return getInternalFilesDir(context, ""); 38 | } 39 | 40 | public static File getMediaDir(Context context, String type) { 41 | File storageDir = getExternalFilesDir(context); 42 | 43 | if ("image".equalsIgnoreCase(type) || "video".equalsIgnoreCase(type)) { 44 | return new File(new File(storageDir, Environment.DIRECTORY_DCIM), "Camera"); 45 | } 46 | else if ("audio".equalsIgnoreCase(type)) { 47 | return new File(storageDir, "Voice Recorder"); 48 | } 49 | return null; 50 | } 51 | 52 | public static boolean isFilesDir(Context context, File file) { 53 | File dir = context.getExternalFilesDir(null); 54 | return file.getAbsolutePath().startsWith(dir.getAbsolutePath()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.OutputStream; 9 | import java.util.Date; 10 | 11 | /** 12 | * File Utilities 13 | * 14 | * @author mcharima5@gmail.com 15 | * @since 2018 16 | */ 17 | public class FileUtil { 18 | 19 | private static boolean mkdirs(File dir) { 20 | if (null == dir) { 21 | return false; 22 | } 23 | if (dir.exists()) { 24 | return true; 25 | } 26 | return dir.mkdirs(); 27 | } 28 | 29 | @SuppressWarnings("BooleanMethodIsAlwaysInverted") 30 | public static boolean delete(File file) { 31 | if (null == file || !file.exists()) { 32 | return false; 33 | } 34 | return file.delete(); 35 | } 36 | 37 | public static boolean exists(File file) { 38 | return file.exists(); 39 | } 40 | 41 | public static String newFilename(String extension) { 42 | String name = DateTimeFormat.format(new Date(), "yyyyMMdd_HHmmss"); 43 | return name + "." + extension; 44 | } 45 | 46 | public static File createFile(File dir, String...pathAndFilename) throws IOException { 47 | File file = dir; 48 | for (String path : pathAndFilename) { 49 | file = new File(file, path); 50 | } 51 | if (!mkdirs(file.getParentFile())) { 52 | throw new IOException("mkdirs failed...!!!!! " + dir); 53 | } 54 | if (exists(file)) { 55 | if (!delete(file)) { 56 | throw new IOException("delete failed...!!!!! " + file); 57 | } 58 | } 59 | if (file.createNewFile()) { 60 | return file; 61 | } 62 | return null; 63 | } 64 | 65 | public static void write(FileInputStream fin, FileOutputStream fos) throws IOException { 66 | try { 67 | byte[] buff = new byte[1024 * 4]; // 1MB = 1048576 = 1024 * 1024, 10KB = 10240 = 10 * 1024 68 | while (true) { 69 | int len = fin.read(buff); 70 | if (-1 == len) { 71 | break; 72 | } 73 | fos.write(buff, 0, len); 74 | } 75 | } 76 | finally { 77 | IOUtil.closeQuietly(fin); 78 | IOUtil.closeQuietly(fos); 79 | } 80 | } 81 | 82 | public static void copyFile(InputStream input, OutputStream output) throws IOException { 83 | byte[] buffer = new byte[10240]; 84 | int n; 85 | while (-1 != (n = input.read(buffer))) { 86 | output.write(buffer, 0, n); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/IOUtil.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import java.io.InputStream; 4 | import java.io.OutputStream; 5 | 6 | import timber.log.Timber; 7 | 8 | /** 9 | * IO Utilities 10 | * 11 | * @author mcharima5@gmail.com 12 | * @since 2016 13 | */ 14 | public class IOUtil { 15 | 16 | public static void closeQuietly(InputStream input) { 17 | try { 18 | if (null != input) { 19 | input.close(); 20 | } 21 | } catch (Exception e) { 22 | Timber.e(e); 23 | } 24 | } 25 | 26 | public static void closeQuietly(OutputStream output) { 27 | try { 28 | if (null != output) { 29 | output.flush(); 30 | } 31 | } catch (Exception e) { 32 | Timber.e(e); 33 | } 34 | try { 35 | if (null != output) { 36 | output.close(); 37 | } 38 | } catch (Exception e) { 39 | Timber.e(e); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/IntentUtil.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import android.app.Activity; 4 | import android.content.ActivityNotFoundException; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.net.Uri; 8 | import android.provider.MediaStore; 9 | 10 | import java.net.URISyntaxException; 11 | 12 | /** 13 | * Android Intent Utilities 14 | * 15 | * @author mcharima5@gmail.com 16 | * @since 2018 17 | */ 18 | public class IntentUtil { 19 | 20 | public static void imageCaptureWithExtraOutput(Context context, int requestCode, Uri output) { 21 | Intent intent = new Intent(); 22 | intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); 23 | if (null != output) { 24 | intent.putExtra(MediaStore.EXTRA_OUTPUT, output); 25 | } 26 | ((Activity) context).startActivityForResult(Intent.createChooser(intent, "Chooser"), requestCode); 27 | } 28 | 29 | public static void view(Context context, Uri uri) throws ActivityNotFoundException { 30 | Intent intent = new Intent(Intent.ACTION_VIEW); 31 | intent.addCategory(Intent.CATEGORY_BROWSABLE); 32 | intent.setData(uri); 33 | context.startActivity(intent); 34 | } 35 | 36 | public static void intentScheme(Context context, String urlString) throws URISyntaxException { 37 | Intent intent = Intent.parseUri(urlString, Intent.URI_INTENT_SCHEME); 38 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 39 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 40 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 41 | intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES); 42 | 43 | try { 44 | context.startActivity(intent); 45 | } catch (ActivityNotFoundException e) { 46 | Intent marketLaunch = new Intent(Intent.ACTION_VIEW); 47 | marketLaunch.setData(Uri.parse("market://details?id=" + intent.getPackage())); 48 | context.startActivity(marketLaunch); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/MediaUtil.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import android.content.ContentResolver; 4 | import android.content.Context; 5 | 6 | /** 7 | * Media Utilities 8 | * 9 | * @author mcharima5@gmail.com 10 | * @since 2020 11 | */ 12 | public class MediaUtil { 13 | 14 | public static ContentResolver getContentResolver(Context context) { 15 | return context.getApplicationContext().getContentResolver(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/PackageUtil.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageInfo; 5 | import android.content.pm.PackageManager; 6 | import android.os.Build; 7 | 8 | /** 9 | * Package Utilities 10 | * 11 | * @author mcharima5@gmail.com 12 | * @since 2018 13 | */ 14 | public class PackageUtil { 15 | 16 | public static String getApplicationName(Context context) throws PackageManager.NameNotFoundException { 17 | return getPackageInfo(context).applicationInfo.loadLabel(context.getPackageManager()).toString(); 18 | } 19 | 20 | public static String getPackageVersionName(Context context) throws PackageManager.NameNotFoundException { 21 | return getPackageInfo(context).versionName; 22 | } 23 | 24 | public static int getPackageVersionCode(Context context) throws PackageManager.NameNotFoundException { 25 | PackageInfo info = getPackageInfo(context); 26 | int packageVersionCode; 27 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 28 | packageVersionCode = (int) info.getLongVersionCode(); 29 | } else { 30 | packageVersionCode = info.versionCode; 31 | } 32 | return packageVersionCode; 33 | } 34 | 35 | public static String getPackageName(Context context) throws PackageManager.NameNotFoundException { 36 | return getPackageInfo(context).packageName; 37 | } 38 | 39 | private static PackageInfo getPackageInfo(Context context) throws PackageManager.NameNotFoundException { 40 | return context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/StringUtil.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import android.os.Bundle; 4 | 5 | import java.util.Iterator; 6 | 7 | /** 8 | * String Utilities 9 | * 10 | * @author mcharima5@gmail.com 11 | * @since 2018 12 | */ 13 | public class StringUtil { 14 | 15 | public static String nvl(Object str, String defaultValue) { 16 | if (null == str) { 17 | return defaultValue; 18 | } 19 | return str.toString(); 20 | } 21 | 22 | public static boolean isEmpty(Object obj) { 23 | if (null == obj) { 24 | return true; 25 | } 26 | 27 | if (obj instanceof String) { 28 | String str = (String) obj; 29 | return str.length() <= 0 || str.trim().length() <= 0; 30 | } 31 | if (obj instanceof String[]) { 32 | String[] arrStr = (String[]) obj; 33 | return arrStr.length <= 0; 34 | } 35 | return false; 36 | } 37 | 38 | public static boolean isNotEmpty(Object obj) { 39 | return !isEmpty(obj); 40 | } 41 | 42 | public static String toString(Bundle bundle) { 43 | if (null == bundle) { 44 | return ""; 45 | } 46 | StringBuilder buff = new StringBuilder(); 47 | Iterator keys = bundle.keySet().iterator(); 48 | while (keys.hasNext()) { 49 | String key = keys.next(); 50 | buff.append((0 != buff.length()) ? "\n" : ""); 51 | buff.append(key).append("=").append(bundle.get(key)); 52 | buff.append(keys.hasNext() ? "," : ""); 53 | } 54 | buff.insert(0, "{\n"); 55 | buff.append("\n}"); 56 | return buff.toString(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/util/UriUtil.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.util; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageManager; 5 | import android.net.Uri; 6 | import android.os.Build; 7 | 8 | import java.io.File; 9 | 10 | import androidx.core.content.FileProvider; 11 | 12 | /** 13 | * Uri Utilities 14 | * 15 | * @author mcharima5@gmail.com 16 | * @since 2018 17 | */ 18 | public class UriUtil { 19 | //private static final String TAG = UriUtil.class.getSimpleName(); 20 | 21 | public static Uri fromFile(Context context, File file) throws PackageManager.NameNotFoundException { 22 | final Uri newUri; 23 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 24 | newUri = FileProvider.getUriForFile(context, PackageUtil.getPackageName(context) + ".fileprovider", file); 25 | } else { 26 | newUri = Uri.fromFile(file); 27 | } 28 | return newUri; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/webview/CSDownloadListener.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.webview; 2 | 3 | import android.app.Activity; 4 | import android.net.Uri; 5 | import android.util.Log; 6 | import android.webkit.DownloadListener; 7 | 8 | import com.snc.zero.download.CSDownloadManager; 9 | 10 | import java.io.File; 11 | import java.net.URLDecoder; 12 | import java.security.InvalidParameterException; 13 | import java.util.Collections; 14 | import java.util.LinkedHashSet; 15 | import java.util.Set; 16 | 17 | /** 18 | * WebView Download Listener 19 | * 20 | * @author mcharima5@gmail.com 21 | * @since 2020 22 | */ 23 | public class CSDownloadListener implements DownloadListener { 24 | private static final String TAG = CSDownloadListener.class.getSimpleName(); 25 | 26 | private final Activity activity; 27 | 28 | public CSDownloadListener(Activity activity) { 29 | this.activity = activity; 30 | } 31 | 32 | @Override 33 | public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) { 34 | String fileName = getFilenameFromDownloadContent(url, contentDisposition); 35 | if (null == fileName) { 36 | return; 37 | } 38 | 39 | CSDownloadManager dm = new CSDownloadManager(); 40 | dm.download(this.activity, url); 41 | } 42 | 43 | private String getFilenameFromDownloadContent(String urlString, String contentDisposition) { 44 | try { 45 | Uri uri = Uri.parse(urlString); 46 | 47 | String fileName = uri.getQueryParameter("clientFileName"); 48 | if (null == fileName) { 49 | fileName = uri.getQueryParameter("filename"); 50 | } 51 | if (null == fileName) { 52 | for (String str : contentDisposition.split(";")) { 53 | if (str.contains("filename=")) { 54 | fileName = contentDisposition.split("filename=")[1]; 55 | } 56 | else if (str.contains("fileName=")) { 57 | fileName = contentDisposition.split("fileName=")[1]; 58 | } 59 | } 60 | } 61 | if (null == fileName) { 62 | Set set = getQueryParameterNames(uri); 63 | if (null == set || set.size() == 0) { 64 | File file = new File(urlString); 65 | fileName = file.getName(); 66 | } 67 | } 68 | if (null == fileName || fileName.length() == 0) { 69 | return null; 70 | } 71 | return URLDecoder.decode(fileName, "UTF-8"); 72 | 73 | } catch (Exception e) { 74 | Log.e(TAG, Log.getStackTraceString(e)); 75 | return null; 76 | } 77 | } 78 | 79 | private Set getQueryParameterNames(Uri uri) { 80 | if (null == uri) { 81 | throw new InvalidParameterException("Can't get parameter from a null Uri"); 82 | } 83 | if (uri.isOpaque()) { 84 | throw new UnsupportedOperationException("This isn't a hierarchical URI."); 85 | } 86 | 87 | String query = uri.getEncodedQuery(); 88 | if (null == query) { 89 | return Collections.emptySet(); 90 | } 91 | 92 | Set names = new LinkedHashSet<>(); 93 | int start = 0; 94 | do { 95 | int next = query.indexOf('&', start); 96 | int end = (next == -1) ? query.length() : next; 97 | 98 | int separator = query.indexOf('=', start); 99 | if (separator > end || separator == -1) { 100 | separator = end; 101 | } 102 | 103 | String name = query.substring(start, separator); 104 | names.add(Uri.decode(name)); 105 | 106 | start = end + 1; 107 | } while (start < query.length()); 108 | 109 | return Collections.unmodifiableSet(names); 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/webview/CSFileChooserListener.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.webview; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | import android.os.Parcelable; 10 | import android.provider.MediaStore; 11 | import android.webkit.ValueCallback; 12 | import android.webkit.WebChromeClient; 13 | import android.webkit.WebView; 14 | 15 | import com.snc.zero.dialog.DialogBuilder; 16 | import com.snc.zero.requetcode.RequestCode; 17 | import com.snc.zero.util.DateTimeFormat; 18 | import com.snc.zero.util.EnvUtil; 19 | import com.snc.zero.util.StringUtil; 20 | import com.snc.zero.util.UriUtil; 21 | import com.snc.zero.webview.listener.FileChooserListener; 22 | 23 | import java.io.File; 24 | import java.util.ArrayList; 25 | import java.util.Date; 26 | import java.util.List; 27 | 28 | import timber.log.Timber; 29 | 30 | /** 31 | * WebView FileChooser Listener 32 | * 33 | * @author mcharima5@gmail.com 34 | * @since 2020 35 | */ 36 | public class CSFileChooserListener implements FileChooserListener { 37 | private static final String ALL_TYPE = "image/*|audio/*|video/*"; 38 | 39 | private final Context context; 40 | 41 | private ValueCallback filePathCallbackNormal; 42 | 43 | private ValueCallback filePathCallbackLollipop; 44 | private final int IMAGE = 0; 45 | private final int AUDIO = 1; 46 | private final int VIDEO = 2; 47 | private Uri[] mediaURIs; 48 | 49 | 50 | ///////////////////////////////////////////////// 51 | // Constructor 52 | ///////////////////////////////////////////////// 53 | 54 | public CSFileChooserListener(Context context) { 55 | this.context = context; 56 | } 57 | 58 | 59 | ///////////////////////////////////////////////// 60 | // Open FileChooser 61 | ///////////////////////////////////////////////// 62 | 63 | @SuppressWarnings({"unused", "RedundantSuppression"}) 64 | @Override 65 | public void onOpenFileChooserNormal(WebView webView, ValueCallback filePathCallback, String acceptType) { 66 | this.filePathCallbackNormal = filePathCallback; 67 | openIntentChooser(acceptType); 68 | } 69 | 70 | @SuppressWarnings({"unused", "RedundantSuppression"}) 71 | @Override 72 | public void onOpenFileChooserLollipop(WebView webView, ValueCallback filePathCallback, String[] acceptTypes) { 73 | this.filePathCallbackLollipop = filePathCallback; 74 | openIntentChooser(acceptTypes); 75 | } 76 | 77 | private void openIntentChooser(String[] acceptTypes) { 78 | String acceptType = ""; 79 | 80 | for (String type : acceptTypes) { 81 | if (StringUtil.isEmpty(type)) { 82 | continue; 83 | } 84 | if (!type.startsWith("image/") 85 | && !type.startsWith("audio/") 86 | && !type.startsWith("video/") 87 | && !type.startsWith("application/")) { 88 | continue; 89 | } 90 | 91 | if (StringUtil.isEmpty(acceptType)) { 92 | acceptType += type; 93 | } else { 94 | acceptType += "," + type; 95 | } 96 | } 97 | 98 | openIntentChooser(acceptType); 99 | } 100 | 101 | private void openIntentChooser(String acceptType) { 102 | String type = acceptType; 103 | 104 | if (type.isEmpty() || "*/*".equalsIgnoreCase(type)) { 105 | type = ALL_TYPE; 106 | } 107 | 108 | try { 109 | mediaURIs = new Uri[3]; 110 | 111 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 112 | List intentList = new ArrayList<>(); 113 | 114 | String fileName = DateTimeFormat.format(new Date(), "yyyyMMdd_HHmmss"); 115 | 116 | if (type.contains("image/")) { 117 | mediaURIs[IMAGE] = UriUtil.fromFile(context, new File(EnvUtil.getMediaDir(context, "image"), fileName + ".jpg")); 118 | 119 | final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 120 | intent.putExtra(MediaStore.EXTRA_OUTPUT, mediaURIs[IMAGE]); 121 | intentList.add(intent); 122 | } 123 | if (type.contains("audio/")) { 124 | mediaURIs[AUDIO] = UriUtil.fromFile(context, new File(EnvUtil.getMediaDir(context, "audio"), fileName + ".m4a")); 125 | 126 | final Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); 127 | intent.putExtra(MediaStore.EXTRA_OUTPUT, mediaURIs[AUDIO]); 128 | intentList.add(intent); 129 | } 130 | if (type.contains("video/")) { 131 | mediaURIs[VIDEO] = UriUtil.fromFile(context, new File(EnvUtil.getMediaDir(context, "video"), fileName + ".mp4")); 132 | 133 | final Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 134 | intent.putExtra(MediaStore.EXTRA_OUTPUT, mediaURIs[VIDEO]); 135 | intentList.add(intent); 136 | } 137 | 138 | // Intent Chooser 139 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 140 | intent.addCategory(Intent.CATEGORY_OPENABLE); 141 | 142 | if (ALL_TYPE.equals(type)) { 143 | intent.setType("*/*"); 144 | } else { 145 | intent.setType(type); 146 | } 147 | 148 | Intent chooserIntent = Intent.createChooser(intent, "Chooser"); 149 | chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray(new Parcelable[] { })); 150 | ((Activity) context).startActivityForResult(chooserIntent, RequestCode.REQUEST_FILE_CHOOSER_LOLLIPOP); 151 | 152 | } else { 153 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 154 | intent.setType("*/*"); 155 | intent.addCategory(Intent.CATEGORY_OPENABLE); 156 | intent.addCategory(Intent.CATEGORY_BROWSABLE); 157 | ((Activity) context).startActivityForResult(Intent.createChooser(intent, "File Chooser"), RequestCode.REQUEST_FILE_CHOOSER_NORMAL); 158 | } 159 | 160 | } catch (Exception e) { 161 | Timber.e(e); 162 | 163 | DialogBuilder.with(context) 164 | .setMessage(e.toString()) 165 | .show(); 166 | } 167 | } 168 | 169 | 170 | ///////////////////////////////////////////////// 171 | // onActivityResult 172 | ///////////////////////////////////////////////// 173 | 174 | public void onActivityResultFileChooserNormal(int requestCode, int resultCode, Intent data) { 175 | Timber.i("[WEBVIEW] onActivityResultFileChooserNormal(): requestCode[" + requestCode + "] resultCode[" + resultCode + "] data[" + data + "]"); 176 | 177 | if (null == filePathCallbackNormal) { 178 | Timber.i("[WEBVIEW] onActivityResultNormal(): filePathCallbackNormal is null !!!"); 179 | return; 180 | } 181 | 182 | if (Activity.RESULT_OK != resultCode) { 183 | filePathCallbackNormal.onReceiveValue(null); 184 | filePathCallbackNormal = null; 185 | return; 186 | } 187 | 188 | Uri result = null == data ? null : data.getData(); 189 | filePathCallbackNormal.onReceiveValue(result); 190 | filePathCallbackNormal = null; 191 | } 192 | 193 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 194 | public void onActivityResultFileChooserLollipop(int requestCode, int resultCode, Intent data) { 195 | Timber.i("[WEBVIEW] onActivityResultFileChooserLollipop(): requestCode[" + requestCode + "] resultCode[" + resultCode + "] data[" + data + "]"); 196 | 197 | if (null == filePathCallbackLollipop) { 198 | Timber.i("[WEBVIEW] onActivityResultLollipop(): filePathCallbackLollipop is null !!!"); 199 | return; 200 | } 201 | 202 | if (Activity.RESULT_OK != resultCode) { 203 | filePathCallbackLollipop.onReceiveValue(null); 204 | filePathCallbackLollipop = null; 205 | return; 206 | } 207 | 208 | try { 209 | if (null != data) { 210 | filePathCallbackLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, data)); 211 | } else { 212 | List results = new ArrayList<>(); 213 | 214 | if (null != mediaURIs) { 215 | if (null != mediaURIs[IMAGE]) { 216 | results.add(mediaURIs[IMAGE]); 217 | } 218 | if (null != mediaURIs[AUDIO]) { 219 | results.add(mediaURIs[AUDIO]); 220 | } 221 | if (null != mediaURIs[VIDEO]) { 222 | results.add(mediaURIs[VIDEO]); 223 | } 224 | } 225 | 226 | filePathCallbackLollipop.onReceiveValue(results.toArray(new Uri[]{})); 227 | } 228 | 229 | } catch (Exception e) { 230 | Timber.e(e); 231 | } finally { 232 | filePathCallbackLollipop = null; 233 | mediaURIs = null; 234 | } 235 | } 236 | 237 | } 238 | -------------------------------------------------------------------------------- /app/src/main/java/com/snc/zero/webview/listener/FileChooserListener.java: -------------------------------------------------------------------------------- 1 | package com.snc.zero.webview.listener; 2 | 3 | import android.net.Uri; 4 | import android.webkit.ValueCallback; 5 | import android.webkit.WebView; 6 | 7 | /** 8 | * File Chooser Listener 9 | * 10 | * @author mcharima5@gmail.com 11 | * @since 2020 12 | */ 13 | public interface FileChooserListener { 14 | 15 | @SuppressWarnings({"unused", "RedundantSuppression"}) 16 | void onOpenFileChooserNormal(WebView webView, ValueCallback filePathCallback, String acceptType); 17 | 18 | @SuppressWarnings({"unused", "RedundantSuppression"}) 19 | void onOpenFileChooserLollipop(WebView webView, ValueCallback filePathCallback, String[] acceptTypes); 20 | 21 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/icon_no_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/drawable/icon_no_image.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/progress_horizontal.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #000000 4 | #001935 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SAMPLE WEBVIEW 3 | 4 | Please the Back button once more shut down. 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/xml/app_backup_rules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/xml/app_extraction_rules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/xml/file_provider_paths.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/test/java/com/snc/sample/webview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.snc.sample.webview; 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 | } -------------------------------------------------------------------------------- /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 | google() 6 | //jcenter() 7 | mavenCentral() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:8.0.2' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | //jcenter() 21 | mavenCentral() 22 | } 23 | 24 | // Note: Some input files use or override a deprecated API. 25 | // Note: Recompile with -Xlint:deprecation for details. 26 | //tasks.withType(JavaCompile) { 27 | // options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" 28 | //} 29 | } 30 | 31 | task clean(type: Delete) { 32 | delete rootProject.buildDir 33 | } 34 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | # WARNING: API 'variant.getAssemble()' is obsolete and has been replaced with 'variant.getAssembleProvider()'. 17 | # It will be removed at the end of 2019. 18 | # For more information, see https://d.android.com/r/tools/task-configuration-avoidance. 19 | # To determine what is calling variant.getAssemble(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace. 20 | #android.debug.obsoleteApi=true 21 | 22 | 23 | # Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. 24 | # Use '--warning-mode all' to show the individual deprecation warnings. 25 | # See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings 26 | org.gradle.warning.mode=all 27 | 28 | 29 | # Androidx 30 | android.useAndroidX=true 31 | android.enableJetifier=true 32 | android.defaults.buildfeatures.buildconfig=true 33 | android.nonTransitiveRClass=false 34 | android.nonFinalResIds=false 35 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArronJo/sample-webview/ab3db31ce5b0a06374239101fe691918a2246565/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Nov 02 18:23:05 KST 2020 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-8.0-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file must *NOT* be checked into Version Control Systems, 2 | # as it contains information specific to your local configuration. 3 | # 4 | # Location of the SDK. This is only used by Gradle. 5 | # For customization when using a Version Control System, please read the 6 | # header note. 7 | #Thu Jun 25 12:52:31 KST 2020 8 | sdk.dir=/Users/jwjo/Library/Android/sdk 9 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | // https://github.com/ArronJo/sample-webview 2 | 3 | include ':app' 4 | --------------------------------------------------------------------------------