Porting web mmo games to native platforms

20
PORTING WEB MMO GAMES TO NATIVE PLATFORMS. WORKING WITH WEBVIEW Vitaliy Zasadnyy Android TechTalk, Feb 9

description

Common tasks during porting web mmo games to native platforms.

Transcript of Porting web mmo games to native platforms

Page 1: Porting web mmo games to native platforms

PORTING WEB MMO GAMES TO NATIVE PLATFORMS.WORKING WITH WEBVIEW

Vitaliy ZasadnyyAndroid TechTalk, Feb 9

Page 2: Porting web mmo games to native platforms

PREHISTORY

7 games

Page 3: Porting web mmo games to native platforms

OUR GAMES

Page 4: Porting web mmo games to native platforms

TASK

● provide custom layout

● show loading screen

● replace some features with native analogs

● 2 platforms

Page 5: Porting web mmo games to native platforms

WebView APILoading Content

void loadUrl(String url)

void loadData(String data, String mimeType, String mimeType)

void postUrl(String url, byte[] postData)

void reload()

Page 6: Porting web mmo games to native platforms

WebView APISetting the Delegate

void setWebViewClient(WebViewClient client)

void setWebChromeClient(WebChromeClient client)

Page 7: Porting web mmo games to native platforms

WebViewClient APILoading Content Callbacks

void onPageStarted(WebView view, String url, Bitmap favicon)

void onPageFinished(WebView view, String url)

void onReceivedError(WebView view, int errorCode, String description, String failingUrl)

boolean shouldOverrideUrlLoading(WebView view, String url)

Page 8: Porting web mmo games to native platforms

WebChromeClient APIEvent Callbacks

boolean onJs...()

void onProgressChanged(WebView view, int newProgress)

Page 9: Porting web mmo games to native platforms

T1: CUSTOM LAYOUT

web android

Page 10: Porting web mmo games to native platforms

T1: CUSTOM LAYOUT

first idea: custom user-agent

Page 11: Porting web mmo games to native platforms

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);

return true; } cancel request

load with extra header

Page 12: Porting web mmo games to native platforms

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 } ...}

Page 13: Porting web mmo games to native platforms

T1: CUSTOM LAYOUT

problem 2: yourWebWiew.reload();

solution 2: public class YourWebView extends WebView { ... @Override public void reload() {

String url = getUrl(); // load url with extra headers } ...}

get current url

not the best

Page 14: Porting web mmo games to native platforms

T1: CUSTOM LAYOUT

problem 3:

solution 3:

post methods (e.g. forms)

there is no solution

AOSP: Issue 9122

Page 15: Porting web mmo games to native platforms

T2: LOADING SCREEN

● starts at game launch

● disappears only when first page is loaded

Page 16: Porting web mmo games to native platforms

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 } ...}

problem

Page 17: Porting web mmo games to native platforms

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! } ...} fixed

Page 18: Porting web mmo games to native platforms

T3: REPLACE SOME FEATURESpublic 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!"); }"); } }}

Page 19: Porting web mmo games to native platforms

IF YOU'VE GOT INTERESTED

NRavo games on:

Page 20: Porting web mmo games to native platforms

THANKS FOR YOUR ATTENTION!QUESTIONS?

presentation will be available on:blog.zasadnyy.org.ua