Advanced Webview


Source link: https://github.com/jjhesk/EZWebView

Advanced Webview

Latest Version v1.7.0

Feature list

  • handler Google SSL alert #2
  • no more memory leak issue in video iframe
  • easy web page margin fixed
  • easy web video implementation
  • easy web content display implementation
  • took care of life cycle issues
  • fantasy animation reveal fade in
  • UriFactory set
  • Fx9C set
  • In32 set
  • CommentBoxUrl resolve facebook, weibo, popbee comment issues
  • Support Post Method
  • support sound cloud
  • extra js script runtime
  • JsBridge integration, make a bridge between Java and JavaScript.
  • Youtube dialog display with material design.
  • Support inject additional CSS for webview load. (use HBCart client)

Download for the Sample APK

For initiating a webview, simply thing to do this to do it once for all.

Demo example code

Remote Repo

 repositories {

maven {
 url "http://dl.bintray.com/jjhesk/maven" 
}

  
}

Dependency

compile 'com.hkm.ezwebview:ezwebviewv:1.7.0'

Step 1.

please locate in the xml for the video display


 <RelativeLayout

android:id="@+id/framevideoplayer"

android:layout_width="match_parent"

android:layout_height="@dimen/item_height_video"

android:background="@color/main_background"

android:padding="1dp"

android:visibility="gone">

 <com.hkm.ezwebview.webviewleakfix.NonLeakingWebView

 android:id="@+id/videoplayer"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:layout_centerInParent="true"

 android:background="@color/main_background"

 android:visibility="gone" />

 <com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar

xmlns:fab="http://schemas.android.com/apk/res-auto"

 android:id="@+id/progressloadingbarpx"

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

 android:layout_centerInParent="true"

 fab:mlpb_enable_circle_background="true"

 fab:mlpb_inner_radius="18dp"

 fab:mlpb_progress_color="@color/second_grey_bg"

 fab:mlpb_show_arrow="false" />

  </RelativeLayout>

if you need to start a content display for html please also specify the xml as below:

<RelativeLayout

android:id="@+id/content_article_frame"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="10dp"

android:layout_marginLeft="10dp"

android:layout_marginRight="10dp"

android:visibility="gone">

 <com.hkm.ezwebview.webviewleakfix.NonLeakingWebView

 android:id="@+id/content_block"

 android:layout_width="match_parent"

 android:layout_height="match_parent"

 android:visibility="gone"

 tool:ignore="WebViewLayout" />

  </RelativeLayout>

HTML content display area

======= This is the fast simple implementation without any callbacks:

  @Override
  public void onViewCreated(View v, Bundle b) {

initBinding(v);

final String contentc = fromFileRaw(getActivity(), R.raw.sample_html);

try {

 Fx9C.setup_content_block_wb(this, content_article_frame, block, contentc);

}
 catch (Exception e) {

 e.printStackTrace();

}

// if (bloadlistenr != null)

//
bloadlistenr.onLoad();

  
}
 

This is the advanced implementation:

  @Override
  public void onViewCreated(View v, Bundle b) {

initBinding(v);

final String contentc = fromFileRaw(getActivity(), R.raw.sample_html);

try {

 Fx9C.setup_content_block_wb(this, content_article_frame, block, contentc, new HClient.Callback() {

@Override

  public void retrieveCookie(String cookie_string) {

}

 
}
, new Runnable() {

  @Override

  public void run() {

ViewCompat.animate(mprogressbar).alpha(0f).withEndAction(new Runnable() {

 @Override

 public void run() {

  mprogressbar.setVisibility(View.GONE);

 
}

}
);

  
}

 
}
);

}
 catch (Exception e) {

 e.printStackTrace();

}

// if (bloadlistenr != null)

//
bloadlistenr.onLoad();

  
}
 

After enhancement

=======

Video embeded content display area

