Java Question Decompiled WebViewWrapper

warwound

Expert
Licensed User
Longtime User
Hi

After reading in another thread about Java Decompiler i have been looking at the B4A Core.jar library.

Specifically looking at the WebViewWrapper class to see if it'd be easier to add new WebView methods to and then recompile that class instead of creating a library with the new methods.

I thought i'd add a 'clearCache' method if possible.

Anyway i exported the decompiled class from Java Decompiler and opened it in Eclipse.
Eclipse shows an error The constructor WebViewClient(BA, String) is undefined as it can find no (overloaded) WebViewClient constructor.

B4X:
super.innerInitialize(ba, eventName, true);
((WebView) getObject()).setWebViewClient(new WebViewClient(ba, eventName) {
   public void onPageFinished(WebView view, String url) {
      this.val$ba.raiseEvent(WebViewWrapper.this.getObject(),
            this.val$eventName + "_pagefinished",
            new Object[] { url });
   }

   public boolean shouldOverrideUrlLoading(WebView view, String url) {
      Boolean b = (Boolean) this.val$ba.raiseEvent(
            WebViewWrapper.this.getObject(), this.val$eventName
                  + "_overrideurl", new Object[] { url });
      if (b != null)
         return b.booleanValue();
      return false;
   }
});

The native WebViewClient constructor signature doesn't match the code in the WebViewWrapper class.

What would i have to do to the code in Eclipse to get it to compile?

Thanks.

Martin.

PS If this sort of reverse engineering is not allowed just let me know and i'll not spend any more time on it!
 

agraham

Expert
Licensed User
Longtime User
Personally I wouldn't replace an "official" library, even just for my own use as if the offical library is changed in future my version would need revisiting. To provide an enhancement I would either use Reflection or write a library to which I pass an instance of whatever it is that I wanted to manipulate.

That said, the decompiler often doesn't get it quite right, particularly in the case where the compiler adds a load of syntactic sugar - in this case an anonymous class. I think it has butchered the definition of the anonymous sublcass of WebViewClient that is being declared and instantiated there by adding to the constructor for WebViewClient the final local variables it refences in the class definition. I think it should probably be "new WebViewClient()" and the code would need the all the "val$" removed and some "final" definitions added as well.
 

warwound

Expert
Licensed User
Longtime User
Personally I wouldn't replace an "official" library, even just for my own use as if the offical library is changed in future my version would need revisiting. To provide an enhancement I would either use Reflection or write a library to which I pass an instance of whatever it is that I wanted to manipulate.

Thanks for the reply.

I hadn't considered that official library updates could make it a hard to maintain project.

I'll stick with a additional library approach!

Martin.
 
Top