Resource prefix v.01

This commit is contained in:
vakrilov
2015-03-10 18:08:17 +02:00
parent 320dd239ba
commit 81c5b76bc3
2 changed files with 41 additions and 21 deletions

View File

@@ -1,8 +1,12 @@
<Page>
<StackLayout>
<Button horizontalAlignment="left" verticalAlignment="top" margin="10 0 10 20" text="top, left" />
<Button horizontalAlignment="center" verticalAlignment="center" text="center, center" />
<Button horizontalAlignment="right" verticalAlignment="bottom" margin="0 30" text="bottom, right" />
<Button horizontalAlignment="stretch" verticalAlignment="stretch" margin="20" text="stretch, stretch" />
<Label text="resource:" />
<Image url="res://icon" stretch="none" horizontalAlignment="left"/>
<Label text="url:" />
<Image url="http://www.google.com/images/errors/logo_sm_2.png" stretch="none" horizontalAlignment="left"/>
<Label text="app file:" />
<Image url="~/app/logo.png" stretch="none" horizontalAlignment="left" />
</StackLayout>
</Page>
</Page>

View File

@@ -13,34 +13,50 @@ var IMAGE = "Image";
var ISLOADING = "isLoading";
var STRETCH = "stretch";
var RESOURCE_PREFIX = "res://";
function isResource(value: string): boolean {
return value.indexOf(RESOURCE_PREFIX) === 0;
}
function isUrl(value: string): boolean {
return value.indexOf("http://") === 0 || value.indexOf("https://") === 0;
}
function isAppFile(value: string): boolean {
return value.indexOf("~/") === 0;
}
function isValidUrl(url: string): boolean {
var value = url ? url.trim() : "";
return value !== "" && (value.indexOf("~/") === 0 || value.indexOf("http://") === 0 || value.indexOf("https://") === 0);
return value !== "" && (isResource(value) || isAppFile(value) || isUrl(value));
}
function onUrlPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var image = <Image>data.object;
var value = data.newValue;
var value: string = data.newValue;
if (isValidUrl(value)) {
value = value.trim();
image.source = null;
image["_url"] = value;
if (value !== "") {
image._setValue(Image.isLoadingProperty, true);
image._setValue(Image.isLoadingProperty, true);
if (value.trim().indexOf("~/") === 0) {
image.source = imageSource.fromFile(value.trim());
image._setValue(Image.isLoadingProperty, false);
} else {
imageSource.fromUrl(value).then((r) => {
if (image["_url"] === value) {
image.source = r;
image._setValue(Image.isLoadingProperty, false);
}
});
}
if (isResource(value)) {
image.source = imageSource.fromResource(value.substr(RESOURCE_PREFIX.length));
image._setValue(Image.isLoadingProperty, false);
}
else if (isAppFile(value)) {
image.source = imageSource.fromFile(value);
image._setValue(Image.isLoadingProperty, false);
} else {
imageSource.fromUrl(value).then((r) => {
if (image["_url"] === value) {
image.source = r;
image._setValue(Image.isLoadingProperty, false);
}
});
}
}
}