mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Renamed image module to image-source. Extended the testRunner to accept module name to run.
This commit is contained in:
20
BCL.csproj
20
BCL.csproj
@ -110,18 +110,18 @@
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="file-system\file-system.d.ts" />
|
||||
<TypeScriptCompile Include="file-system\file-system-access.d.ts" />
|
||||
<TypeScriptCompile Include="image\image-native.android.ts">
|
||||
<DependentUpon>image-native.d.ts</DependentUpon>
|
||||
<TypeScriptCompile Include="image-source\image-source-native.android.ts">
|
||||
<DependentUpon>image-source-native.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="image\image-native.ios.ts">
|
||||
<DependentUpon>image-native.d.ts</DependentUpon>
|
||||
<TypeScriptCompile Include="image-source\image-source-native.ios.ts">
|
||||
<DependentUpon>image-source-native.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="image\image.ts">
|
||||
<DependentUpon>image.d.ts</DependentUpon>
|
||||
<TypeScriptCompile Include="image-source\image-source.d.ts" />
|
||||
<TypeScriptCompile Include="image-source\image-source-native.d.ts" />
|
||||
<TypeScriptCompile Include="image-source\image-source.ts">
|
||||
<DependentUpon>image-source.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="image\image.d.ts" />
|
||||
<TypeScriptCompile Include="image\image-native.d.ts" />
|
||||
<TypeScriptCompile Include="image\index.ts" />
|
||||
<TypeScriptCompile Include="image-source\index.ts" />
|
||||
<TypeScriptCompile Include="location\location.android.ts">
|
||||
<DependentUpon>location.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
@ -188,7 +188,7 @@
|
||||
<DependentUpon>http-request.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="application\application-common.ts" />
|
||||
<Content Include="image\Readme.md" />
|
||||
<Content Include="image-source\Readme.md" />
|
||||
<TypeScriptCompile Include="local-settings\index.ts" />
|
||||
<TypeScriptCompile Include="local-settings\local-settings.d.ts" />
|
||||
<TypeScriptCompile Include="local-settings\local-settings.android.ts">
|
||||
|
@ -121,7 +121,7 @@ export var test_getImage = function () {
|
||||
// </snippet>
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 3);
|
||||
TKUnit.assert(result instanceof require("image").Image, "Result from getImage() should be valid Image object!");
|
||||
TKUnit.assert(result instanceof require("image-source").ImageSource, "Result from getImage() should be valid ImageSource object!");
|
||||
};
|
||||
|
||||
export var test_getImage_fail = function () {
|
||||
|
@ -1,19 +1,19 @@
|
||||
import image = require("image/image");
|
||||
import imageSource = require("image-source/image-source");
|
||||
import app = require("application/application");
|
||||
import fs = require("file-system/file-system");
|
||||
import TKUnit = require("Tests/TKUnit");
|
||||
|
||||
export var testFromResource = function () {
|
||||
var img = image.fromResource(getTestImageName());
|
||||
var img = imageSource.fromResource(getTestImageName());
|
||||
TKUnit.assert(img.height > 0, "image.fromResource failed");
|
||||
}
|
||||
|
||||
export var testFromUrl = function () {
|
||||
var completed;
|
||||
var result: image.Image;
|
||||
var result: imageSource.ImageSource;
|
||||
|
||||
image.fromUrl("http://www.google.com/images/errors/logo_sm_2.png")
|
||||
.then(function (res: image.Image) {
|
||||
imageSource.fromUrl("http://www.google.com/images/errors/logo_sm_2.png")
|
||||
.then(function (res: imageSource.ImageSource) {
|
||||
completed = true;
|
||||
result = res;
|
||||
})
|
||||
@ -31,11 +31,11 @@ export var testFromUrl = function () {
|
||||
}
|
||||
|
||||
export var testSaveToFile = function () {
|
||||
var img = image.fromResource(getTestImageName());
|
||||
var img = imageSource.fromResource(getTestImageName());
|
||||
var folder = fs.knownFolders.documents();
|
||||
var path = fs.path.join(folder.path, "Test.png");
|
||||
|
||||
var saved = img.saveToFile(path, image.ImageFormat.PNG);
|
||||
var saved = img.saveToFile(path, imageSource.ImageFormat.PNG);
|
||||
TKUnit.assert(saved, "Image not saved to file");
|
||||
TKUnit.assert(fs.File.exists(path), "Image not saved to file");
|
||||
}
|
||||
@ -44,7 +44,7 @@ export var testFromFile = function () {
|
||||
var folder = fs.knownFolders.documents();
|
||||
var path = fs.path.join(folder.path, "Test.png");
|
||||
|
||||
var img = image.fromFile(path);
|
||||
var img = imageSource.fromFile(path);
|
||||
|
||||
TKUnit.assert(img.height > 0, "image.fromResource failed");
|
||||
|
||||
@ -55,7 +55,7 @@ export var testFromFile = function () {
|
||||
}
|
||||
|
||||
export var testNativeFields = function () {
|
||||
var img = image.fromResource(getTestImageName());
|
||||
var img = imageSource.fromResource(getTestImageName());
|
||||
if (app.android) {
|
||||
TKUnit.assert(img.android != null, "Image.android not updated.");
|
||||
} else if (app.ios) {
|
||||
|
@ -1,14 +1,18 @@
|
||||
var TKUnit = require("Tests/TKUnit");
|
||||
var fsTests = require("Tests/file-system-tests");
|
||||
var httpTests = require("Tests/http-tests");
|
||||
var locationTests = require("Tests/location-tests");
|
||||
var localSettingsTests = require("Tests/local-settings-tests");
|
||||
var imageTests = require("Tests/image-tests");
|
||||
|
||||
export var runAll = function () {
|
||||
TKUnit.runTestModule(imageTests, "IMAGE");
|
||||
TKUnit.runTestModule(fsTests, "FILE SYSTEM");
|
||||
TKUnit.runTestModule(httpTests, "HTTP");
|
||||
TKUnit.runTestModule(locationTests, "LOCATION");
|
||||
TKUnit.runTestModule(localSettingsTests, "LOCAL SETTINGS");
|
||||
var allTests = {};
|
||||
allTests["FILE SYSTEM"] = require("Tests/file-system-tests");
|
||||
allTests["HTTP"] = require("Tests/http-tests");
|
||||
allTests["LOCATION"] = require("Tests/location-tests");
|
||||
allTests["LOCAL SETTINGS"] = require("Tests/local-settings-tests");
|
||||
allTests["IMAGE SOURCE"] = require("Tests/image-tests");
|
||||
|
||||
export var runAll = function (moduleName?: string) {
|
||||
for (var name in allTests) {
|
||||
if(moduleName && (moduleName.toLowerCase() !== name.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TKUnit.runTestModule(allTests[name], name);
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
declare var module, require;
|
||||
module.exports = require("file-system/file_system");
|
||||
module.exports = require("file-system/file-system");
|
@ -25,7 +25,7 @@ export function request(options: http.HttpRequestOptions): promises.Promise<http
|
||||
raw: data,
|
||||
toString: () => { return null },
|
||||
toJSON: () => { return null },
|
||||
toImage: () => { return require("image").fromNativeBitmap(data); }
|
||||
toImage: () => { return require("image-source").fromNativeSource(data); }
|
||||
},
|
||||
statusCode: 0,
|
||||
headers: {}
|
||||
|
4
http/http-request.d.ts
vendored
4
http/http-request.d.ts
vendored
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* The http client interface.
|
||||
*/
|
||||
import image_module = require("image/image");
|
||||
import image_module = require("image-source/image-source");
|
||||
import promises = require("promises/promises");
|
||||
|
||||
export declare function request(options: HttpRequestOptions): promises.Promise<HttpResponse>;
|
||||
@ -24,5 +24,5 @@ export interface HttpContent {
|
||||
raw: any;
|
||||
toString: () => string;
|
||||
toJSON: () => any;
|
||||
toImage: () => image_module.Image;
|
||||
toImage: () => image_module.ImageSource;
|
||||
}
|
@ -54,7 +54,7 @@ export function request(options: http.HttpRequestOptions): promises.Promise<http
|
||||
raw: data,
|
||||
toString: () => { return NSDataToString(data); },
|
||||
toJSON: () => { return JSON.parse(NSDataToString(data)); },
|
||||
toImage: () => { return require("image").fromData(data); }
|
||||
toImage: () => { return require("image-source").fromData(data); }
|
||||
},
|
||||
statusCode: response.statusCode(),
|
||||
headers: headers
|
||||
|
@ -1,4 +1,4 @@
|
||||
import image_module = require("image/image");
|
||||
import image_module = require("image-source/image-source");
|
||||
import promises = require("promises/promises");
|
||||
import http = require("http/http-request");
|
||||
|
||||
@ -37,8 +37,8 @@ export function getJSON<T>(url: string): promises.Promise<T> {
|
||||
/**
|
||||
* Gets image from url.
|
||||
*/
|
||||
export function getImage(url: string): promises.Promise<image_module.Image> {
|
||||
var d = promises.defer<image_module.Image>();
|
||||
export function getImage(url: string): promises.Promise<image_module.ImageSource> {
|
||||
var d = promises.defer<image_module.ImageSource>();
|
||||
|
||||
http.request({ url: url, method: "GET" })
|
||||
.then(r => d.resolve(r.content.toImage()))
|
||||
|
@ -1,6 +1,6 @@
|
||||
The way we get local path here is different for now. Maybe we should get it from FS module in the future samples. Sample code Android:
|
||||
|
||||
```
|
||||
var Image = require("image").Image;
|
||||
var baseImage = Image.imageFromResource('foxie');
|
||||
var ImageSource = require("image-source").ImageSource;
|
||||
var source = ImageSource.imageFromResource('foxie');
|
||||
```
|
@ -9,9 +9,9 @@ export declare enum ImageFormat {
|
||||
}
|
||||
|
||||
/**
|
||||
* Encapsulates the common abstraction behind a platform specific image object.
|
||||
* Encapsulates the common abstraction behind a platform specific object (typically a Bitmap) that is used as a source for images.
|
||||
*/
|
||||
export declare class Image {
|
||||
export declare class ImageSource {
|
||||
/**
|
||||
* Gets the height of this instance. This is a read-only property.
|
||||
*/
|
||||
@ -48,10 +48,10 @@ export declare class Image {
|
||||
loadFromData(data: any): boolean;
|
||||
|
||||
/**
|
||||
* Sets the provided native bitmap object.
|
||||
* Sets the provided native source object (typically a Bitmap).
|
||||
* This will update either the android or ios properties, depending on the target os.
|
||||
*/
|
||||
setNativeBitmap(source: any): boolean;
|
||||
setNativeSource(source: any): boolean;
|
||||
|
||||
/**
|
||||
* Saves this instance to the specified file, using the provided image format and quality.
|
||||
@ -62,25 +62,25 @@ export declare class Image {
|
||||
/**
|
||||
* Creates a new Image instance and loads it from the specified resource name.
|
||||
*/
|
||||
export declare function fromResource(name: string): Image;
|
||||
export declare function fromResource(name: string): ImageSource;
|
||||
|
||||
/**
|
||||
* Creates a new Image instance and loads it from the specified file.
|
||||
*/
|
||||
export declare function fromFile(path: string): Image;
|
||||
export declare function fromFile(path: string): ImageSource;
|
||||
|
||||
/**
|
||||
* Creates a new Image instance and loads it from the specified resource name.
|
||||
*/
|
||||
export declare function fromData(data: any): Image;
|
||||
export declare function fromData(data: any): ImageSource;
|
||||
|
||||
/**
|
||||
* Creates a new Image instance and sets the provided native bitmap object.
|
||||
* The native bitmap object will update either the android or ios properties, depending on the target os.
|
||||
* Creates a new Image instance and sets the provided native source object (typically a Bitmap).
|
||||
* The native source object will update either the android or ios properties, depending on the target os.
|
||||
*/
|
||||
export declare function fromNativeBitmap(source: any): Image;
|
||||
export declare function fromNativeSource(source: any): ImageSource;
|
||||
|
||||
/**
|
||||
* Downloads the image from the provided Url and creates a new Image instance from it.
|
||||
*/
|
||||
export declare function fromUrl(url: string): promises.Promise<Image>;
|
||||
export declare function fromUrl(url: string): promises.Promise<ImageSource>;
|
@ -1,5 +1,5 @@
|
||||
import app = require("application/application");
|
||||
import impl = require("image/image-native");
|
||||
import native = require("image-source/image-source-native");
|
||||
import promises = require("promises/promises");
|
||||
import http = require("http/http");
|
||||
|
||||
@ -8,7 +8,7 @@ export enum ImageFormat {
|
||||
JPEG,
|
||||
}
|
||||
|
||||
export class Image {
|
||||
export class ImageSource {
|
||||
public android: android.graphics.Bitmap;
|
||||
public ios: UIKit.UIImage;
|
||||
|
||||
@ -17,30 +17,30 @@ export class Image {
|
||||
}
|
||||
|
||||
public loadFromResource(name: string): boolean {
|
||||
var nativeInstance = impl.fromResource(name);
|
||||
var nativeInstance = native.fromResource(name);
|
||||
this.setNativeInstance(nativeInstance);
|
||||
return nativeInstance != null;
|
||||
}
|
||||
|
||||
public loadFromFile(path: string): boolean {
|
||||
var nativeInstance = impl.fromFile(path);
|
||||
var nativeInstance = native.fromFile(path);
|
||||
this.setNativeInstance(nativeInstance);
|
||||
return (nativeInstance != null);
|
||||
}
|
||||
|
||||
public loadFromData(data: any): boolean {
|
||||
var nativeInstance = impl.fromData(data);
|
||||
var nativeInstance = native.fromData(data);
|
||||
this.setNativeInstance(nativeInstance);
|
||||
return (nativeInstance != null);
|
||||
}
|
||||
|
||||
public setNativeBitmap(source: any): boolean {
|
||||
public setNativeSource(source: any): boolean {
|
||||
this.setNativeInstance(source);
|
||||
return source != null;
|
||||
}
|
||||
|
||||
public saveToFile(path: string, format: ImageFormat, quality?: number): boolean {
|
||||
return impl.saveToFile(this.getNativeInstance(), path, format, quality);
|
||||
return native.saveToFile(this.getNativeInstance(), path, format, quality);
|
||||
}
|
||||
|
||||
get height(): number {
|
||||
@ -85,26 +85,26 @@ export class Image {
|
||||
}
|
||||
}
|
||||
|
||||
export function fromResource(name: string): Image {
|
||||
var image = new Image();
|
||||
export function fromResource(name: string): ImageSource {
|
||||
var image = new ImageSource();
|
||||
return image.loadFromResource(name) ? image : null;
|
||||
}
|
||||
|
||||
export function fromFile(path: string): Image {
|
||||
var image = new Image();
|
||||
export function fromFile(path: string): ImageSource {
|
||||
var image = new ImageSource();
|
||||
return image.loadFromFile(path) ? image : null;
|
||||
}
|
||||
|
||||
export function fromData(data: any): Image {
|
||||
var image = new Image();
|
||||
export function fromData(data: any): ImageSource {
|
||||
var image = new ImageSource();
|
||||
return image.loadFromData(data) ? image : null;
|
||||
}
|
||||
|
||||
export function fromNativeBitmap(source: any): Image {
|
||||
var image = new Image();
|
||||
return image.setNativeBitmap(source) ? image : null;
|
||||
export function fromNativeSource(source: any): ImageSource {
|
||||
var image = new ImageSource();
|
||||
return image.setNativeSource(source) ? image : null;
|
||||
}
|
||||
|
||||
export function fromUrl(url: string): promises.Promise<Image> {
|
||||
export function fromUrl(url: string): promises.Promise<ImageSource> {
|
||||
return http.getImage(url);
|
||||
}
|
2
image-source/index.ts
Normal file
2
image-source/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
declare var module, require;
|
||||
module.exports = require("image-source/image-source");
|
@ -1,2 +0,0 @@
|
||||
declare var module, require;
|
||||
module.exports = require("image/image");
|
Reference in New Issue
Block a user