diff --git a/apk/demo/org/domokit/sky/demo/SkyDemoActivity.java b/apk/demo/org/domokit/sky/demo/SkyDemoActivity.java index 0fff47c115ec2c9ba7f360379ed5c8aaa52a17e0..cbc4abb260e10654a7f895451bcb030c55103609 100644 --- a/apk/demo/org/domokit/sky/demo/SkyDemoActivity.java +++ b/apk/demo/org/domokit/sky/demo/SkyDemoActivity.java @@ -21,8 +21,18 @@ public class SkyDemoActivity extends SkyActivity { if (Intent.ACTION_MAIN.equals(action)) { loadUrl(DEFAULT_URL); - } else if (Intent.ACTION_VIEW.equals(action)) { + return; + } + + if (Intent.ACTION_VIEW.equals(action)) { + String bundleName = intent.getStringExtra("bundleName"); + if (bundleName != null && loadBundleByName(bundleName)) { + return; + } loadUrl(intent.getDataString()); + return; } + + super.onSkyReady(); } } diff --git a/apk/demo/org/domokit/sky/demo/SkyDemoApplication.java b/apk/demo/org/domokit/sky/demo/SkyDemoApplication.java index 4a6aa44ba9122e47c1fa19eef6ceb939fab9a88b..d1c8a6f7561668e37eb542ca8d46ceb6019be0a9 100644 --- a/apk/demo/org/domokit/sky/demo/SkyDemoApplication.java +++ b/apk/demo/org/domokit/sky/demo/SkyDemoApplication.java @@ -16,6 +16,7 @@ import org.chromium.mojom.media.MediaService; import org.chromium.mojom.sensors.SensorService; import org.domokit.intents.ActivityManagerImpl; import org.domokit.media.MediaServiceImpl; +import org.domokit.sky.shell.ResourceExtractor; import org.domokit.sky.shell.ServiceFactory; import org.domokit.sky.shell.ServiceRegistry; import org.domokit.sky.shell.SkyApplication; @@ -24,32 +25,43 @@ import org.domokit.sky.shell.SkyApplication; * SkyDemo implementation of {@link android.app.Application} */ public class SkyDemoApplication extends SkyApplication { + private static final String[] DEMO_RESOURCES = { + "mine_digger.skyx", + "stocks.skyx", + }; + + @Override + protected void onBeforeResourceExtraction(ResourceExtractor extractor) { + super.onBeforeResourceExtraction(extractor); + extractor.addResources(DEMO_RESOURCES); + } + @Override - public void onCreate() { - super.onCreate(); + public void onServiceRegistryAvailable(ServiceRegistry registry) { + super.onServiceRegistryAvailable(registry); - ServiceRegistry.SHARED.register(SensorService.MANAGER.getName(), new ServiceFactory() { + registry.register(SensorService.MANAGER.getName(), new ServiceFactory() { @Override public void connectToService(Context context, Core core, MessagePipeHandle pipe) { SensorService.MANAGER.bind(new SensorServiceImpl(context), pipe); } }); - ServiceRegistry.SHARED.register(KeyboardService.MANAGER.getName(), new ServiceFactory() { + registry.register(KeyboardService.MANAGER.getName(), new ServiceFactory() { @Override public void connectToService(Context context, Core core, MessagePipeHandle pipe) { KeyboardService.MANAGER.bind(new KeyboardServiceImpl(context), pipe); } }); - ServiceRegistry.SHARED.register(ActivityManager.MANAGER.getName(), new ServiceFactory() { + registry.register(ActivityManager.MANAGER.getName(), new ServiceFactory() { @Override public void connectToService(Context context, Core core, MessagePipeHandle pipe) { ActivityManager.MANAGER.bind(new ActivityManagerImpl(context), pipe); } }); - ServiceRegistry.SHARED.register(MediaService.MANAGER.getName(), new ServiceFactory() { + registry.register(MediaService.MANAGER.getName(), new ServiceFactory() { @Override public void connectToService(Context context, Core core, MessagePipeHandle pipe) { MediaService.MANAGER.bind(new MediaServiceImpl(context, core), pipe); diff --git a/sdk/home.dart b/sdk/home.dart index 782648134b5a67588371760e19e3c3dac7f6d551..ea1beee56fed2a6b4da677a51bcda84888600012 100644 --- a/sdk/home.dart +++ b/sdk/home.dart @@ -19,7 +19,7 @@ import 'package:sky/widgets/scaffold.dart'; import 'package:sky/widgets/theme.dart'; import 'package:sky/widgets/tool_bar.dart'; -void launch(String relativeUrl) { +void launch(String relativeUrl, String bundleName) { Uri url = Uri.base.resolve(relativeUrl); ActivityManagerProxy activityManager = new ActivityManagerProxy.unbound(); @@ -30,6 +30,14 @@ void launch(String relativeUrl) { ..action = 'android.intent.action.VIEW' ..component = component ..url = url.toString(); + + if (bundleName != null) { + StringExtra extra = new StringExtra() + ..name = 'bundleName' + ..value = bundleName; + intent.stringExtras = [extra]; + } + shell.requestService(null, activityManager); activityManager.ptr.startActivity(intent); } @@ -37,16 +45,18 @@ void launch(String relativeUrl) { class SkyDemo { String name; String href; + String bundleName; String description; typography.TextTheme textTheme; BoxDecoration decoration; - SkyDemo({ this.name, this.href, this.description, this.textTheme, this.decoration }); + SkyDemo({ this.name, this.href, this.bundleName, this.description, this.textTheme, this.decoration }); } List demos = [ new SkyDemo( name: 'Stocks', href: 'example/stocks/lib/main.dart', + bundleName: 'stocks.skyx', description: 'Multi-screen app with scrolling list', textTheme: typography.black, decoration: new BoxDecoration( @@ -94,7 +104,8 @@ List demos = [ // 'Touch Demo', 'examples/rendering/touch_demo.dart', 'Simple example showing handling of touch events at a low level'), new SkyDemo( name: 'Minedigger Game', - href: 'example/mine_digger/mine_digger.dart', + href: 'example/mine_digger/lib/main.dart', + bundleName: 'mine_digger.skyx', description: 'Clone of the classic Minesweeper game', textTheme: typography.white ), @@ -119,7 +130,7 @@ class DemoList extends FixedHeightScrollable { Widget buildDemo(SkyDemo demo) { return new Listener( key: demo.name, - onGestureTap: (_) => launch(demo.href), + onGestureTap: (_) => launch(demo.href, demo.bundleName), child: new Container( height: kCardHeight, child: new Card( diff --git a/services/intents/intents.mojom b/services/intents/intents.mojom index 33cdb927286ddc63d21e234411d3e540bdca9d76..4e0ae3abbcafc8827933c1bdaf5ec245415368cb 100644 --- a/services/intents/intents.mojom +++ b/services/intents/intents.mojom @@ -4,6 +4,11 @@ module intents; +struct StringExtra { + string name; + string value; +}; + struct ComponentName { string package_name; string class_name; @@ -13,6 +18,7 @@ struct Intent { string action; string url; ComponentName? component; + array? string_extras; }; // TODO(abarth): This interface seems very specific to Android. Do we want to diff --git a/services/intents/src/org/domokit/intents/ActivityManagerImpl.java b/services/intents/src/org/domokit/intents/ActivityManagerImpl.java index 51ca4ca2971dcc50fabe77287d2485a29c742ecb..a59bc41722cb6e5398a6329a6fbf082de406c3a2 100644 --- a/services/intents/src/org/domokit/intents/ActivityManagerImpl.java +++ b/services/intents/src/org/domokit/intents/ActivityManagerImpl.java @@ -13,6 +13,7 @@ import org.chromium.mojo.system.MojoException; import org.chromium.mojom.intents.ActivityManager; import org.chromium.mojom.intents.ComponentName; import org.chromium.mojom.intents.Intent; +import org.chromium.mojom.intents.StringExtra; /** * Android implementation of ActivityManager. @@ -43,6 +44,12 @@ public class ActivityManagerImpl implements ActivityManager { androidIntent.setComponent(androidComponent); } + if (intent.stringExtras != null) { + for (StringExtra extra : intent.stringExtras) { + androidIntent.putExtra(extra.name, extra.value); + } + } + androidIntent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK); try { diff --git a/shell/android/org/domokit/sky/shell/SkyActivity.java b/shell/android/org/domokit/sky/shell/SkyActivity.java index 0724ebf9a1d4efcfafaafdb4538ff2ce4af1f106..de84817719f6a725f88ff88354e175cd5355a5c6 100644 --- a/shell/android/org/domokit/sky/shell/SkyActivity.java +++ b/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/shell/android/org/domokit/sky/shell/SkyApplication.java b/shell/android/org/domokit/sky/shell/SkyApplication.java index a20da1e14b81e1c4476c8f4de82eaeb77a789c92..eabb6608a4abe246de933371083aeac9ef9ce70c 100644 --- a/shell/android/org/domokit/sky/shell/SkyApplication.java +++ b/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); - } - }); - } }