Porting web-based massively multiplayer online (MMO) games to native platforms like Android requires working with the WebView component. This involves customizing the layout by adding custom headers, showing a loading screen when content loads using callbacks from WebViewClient, and replacing some web features with native equivalents by overriding the shouldOverrideUrlLoading method. The presentation covered techniques for customizing the layout with extra headers, displaying and hiding a loading screen during page loads, and replacing web functionality with native code using the WebViewClient API.
1 of 20
Download to read offline
More Related Content
Porting web mmo games to native platforms
1. PORTING WEB MMO GAMES
TO NATIVE PLATFORMS.
WORKING WITH WEBVIEW
Vitaliy Zasadnyy
Android TechTalk, Feb 9
11. T1: CUSTOM LAYOUT
better idea: custom headers
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Map<String, String> extraHeaders =
new HashMap<String, String>();
extraHeaders.put(
EXTRA_HEADER_CLIENT_TYPE, EXTRA_HEADER_VALUE));
view.loadUrl(url, extraHeaders);
load with extra header
cancel request
return true;
}
12. T1: CUSTOM LAYOUT
problem 1: yourWebWiew.loadUrl("some url");
solution 1:
public class YourWebView extends WebView {
...
@Override
public void loadUrl(String url) {
// load url with extra headers
}
...
}
13. T1: CUSTOM LAYOUT
problem 2: yourWebWiew.reload();
solution 2:
public class YourWebView extends WebView {
...
@Override get current url
public void reload() {
String url = getUrl();
// load url with extra headers
}
...
he b est
}
not t
14. T1: CUSTOM LAYOUT
problem 3: post methods (e.g. forms)
solution 3: there is no solution
AOSP: Issue 9122
15. T2: LOADING SCREEN
¢ starts at game launch
¢ disappears only when
first page is loaded
16. T2: LOADING SCREEN
public class YourWebViewClient extends WebViewClient {
...
@Override
public void onPageStarted(WebView view, String url,
Bitmap
favicon) {
// show loading dialog
}
@Override
public void onPageFinished(WebView view, String url) {
// hide loading dialog
}
lem
...
rob
}
p
17. T2: LOADING SCREEN
public class YourWebViewClient extends WebViewClient {
private String mStartUrl;
...
@Override
public void onPageStarted(WebView view, String url, Bitmap
favicon) {
mStartUrl = url;
// show fullscreen loading dialog
}
@Override
public void onPageFinished(WebView view, String url) {
if (mStartUrl.equals(url))
// hide loading dialog
else
// redirect!
}
ixed
...
f
}
18. T3: REPLACE SOME FEATURES
public class NravoWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view,
String url) {
// override behavior here
}
@Override
public void onPageStarted(WebView view, String url,
Bitmap
favicon) {}
@Override
public void onPageFinished(WebView view, String url) {
if (!mIsRedirect) {
view.loadUrl("javascript: { alert("Horray!");
}");
}
}
}