Wednesday, March 12, 2008

GWT: The Road to 1.5, Linkers

The Google Web Toolkit compiler is a marvelous tool for turning Java code into highly optimized Javascript, but prior to GWT 1.5, there was no mechanism for developers to customize the packaging of the compiler output, or the bootstrap of the application.

C developers are used to the ability to override the entry point glue code ('start' method in crt1.o for example), or to package statically, dynamically, etc, so why not provide this capability for GWT developers as well?

This will allow GWT compiled code to packaged and bootstrapped into environments like Flash/AIR Apollo, Gears, Gadget Containers, and the example I'm going to show today: Android Offline/Online Hybrid applications.

What's a Syndroid


As part of my ongoing prototyping in Syndroid, I stumbled onto the idea of a hybrid Android application. One where some of the UI can be rendered via GWT in the embedded WebKit, and the other part, running as native Java/Dalvik code accessing Android APIs.

For example, you may wish to develop a Gadget with GWT, that runs in several containers, but when it runs on Android, it has additional access to information like Contacts, Location, etc. How can GWT code call native Android functions?

Generators Again? The Android Native Interface


Before showing you the magic sauce that permits this, let's look at an example API of how we might like this to work. This will all seem familiar to those who use GWT RPC. First, let's create an interface that will trigger a GWT Generator.

package org.timepedia.syndroid.client.android;
public interface AndroidNativeInterface {}

and a sample interface exposing a method to retrieve our GPS coordinates

package org.timepedia.syndroid.client.android;
@ImplementedBy(LocationServiceImpl.class)
public interface LocationService extends AndroidNativeInterface {
String getLocation();
}

next, Android implementation code (*warning, code may not work, I just typed it into the blog without testing)

package org.timepedia.syndroid.android;
public class LocationServiceImpl implements LocationService {
public Location getLocation() {
LocationManager lm = (LocationManager)
Context.getSystemService(Context.LOCATION_SERVICE);
return locationManager.getCurrentLocation("gps").toString();
}
}

finally, some GWT code that uses it

LocationService lService = (LocationService)GWT.create(LocationService.class);
Window.alert("My location is: "+lService.getLocation());

Great, but how does it work, and how do Linkers fit in?


There are a few ways that RPC calls between GWT and Android could work. For example, a traditional XHR request could be made to a HTTP service running on Android. But this would require the API to be asynchronous and have a high overhead.

It turns out, that the native WebKit that comes with Android has the capability to extend the native Javascript APIs available via Java. For example,

WebView wv=new WebView(this);
wv.getSettings().setJavaScriptEnabled(true);
wv.addJavascriptInterface(new LocationServiceImpl(), "locationService");

This binds our Android LocationServiceImpl instance to a globally scoped JavaScript object called 'locationService', allowing Javascript code to invoke the locationService.getLocation() method.

We now have two problems to solve, first, generate GWT code in a Generator that invokes this $wnd.locationService.getLocation() global object, and secondly, to generate Android bootstrap code (shown above), an AndroidManifest, and package up everything into a APK file that can be installed on a phone. The latter problem is what Linkers help solve.

The Generator's Job


I won't go into detail about how to implement the Generator, as it's been covered before in this blog, the Generator essentially creates a LocationServiceImpl class, with JSNI method getLocation(), which calls $wnd.locationService.getLocation()

The Linker's Job


The Linker has the bulk of the grunt work here. Here's what it must accomplish:
1. Generate Bootstrap Android application
2. For each generated AndroidNativeInterface, add Javascript bindings
3. Place all generated resources in proper Android asset layout
4. Create Android Manifest file
5. Add extra code to load the initial WebView start page with GWT app
6. Invoke Android tools to compile Dalvik code, and package APK files.


The Linker and LinkerContext interface in GWT 1.5 allow one to specify in a module file, which sets of Linkers are run. GWT 1.5 provides some standard ones like the IFrameLinker and XSLinker, which generate the ordinary selection scripts we see in 1.4. The LinkerContext interface provides a mechanism to discover the outputs from the compiler pass, and to emit new ones.

I'll have to end this installment here, because it is getting long and I need to get back to work, in the next installment, I'll show some actual Linker code for an AndroidGadgetLinker.

5 comments:

GK said...

very interesting, thanks!

Anonymous said...

(法新社倫敦四日電) 英國情色大亨芮孟的公司昨天說,芮孟日前去世日本av,享壽成人電影八十二歲;這位身價上億的房地產開發商,曾經在倫成人網站敦推出第一場脫衣舞表演。色情


芮孟的財產估成人網站計達sex六億a片下載五千萬色情英鎊(台幣將近四百億)成人光碟,由於情色他名下事業大多分布在情色視訊倫敦夜生活區蘇活區,因此擁有「成人影片蘇活之王」的稱號。


