Feb 22 2009

How is Mosembro different from OilCan?

Category: Android, MosembroAleksander Kmetec @ 4:42 am
Alternate logo.
Image via Wikipedia

If you looked at OilCan – a Greasemonkey-like browser extension for Android – and Mosembro, you’d quickly realize that they have a lot in common. Both are experimental browser extensions which run on Android, both aim to make websites friendlier, both support installable actions written in JavaScript, and both make it possible for those scripts to modify web pages and launch other applications. And since looking at OilCan’s source code has allowed me to avoid reinventing the wheel at several occasions, some pretty obvious similarities can also be spotted at the source code level.

So, with so many things in common, how are they different at all?

The main difference, I believe, is what causes user scripts to be triggered. A typical OilCan script is triggered by a web page’s URL and is executed only once. Its goal is to change the content or functionality of a very specific document. Mosembro scripts, on the other hand, are triggered by embedded microformats and can be executed dozens of times for each page, while not caring about which page they were executed on.

I could say at this point that OilCan’s approach to invoking scripts could be compared to function calls in programming languages and Mosembro’s approach compared to what is done in aspect oriented programming, with functionality implemented by actions attached to bits of semantic content being cross-cutting concerns, but I’m not sure about it, so I won’t. ;-)

Also, because Mosembro is very narrowly focused on adding functionality to web pages based on semantic data embedded in them it can also provide additional infrastructure, like microformat parsers and action menus, which wouldn’t exactly fit in with a more general purpose framework. And finally, there’s the integrated support for site-level search.

So, there you have it. While it’s true that both apps have a lot in common, it’s their unique features that really matter.

Reblog this post [with Zemanta]

Tags: , , ,


Feb 19 2009

Mosembro r5 now available for download

Category: Android, Mobile, Mobile web, Mosembro, UncategorizedAleksander Kmetec @ 8:59 pm

The first major Mosembro release after r2 is now available for download.

If you already have Mosembro installed, uninstall it first by running: adb uninstall com.lexandera.mosembro
The new version can then be installed by executing the following command: adb install mosembro-r2.apk

New features include:

  • It is now possible to install addidional actions which extend Mosembro’s functionality.
  • Addresses can be copied to clipboard.
  • Improved security and various bugfixes.

Screenshots of new features:

Mosmbro r5 screenshots

Mosembro r5: dialogs for installing and managing installed actions

Several simple actions can be installed from the bottom of the demo page which is loaded when Mosembro starts up. Go & try them out.


Feb 01 2009

Intercepting page loads in WebView

Category: Android, WebView examplesAleksander Kmetec @ 6:20 am

It is time for another WebView example. This time on how you can intercept any attempts at loading a web page and redirect the user to a different URL instead.

This can be achieved simply by registering a WebViewClient which overrides the shouldOverrideUrlLoading() method in which you tell the WebView to load a different URL from the one the user had requested.

The example below loads lexandera.com first, but when the user clicks any link on the page, he is redirected to yahoo.com:


WebView browser = (WebView)findViewById(R.id.browser);
browser.setWebViewClient(new WebViewClient() {
    /* On Android 1.1 shouldOverrideUrlLoading() will be called every time the user clicks a link,
     * but on Android 1.5 it will be called for every page load, even if it was caused by calling loadUrl()! */
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        /* intercept all page load attempts and load yahoo.com instead */
        String myAlternativeURL = "http://yahoo.com";
        if (!url.equals(myAlternativeURL)) {
            view.loadUrl(myAlternativeURL);
            return true;
        }

        return false;
    }
});

browser.loadUrl("http://lexandera.com/");

Please note that calling loadUrl() does not trigger the shouldOverrideUrlLoading() method, which means that we do not need to worry about endless recursion when calling loadUrl() from within shouldOverrideUrlLoading()!

UPDATE: The above statement is no longer true for Android 1.5! Calling loadUrl() will now also trigger the shouldOverrideUrlLoading() method! This means that you need to make sure that you are not creating an infinite loop when calling loadUrl() from shouldOverrideUrlLoading()!

Reblog this post [with Zemanta]

Tags: , ,