├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── kazy │ │ └── lx │ │ └── sample │ │ ├── RootActivity.java │ │ └── UnsupportedProtcolInterceptor.java │ └── res │ ├── layout │ └── activity_root.xml │ ├── menu │ └── menu_root.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── kazy │ │ └── lx │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── kazy │ │ └── lx │ │ ├── LoadingInterceptor.java │ │ ├── LxWebContainerView.java │ │ ├── LxWebView.java │ │ ├── WebViewState.java │ │ └── WebViewStateListener.java │ └── res │ ├── layout │ └── view_lx_web_container.xml │ ├── values-ja │ └── strings.xml │ └── values │ ├── attr.xml │ └── strings.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | # Proguard files 23 | proguard.map 24 | 25 | # Intellij project files 26 | *.iml 27 | *.ipr 28 | *.iws 29 | .idea/* 30 | !.idea/codeStyleSettings.xml 31 | 32 | # Gradle files 33 | .gradle 34 | build 35 | 36 | # Credentials 37 | shared_settings.gradle 38 | signing.gradle 39 | 40 | # bundle files 41 | .bundle 42 | vendor/bundle 43 | 44 | .DS_Store 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LxWebView 2 | ============ 3 | [![](https://jitpack.io/v/kazy1991/LxWebView.svg)](https://jitpack.io/#kazy1991/LxWebView) 4 | 5 | 6 | This library provides you useful interfaces which tells loading-state and intercept url loading. 7 | You ,not any more, should not create Custom WebView Class. 8 | 9 | Feature 10 | -------- 11 | 12 | * Setting `WebSettings` with xml attributes. 13 | * Provides correct loading-state Callback ( show errorView and loadingView etc) 14 | * Provides loading url interceptor ( bind action with custom_url_sheme etc) 15 | 16 | How to 17 | -------- 18 | 19 | ##### Step 1. Add the JitPack repository to your build file 20 | 21 | ```groovy 22 | repositories { 23 | maven { 24 | url "https://jitpack.io" 25 | } 26 | } 27 | ``` 28 | 29 | ##### Step 2. Add the dependency in the form 30 | 31 | ```groovy 32 | dependencies { 33 | compile 'com.github.kazy1991:LxWebView:0.2.0' 34 | } 35 | ``` 36 | 37 | ##### Step 3. Replace LxWebView with Webview in your layout xml 38 | 39 | ```xml 40 | 45 | 56 | 57 | ``` 58 | 59 | License 60 | ------- 61 | 62 | Copyright 2015 Kazuki Yoshida 63 | 64 | Licensed under the Apache License, Version 2.0 (the "License"); 65 | you may not use this file except in compliance with the License. 66 | You may obtain a copy of the License at 67 | 68 | http://www.apache.org/licenses/LICENSE-2.0 69 | 70 | Unless required by applicable law or agreed to in writing, software 71 | distributed under the License is distributed on an "AS IS" BASIS, 72 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 73 | See the License for the specific language governing permissions and 74 | limitations under the License. 75 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion compile_sdk_version as int 5 | buildToolsVersion build_tools_version 6 | 7 | defaultConfig { 8 | applicationId "com.kazy.luxewebview" 9 | minSdkVersion min_sdk_version 10 | targetSdkVersion target_sdk_version 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile "com.android.support:appcompat-v7:$support_lib_version" 24 | compile 'com.jakewharton:butterknife:6.1.0' 25 | compile project(':library') 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/kazuki-yoshida/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/kazy/lx/sample/RootActivity.java: -------------------------------------------------------------------------------- 1 | package com.kazy.lx.sample; 2 | 3 | import com.kazy.lx.LxWebContainerView; 4 | import com.kazy.lx.WebViewStateListener; 5 | 6 | import android.graphics.Bitmap; 7 | import android.os.Bundle; 8 | import android.support.v7.app.ActionBarActivity; 9 | import android.webkit.WebView; 10 | 11 | import butterknife.ButterKnife; 12 | import butterknife.InjectView; 13 | 14 | public class RootActivity extends ActionBarActivity { 15 | 16 | @InjectView(R.id.webview_view) 17 | LxWebContainerView webContainerView; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_root); 23 | ButterKnife.inject(this); 24 | webContainerView.addLoadingInterceptor(new UnsupportedProtcolInterceptor(this)); 25 | webContainerView.loadUrl("http://yahoo.co.jp"); 26 | webContainerView.addOnWebViewStateListener(new WebViewStateListener() { 27 | @Override 28 | public void onStartLoading(String url, Bitmap favicon) { 29 | 30 | } 31 | 32 | @Override 33 | public void onError(int errorCode, String description, String failingUrl) { 34 | 35 | } 36 | 37 | @Override 38 | public void onFinishLoaded(String loadedUrl) { 39 | 40 | } 41 | 42 | @Override 43 | public void onProgressChanged(WebView view, int progress) { 44 | 45 | } 46 | }); 47 | } 48 | 49 | @Override 50 | public void onBackPressed() { 51 | if (webContainerView.canGoBack()) { 52 | webContainerView.goBack(); 53 | } else { 54 | super.onBackPressed(); 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/kazy/lx/sample/UnsupportedProtcolInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.kazy.lx.sample; 2 | 3 | import com.kazy.lx.LoadingInterceptor; 4 | 5 | import android.app.Activity; 6 | import android.content.Intent; 7 | import android.net.Uri; 8 | 9 | public class UnsupportedProtcolInterceptor implements LoadingInterceptor { 10 | 11 | private Activity activity; 12 | 13 | public UnsupportedProtcolInterceptor(Activity activity) { 14 | this.activity = activity; 15 | } 16 | 17 | @Override 18 | public boolean validate(Uri uri) { 19 | return !uri.getScheme().equals("http") && !uri.getScheme().equals("https"); 20 | } 21 | 22 | @Override 23 | public void exec(Uri uri) { 24 | Intent intent = new Intent(Intent.ACTION_VIEW, uri); 25 | activity.startActivity(intent); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_root.xml: -------------------------------------------------------------------------------- 1 | 6 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_root.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k4zy/LxWebView/f1b44631c869b5326b2deead28cd71adc2fa5433/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k4zy/LxWebView/f1b44631c869b5326b2deead28cd71adc2fa5433/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k4zy/LxWebView/f1b44631c869b5326b2deead28cd71adc2fa5433/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k4zy/LxWebView/f1b44631c869b5326b2deead28cd71adc2fa5433/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #88dddddd 4 | #2a2a2a 5 | #7d7d7d 6 | #656565 7 | #4c4c4c 8 | #e5e5e5 9 | #808080 10 | #FAFAFA 11 | #f1f1f1 12 | #e91e63 13 | #ec407a 14 | #42A5F5 15 | #5f93de 16 | #FFC107 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | LuxeWebview 3 | RootActivity 4 | 5 | Hello world! 6 | Settings 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /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 | mavenCentral() 6 | jcenter() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:2.3.0' 10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | mavenCentral() 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # SDK versions 2 | compile_sdk_version=25 3 | build_tools_version=25.0.2 4 | min_sdk_version=15 5 | target_sdk_version=25 6 | # Library versions 7 | support_lib_version=25.3.1 8 | # Build options 9 | org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | org.gradle.parallel=true 11 | org.gradle.daemon=true 12 | org.gradle.configureondemand=true 13 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k4zy/LxWebView/f1b44631c869b5326b2deead28cd71adc2fa5433/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 05 07:08:08 JST 2017 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-3.4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | android { 5 | compileSdkVersion compile_sdk_version as int 6 | buildToolsVersion build_tools_version 7 | 8 | defaultConfig { 9 | minSdkVersion min_sdk_version 10 | targetSdkVersion target_sdk_version 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/kazuki-yoshida/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/androidTest/java/com/kazy/lx/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.kazy.lx; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | 11 | public ApplicationTest() { 12 | super(Application.class); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /library/src/main/java/com/kazy/lx/LoadingInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.kazy.lx; 2 | 3 | import android.net.Uri; 4 | 5 | public interface LoadingInterceptor { 6 | public boolean validate(Uri uri); 7 | public void exec(Uri uri); 8 | } 9 | -------------------------------------------------------------------------------- /library/src/main/java/com/kazy/lx/LxWebContainerView.java: -------------------------------------------------------------------------------- 1 | package com.kazy.lx; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Bitmap; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.view.animation.AlphaAnimation; 10 | import android.view.animation.Animation; 11 | import android.webkit.WebView; 12 | import android.widget.Button; 13 | import android.widget.ProgressBar; 14 | import android.widget.RelativeLayout; 15 | 16 | import java.util.Map; 17 | 18 | public class LxWebContainerView extends RelativeLayout { 19 | 20 | private LxWebView lxWebView; 21 | 22 | private ProgressBar progressBar; 23 | 24 | private ViewGroup errorView; 25 | 26 | private Button reloadButton; 27 | 28 | private static final Animation animation = new AlphaAnimation(1f, 0f); 29 | 30 | public LxWebContainerView(Context context) { 31 | super(context); 32 | initialize(); 33 | } 34 | 35 | public LxWebContainerView(Context context, AttributeSet attrs) { 36 | super(context, attrs); 37 | initialize(); 38 | setupWebSettings(attrs); 39 | } 40 | 41 | public LxWebContainerView(Context context, AttributeSet attrs, int defStyleAttr) { 42 | super(context, attrs, defStyleAttr); 43 | initialize(); 44 | setupWebSettings(attrs); 45 | } 46 | 47 | private void setupWebSettings(AttributeSet attrs) { 48 | TypedArray args = getContext().obtainStyledAttributes(attrs, R.styleable.Lx); 49 | lxWebView.setupWebSettings(args); 50 | args.recycle(); 51 | } 52 | 53 | private void initialize() { 54 | bindViews(); 55 | bindWebViewState(); 56 | animation.setDuration(1000); 57 | } 58 | 59 | private void bindWebViewState() { 60 | lxWebView.addOnWebViewStateListener(new WebViewStateListener() { 61 | @Override 62 | public void onStartLoading(String url, Bitmap favicon) { 63 | progressBar.clearAnimation(); 64 | progressBar.setProgress(0); 65 | progressBar.setVisibility(View.VISIBLE); 66 | errorView.setVisibility(View.GONE); 67 | } 68 | 69 | @Override 70 | public void onError(int errorCode, String description, String failingUrl) { 71 | progressBar.setVisibility(View.GONE); 72 | lxWebView.setVisibility(View.GONE); 73 | errorView.setVisibility(View.VISIBLE); 74 | } 75 | 76 | @Override 77 | public void onFinishLoaded(String loadedUrl) { 78 | progressBar.startAnimation(animation); 79 | progressBar.setVisibility(View.GONE); 80 | lxWebView.setVisibility(View.VISIBLE); 81 | errorView.setVisibility(View.GONE); 82 | } 83 | 84 | @Override 85 | public void onProgressChanged(WebView view, int progress) { 86 | if (lxWebView.getVisibility() != View.VISIBLE && progress > 80) { 87 | lxWebView.setVisibility(View.VISIBLE); 88 | } 89 | progressBar.setProgress(progress); 90 | } 91 | }); 92 | } 93 | 94 | private void bindViews() { 95 | View.inflate(getContext(), R.layout.view_lx_web_container, this); 96 | lxWebView = (LxWebView) findViewById(R.id.web_view); 97 | progressBar = (ProgressBar) findViewById(R.id.progress_bar); 98 | errorView = (ViewGroup) findViewById(R.id.error_view); 99 | reloadButton = (Button) findViewById(R.id.reload_button); 100 | reloadButton.setOnClickListener(new OnClickListener() { 101 | @Override 102 | public void onClick(View v) { 103 | if (lxWebView != null) { 104 | lxWebView.reload(); 105 | } 106 | } 107 | }); 108 | } 109 | 110 | public void addOnWebViewStateListener(WebViewStateListener webViewStateListener) { 111 | lxWebView.addOnWebViewStateListener(webViewStateListener); 112 | } 113 | 114 | public void addLoadingInterceptor(LoadingInterceptor loadingInterceptor) { 115 | lxWebView.addLoadingInterceptor(loadingInterceptor); 116 | } 117 | 118 | public void loadUrl(String url) { 119 | lxWebView.loadUrl(url); 120 | } 121 | 122 | public void loadUrl(String url, Map additionalHttpHeaders) { 123 | lxWebView.loadUrl(url, additionalHttpHeaders); 124 | } 125 | 126 | public boolean canGoBack() { 127 | return lxWebView.canGoBack(); 128 | } 129 | 130 | public void goBack() { 131 | lxWebView.goBack(); 132 | } 133 | 134 | public String getTitle() { 135 | return lxWebView.getTitle(); 136 | } 137 | 138 | public String getUrl() { 139 | return lxWebView.getUrl(); 140 | } 141 | 142 | public String getUserAgentString() { 143 | return lxWebView.getSettings().getUserAgentString(); 144 | } 145 | 146 | public void setUserAgentString(String ua) { 147 | lxWebView.getSettings().setUserAgentString(ua); 148 | 149 | } 150 | 151 | public android.webkit.WebSettings getSettings() { 152 | return lxWebView.getSettings(); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /library/src/main/java/com/kazy/lx/LxWebView.java: -------------------------------------------------------------------------------- 1 | package com.kazy.lx; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Bitmap; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | import android.util.AttributeSet; 10 | import android.webkit.WebChromeClient; 11 | import android.webkit.WebSettings; 12 | import android.webkit.WebView; 13 | import android.webkit.WebViewClient; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | public class LxWebView extends WebView { 20 | 21 | private WebViewState state = WebViewState.STOP; 22 | 23 | private List webViewStateListeners = new ArrayList<>(); 24 | 25 | private List loadingInterceptors = new ArrayList<>(); 26 | 27 | public LxWebView(Context context) { 28 | super(context); 29 | initialize(); 30 | } 31 | 32 | public LxWebView(Context context, AttributeSet attrs) { 33 | super(context, attrs); 34 | initialize(attrs); 35 | } 36 | 37 | public LxWebView(Context context, AttributeSet attrs, int defStyle) { 38 | super(context, attrs, defStyle); 39 | initialize(attrs); 40 | } 41 | 42 | public void addOnWebViewStateListener(WebViewStateListener webViewStateListener) { 43 | webViewStateListeners.add(webViewStateListener); 44 | } 45 | 46 | private void initialize() { 47 | setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); 48 | setWebViewClient(new WebServiceViewClient()); 49 | setWebChromeClient(new WebServiceChromeClient()); 50 | } 51 | 52 | private void initialize(AttributeSet attrs) { 53 | TypedArray args = getContext().obtainStyledAttributes(attrs, R.styleable.Lx); 54 | setupWebSettings(args); 55 | args.recycle(); 56 | setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); 57 | setWebViewClient(new WebServiceViewClient()); 58 | setWebChromeClient(new WebServiceChromeClient()); 59 | } 60 | 61 | @SuppressLint("SetJavaScriptEnabled") 62 | protected void setupWebSettings(TypedArray args) { 63 | boolean allowContentAccess = args.getBoolean(R.styleable.Lx_allow_content_access, true); 64 | boolean allowFileAccess = args.getBoolean(R.styleable.Lx_allow_file_access, true); 65 | boolean allowFileAccessFromFileURLs = args.getBoolean(R.styleable.Lx_allow_file_access_from_file_urls, true); 66 | boolean allowUniversalAccessFromFileURLs = args.getBoolean(R.styleable.Lx_allow_universal_access_from_file_urls, false); 67 | boolean appCacheEnabled = args.getBoolean(R.styleable.Lx_app_cache_enabled, false); 68 | boolean blockNetworkImage = args.getBoolean(R.styleable.Lx_block_network_image, false); 69 | boolean blockBlockNetworkLoads = args.getBoolean(R.styleable.Lx_block_network_loads, false); 70 | boolean builtInZoomControls = args.getBoolean(R.styleable.Lx_built_in_zoom_controls, false); 71 | int cacheMode = args.getInt(R.styleable.Lx_cache_mode, WebSettings.LOAD_DEFAULT); 72 | boolean databaseEnabled = args.getBoolean(R.styleable.Lx_database_enabled, false); 73 | boolean displayZoomControls = args.getBoolean(R.styleable.Lx_display_zoom_controls, false); 74 | boolean domStorageEnabled = args.getBoolean(R.styleable.Lx_dom_storage_enabled, false); 75 | boolean geolocationEnabled = args.getBoolean(R.styleable.Lx_geolocation_enabled, true); 76 | boolean javaScriptCanOpenWindowsAutomatically = args.getBoolean(R.styleable.Lx_java_script_can_open_windows_automatically, false); 77 | boolean jsEnabled = args.getBoolean(R.styleable.Lx_java_script_enabled, false); 78 | boolean loadWithOverviewMode = args.getBoolean(R.styleable.Lx_load_with_overview_mode, false); 79 | boolean loadsImagesAutomatically = args.getBoolean(R.styleable.Lx_loads_images_automatically, true); 80 | boolean needInitialFocus = args.getBoolean(R.styleable.Lx_need_initial_focus, false); 81 | boolean saveFormEnabled = args.getBoolean(R.styleable.Lx_save_form_data, true); 82 | boolean supportMultipleWindows = args.getBoolean(R.styleable.Lx_support_multiple_windows,false); 83 | boolean supportZoom = args.getBoolean(R.styleable.Lx_support_zoom, true); 84 | boolean useWideViewPort = args.getBoolean(R.styleable.Lx_use_wide_view_port, true); 85 | 86 | WebSettings setting = getSettings(); 87 | setting.setAllowContentAccess(allowContentAccess); 88 | setting.setAllowFileAccess(allowFileAccess); 89 | setting.setAllowFileAccessFromFileURLs(allowFileAccessFromFileURLs); 90 | setting.setAllowUniversalAccessFromFileURLs(allowUniversalAccessFromFileURLs); 91 | setting.setAppCacheEnabled(appCacheEnabled); 92 | setting.setBlockNetworkImage(blockNetworkImage); 93 | setting.setBlockNetworkLoads(blockBlockNetworkLoads); 94 | setting.setBuiltInZoomControls(builtInZoomControls); 95 | setting.setCacheMode(cacheMode); 96 | setting.setDatabaseEnabled(databaseEnabled); 97 | setting.setDisplayZoomControls(displayZoomControls); 98 | setting.setDomStorageEnabled(domStorageEnabled); 99 | setting.setGeolocationEnabled(geolocationEnabled); 100 | setting.setJavaScriptCanOpenWindowsAutomatically(javaScriptCanOpenWindowsAutomatically); 101 | setting.setJavaScriptEnabled(jsEnabled); 102 | setting.setLoadWithOverviewMode(loadWithOverviewMode); 103 | setting.setLoadsImagesAutomatically(loadsImagesAutomatically); 104 | setting.setNeedInitialFocus(needInitialFocus); 105 | setting.setSaveFormData(saveFormEnabled); 106 | setting.setSupportMultipleWindows(supportMultipleWindows); 107 | setting.setSupportZoom(supportZoom); 108 | setting.setUseWideViewPort(useWideViewPort); 109 | 110 | if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { 111 | setting.setSavePassword(false); 112 | } 113 | } 114 | 115 | public void addLoadingInterceptor(LoadingInterceptor loadingInterceptor) { 116 | this.loadingInterceptors.add(loadingInterceptor); 117 | } 118 | 119 | private class WebServiceChromeClient extends WebChromeClient { 120 | 121 | @Override 122 | public void onProgressChanged(WebView view, int progress) { 123 | super.onProgressChanged(view, progress); 124 | if(state == WebViewState.LOADING){ 125 | for(WebViewStateListener listener : webViewStateListeners){ 126 | listener.onProgressChanged(view, progress); 127 | } 128 | } 129 | } 130 | 131 | } 132 | 133 | private class WebServiceViewClient extends WebViewClient { 134 | 135 | @Override 136 | public void onPageStarted(WebView view, String url, Bitmap favicon) { 137 | super.onPageStarted(view, url, favicon); 138 | if (state == WebViewState.STOP) { 139 | state = WebViewState.LOADING; 140 | for(WebViewStateListener listener : webViewStateListeners){ 141 | listener.onStartLoading(url, favicon); 142 | } 143 | } 144 | } 145 | 146 | @Override 147 | public void onReceivedError(WebView view, int errorCode, String description, 148 | String failingUrl) { 149 | super.onReceivedError(view, errorCode, description, failingUrl); 150 | state = WebViewState.ERROR; 151 | for(WebViewStateListener listener : webViewStateListeners){ 152 | listener.onError(errorCode, description, failingUrl); 153 | } 154 | } 155 | 156 | @Override 157 | public void onPageFinished(WebView view, String loadedUrl) { 158 | super.onPageFinished(view, loadedUrl); 159 | if (state == WebViewState.LOADING) { 160 | for(WebViewStateListener listener : webViewStateListeners){ 161 | listener.onProgressChanged(view, 100); 162 | listener.onFinishLoaded(loadedUrl); 163 | } 164 | } 165 | state = WebViewState.STOP; 166 | } 167 | 168 | @Override 169 | public boolean shouldOverrideUrlLoading(WebView view, String loadingUrl) { 170 | if (loadingUrl == null || loadingInterceptors == null) { 171 | return false; 172 | } 173 | return intercept(Uri.parse(loadingUrl)); 174 | } 175 | 176 | } 177 | 178 | @Override 179 | public void loadUrl(String url) { 180 | if (intercept(Uri.parse(url))) { 181 | return; 182 | } 183 | super.loadUrl(url); 184 | } 185 | 186 | @Override 187 | public void loadUrl(String url, Map additionalHttpHeaders) { 188 | if (intercept(Uri.parse(url))) { 189 | return; 190 | } 191 | super.loadUrl(url, additionalHttpHeaders); 192 | } 193 | 194 | private boolean intercept(Uri uri) { 195 | for (LoadingInterceptor loadingInterceptor : loadingInterceptors) { 196 | if (loadingInterceptor.validate(uri)) { 197 | loadingInterceptor.exec(uri); 198 | return true; 199 | } 200 | } 201 | return false; 202 | } 203 | 204 | } 205 | -------------------------------------------------------------------------------- /library/src/main/java/com/kazy/lx/WebViewState.java: -------------------------------------------------------------------------------- 1 | package com.kazy.lx; 2 | 3 | public enum WebViewState { 4 | STOP, LOADING, ERROR 5 | } 6 | -------------------------------------------------------------------------------- /library/src/main/java/com/kazy/lx/WebViewStateListener.java: -------------------------------------------------------------------------------- 1 | package com.kazy.lx; 2 | 3 | import android.graphics.Bitmap; 4 | import android.webkit.WebView; 5 | 6 | public interface WebViewStateListener { 7 | 8 | public void onStartLoading(String url, Bitmap favicon); 9 | 10 | public void onError(int errorCode, String description, String failingUrl); 11 | 12 | public void onFinishLoaded(String loadedUrl); 13 | 14 | public void onProgressChanged(WebView view, int progress); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /library/src/main/res/layout/view_lx_web_container.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 17 | 22 | 32 | 41 |