Hi,
I've some first results regarding the feasibility of phonegap+zim on android.
While it basically works to load an article (without images) and display it
(thanks to Arunesh for doing the java port),
I've encountered some major challenges:
1. How to display images?
It is apparently quite tricky to display images which are not either internet
links or local files in a webview on android:
The most promising concepts I found are:
a). Extract images from zim to local file system and provide them over a
ContentProvider.
b) Replace image src with base64 encoded image data. (Either directly on loading
of article or by using java script)
I'll try to implement at least one of this approaches to find out whether it is
feasible to do so.
However, obviously both approaches are not really perfect solutions, so if
anybody has a better idea please let me know.
Note that there actually would be a good way to do it
(WebViewClient.shouldInterceptRequest()) but unfortunately this is API-level 11
which means
that there is no android mobile phone currently available in the market which
supports it. Note that additionally it would not be possible
to use this with current phonegap versions. Therefore it would be nice if in
future phonegap versions this functionality is provided to plugins. While
this would not help for current mobile phones, it would allow a more efficient
implementation of zim support in the future.
2. Performance
The JAVA liblzma performance is pretty bad: To increase efficiency of
compression in the zim-format articles (and also all
other data like images) are stored in clusters. Cluster size is apparently about
1 MB. This implies that loading an article
which is stored at the end of a cluster involves decompressing the complete
cluster. While this is not a problem with C code
even on embedded devices, it seems to be a problem with Java: Reading an article
at the end of a cluster takes close to 20 s on
my test android phone. As the phone is pretty low end (Orange
Boston ) and uses an old android version (Eclair) without a just-in-timer
compiler I expect that other models
are significantly faster. However, I doubt that the performance gain will be
sufficient to bring article load time in a range of << 1 s.
I am going to try it out, but I'd expect that we probably have to switch to
native code for zimlib support. (At least for liblzma).
An other approach is to reduce cluster size of zim files. I am not sure right
now whether this would be sufficiently fast, but it is
worth considering it as an option: While for android being able to use the java
implementation is a benefit, it is also not a big thing
if native code has to be used. However, more concerning is that it may not be
possible to support for Windows Mobile at all with the
current cluster size. (Because AFAIK not native code is supported)
Note that both issues are not only related to phonegap, they would basically
also affect a regular android app. (1. only
if webview is used, which is however the by far simplest approach, except for
the image issue)
Best regards,
Christian