Chromium Code Reviews| 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/framework/shell.dart' as shell; | 8 import 'package:sky/framework/shell.dart' as shell; |
| 9 import 'package:sky/painting/box_painter.dart'; | |
| 9 import 'package:sky/theme/colors.dart' as colors; | 10 import 'package:sky/theme/colors.dart' as colors; |
| 10 import 'package:sky/theme/edges.dart'; | 11 import 'package:sky/theme/edges.dart'; |
| 11 import 'package:sky/theme/typography.dart' as typography; | 12 import 'package:sky/theme/typography.dart' as typography; |
| 13 import 'package:sky/widgets/card.dart'; | |
| 14 import 'package:sky/widgets/fixed_height_scrollable.dart'; | |
| 15 import 'package:sky/widgets/flat_button.dart'; | |
| 12 import 'package:sky/widgets/material.dart'; | 16 import 'package:sky/widgets/material.dart'; |
| 13 import 'package:sky/widgets/raised_button.dart'; | |
| 14 import 'package:sky/widgets/scaffold.dart'; | 17 import 'package:sky/widgets/scaffold.dart'; |
| 18 import 'package:sky/widgets/theme.dart'; | |
| 15 import 'package:sky/widgets/tool_bar.dart'; | 19 import 'package:sky/widgets/tool_bar.dart'; |
| 16 import 'package:sky/widgets/basic.dart'; | 20 import 'package:sky/widgets/basic.dart'; |
| 17 | 21 |
| 18 void launch(String relativeUrl) { | 22 void launch(String relativeUrl) { |
| 19 Uri url = Uri.base.resolve(relativeUrl); | 23 Uri url = Uri.base.resolve(relativeUrl); |
| 20 url = url.replace(scheme: 'sky'); | 24 url = url.replace(scheme: 'sky'); |
| 21 | 25 |
| 22 ActivityManagerProxy activityManager = new ActivityManagerProxy.unbound(); | 26 ActivityManagerProxy activityManager = new ActivityManagerProxy.unbound(); |
| 23 Intent intent = new Intent() | 27 Intent intent = new Intent() |
| 24 ..action = 'android.intent.action.VIEW' | 28 ..action = 'android.intent.action.VIEW' |
| 25 ..url = url.toString(); | 29 ..url = url.toString(); |
| 26 shell.requestService(null, activityManager); | 30 shell.requestService(null, activityManager); |
| 27 activityManager.ptr.startActivity(intent); | 31 activityManager.ptr.startActivity(intent); |
| 28 } | 32 } |
| 29 | 33 |
| 30 class SkyDemo extends Component { | 34 class SkyDemo { |
| 31 String text; | 35 String name; |
| 32 String href; | 36 String href; |
| 37 String description; | |
| 38 typography.TextTheme textTheme; | |
| 39 BoxDecoration decoration; | |
| 40 SkyDemo({ this.name, this.href, this.description, this.textTheme, this.decorat ion }); | |
| 41 } | |
| 33 | 42 |
| 34 SkyDemo(String text, this.href) : this.text = text, super(key: text); | 43 List<Widget> demos = [ |
| 44 new SkyDemo( | |
| 45 name: 'Stocks', | |
| 46 href: 'examples/stocks2/lib/stock_app.dart', | |
| 47 description: 'Multi-screen app with scrolling list', | |
| 48 textTheme: typography.black, | |
| 49 decoration: new BoxDecoration( | |
| 50 backgroundImage: new BackgroundImage( | |
| 51 src: 'examples/stocks2/res/thumbnail.png', | |
| 52 fit: BackgroundFit.cover | |
| 53 ), | |
| 54 shape: Shape.circle | |
| 55 ) | |
| 56 ), | |
| 57 new SkyDemo( | |
| 58 name: 'Asteroids', | |
| 59 href: 'examples/game/main.dart', | |
| 60 description: '2D game using sprite sheets to achieve high performance', | |
| 61 textTheme: typography.white, | |
| 62 decoration: new BoxDecoration( | |
| 63 backgroundImage: new BackgroundImage( | |
| 64 src: 'examples/game/res/thumbnail.png', | |
| 65 fit: BackgroundFit.cover | |
| 66 ) | |
| 67 ) | |
| 68 ), | |
| 69 new SkyDemo( | |
| 70 name: 'Interactive Flex', | |
| 71 href: 'examples/rendering/interactive_flex.dart', | |
| 72 description: 'Swipe to adjust the layout of the app', | |
| 73 textTheme: typography.white, | |
| 74 decoration: new BoxDecoration( | |
| 75 backgroundColor: const Color(0xFF0081C6) | |
| 76 ) | |
| 77 ), | |
| 78 new SkyDemo( | |
| 79 name: 'Sector', | |
| 80 href: 'examples/widgets/sector.dart', | |
| 81 description: 'Demo of alternative layouts', | |
| 82 textTheme: typography.black, | |
| 83 decoration: new BoxDecoration( | |
| 84 backgroundColor: colors.Black, | |
| 85 backgroundImage: new BackgroundImage( | |
| 86 src: 'examples/widgets/sector_thumbnail.png', | |
| 87 fit: BackgroundFit.cover | |
| 88 ) | |
| 89 ) | |
| 90 ), | |
| 91 // new SkyDemo( | |
| 92 // 'Touch Demo', 'examples/rendering/touch_demo.dart', 'Simple example showi ng handling of touch events at a low level'), | |
| 93 new SkyDemo( | |
| 94 name: 'Minedigger Game', | |
| 95 href: 'examples/mine_digger/mine_digger.dart', | |
| 96 description: 'Clone of the classic Minesweeper game', | |
| 97 textTheme: typography.white | |
| 98 ), | |
| 35 | 99 |
| 36 void _handlePress() { | 100 // TODO(eseidel): We could use to separate these groups? |
| 37 launch(href); | 101 // new SkyDemo('Old Stocks App', 'examples/stocks/main.sky'), |
| 102 // new SkyDemo('Old Touch Demo', 'examples/raw/touch-demo.sky'), | |
| 103 // new SkyDemo('Old Spinning Square', 'examples/raw/spinning-square.sky'), | |
| 104 | |
| 105 // TODO(jackson): This doesn't seem to be working | |
| 106 // new SkyDemo('Licences (Old)', 'LICENSES.sky'), | |
|
Hixie
2015/06/26 23:13:26
we should get this working asap...
jackson
2015/06/29 16:53:24
Agree, I'll file an issue
| |
| 107 ]; | |
| 108 | |
| 109 const double kCardHeight = 120.0; | |
| 110 | |
| 111 class DemoList extends FixedHeightScrollable { | |
| 112 DemoList({ String key }) : super(key: key, itemHeight: kCardHeight) { | |
| 113 itemCount = demos.length; | |
| 38 } | 114 } |
| 39 | 115 |
| 40 Widget build() { | 116 Widget buildDemo(SkyDemo demo) { |
| 41 return new ConstrainedBox( | 117 return new Listener( |
| 42 constraints: const BoxConstraints.expandWidth(), | 118 key: demo.name, |
| 43 child: new RaisedButton( | 119 onGestureTap: (_) => launch(demo.href), |
| 44 child: new Text(text), | 120 child: new Container( |
| 45 onPressed: _handlePress | 121 height: kCardHeight, |
| 122 child: new Card( | |
| 123 child: new Flex([ | |
| 124 new Flexible( | |
| 125 child: new Stack([ | |
| 126 new Container( | |
| 127 decoration: demo.decoration, | |
| 128 child: new Container() | |
| 129 ), | |
| 130 new Container( | |
| 131 margin: const EdgeDims.all(24.0), | |
| 132 child: new Block([ | |
| 133 new Text(demo.name, style: demo.textTheme.title), | |
| 134 new Text(demo.description, style: demo.textTheme.subhead) | |
| 135 ]) | |
| 136 ) | |
| 137 ]) | |
| 138 ), | |
| 139 ], direction: FlexDirection.vertical) | |
| 140 ) | |
| 46 ) | 141 ) |
| 47 ); | 142 ); |
| 48 } | 143 } |
| 144 | |
| 145 List<Widget> buildItems(int start, int count) { | |
| 146 return demos | |
| 147 .skip(start) | |
| 148 .take(count) | |
| 149 .map(buildDemo) | |
| 150 .toList(growable: false); | |
| 151 } | |
| 49 } | 152 } |
| 50 | 153 |
| 51 class SkyHome extends App { | 154 class SkyHome extends App { |
| 52 Widget build() { | 155 Widget build() { |
| 53 List<Widget> children = [ | 156 return new Theme( |
| 54 new SkyDemo('Stocks App', 'lib/example/stocks2/lib/stock_app.dart'), | 157 data: new ThemeData.dark( |
| 55 new SkyDemo('Asteroids Game', 'lib/example/game/main.dart'), | 158 primary: colors.Teal, |
| 56 new SkyDemo('Interactive Flex', 'lib/example/rendering/interactive_flex.da rt'), | 159 accent: colors.Orange |
| 57 new SkyDemo('Sector Layout', 'lib/example/widgets/sector.dart'), | 160 ), |
| 58 new SkyDemo('Touch Demo', 'lib/example/rendering/touch_demo.dart'), | 161 child: new Scaffold( |
| 59 new SkyDemo('Minedigger Game', 'lib/example/mine_digger/mine_digger.dart') , | 162 toolbar: new ToolBar(center: new Text('Sky Demos')), |
| 60 | 163 body: new Material( |
| 61 // TODO(eseidel): We could use to separate these groups? | 164 edge: MaterialEdge.canvas, |
| 62 new SkyDemo('Old Stocks App', 'lib/example/stocks/main.sky'), | 165 child: new DemoList() |
| 63 new SkyDemo('Old Touch Demo', 'lib/example/raw/touch-demo.sky'), | |
| 64 new SkyDemo('Old Spinning Square', 'lib/example/raw/spinning-square.sky'), | |
| 65 | |
| 66 new SkyDemo('Licences (Old)', 'LICENSES.sky'), | |
| 67 ]; | |
| 68 | |
| 69 return new Scaffold( | |
| 70 toolbar: new ToolBar( | |
| 71 center: new Text('Sky Demos', style: typography.white.title), | |
| 72 backgroundColor: colors.Blue[500]), | |
| 73 body: new Material( | |
| 74 edge: MaterialEdge.canvas, | |
| 75 child: new Flex( | |
| 76 children, | |
| 77 direction: FlexDirection.vertical, | |
| 78 justifyContent: FlexJustifyContent.spaceAround | |
| 79 ) | 166 ) |
| 80 ) | 167 ) |
| 81 ); | 168 ); |
| 82 } | 169 } |
| 83 } | 170 } |
| 84 | 171 |
| 85 void main() { | 172 void main() { |
| 86 runApp(new SkyHome()); | 173 runApp(new SkyHome()); |
| 87 } | 174 } |
| OLD | NEW |