提交 b4b5b8e6 编写于 作者: A Adam Barth

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.
上级 2e477f06
......@@ -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();
}
}
......@@ -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);
......
......@@ -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<Widget> 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<Widget> 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(
......
......@@ -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<StringExtra>? string_extras;
};
// TODO(abarth): This interface seems very specific to Android. Do we want to
......
......@@ -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 {
......
......@@ -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;
}
}
......@@ -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);
}
});
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册