From 4c41ecb0d5ecb96378af2494845d9c3af9c8802f Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 2 Jul 2015 16:43:09 -0700 Subject: [PATCH] Make it possible to load Sky demos from local bundles This CL teaches SkyDemo how to load Sky applications from local bundles. It also teaches home.dart how to request a load from a bundle. TBR=eseidel@chromium.org Review URL: https://codereview.chromium.org/1213203008. --- .../org/domokit/sky/shell/SkyActivity.java | 10 +++++++ .../org/domokit/sky/shell/SkyApplication.java | 30 ++++++++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/shell/android/org/domokit/sky/shell/SkyActivity.java b/engine/src/flutter/shell/android/org/domokit/sky/shell/SkyActivity.java index 0724ebf9a1d..de84817719f 100644 --- a/engine/src/flutter/shell/android/org/domokit/sky/shell/SkyActivity.java +++ b/engine/src/flutter/shell/android/org/domokit/sky/shell/SkyActivity.java @@ -85,4 +85,14 @@ public class SkyActivity extends Activity { public void loadUrl(String url) { mView.loadUrl(url); } + + public boolean loadBundleByName(String name) { + File dataDir = new File(PathUtils.getDataDirectory(this)); + File bundle = new File(dataDir, name); + if (!bundle.exists()) { + return false; + } + mView.loadBundle(bundle.getPath()); + return true; + } } diff --git a/engine/src/flutter/shell/android/org/domokit/sky/shell/SkyApplication.java b/engine/src/flutter/shell/android/org/domokit/sky/shell/SkyApplication.java index a20da1e14b8..eabb6608a4a 100644 --- a/engine/src/flutter/shell/android/org/domokit/sky/shell/SkyApplication.java +++ b/engine/src/flutter/shell/android/org/domokit/sky/shell/SkyApplication.java @@ -41,7 +41,25 @@ public class SkyApplication extends BaseChromiumApplication { initJavaUtils(); initResources(); initNative(); - initServiceRegistry(); + onServiceRegistryAvailable(ServiceRegistry.SHARED); + } + + /** + * Override this function to add more resources for extraction. + */ + protected void onBeforeResourceExtraction(ResourceExtractor extractor) { + extractor.addResources(SKY_RESOURCES); + } + + /** + * Override this function to register more services. + */ + protected void onServiceRegistryAvailable(ServiceRegistry registry) { + registry.register(NetworkService.MANAGER.getName(), new ServiceFactory() { + public void connectToService(Context context, Core core, MessagePipeHandle pipe) { + new NetworkServiceImpl(context, core, pipe); + } + }); } private void initJavaUtils() { @@ -51,7 +69,7 @@ public class SkyApplication extends BaseChromiumApplication { private void initResources() { mResourceExtractor = new ResourceExtractor(getApplicationContext()); - mResourceExtractor.addResources(SKY_RESOURCES); + onBeforeResourceExtraction(mResourceExtractor); mResourceExtractor.start(); } @@ -63,12 +81,4 @@ public class SkyApplication extends BaseChromiumApplication { throw new RuntimeException(e); } } - - private void initServiceRegistry() { - ServiceRegistry.SHARED.register(NetworkService.MANAGER.getName(), new ServiceFactory() { - public void connectToService(Context context, Core core, MessagePipeHandle pipe) { - new NetworkServiceImpl(context, core, pipe); - } - }); - } }