mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
Change image.android to use the new image.Cache class from widgets. (#2832)
* Change image.android to use the new image.Cahce class from widgets. * fix npm scripts * npm tsc will compile all so no need for npm run dev-tsc-tests * fix tslint error * image-tests use memory only cache. * fix exception in image.android * Change image-tests so that Image won't be GC immediately. * Change cacheMode to enum
This commit is contained in:
85
.vscode/launch.json
vendored
85
.vscode/launch.json
vendored
@ -2,84 +2,69 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch on iOS Device",
|
||||
"name": "Sync on iOS",
|
||||
"type": "nativescript",
|
||||
"platform": "ios",
|
||||
"request": "launch",
|
||||
"appRoot": "${workspaceRoot}/tests",
|
||||
"appRoot": "${workspaceRoot}",
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": false,
|
||||
"rebuild": false,
|
||||
"syncAllFiles": false
|
||||
},
|
||||
{
|
||||
"name": "Launch on iOS",
|
||||
"type": "nativescript",
|
||||
"platform": "ios",
|
||||
"request": "launch",
|
||||
"appRoot": "${workspaceRoot}",
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": false,
|
||||
"rebuild": true
|
||||
},
|
||||
{
|
||||
"name": "Attach on iOS",
|
||||
"type": "nativescript",
|
||||
"platform": "ios",
|
||||
"request": "attach",
|
||||
"appRoot": "${workspaceRoot}",
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": false
|
||||
},
|
||||
{
|
||||
"name": "Attach on iOS Device",
|
||||
"type": "nativescript",
|
||||
"platform": "ios",
|
||||
"request": "attach",
|
||||
"appRoot": "${workspaceRoot}/tests",
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": false
|
||||
},
|
||||
{
|
||||
"name": "Launch on iOS Emulator",
|
||||
"type": "nativescript",
|
||||
"platform": "ios",
|
||||
"request": "launch",
|
||||
"appRoot": "${workspaceRoot}/tests",
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": true
|
||||
},
|
||||
{
|
||||
"name": "Attach on iOS Emulator",
|
||||
"type": "nativescript",
|
||||
"platform": "ios",
|
||||
"request": "attach",
|
||||
"appRoot": "${workspaceRoot}/tests",
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": true
|
||||
},
|
||||
{
|
||||
"name": "Launch on Android Device",
|
||||
"name": "Sync on Android",
|
||||
"type": "nativescript",
|
||||
"platform": "android",
|
||||
"request": "launch",
|
||||
"appRoot": "${workspaceRoot}/tests",
|
||||
"appRoot": "${workspaceRoot}",
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": false
|
||||
"emulator": false,
|
||||
"rebuild": false
|
||||
},
|
||||
{
|
||||
"name": "Launch on Android Emulator",
|
||||
"name": "Launch on Android",
|
||||
"type": "nativescript",
|
||||
"platform": "android",
|
||||
"request": "launch",
|
||||
"appRoot": "${workspaceRoot}/tests",
|
||||
"appRoot": "${workspaceRoot}",
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": true
|
||||
"emulator": false,
|
||||
"rebuild": true
|
||||
},
|
||||
{
|
||||
"name": "Attach on Android Device",
|
||||
"name": "Attach on Android",
|
||||
"type": "nativescript",
|
||||
"platform": "android",
|
||||
"request": "attach",
|
||||
"appRoot": "${workspaceRoot}/tests",
|
||||
"appRoot": "${workspaceRoot}",
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": false
|
||||
},
|
||||
{
|
||||
"name": "Attach on Android Emulator",
|
||||
"type": "nativescript",
|
||||
"platform": "android",
|
||||
"request": "attach",
|
||||
"appRoot": "${workspaceRoot}/tests",
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": true
|
||||
}
|
||||
]
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
"tns-core-modules": "2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tns-platform-declarations": "*",
|
||||
"babel-traverse": "6.10.4",
|
||||
"babel-types": "6.11.1",
|
||||
"babylon": "6.8.3",
|
||||
|
@ -36,17 +36,16 @@
|
||||
"tsc": "tsc",
|
||||
"tsc-w": "tsc --skipLibCheck -w",
|
||||
"dev-tsc-tns-platform-declarations": "tsc -p tns-platform-declarations",
|
||||
"dev-tsc-tns-core-modules": "tsc -p tns-core-modules",
|
||||
"dev-tsc-tests": "tsc -p tests",
|
||||
"dev-tsc-apps": "tsc -p apps",
|
||||
"dev-tsc-all": "npm run dev-tsc-tns-platform-declarations && npm run dev-tsc-tns-core-modules && npm run dev-tsc-tests && npm run dev-tsc-apps",
|
||||
"dev-tsc-all": "npm run dev-tsc-tns-platform-declarations && npm run tsc && npm run dev-tsc-tests && npm run dev-tsc-apps",
|
||||
"dev-link-tns-platform-declarations": "cd tns-platform-declarations && npm link",
|
||||
"dev-link-tns-core-modules": "cd tns-core-modules && npm link",
|
||||
"dev-link-tests": "cd tests && npm link tns-platform-declarations && npm link tns-core-modules",
|
||||
"dev-link-apps": "cd apps && npm link tns-platform-declarations && npm link tns-core-modules",
|
||||
"dev-declarations": "npm run setup && rm -rf tns-platform-declarations/ios/objc* && TNS_TYPESCRIPT_DECLARATIONS_PATH=$PWD/tns-platform-declarations/ios/objc tns build ios --path tests",
|
||||
"test": "npm run test-android && npm run test-ios",
|
||||
"pretest": "npm run setup && npm run dev-tsc-tns-core-modules && npm run dev-tsc-tests",
|
||||
"pretest": "npm run setup && npm run tsc",
|
||||
"test-android": "tns run android --path tests --justlaunch",
|
||||
"test-ios": "tns run ios --path tests --justlaunch",
|
||||
"test-watch-android": "npm run pretest && concurrently --kill-others \"npm run tsc-tiw\" \"tns livesync android --path tests --watch\"",
|
||||
|
10
tests/.vscode/tasks.json
vendored
Normal file
10
tests/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "0.1.0",
|
||||
"command": "tsc",
|
||||
"isShellCommand": true,
|
||||
"args": ["-p", "."],
|
||||
"showOutput": "silent",
|
||||
"problemMatcher": "$tsc"
|
||||
}
|
@ -214,7 +214,7 @@ export function assertNotEqual(actual: any, expected: any, message?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export function assertEqual(actual: any, expected: any, message?: string) {
|
||||
export function assertEqual<T extends { equals?(arg: T): boolean }>(actual: T, expected: T, message?: string) {
|
||||
if (!types.isNullOrUndefined(actual)
|
||||
&& !types.isNullOrUndefined(expected)
|
||||
&& types.getClass(actual) === types.getClass(expected)
|
||||
|
@ -501,11 +501,11 @@ export function test_ObservableShouldEmitPropertyChangeWithSameObjectUsingWrappe
|
||||
export function test_CorrectEventArgsWhenWrappedValueIsUsed() {
|
||||
let testArray = [1];
|
||||
let testObservable = new observable.Observable({ "property1": testArray});
|
||||
let actualArgsValue = 0;
|
||||
let actualArgsValue;
|
||||
let propertyChangeHandler = function (args) {
|
||||
actualArgsValue = args.value;
|
||||
|
||||
}
|
||||
|
||||
testObservable.on(observable.Observable.propertyChangeEvent, propertyChangeHandler);
|
||||
testArray.push(2);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Image } from "ui/image";
|
||||
import { StackLayout } from "ui/layouts/stack-layout";
|
||||
import { GridLayout } from "ui/layouts/grid-layout";
|
||||
import {isIOS} from "platform";
|
||||
import { isIOS, isAndroid } from "platform";
|
||||
import { PropertyChangeData } from "data/observable";
|
||||
import utils = require("utils/utils");
|
||||
|
||||
@ -24,6 +24,11 @@ import color = require("color");
|
||||
|
||||
var imagePath = fs.path.join(__dirname, "../../logo.png");
|
||||
|
||||
if (isAndroid) {
|
||||
var imageModule = require("ui/image");
|
||||
imageModule.currentMode = imageModule.CacheMode.memory; // use memory cache only.
|
||||
}
|
||||
|
||||
export var test_Image_Members = function () {
|
||||
var image = new ImageModule.Image();
|
||||
TKUnit.assert(types.isUndefined(image.src), "Image.src is defined");
|
||||
@ -63,10 +68,10 @@ function runImageTest(done, image: ImageModule.Image, src: string) {
|
||||
testModel.off(ObservableModule.Observable.propertyChangeEvent, handler);
|
||||
|
||||
try {
|
||||
let imageIsLoaded = !!image.imageSource;
|
||||
let imageIsLoaded = isIOS ? !!image.imageSource : true;
|
||||
TKUnit.assertTrue(!image.isLoading, "Image.isLoading should be false.");
|
||||
TKUnit.assertTrue(!testModel.get("imageIsLoading"), "imageIsLoading on viewModel should be false.");
|
||||
TKUnit.assertTrue(imageIsLoaded, "imageIsLoading should be true.");
|
||||
TKUnit.assertTrue(imageIsLoaded, "imageSource should be set.");
|
||||
if (done) {
|
||||
done(null);
|
||||
}
|
||||
@ -86,6 +91,8 @@ function runImageTest(done, image: ImageModule.Image, src: string) {
|
||||
twoWay: true
|
||||
}, testModel);
|
||||
|
||||
let page = helper.getCurrentPage();
|
||||
page.content = image;
|
||||
image.src = src;
|
||||
testModel.on(ObservableModule.Observable.propertyChangeEvent, handler);
|
||||
if (done) {
|
||||
@ -102,6 +109,7 @@ export var test_SettingImageSrc = function (done) {
|
||||
var image = new ImageModule.Image();
|
||||
image.src = "https://www.google.com/images/errors/logo_sm_2.png";
|
||||
// << img-create-src
|
||||
(<any>image).useCache = false;
|
||||
runImageTest(done, image, image.src)
|
||||
}
|
||||
|
||||
@ -125,6 +133,7 @@ export var test_SettingImageSrcToDataURI = function () {
|
||||
|
||||
export var test_SettingImageSrcToFileWithinAppAsync = function (done) {
|
||||
var image = new ImageModule.Image();
|
||||
(<any>image).useCache = false;
|
||||
image.loadMode = "async";
|
||||
image.src = "~/logo.png";
|
||||
runImageTest(done, image, image.src)
|
||||
@ -339,6 +348,7 @@ export var test_SettingImageSourceWhenSizedToContentShouldInvalidate = ios(() =>
|
||||
export var test_DimensionsAreRoundedAfterScale = function () {
|
||||
let host = new StackLayout();
|
||||
let image = new Image();
|
||||
(<any>image).useCache = false;
|
||||
image.src = "~/ui/image/700x50.png";
|
||||
let imageWidth = 700;
|
||||
let imageHeight = 50;
|
||||
@ -350,8 +360,7 @@ export var test_DimensionsAreRoundedAfterScale = function() {
|
||||
host.addChild(image);
|
||||
let mainPage = helper.getCurrentPage();
|
||||
mainPage.content = host;
|
||||
TKUnit.waitUntilReady(() => host.isLoaded);
|
||||
TKUnit.waitUntilReady(() => image.isLayoutValid);
|
||||
TKUnit.waitUntilReady(() => host.isLayoutValid);
|
||||
|
||||
let scale = hostWidth / imageWidth;
|
||||
let expectedHeight = Math.round(imageHeight * scale);
|
||||
|
@ -756,7 +756,7 @@ export function test_border_color() {
|
||||
let blue = new color.Color("blue");
|
||||
let hex = blue.hex;
|
||||
testView.style.borderColor = hex;
|
||||
TKUnit.assertEqual(testView.style.borderColor, blue, "all");
|
||||
TKUnit.assertEqual((<any>testView.style.borderColor), blue, "all");
|
||||
TKUnit.assertEqual(testView.style.borderTopColor, blue, "top");
|
||||
TKUnit.assertEqual(testView.style.borderRightColor, blue, "right");
|
||||
TKUnit.assertEqual(testView.style.borderBottomColor, blue, "bottom");
|
||||
@ -774,7 +774,7 @@ export function test_border_width() {
|
||||
TKUnit.assertEqual(testView.style.borderLeftWidth, 10, "left");
|
||||
|
||||
testView.style.borderWidth = "20";
|
||||
TKUnit.assertEqual(testView.style.borderWidth, 20, "all");
|
||||
TKUnit.assertEqual((<any>testView.style.borderWidth), 20, "all");
|
||||
TKUnit.assertEqual(testView.style.borderTopWidth, 20, "top");
|
||||
TKUnit.assertEqual(testView.style.borderRightWidth, 20, "right");
|
||||
TKUnit.assertEqual(testView.style.borderBottomWidth, 20, "bottom");
|
||||
@ -792,7 +792,7 @@ export function test_border_radius() {
|
||||
TKUnit.assertEqual(testView.style.borderBottomLeftRadius, 10, "left");
|
||||
|
||||
testView.style.borderRadius = "20";
|
||||
TKUnit.assertEqual(testView.style.borderRadius, 20, "all");
|
||||
TKUnit.assertEqual((<any>testView.style.borderRadius), 20, "all");
|
||||
TKUnit.assertEqual(testView.style.borderTopLeftRadius, 20, "top");
|
||||
TKUnit.assertEqual(testView.style.borderTopRightRadius, 20, "right");
|
||||
TKUnit.assertEqual(testView.style.borderBottomRightRadius, 20, "bottom");
|
||||
|
@ -16,6 +16,7 @@
|
||||
"tns-core-modules": "2.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tns-platform-declarations": "*",
|
||||
"babel-traverse": "6.9.0",
|
||||
"babel-types": "6.9.0",
|
||||
"babylon": "6.8.0",
|
||||
|
@ -96,7 +96,7 @@ export class Image extends view.View implements definition.Image {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_createImageSourceFromSrc(): void {
|
||||
public _createImageSourceFromSrc(): void {
|
||||
var value = this.src;
|
||||
if (types.isString(value)) {
|
||||
value = value.trim();
|
||||
|
@ -1,27 +1,36 @@
|
||||
import imageCommon = require("./image-common");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import * as enumsModule from "ui/enums";
|
||||
import style = require("ui/styling/style");
|
||||
import view = require("ui/core/view");
|
||||
import enums = require("ui/enums");
|
||||
import types = require("utils/types");
|
||||
import imageSource = require("image-source");
|
||||
import utils = require("utils/utils");
|
||||
import * as fs from "file-system";
|
||||
import * as application from "application";
|
||||
|
||||
global.moduleMerge(imageCommon, exports);
|
||||
|
||||
var enums: typeof enumsModule;
|
||||
function ensureEnums() {
|
||||
if (!enums) {
|
||||
enums = require("ui/enums");
|
||||
}
|
||||
const FILE_PREFIX = "file:///";
|
||||
let ASYNC = "async";
|
||||
let imageFetcher: org.nativescript.widgets.image.Fetcher;
|
||||
let imageCache: org.nativescript.widgets.image.Cache;
|
||||
|
||||
export enum CacheMode {
|
||||
none,
|
||||
memory,
|
||||
diskAndMemory
|
||||
}
|
||||
|
||||
export let currentCacheMode: CacheMode;
|
||||
|
||||
function onStretchPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var image = <Image>data.object;
|
||||
let image = <Image>data.object;
|
||||
if (!image.android) {
|
||||
return;
|
||||
}
|
||||
|
||||
ensureEnums();
|
||||
|
||||
switch (data.newValue) {
|
||||
case enums.Stretch.aspectFit:
|
||||
image.android.setScaleType(android.widget.ImageView.ScaleType.FIT_CENTER);
|
||||
@ -48,6 +57,34 @@ function onImageSourcePropertyChanged(data: dependencyObservable.PropertyChangeD
|
||||
image._setNativeImage(data.newValue);
|
||||
}
|
||||
|
||||
export function initImageCache(context: android.content.Context, mode = CacheMode.diskAndMemory, memoryCacheSize: number = 0.25, diskCacheSize: number = 10 * 1024 * 1024): void {
|
||||
if (currentCacheMode === mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentCacheMode = mode;
|
||||
if (!imageFetcher) {
|
||||
imageFetcher = new org.nativescript.widgets.image.Fetcher(context);
|
||||
}
|
||||
|
||||
// Disable cache.
|
||||
if (mode === CacheMode.none) {
|
||||
if (imageCache != null && imageFetcher != null) {
|
||||
imageFetcher.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
let params = new org.nativescript.widgets.image.Cache.CacheParams(context, "_imageCache");
|
||||
params.setMemCacheSizePercent(memoryCacheSize); // Set memory cache to % of app memory
|
||||
params.diskCacheEnabled = mode === CacheMode.diskAndMemory;
|
||||
params.diskCacheSize = diskCacheSize;
|
||||
imageCache = org.nativescript.widgets.image.Cache.getInstance(params);
|
||||
imageFetcher.addImageCache(imageCache);
|
||||
imageFetcher.initCache();
|
||||
}
|
||||
|
||||
initImageCache(application.android.nativeApp);
|
||||
|
||||
// register the setNativeValue callback
|
||||
(<proxy.PropertyMetadata>imageCommon.Image.imageSourceProperty.metadata).onSetNativeValue = onImageSourcePropertyChanged;
|
||||
(<proxy.PropertyMetadata>imageCommon.Image.stretchProperty.metadata).onSetNativeValue = onStretchPropertyChanged;
|
||||
@ -55,21 +92,79 @@ function onImageSourcePropertyChanged(data: dependencyObservable.PropertyChangeD
|
||||
export class Image extends imageCommon.Image {
|
||||
private _android: org.nativescript.widgets.ImageView;
|
||||
|
||||
public decodeWidth = 0;
|
||||
public decodeHeight = 0;
|
||||
public useCache = true;
|
||||
|
||||
get android(): org.nativescript.widgets.ImageView {
|
||||
return this._android;
|
||||
}
|
||||
|
||||
public _createUI() {
|
||||
this._android = new org.nativescript.widgets.ImageView(this._context);
|
||||
this._createImageSourceFromSrc();
|
||||
}
|
||||
|
||||
public _setNativeImage(nativeImage: any) {
|
||||
let rotation = (nativeImage && nativeImage.rotationAngle) ? nativeImage.rotationAngle : 0 ;
|
||||
if (!nativeImage) {
|
||||
return;
|
||||
}
|
||||
|
||||
let rotation = nativeImage.rotationAngle ? nativeImage.rotationAngle : 0 ;
|
||||
if (rotation > 0) {
|
||||
this.android.setRotationAngle(rotation);
|
||||
}
|
||||
this.android.setImageBitmap(nativeImage.android);
|
||||
}
|
||||
|
||||
public _createImageSourceFromSrc() {
|
||||
let imageView = this._android;
|
||||
if (!imageView) {
|
||||
return;
|
||||
}
|
||||
|
||||
let value = this.src;
|
||||
let async = this.loadMode === ASYNC;
|
||||
let owner = new WeakRef<Image>(this);
|
||||
let listener = new org.nativescript.widgets.image.Worker.OnImageLoadedListener({
|
||||
onImageLoaded: function (success) {
|
||||
let that = owner.get();
|
||||
if (that) {
|
||||
that._setValue(Image.isLoadingProperty, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this._resetValue(Image.imageSourceProperty);
|
||||
if (types.isString(value)) {
|
||||
value = value.trim();
|
||||
this._setValue(Image.isLoadingProperty, true);
|
||||
|
||||
if (utils.isDataURI(value)) {
|
||||
// TODO: Check with runtime what should we do in case of base64 string.
|
||||
super._createImageSourceFromSrc();
|
||||
}
|
||||
else if (imageSource.isFileOrResourcePath(value)) {
|
||||
if (value.indexOf(utils.RESOURCE_PREFIX) === 0) {
|
||||
imageFetcher.loadImage(value, imageView, this.decodeWidth, this.decodeHeight, this.useCache, async, listener);
|
||||
}
|
||||
else {
|
||||
let fileName = value;
|
||||
if (fileName.indexOf("~/") === 0) {
|
||||
fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
|
||||
}
|
||||
|
||||
imageFetcher.loadImage(FILE_PREFIX + fileName, imageView, this.decodeWidth, this.decodeHeight, this.useCache, async, listener);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// For backwards compatibility http always use async loading.
|
||||
imageFetcher.loadImage(value, imageView, this.decodeWidth, this.decodeHeight, this.useCache, true, listener);
|
||||
}
|
||||
} else {
|
||||
super._createImageSourceFromSrc();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ImageStyler implements style.Styler {
|
||||
|
@ -54,53 +54,3 @@ declare module android {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare module org {
|
||||
export module nativescript {
|
||||
export module widgets {
|
||||
export module Async {
|
||||
export class CompleteCallback {
|
||||
constructor(implementation: ICompleteCallback);
|
||||
onComplete(result: Object, context: Object): void;
|
||||
}
|
||||
|
||||
export interface ICompleteCallback {
|
||||
onComplete(result: Object, context: Object): void;
|
||||
}
|
||||
|
||||
export module Image {
|
||||
export function download(url: string, callback: CompleteCallback, context: any);
|
||||
}
|
||||
|
||||
export module Http {
|
||||
export class KeyValuePair {
|
||||
public key: string;
|
||||
public value: string;
|
||||
constructor(key: string, value: string);
|
||||
}
|
||||
|
||||
export class RequestOptions {
|
||||
public url: string;
|
||||
public method: string;
|
||||
public headers: java.util.ArrayList<KeyValuePair>;
|
||||
public content: string;
|
||||
public timeout: number;
|
||||
public screenWidth: number;
|
||||
public screenHeight: number;
|
||||
}
|
||||
|
||||
export class RequestResult {
|
||||
public raw: java.io.ByteArrayOutputStream;
|
||||
public headers: java.util.ArrayList<KeyValuePair>;
|
||||
public statusCode: number;
|
||||
public responseAsString: string;
|
||||
public responseAsImage: android.graphics.Bitmap;
|
||||
public error: java.lang.Exception;
|
||||
}
|
||||
|
||||
export function MakeRequest(options: RequestOptions, callback: CompleteCallback, context: any);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,50 @@
|
||||
declare module org {
|
||||
module nativescript {
|
||||
module widgets {
|
||||
export module Async {
|
||||
export class CompleteCallback {
|
||||
constructor(implementation: ICompleteCallback);
|
||||
onComplete(result: Object, context: Object): void;
|
||||
}
|
||||
|
||||
export interface ICompleteCallback {
|
||||
onComplete(result: Object, context: Object): void;
|
||||
}
|
||||
|
||||
export module Image {
|
||||
export function download(url: string, callback: CompleteCallback, context: any);
|
||||
}
|
||||
|
||||
export module Http {
|
||||
export class KeyValuePair {
|
||||
public key: string;
|
||||
public value: string;
|
||||
constructor(key: string, value: string);
|
||||
}
|
||||
|
||||
export class RequestOptions {
|
||||
public url: string;
|
||||
public method: string;
|
||||
public headers: java.util.ArrayList<KeyValuePair>;
|
||||
public content: string;
|
||||
public timeout: number;
|
||||
public screenWidth: number;
|
||||
public screenHeight: number;
|
||||
}
|
||||
|
||||
export class RequestResult {
|
||||
public raw: java.io.ByteArrayOutputStream;
|
||||
public headers: java.util.ArrayList<KeyValuePair>;
|
||||
public statusCode: number;
|
||||
public responseAsString: string;
|
||||
public responseAsImage: android.graphics.Bitmap;
|
||||
public error: java.lang.Exception;
|
||||
}
|
||||
|
||||
export function MakeRequest(options: RequestOptions, callback: CompleteCallback, context: any);
|
||||
}
|
||||
}
|
||||
|
||||
export class BorderDrawable extends android.graphics.drawable.ColorDrawable {
|
||||
constructor(density: number);
|
||||
public refresh(
|
||||
@ -309,6 +353,48 @@
|
||||
iconId: number;
|
||||
iconDrawable: android.graphics.drawable.Drawable;
|
||||
}
|
||||
|
||||
export namespace image {
|
||||
|
||||
export class Cache {
|
||||
private constructor();
|
||||
public static getInstance(cacheParams: Cache.CacheParams): Cache;
|
||||
}
|
||||
|
||||
export class Worker {
|
||||
|
||||
}
|
||||
|
||||
export namespace Worker {
|
||||
interface IOnImageLoadedListener {
|
||||
onImageLoaded(success: boolean): void;
|
||||
}
|
||||
|
||||
export class OnImageLoadedListener implements IOnImageLoadedListener {
|
||||
constructor(implementation: IOnImageLoadedListener);
|
||||
public onImageLoaded(success: boolean): void;
|
||||
}
|
||||
}
|
||||
|
||||
export class Fetcher extends Worker {
|
||||
constructor(context: android.content.Context);
|
||||
public addImageCache(cache: Cache): void;
|
||||
public initCache(): void;
|
||||
public clearCache(): void;
|
||||
public loadImage(data: Object, imageView: ImageView,
|
||||
decodeWidth: number, decodeHeight: number, useCache: boolean, async: boolean,
|
||||
listener: Worker.IOnImageLoadedListener): void;
|
||||
}
|
||||
|
||||
export namespace Cache {
|
||||
export class CacheParams {
|
||||
constructor(context: android.content.Context, diskCacheDirectoryName: string);
|
||||
public setMemCacheSizePercent(percent: number): void;
|
||||
public diskCacheEnabled: boolean;
|
||||
public diskCacheSize: number;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,6 @@
|
||||
{
|
||||
"name": "tns-platform-declarations",
|
||||
"version": "2.4.0",
|
||||
"nativescript": {
|
||||
"platforms": {
|
||||
"ios": "2.4.0",
|
||||
"android": "2.4.0"
|
||||
}
|
||||
},
|
||||
"description": "Platform-specific TypeScript declarations for NativeScript for accessing native objects",
|
||||
"main": "",
|
||||
"scripts": {
|
||||
|
Reference in New Issue
Block a user