B4A Library Little WebView Extension v1.20

Surfing the internet over 3GP/UTMS/... is pretty slow and pretty expensive in my country. I want to have a tiny, fast web browser without not needed functions to keep data traffic as small as possible.

The WebView does not have a lot of properties to get control of traffic releated stuff. That's why i wrote this little library. The attachement contains a fully working example and shows all functions.

What you can do with it:
------------------------
- Get and set the state of accepting cookies
- Get and set the state of loading images
- Get and set the state of enabling javascript
- Get and set the state of enabling plugins
- Get the progress of current page loading
- Get the title of the current page
- Scrolling the current page half the page or full up and down
- Zoom in and out

I tested it a long time, it works perfect on my tablet with Android 3.2 and Smartphone with Android 2.3.7 (Custom Rom)

The meaning of the scrolling and zooming functions is simpel. I hold the tablet in one hand and don't want to wipe with my fingers all the time over the display. So I made a few buttons on the side of the webview. Now i can surf the internet with tapping a few buttons :)

Here is a screenshot of my selfmade tablet webbrowser:
http://www.thalmy.ch/diesunddas/minibrowser.jpg

Whats coming next:
-------------------
Get the favicon of the current page. This works right now, but i can not display the image because favicons are ICO bitmaps. I have to find out how I can convert them to BMP bitmaps. And I also want to read the OS Browser bookmarks wich are stored in an internal database.
 

Attachments

  • WebViewXtenderExample.zip
    279.6 KB · Views: 2,673

NeoTechni

Well-Known Member
Licensed User
Longtime User
I've having trouble getting it to scroll to the bottom of the page right after the page loads. It scrolls once, then goes right back to the top and refuses to go back down
 

Roeschti

Member
Licensed User
Longtime User
Well, the base of the lib is the official stuff from here:
WebView | Android Developers

I dont have ICS on my devices, so maybe there are differences in the behaviour / implementation in diffrent API levels.

Check the link above and feel free to change the lib in the way you like it :)
 

francoisg

Active Member
Licensed User
Longtime User
WebView Events

Hi,
will it be possible for you to add WebView events handling? I need to know when the zoom scale changes for instance (onScaleChanged) / the page is being scrolled (onScrollchanged)!

Then the hard one - would it be possible to catch the onDraw event?
 

jroriz

Active Member
Licensed User
Longtime User
Same for me.

To get the thing done, I used:

B4X:
Dim InTopEdge As Int
InTopEdge = wvXtender.getScrollY(WebView1)
   
'wvXtender.scrollBY(WebView1, 0, 1) -- does not work...
wvXtender.scrollTO(WebView1, 0, InTopEdge + 1)
 

Shaun

Member
Licensed User
Longtime User
I just want to thank you for your work on this! This is perfect for a project I am doing for my boss. I'm making an android version of our web based, 'in out board', which lets folks know where we are and what we are doing at work. This library makes my little app very rich.

Another programmer at work has been attempting to make this simple Droid (his first stab at Android programming) app in Java for over a month. Took me a few hours with B4a and this library, and mine is a lot cleaner and nicer features! Lovin' it!
 

Derek Johnson

Active Member
Licensed User
Longtime User
I've used this hack to get handle the 404 Not Found Error. It relies on the returned document title being '404 Page Not Found'

B4X:
Sub WebView1_PageFinished (Url As String)
WebEx.executeJavascript(WebView1, "B4A.CallSub('JavascriptCallback', true, document.title)")
End Sub

Sub JavascriptCallback(string1 As String)
       If string1.StartsWith("404") Then
           log("Page not found! ")
       End If
    Activity.Title=string1
End Sub
 

fash866

Member
Licensed User
Longtime User
I updated the library to v1.40

NEW in this release:

getHost:
return host name of given URL

getTitle:
Returns title of current page

getFaviconFromUrl:
Returns the favicon (a bitmap, not the ICO Bitmap!) of a given URL. You can specify a default icon, if URL has no favicon. I use it to show the bitamp in a imageview.

getFaviconFromUrl2:
Returns the favicon (a bitmap, not the ICO Bitmap!) of a given URL and does auto converting if URL has a favicon. If not, it returns default bitmap

scrollTo:
Set the scrolled position of your view in given x and y positions as int values.

scrollBy:
Move the scrolled position of your view in given x and y positions as int values.

getScrollX:
Return the scrolled left position of this view. This is the left edge of the displayed part of your view.

getScrollY:
Return the scrolled top position of this view. This is the top edge of the displayed part of your view

isHorizontalScrollBarEnabled:
Indicate whether the horizontal scrollbar should be drawn or not. The scrollbar is not drawn by default.

setHorizontalScrollBarEnabled:
Define whether the horizontal scrollbar should be drawn or not

isVerticalScrollBarEnabled:
Indicate whether the horizontal scrollbar should be drawn or not.

setVerticalScrollBarEnabled:
Define whether the vertical scrollbar should be drawn or not

setScrollBarStyle:
Specify the style of the scrollbars.

What is the meaning of this scroll functions? I hate to scroll all the time down on many pages, if they have a large header like Basic4android (Basic for Android) - Rapid Application Development :) if you wanna surf the forum here, you have to scroll down third part of the display to see the first thread, and this every time. So I scroll down once to the beginning of the forum, read with "getScrollX" the x position and store it together with the host name. From this moment on after page load is finished, it scrolls automaticly down to the stored position with "scrollTo". This works in all directons (left, right, up and down)

Sorry for my bad english, I was never in the mood to learn it correctly :)
I am try.
 

Roeschti

Member
Licensed User
Longtime User
Wow, such a long time ago and my lib is still in use! Have fun and keep rockin' :D
 

Leni Berry

Active Member
Licensed User
Longtime User
how to get page source like in chrome menu "view page source"? is it possible with this library?
 

danijel

Active Member
Licensed User
Longtime User
Hi @Roeschti. Still rockin in 2016 :D
But this is not working for me.
I always get default icon :/

B4X:
Sub Webview1_PageFinished (Url As String)

    Dim FavIco, DefaultIcon As Bitmap
    DefaultIcon.Initialize(File.DirAssets, "home.png")
    FavIco.Initialize3(wvXtender.getFaviconFromUrl(Url, DefaultIcon))
    FavIcon.Bitmap=FavIco
   
End Sub


Can you please provide me working code?
 
Top