Porting web mmo games to native platforms

download Porting web mmo games to native platforms

of 20

  • date post

    18-Nov-2014
  • Category

    Documents

  • view

    443
  • download

    1

Embed Size (px)

description

Common tasks during porting web mmo games to native platforms.

Transcript of Porting web mmo games to native platforms

  • 1. PORTING WEB MMO GAMESTO NATIVE PLATFORMS.WORKING WITH WEBVIEW Vitaliy Zasadnyy Android TechTalk, Feb 9
  • 2. PREHISTORY 7 games
  • 3. OUR GAMES
  • 4. TASK 2 platforms provide custom layout show loading screen replace some features with native analogs
  • 5. WebView APILoading Contentvoid loadUrl(String url)void loadData(String data, String mimeType, String mimeType)void postUrl(String url, byte[] postData)void reload()
  • 6. WebView APISetting the Delegatevoid setWebViewClient(WebViewClient client)void setWebChromeClient(WebChromeClient client)
  • 7. WebViewClient APILoading Content Callbacksvoid 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)
  • 8. WebChromeClient APIEvent Callbacksboolean onJs...()void onProgressChanged(WebView view, int newProgress)
  • 9. T1: CUSTOM LAYOUT web android
  • 10. T1: CUSTOM LAYOUT first idea: custom user-agent
  • 11. T1: CUSTOM LAYOUT better idea: custom headers@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) { Map extraHeaders = new HashMap(); extraHeaders.put( EXTRA_HEADER_CLIENT_TYPE, EXTRA_HEADER_VALUE)); view.loadUrl(url, extraHeaders); load with extra header cancel request return true;}
  • 12. T1: CUSTOM LAYOUTproblem 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 LAYOUTproblem 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 LAYOUTproblem 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 SCREENpublic 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 SCREENpublic 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 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!");}"); } }}
  • 19. IF YOUVE GOT INTERESTED NRavo games on:
  • 20. THANKS FOR YOUR ATTENTION! QUESTIONS? presentation will be available on: blog.zasadnyy.org.ua