Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Porting web MMO games to native platforms. Work...

Porting web MMO games to native platforms. Working with WebView

Recording: http://www.paylas.com/video/android-gelistirici-gunleri-vitaliy-zasadnyy

Presentation about porting Web MMO games to Android and iOS. Sharing own experience and best practices.

Vitaliy Zasadnyy

June 14, 2013
Tweet

More Decks by Vitaliy Zasadnyy

Other Decks in Programming

Transcript

  1. TASK FOR TODAY • provide custom layout • show loading

    screen • fancy progress dialog • replace some features with native analogs • Game container for
  2. WebView API Loading Content void loadUrl(String url) void loadData(String data,

    String mimeType, String mimeType) void postUrl(String url, byte[] postData) void reload()
  3. WebViewClient API Loading 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)
  4. T1: CUSTOM LAYOUT easy way == client side way @Override

    public void onPageFinished(WebView view, String url) { view.loadUrl("javascript:{ /* js source */}"); }
  5. T1: CUSTOM LAYOUT easy way == client side way @Override

    public void onPageFinished(WebView view, String url) { ... view.loadUrl("javascript:{ /* js source */}"); } performance drawback
  6. T1: CUSTOM LAYOUT @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 better idea: custom headers
  7. 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 } ... }
  8. 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
  9. T1: CUSTOM LAYOUT problem 3: solution 3: post methods (e.g.

    forms) there is no solution AOSP: Issue 9122
  10. 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
  11. 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
  12. 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!"); }"); } } }