As I am sure you all know. Setting up a WebView is a matter of creating a webview browser client, setting properties and loading a resource into the browser client. I have created several android apps that do exactly that.
What i would like to try now is horizontal swiping of different web resources. Imagine a main home page at one url, a categories page at another url and a search page at another url. I would like to create a UI construct that allows swiping from the main home page url view to a view displaying the categories url and then another swipe that shows the view with the search resource (think the new android market UI – swipe left shows categories).
I have read up on ViewFlipper and several posts here, but I am not able to find a comprehensive example of how to integrate the browser instantiation with view flipping/swiping.
Question: Can someone provide an example that can perform some variation of the above and/or provide a link to an example that shows browser instantiation with web view flipping/ swiping.
Feel free to correct my suggested implementation… there may be a better way to do this that I haven’t considered yet…
Well, I’ve worked on this for some time and I have a solution that works. I am not sure it is the most effective solution, but I just kept researching and writing code until I figured out something that made sense. With the following code I need to give a big shout out to Android & Amir at http://android-journey.blogspot.com/2010/01/android-webview.html for helping me figure this out. He’s got some great stuff and you all should check it out.
The first step is to create a class in your Activity package called SimpleGestureFilter and use the code found here. This comes directly from Amir and dramatically simplifies the gesture interactions for swipe.
The next step is to use ViewFlipper for your layout. I was using buttons and several other things so there is more in this layout file than necessary, but you should get the picture.
As you can see, the xml describes a linear layout that contains a ViewFlipper. In the view flipper there are three WebViews.
The final step is the Activity…
So… The basic pattern I came up with is to use a single web client and browser settings. I use the onCreate method to load the views, set the first view and then an Async method to load the other views after the main view is loaded. So two of the views load in the background. I them use the patterns Amir passed on to manage swipe. I use buttons and JS interfaces to invoke the same animations on clicks.
The final result is swipe and click animations for ViewFlipping webviews similar to the UI you’ll see in the new android market UI. Feel free to recommend any additional implementation that might make this pattern stronger.