1111import android .graphics .Bitmap ;
1212import android .graphics .BitmapFactory ;
1313import android .graphics .drawable .Icon ;
14- import android .support .v4 .content .pm .ShortcutManagerCompat ;
15- import android .support .v4 .content .pm .ShortcutInfoCompat ;
16- import android .support .v4 .graphics .drawable .IconCompat ;
1714import android .net .Uri ;
1815import android .net .http .SslCertificate ;
1916import android .net .http .SslError ;
2320import android .webkit .*;
2421import android .widget .FrameLayout ;
2522import java .util .*;
26- import java .net .MalformedURLException ;
2723import java .net .URL ;
2824import java .io .ByteArrayInputStream ;
2925import java .nio .charset .StandardCharsets ;
3026import android .content .pm .ShortcutInfo ;
3127import android .content .pm .ShortcutManager ;
28+ import android .view .MotionEvent ;
3229import com .google .appinventor .components .annotations .DesignerComponent ;
3330import com .google .appinventor .components .annotations .SimpleFunction ;
3431import com .google .appinventor .components .annotations .SimpleObject ;
5047import com .google .appinventor .components .annotations .DesignerProperty ;
5148import com .google .appinventor .components .annotations .PropertyCategory ;
5249import com .google .appinventor .components .common .PropertyTypeConstants ;
53- import android .view .MotionEvent ;
5450@ DesignerComponent (version = 8 , description ="An extended form of Web Viewer <br> Developed by Sunny Gupta" , category = ComponentCategory .EXTENSION , nonVisible = true , iconName = "https://res.cloudinary.com/andromedaviewflyvipul/image/upload/c_scale,h_20,w_20/v1571472765/ktvu4bapylsvnykoyhdm.png" ,helpUrl ="https://github.com/vknow360/CustomWebView" )
5551@ UsesActivities (activities = {@ ActivityElement (intentFilters = {@ IntentFilterElement (actionElements = {@ ActionElement (name = "android.intent.action.VIEW" )}, categoryElements = {@ CategoryElement (name = "android.intent.category.DEFAULT" ), @ CategoryElement (name = "android.intent.category.BROWSABLE" )}, dataElements = {@ DataElement (scheme = "http" ), @ DataElement (scheme = "https" )}), @ IntentFilterElement (actionElements = {@ ActionElement (name = "android.intent.action.VIEW" )}, categoryElements = {@ CategoryElement (name = "android.intent.category.DEFAULT" ), @ CategoryElement (name = "android.intent.category.BROWSABLE" )}, dataElements = {@ DataElement (scheme = "http" ), @ DataElement (scheme = "https" ), @ DataElement (mimeType = "text/html" ), @ DataElement (mimeType = "text/plain" ), @ DataElement (mimeType = "application/xhtml+xml" )})},name ="com.sunny.CustomWebView.WebActivity" )})
5652@ SimpleObject (external =true )
5753@ UsesPermissions (permissionNames ="android.permission.WRITE_EXTERNAL_STORAGE,android.permission.ACCESS_DOWNLOAD_MANAGER,android.permission.ACCESS_FINE_LOCATION,android.permission.RECORD_AUDIO, android.permission.MODIFY_AUDIO_SETTINGS, android.permission.CAMERA,android.permission.VIBRATE,android.webkit.resource.VIDEO_CAPTURE,android.webkit.resource.AUDIO_CAPTURE,android.launcher.permission.INSTALL_SHORTCUT" )
5854public final class CustomWebView extends AndroidNonvisibleComponent {
59- public boolean NO_VIEW = true ;
6055 public Activity activity ;
6156 public WebView webView ;
6257 public Context context ;
@@ -92,8 +87,8 @@ public final class CustomWebView extends AndroidNonvisibleComponent{
9287 public int zoomPercent = 100 ;
9388 public boolean zoomEnabled = true ;
9489 public boolean displayZoom = true ;
95- public Message rObj ;
96- public CustomWebView (ComponentContainer container ) {
90+ public Message resultObj ;
91+ public CustomWebView (ComponentContainer container ) {
9792 super (container .$form ());
9893 activity = container .$context ();
9994 context = (Context ) activity ;
@@ -222,7 +217,7 @@ public boolean onLongClick(View view) {
222217 str = (String )message .getData ().get ("url" );
223218 }
224219 LongClicked (item ,str ,type );
225- return true ;
220+ return ! longClickable ;
226221 }
227222 });
228223 web .setOnScrollChangeListener (new View .OnScrollChangeListener () {
@@ -438,7 +433,7 @@ public boolean LongClickable() {
438433 return longClickable ;
439434 }
440435 @ SimpleProperty (description ="Sets the initial scale for active WebView. 0 means default. If initial scale is greater than 0, WebView starts with this value as initial scale. " )
441- public void InitialiScale (int scale ){
436+ public void InitialScale (int scale ){
442437 if (webView != null ) {
443438 webView .setInitialScale (scale );
444439 }
@@ -710,6 +705,13 @@ public void ClearInternalHistory(){
710705 webView .clearHistory ();
711706 }
712707 }
708+ @ SimpleFunction ()
709+ public void LoadInNewWindow (int id ){
710+ WebView w = wv .get (id );
711+ WebView .WebViewTransport transport = (WebView .WebViewTransport ) resultObj .obj ;
712+ transport .setWebView (w );
713+ resultObj .sendToTarget ();
714+ }
713715 @ SimpleFunction (description ="Performs zoom in in the WebView" )
714716 public void ZoomIn (){
715717 if (webView != null ){
@@ -761,7 +763,8 @@ public void RemoveWebView(int id){
761763 ((FrameLayout )w .getParent ()).removeView (w );
762764 w .destroy ();
763765 wv .remove (id );
764- OnWebViewRemoved (id );
766+ iD = 0 ;
767+ OnWebViewRemoved (id );
765768 }
766769 }
767770 @ SimpleFunction (description ="Gets whether the page can go back or forward the given number of steps." )
@@ -1065,7 +1068,7 @@ public void onClick(DialogInterface dialog, int which) {
10651068
10661069 @ Override
10671070 public void onShowCustomView (View paramView , CustomViewCallback paramCustomViewCallback ) {
1068- if ( wv . get ( CurrentId ()) == paramView ){
1071+ OnShowCustomView ();
10691072 if (mCustomView != null ) {
10701073 onHideCustomView ();
10711074 return ;
@@ -1085,8 +1088,6 @@ public void onSystemUiVisibilityChange(int i) {
10851088 updateControls ();
10861089 }
10871090 });
1088- OnShowCustomView ();
1089- }
10901091 }
10911092 void updateControls () {
10921093 FrameLayout .LayoutParams params = (FrameLayout .LayoutParams ) mCustomView .getLayoutParams ();
@@ -1102,14 +1103,14 @@ void updateControls() {
11021103
11031104 @ Override
11041105 public void onHideCustomView () {
1106+ OnHideCustomView ();
11051107 ((FrameLayout ) activity .getWindow ().getDecorView ()).removeView (mCustomView );
11061108 mCustomView = null ;
11071109 activity .getWindow ().getDecorView ().setSystemUiVisibility (mOriginalSystemUiVisibility );
11081110 activity .setRequestedOrientation (mOriginalOrientation );
11091111 mCustomViewCallback .onCustomViewHidden ();
11101112 mCustomViewCallback = null ;
11111113 activity .setRequestedOrientation (ActivityInfo .SCREEN_ORIENTATION_USER );
1112- OnHideCustomView ();
11131114 }
11141115
11151116 @ Override
@@ -1125,11 +1126,12 @@ public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePathCall
11251126 @ Override
11261127 public boolean onCreateWindow (WebView view , boolean isDialog , boolean isUserGesture , Message resultMsg ) {
11271128 if (SupportMultipleWindows ()){
1128- Message href = view .getHandler ().obtainMessage ();
1129+ /* Message href = view.getHandler().obtainMessage();
11291130 view.requestFocusNodeHref(href);
1130- String u = href .getData ().getString ("url" ) != null ? href .getData ().getString ("url" ):"" ;
1131+ String u = href.getData().getString("url") != null ? href.getData().getString("url"):"";*/
1132+ resultObj = resultMsg ;
11311133 List <WebView > w = new ArrayList <>(wv .values ());
1132- OnNewWindowRequest (new ArrayList <>(wv .keySet ()).get (w .indexOf (view )),u , isDialog ,isUserGesture );
1134+ OnNewWindowRequest (new ArrayList <>(wv .keySet ()).get (w .indexOf (view )),/*u,*/ isDialog ,isUserGesture );
11331135 }
11341136 return SupportMultipleWindows ();
11351137 }
@@ -1211,8 +1213,8 @@ public void ResubmitForm(boolean reSubmit){
12111213 }
12121214 }
12131215 @ SimpleEvent (description ="Event raised when new window is requested by webview with boolean 'isDialog' and 'isPopup'" )
1214- public void OnNewWindowRequest (int id ,String url ,boolean isDialog ,boolean isPopup ){
1215- EventDispatcher .dispatchEvent (this ,"OnNewWindowRequest" ,id ,url ,isDialog ,isPopup );
1216+ public void OnNewWindowRequest (int id ,/* String url,*/ boolean isDialog ,boolean isPopup ){
1217+ EventDispatcher .dispatchEvent (this ,"OnNewWindowRequest" ,id ,/* url,*/ isDialog ,isPopup );
12161218 }
12171219 @ SimpleEvent (description ="Event raised when current page enters in full screen mode" )
12181220 public void OnShowCustomView (){
@@ -1540,7 +1542,7 @@ public class AdBlocker {
15401542 public boolean isAd (String url ) {
15411543 try {
15421544 return isAdHost (url != null && new URL (url ).getHost () != null ? new URL (url ).getHost () : "" );
1543- } catch (MalformedURLException e ) {
1545+ } catch (Exception e ) {
15441546 e .printStackTrace ();
15451547 }
15461548 return isAdHost ("" );
0 commit comments