提交 6f19816e 编写于 作者: A Adam Barth

SkyDemo.apk should show thumbmails when offline

We now get the thumbnails from the root bundle when offline and otherwise fall
back to the network.

R=eseidel@chromium.org, eseidel@google.com

Review URL: https://codereview.chromium.org/1212343009.
上级 b69a2e76
......@@ -5,6 +5,7 @@
import 'dart:sky';
import 'package:mojom/intents/intents.mojom.dart';
import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/mojo/shell.dart' as shell;
import 'package:sky/painting/box_painter.dart';
import 'package:sky/theme/colors.dart' as colors;
......@@ -18,6 +19,15 @@ import 'package:sky/widgets/scaffold.dart';
import 'package:sky/widgets/theme.dart';
import 'package:sky/widgets/tool_bar.dart';
AssetBundle _initBundle() {
if (rootBundle != null)
return rootBundle;
const String _kAssetBase = '..';
return new NetworkAssetBundle(Uri.base.resolve(_kAssetBase));
}
final AssetBundle _bundle = _initBundle();
void launch(String relativeUrl, String bundle) {
Uri url = Uri.base.resolve(relativeUrl);
......@@ -60,7 +70,7 @@ List<Widget> demos = [
textTheme: typography.black,
decoration: new BoxDecoration(
backgroundImage: new BackgroundImage(
src: '../assets/stocks_thumbnail.png',
image: _bundle.loadImage('assets/stocks_thumbnail.png'),
fit: BackgroundFit.cover
)
)
......@@ -72,7 +82,7 @@ List<Widget> demos = [
textTheme: typography.white,
decoration: new BoxDecoration(
backgroundImage: new BackgroundImage(
src: '../assets/game_thumbnail.png',
image: _bundle.loadImage('assets/game_thumbnail.png'),
fit: BackgroundFit.cover
)
)
......@@ -96,7 +106,7 @@ List<Widget> demos = [
decoration: new BoxDecoration(
backgroundColor: colors.Black,
backgroundImage: new BackgroundImage(
src: '../assets/sector_thumbnail.png',
image: _bundle.loadImage('assets/sector_thumbnail.png'),
fit: BackgroundFit.cover
)
)
......
......@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:math' as math;
import 'dart:sky' as sky;
import 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path;
import '../base/lerp.dart';
import 'shadows.dart';
import 'package:sky/mojo/net/image_cache.dart' as image_cache;
class BorderSide {
const BorderSide({
......@@ -140,19 +140,18 @@ enum BackgroundRepeat { repeat, repeatX, repeatY, noRepeat }
// to do animated images.
class BackgroundImage {
final String src;
final BackgroundFit fit;
final BackgroundRepeat repeat;
BackgroundImage({
this.src,
Future<sky.Image> image,
this.fit: BackgroundFit.scaleDown,
this.repeat: BackgroundRepeat.noRepeat
}) {
image_cache.load(src).then((image) {
if (image == null)
image.then((resolvedImage) {
if (resolvedImage == null)
return;
_image = image;
_size = new Size(image.width.toDouble(), image.height.toDouble());
_image = resolvedImage;
_size = new Size(resolvedImage.width.toDouble(), resolvedImage.height.toDouble());
for (Function listener in _listeners) {
listener();
}
......@@ -174,7 +173,7 @@ class BackgroundImage {
_listeners.remove(listener);
}
String toString() => 'BackgroundImage($src, $fit, $repeat)';
String toString() => 'BackgroundImage($fit, $repeat)';
}
enum Shape { rectangle, circle }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册