部落格av公司「保羅芮孟集團」旗下成人影片成人行多種情色雜誌,包括成人網站avRazAV片zle」、「男性世情色a片」以及情色電影「Mayfair」。


色情影片孟本名傑av女優福瑞.安東尼.成人電影奎恩,父親av為搬情色電影運承包商。芮孟av女優十五歲離開學校,矢言要在表演事a片成人影片留名,起先部落格表演讀心術,後來成為巡迴歌舞雜耍表演的部落格a片作人。


a片下載許多評論家認為,他把情色表演帶進a片主流社會色情,一九五九年主持破天荒的脫衣舞表演,後來更靠著在蘇活區與倫avav女優西區開發房地產賺得大筆財色情a片富。


有人形容avdvd芮孟是英成人國的海夫納,地位等同美國的「花花公子」創辦人海夫納。

Anonymous said...

aa片免費看
微風論壇
080哈啦聊天室
6k聊天室
成人聊天室上班族
捷克論壇
大眾論壇
plus論壇
080視訊聊天室
520視訊聊天室
尋夢園上班族聊天室
成人聊天室上班族
a片
a片影片
免費情色影片
免費a片觀看
小弟第貼影片區
免費av影片
免費h影片試看
H漫 - 卡通美女短片
小魔女貼影片
免費影片觀賞
無碼a片網
美女pc交友相簿
美女交友-哈啦聊天室
中文a片線上試看
免費電影下載區
免費試看a短片
免費卡通aa片觀看
女優影片無碼直播
免費性感a片試看
日本AV女優影音娛樂網
日本av女優無碼dvd
辣妹視訊 - 免費聊天室
美女交友視訊聊天室
080免費視訊聊天室
尋夢園聊天室
080苗栗人聊天室
a片下載
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結
好站推薦友情連結

Anonymous said...

☆ 學生情色自拍 ☆☆ 學生情色自拍 ☆☆ 學生情色自拍 ☆☆ 學生情色自拍 ☆☆ 純情色妹妹自拍 ☆☆ 純情色妹妹自拍 ☆☆ 純情色妹妹自拍 ☆☆ 純情色妹妹自拍 ☆☆ 純情色妹妹自拍 ☆☆ 純情色妹妹自拍 ☆☆ 純情色妹妹自拍 ☆☆ 純情色妹妹自拍 ☆☆ 純情色妹妹自拍 ☆☆ 純情色妹妹自拍 ☆免費色情短片線上觀看免費色情短片線上觀看免費色情短片線上觀看免費色情短片線上觀看免費色情短片線上觀看免費色情短片線上觀看免費色情短片線上觀看免費色情短片線上觀看免費色情短片線上觀看免費色情短片線上觀看影片交流,免費色情影片交流,免費色情影片交流,免費色情影片交流,免費色情影片交流,免費色情影片交流,免費色情影片交流,免費色情影片交流,免費色情影片交流,免費色情影片交流,免費色情成人影片,sex貼片區成人影片,sex貼片區成人影片,sex貼片區成人影片,sex貼片區成人影片,sex貼片區成人影片,sex貼片區成人影片,sex貼片區成人影片,sex貼片區成人影片,sex貼片區成人影片,sex貼片區免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費色咪咪影片網,免費色咪咪影片網,免費色咪咪影片網,免費色咪咪影片網,免費色咪咪影片網,免費色咪咪影片網,免費色咪咪影片網,免費色咪咪影片網,免費色咪咪影片網,免費色咪咪影片網,a片城,免費色情影片a片城,免費色情影片a片城,免費色情影片a片城,免費色情影片a片城,免費色情影片a片城,免費色情影片a片城,免費色情影片a片城,免費色情影片a片城,免費色情影片a片城,免費色情影片免費a片觀賞免費a片觀賞免費a片觀賞免費a片觀賞免費a片觀賞免費a片觀賞免費a片觀賞免費a片觀賞免費a片觀賞免費a片觀賞免費a長片線上看免費a長片線上看免費a長片線上看免費a長片線上看免費a長片線上看免費a長片線上看免費a長片線上看免費a長片線上看免費a長片線上看免費a長片線上看線上免費a片線上免費a片線上免費a片線上免費a片線上免費a片線上免費a片線上免費a片線上免費a片線上免費a片線上免費a片色咪咪影片網色咪咪影片網

Anonymous said...

減肥,
減重,
熱水器,
洗碗機,
瓦斯爐,
油煙機,
廚具,
烤箱,
喜特麗,
電解水,
櫻花牌,
林內,
不動產估價師事務所,
不動產估價師,
無形資產評估,
展示架,
陳列架,
鐵架,
倉儲架,
角鋼架