| 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: 'example/stocks/lib/main.dart', |
| 47 description: 'Multi-screen app with scrolling list', |
| 48 textTheme: typography.black, |
| 49 decoration: new BoxDecoration( |
| 50 backgroundImage: new BackgroundImage( |
| 51 src: 'example/stocks/thumbnail.png', |
| 52 fit: BackgroundFit.cover |
| 53 ) |
| 54 ) |
| 55 ), |
| 56 new SkyDemo( |
| 57 name: 'Asteroids', |
| 58 href: 'example/game/main.dart', |
| 59 description: '2D game using sprite sheets to achieve high performance', |
| 60 textTheme: typography.white, |
| 61 decoration: new BoxDecoration( |
| 62 backgroundImage: new BackgroundImage( |
| 63 src: 'example/game/res/thumbnail.png', |
| 64 fit: BackgroundFit.cover |
| 65 ) |
| 66 ) |
| 67 ), |
| 68 new SkyDemo( |
| 69 name: 'Interactive Flex', |
| 70 href: 'example/rendering/interactive_flex.dart', |
| 71 description: 'Swipe to adjust the layout of the app', |
| 72 textTheme: typography.white, |
| 73 decoration: new BoxDecoration( |
| 74 backgroundColor: const Color(0xFF0081C6) |
| 75 ) |
| 76 ), |
| 77 new SkyDemo( |
| 78 name: 'Sector', |
| 79 href: 'example/widgets/sector.dart', |
| 80 description: 'Demo of alternative layouts', |
| 81 textTheme: typography.black, |
| 82 decoration: new BoxDecoration( |
| 83 backgroundColor: colors.Black, |
| 84 backgroundImage: new BackgroundImage( |
| 85 src: 'example/widgets/sector_thumbnail.png', |
| 86 fit: BackgroundFit.cover |
| 87 ) |
| 88 ) |
| 89 ), |
| 90 // new SkyDemo( |
| 91 // 'Touch Demo', 'examples/rendering/touch_demo.dart', 'Simple example showi
ng handling of touch events at a low level'), |
| 92 new SkyDemo( |
| 93 name: 'Minedigger Game', |
| 94 href: 'example/mine_digger/mine_digger.dart', |
| 95 description: 'Clone of the classic Minesweeper game', |
| 96 textTheme: typography.white |
| 97 ), |
| 35 | 98 |
| 36 void _handlePress() { | 99 // TODO(eseidel): We could use to separate these groups? |
| 37 launch(href); | 100 // new SkyDemo('Old Stocks App', 'examples/stocks/main.sky'), |
| 101 // new SkyDemo('Old Touch Demo', 'examples/raw/touch-demo.sky'), |
| 102 // new SkyDemo('Old Spinning Square', 'examples/raw/spinning-square.sky'), |
| 103 |
| 104 // TODO(jackson): This doesn't seem to be working |
| 105 // new SkyDemo('Licenses', 'LICENSES.sky'), |
| 106 ]; |
| 107 |
| 108 const double kCardHeight = 120.0; |
| 109 |
| 110 class DemoList extends FixedHeightScrollable { |
| 111 DemoList({ String key }) : super(key: key, itemHeight: kCardHeight) { |
| 112 itemCount = demos.length; |
| 38 } | 113 } |
| 39 | 114 |
| 40 Widget build() { | 115 Widget buildDemo(SkyDemo demo) { |
| 41 return new ConstrainedBox( | 116 return new Listener( |
| 42 constraints: const BoxConstraints.expandWidth(), | 117 key: demo.name, |
| 43 child: new RaisedButton( | 118 onGestureTap: (_) => launch(demo.href), |
| 44 child: new Text(text), | 119 child: new Container( |
| 45 onPressed: _handlePress | 120 height: kCardHeight, |
| 121 child: new Card( |
| 122 child: new Flex([ |
| 123 new Flexible( |
| 124 child: new Stack([ |
| 125 new Container( |
| 126 decoration: demo.decoration, |
| 127 child: new Container() |
| 128 ), |
| 129 new Container( |
| 130 margin: const EdgeDims.all(24.0), |
| 131 child: new Block([ |
| 132 new Text(demo.name, style: demo.textTheme.title), |
| 133 new Text(demo.description, style: demo.textTheme.subhead) |
| 134 ]) |
| 135 ) |
| 136 ]) |
| 137 ), |
| 138 ], direction: FlexDirection.vertical) |
| 139 ) |
| 46 ) | 140 ) |
| 47 ); | 141 ); |
| 48 } | 142 } |
| 143 |
| 144 List<Widget> buildItems(int start, int count) { |
| 145 return demos |
| 146 .skip(start) |
| 147 .take(count) |
| 148 .map(buildDemo) |
| 149 .toList(growable: false); |
| 150 } |
| 49 } | 151 } |
| 50 | 152 |
| 51 class SkyHome extends App { | 153 class SkyHome extends App { |
| 52 Widget build() { | 154 Widget build() { |
| 53 List<Widget> children = [ | 155 return new Theme( |
| 54 new SkyDemo('Stocks App', 'example/stocks/lib/main.dart'), | 156 data: new ThemeData.dark( |
| 55 new SkyDemo('Asteroids Game', 'example/game/main.dart'), | 157 primary: colors.Teal, |
| 56 new SkyDemo('Interactive Flex', 'example/rendering/interactive_flex.dart')
, | 158 accent: colors.Orange |
| 57 new SkyDemo('Sector Layout', 'example/widgets/sector.dart'), | 159 ), |
| 58 new SkyDemo('Touch Demo', 'example/rendering/touch_demo.dart'), | 160 child: new Scaffold( |
| 59 new SkyDemo('Minedigger Game', 'example/mine_digger/lib/main.dart'), | 161 toolbar: new ToolBar(center: new Text('Sky Demos')), |
| 60 | 162 body: new Material( |
| 61 new SkyDemo('Licences (Old)', 'LICENSES.sky'), | 163 edge: MaterialEdge.canvas, |
| 62 ]; | 164 child: new DemoList() |
| 63 | |
| 64 return new Scaffold( | |
| 65 toolbar: new ToolBar( | |
| 66 center: new Text('Sky Demos', style: typography.white.title), | |
| 67 backgroundColor: colors.Blue[500]), | |
| 68 body: new Material( | |
| 69 edge: MaterialEdge.canvas, | |
| 70 child: new Flex( | |
| 71 children, | |
| 72 direction: FlexDirection.vertical, | |
| 73 justifyContent: FlexJustifyContent.spaceAround | |
| 74 ) | 165 ) |
| 75 ) | 166 ) |
| 76 ); | 167 ); |
| 77 } | 168 } |
| 78 } | 169 } |
| 79 | 170 |
| 80 void main() { | 171 void main() { |
| 81 runApp(new SkyHome()); | 172 runApp(new SkyHome()); |
| 82 } | 173 } |
| OLD | NEW |