=======

 try {

 CircleProgressBar bprogressbar = (CircleProgressBar)this.findViewById(R.id.progressloadingbarpx);

 Fx9C.setup_web_video(

this,

video_frame,

mVideo,

bprogressbar,

video_embed_code_webvoew,

new HClient.Callback() {

 @Override

 public void startNewActivity(String s, String s1, String s2, Context context) {

  
}

  @Override

 public void startFeedList(String s, Context context) {

  
}

  @Override

 public void openUri(String s, Context context) {

  
}

  @Override

 public void retrieveCookie(String s) {

  
}

}
, null);

}
 catch (Exception e) {

 e.printStackTrace();

}

Register a Java handler function so that js can call

 webView.registerHandler("submitFromWeb", new BridgeHandler() {

@Override

public void handler(String data, CallBackFunction function) {

 Log.i(TAG, "handler = submitFromWeb, data from web = " + data);

 function.onCallBack("submitFromWeb exe, response data from Java");

}

  
}
);
 

js can call this Java handler method "submitFromWeb" through:

 WebViewJavascriptBridge.callHandler(

'submitFromWeb'

, {
'param': str1
}

, function(responseData) {

 document.getElementById("show").innerHTML = "send get responseData from java, data = " + responseData

}

  );
 

You can set a default handler in Java, so that js can send message to Java without assigned handlerName

 webView.setDefaultHandler(new DefaultHandler());
 
 window.WebViewJavascriptBridge.send(

data

, function(responseData) {

 document.getElementById("show").innerHTML = "repsonseData from java, data = " + responseData

}

  );
 

Register a JavaScript handler function so that Java can call

 WebViewJavascriptBridge.registerHandler("functionInJs", function(data, responseCallback) {

document.getElementById("show").innerHTML = ("data from Java: = " + data);

var responseData = "Javascript Says Right back aka!";

responseCallback(responseData);

  
}
);
 

Java can call this js handler function "functionInJs" through:

 webView.callHandler("functionInJs", new Gson().toJson(user), new CallBackFunction() {

@Override

public void onCallBack(String data) {

 
}

  
}
);
 

You can also define a default handler use init method, so that Java can send message to js without assigned handlerName

for example:

 bridge.init(function(message, responseCallback) {

console.log('JS got a message', message);

var data = {

 'Javascript Responds': 'Wee!'

}
;

console.log('JS responding with', data);

responseCallback(data);

  
}
);
 
 webView.send("hello");

will print 'JS got a message hello' and 'JS responding with' in webview console.

Notice

This lib will inject a WebViewJavascriptBridge Object to window object. So in your js, before use WebViewJavascriptBridge, you must detect if WebViewJavascriptBridge exist. If WebViewJavascriptBridge does not exit, you can listen to WebViewJavascriptBridgeReady event, as the blow code shows:

 if (window.WebViewJavascriptBridge) {

//do your work here
  
}
 else {

document.addEventListener(

 'WebViewJavascriptBridgeReady'

 , function() {

  //do your work here

 
}
,

 false

);

  
}
 

Dialog webview implementation

For fragment that uses support.v4 package: The youtube video ID will be taken in place

EzWebDialogNonLeakv4.newInstanceYoutube("_Oh9oSZSUbQ").show(getFragmentManager());

For normal support:

EzWebDialogNonLeak.newInstanceYoutube("_Oh9oSZSUbQ").show(getFragmentManager());

Thank you for your support and we will bring more amazing libraries to your productive works. We are accepting bitcoin by the address as below. Please scan the QR code to start

License

Copyright 2015 jjHESK, HKM UNITED  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

A safe JsBridge framework.

PhotoFiltersSDK aims to provide fast, powerful and flexible image processing instrument for creating awesome effects on any image media.

Easy Android form validation in Rx way.

This library can be used to implement Material Designed Settings/Preference Screen on Pre-Lollipop devices.

A clean, minimalistic, easy-to-use and highly customizable pin lock custom view for Android.

HintCase is a library for Android that will help you create really awesome hints/tips for your apps.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes