OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import 'dart:sky'; | 5 import 'dart:sky'; |
6 | 6 |
7 import 'package:mojom/intents/intents.mojom.dart'; | 7 import 'package:mojom/intents/intents.mojom.dart'; |
8 import 'package:sky/mojo/shell.dart' as shell; | 8 import 'package:sky/mojo/shell.dart' as shell; |
9 import 'package:sky/painting/box_painter.dart'; | 9 import 'package:sky/painting/box_painter.dart'; |
10 import 'package:sky/theme/colors.dart' as colors; | 10 import 'package:sky/theme/colors.dart' as colors; |
11 import 'package:sky/theme/edges.dart'; | 11 import 'package:sky/theme/edges.dart'; |
12 import 'package:sky/theme/typography.dart' as typography; | 12 import 'package:sky/theme/typography.dart' as typography; |
13 import 'package:sky/widgets/basic.dart'; | 13 import 'package:sky/widgets/basic.dart'; |
14 import 'package:sky/widgets/card.dart'; | 14 import 'package:sky/widgets/card.dart'; |
15 import 'package:sky/widgets/fixed_height_scrollable.dart'; | 15 import 'package:sky/widgets/fixed_height_scrollable.dart'; |
16 import 'package:sky/widgets/flat_button.dart'; | 16 import 'package:sky/widgets/flat_button.dart'; |
17 import 'package:sky/widgets/material.dart'; | 17 import 'package:sky/widgets/material.dart'; |
18 import 'package:sky/widgets/scaffold.dart'; | 18 import 'package:sky/widgets/scaffold.dart'; |
19 import 'package:sky/widgets/theme.dart'; | 19 import 'package:sky/widgets/theme.dart'; |
20 import 'package:sky/widgets/tool_bar.dart'; | 20 import 'package:sky/widgets/tool_bar.dart'; |
21 | 21 |
22 void launch(String relativeUrl, String bundleName) { | 22 void launch(String relativeUrl, String bundle) { |
23 Uri url = Uri.base.resolve(relativeUrl); | 23 Uri url = Uri.base.resolve(relativeUrl); |
24 | 24 |
25 ActivityManagerProxy activityManager = new ActivityManagerProxy.unbound(); | 25 ActivityManagerProxy activityManager = new ActivityManagerProxy.unbound(); |
26 ComponentName component = new ComponentName() | 26 ComponentName component = new ComponentName() |
27 ..packageName = 'org.domokit.sky.demo' | 27 ..packageName = 'org.domokit.sky.demo' |
28 ..className = 'org.domokit.sky.demo.SkyDemoActivity'; | 28 ..className = 'org.domokit.sky.demo.SkyDemoActivity'; |
29 Intent intent = new Intent() | 29 Intent intent = new Intent() |
30 ..action = 'android.intent.action.VIEW' | 30 ..action = 'android.intent.action.VIEW' |
31 ..component = component | 31 ..component = component |
32 ..url = url.toString(); | 32 ..url = url.toString(); |
33 | 33 |
34 if (bundleName != null) { | 34 if (bundle != null) { |
35 StringExtra extra = new StringExtra() | 35 StringExtra extra = new StringExtra() |
36 ..name = 'bundleName' | 36 ..name = 'bundleName' |
37 ..value = bundleName; | 37 ..value = bundle; |
38 intent.stringExtras = [extra]; | 38 intent.stringExtras = [extra]; |
39 } | 39 } |
40 | 40 |
41 shell.requestService(null, activityManager); | 41 shell.requestService(null, activityManager); |
42 activityManager.ptr.startActivity(intent); | 42 activityManager.ptr.startActivity(intent); |
43 } | 43 } |
44 | 44 |
45 class SkyDemo { | 45 class SkyDemo { |
46 String name; | 46 String name; |
47 String href; | 47 String href; |
48 String bundleName; | 48 String bundle; |
49 String description; | 49 String description; |
50 typography.TextTheme textTheme; | 50 typography.TextTheme textTheme; |
51 BoxDecoration decoration; | 51 BoxDecoration decoration; |
52 SkyDemo({ this.name, this.href, this.bundleName, this.description, this.textTh
eme, this.decoration }); | 52 SkyDemo({ this.name, this.href, this.bundle, this.description, this.textTheme,
this.decoration }); |
53 } | 53 } |
54 | 54 |
55 List<Widget> demos = [ | 55 List<Widget> demos = [ |
56 new SkyDemo( | 56 new SkyDemo( |
57 name: 'Stocks', | 57 name: 'Stocks', |
58 href: 'example/stocks/lib/main.dart', | 58 href: 'example/stocks/lib/main.dart', |
59 bundleName: 'stocks.skyx', | 59 bundle: 'stocks.skyx', |
60 description: 'Multi-screen app with scrolling list', | 60 description: 'Multi-screen app with scrolling list', |
61 textTheme: typography.black, | 61 textTheme: typography.black, |
62 decoration: new BoxDecoration( | 62 decoration: new BoxDecoration( |
63 backgroundImage: new BackgroundImage( | 63 backgroundImage: new BackgroundImage( |
64 src: 'example/stocks/thumbnail.png', | 64 src: 'example/stocks/thumbnail.png', |
65 fit: BackgroundFit.cover | 65 fit: BackgroundFit.cover |
66 ) | 66 ) |
67 ) | 67 ) |
68 ), | 68 ), |
69 new SkyDemo( | 69 new SkyDemo( |
70 name: 'Asteroids', | 70 name: 'Asteroids', |
71 href: 'example/game/main.dart', | 71 href: 'example/game/main.dart', |
72 description: '2D game using sprite sheets to achieve high performance', | 72 description: '2D game using sprite sheets to achieve high performance', |
73 textTheme: typography.white, | 73 textTheme: typography.white, |
74 decoration: new BoxDecoration( | 74 decoration: new BoxDecoration( |
75 backgroundImage: new BackgroundImage( | 75 backgroundImage: new BackgroundImage( |
76 src: 'example/game/res/thumbnail.png', | 76 src: 'example/game/res/thumbnail.png', |
77 fit: BackgroundFit.cover | 77 fit: BackgroundFit.cover |
78 ) | 78 ) |
79 ) | 79 ) |
80 ), | 80 ), |
81 new SkyDemo( | 81 new SkyDemo( |
82 name: 'Interactive Flex', | 82 name: 'Interactive Flex', |
83 href: 'example/rendering/interactive_flex.dart', | 83 href: 'example/rendering/interactive_flex.dart', |
| 84 bundle: 'interactive_flex.skyx', |
84 description: 'Swipe to adjust the layout of the app', | 85 description: 'Swipe to adjust the layout of the app', |
85 textTheme: typography.white, | 86 textTheme: typography.white, |
86 decoration: new BoxDecoration( | 87 decoration: new BoxDecoration( |
87 backgroundColor: const Color(0xFF0081C6) | 88 backgroundColor: const Color(0xFF0081C6) |
88 ) | 89 ) |
89 ), | 90 ), |
90 new SkyDemo( | 91 new SkyDemo( |
91 name: 'Sector', | 92 name: 'Sector', |
92 href: 'example/widgets/sector.dart', | 93 href: 'example/widgets/sector.dart', |
| 94 bundle: 'sector.skyx', |
93 description: 'Demo of alternative layouts', | 95 description: 'Demo of alternative layouts', |
94 textTheme: typography.black, | 96 textTheme: typography.black, |
95 decoration: new BoxDecoration( | 97 decoration: new BoxDecoration( |
96 backgroundColor: colors.Black, | 98 backgroundColor: colors.Black, |
97 backgroundImage: new BackgroundImage( | 99 backgroundImage: new BackgroundImage( |
98 src: 'example/widgets/sector_thumbnail.png', | 100 src: 'example/widgets/sector_thumbnail.png', |
99 fit: BackgroundFit.cover | 101 fit: BackgroundFit.cover |
100 ) | 102 ) |
101 ) | 103 ) |
102 ), | 104 ), |
103 // new SkyDemo( | 105 // new SkyDemo( |
104 // 'Touch Demo', 'examples/rendering/touch_demo.dart', 'Simple example showi
ng handling of touch events at a low level'), | 106 // 'Touch Demo', 'examples/rendering/touch_demo.dart', 'Simple example showi
ng handling of touch events at a low level'), |
105 new SkyDemo( | 107 new SkyDemo( |
106 name: 'Minedigger Game', | 108 name: 'Minedigger Game', |
107 href: 'example/mine_digger/lib/main.dart', | 109 href: 'example/mine_digger/lib/main.dart', |
108 bundleName: 'mine_digger.skyx', | 110 bundle: 'mine_digger.skyx', |
109 description: 'Clone of the classic Minesweeper game', | 111 description: 'Clone of the classic Minesweeper game', |
110 textTheme: typography.white | 112 textTheme: typography.white |
111 ), | 113 ), |
112 | 114 |
113 // TODO(eseidel): We could use to separate these groups? | 115 // TODO(eseidel): We could use to separate these groups? |
114 // new SkyDemo('Old Stocks App', 'examples/stocks/main.sky'), | 116 // new SkyDemo('Old Stocks App', 'examples/stocks/main.sky'), |
115 // new SkyDemo('Old Touch Demo', 'examples/raw/touch-demo.sky'), | 117 // new SkyDemo('Old Touch Demo', 'examples/raw/touch-demo.sky'), |
116 // new SkyDemo('Old Spinning Square', 'examples/raw/spinning-square.sky'), | 118 // new SkyDemo('Old Spinning Square', 'examples/raw/spinning-square.sky'), |
117 | 119 |
118 // TODO(jackson): This doesn't seem to be working | 120 // TODO(jackson): This doesn't seem to be working |
119 // new SkyDemo('Licenses', 'LICENSES.sky'), | 121 // new SkyDemo('Licenses', 'LICENSES.sky'), |
120 ]; | 122 ]; |
121 | 123 |
122 const double kCardHeight = 120.0; | 124 const double kCardHeight = 120.0; |
123 const EdgeDims kListPadding = const EdgeDims.all(4.0); | 125 const EdgeDims kListPadding = const EdgeDims.all(4.0); |
124 | 126 |
125 class DemoList extends FixedHeightScrollable { | 127 class DemoList extends FixedHeightScrollable { |
126 DemoList({ String key }) : super(key: key, itemHeight: kCardHeight, padding: k
ListPadding) { | 128 DemoList({ String key }) : super(key: key, itemHeight: kCardHeight, padding: k
ListPadding) { |
127 itemCount = demos.length; | 129 itemCount = demos.length; |
128 } | 130 } |
129 | 131 |
130 Widget buildDemo(SkyDemo demo) { | 132 Widget buildDemo(SkyDemo demo) { |
131 return new Listener( | 133 return new Listener( |
132 key: demo.name, | 134 key: demo.name, |
133 onGestureTap: (_) => launch(demo.href, demo.bundleName), | 135 onGestureTap: (_) => launch(demo.href, demo.bundle), |
134 child: new Container( | 136 child: new Container( |
135 height: kCardHeight, | 137 height: kCardHeight, |
136 child: new Card( | 138 child: new Card( |
137 child: new Flex([ | 139 child: new Flex([ |
138 new Flexible( | 140 new Flexible( |
139 child: new Stack([ | 141 child: new Stack([ |
140 new Container( | 142 new Container( |
141 decoration: demo.decoration, | 143 decoration: demo.decoration, |
142 child: new Container() | 144 child: new Container() |
143 ), | 145 ), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 child: new DemoList() | 181 child: new DemoList() |
180 ) | 182 ) |
181 ) | 183 ) |
182 ); | 184 ); |
183 } | 185 } |
184 } | 186 } |
185 | 187 |
186 void main() { | 188 void main() { |
187 runApp(new SkyHome()); | 189 runApp(new SkyHome()); |
188 } | 190 } |
OLD | NEW |