Merge pull request #3010 from NativeScript/hhristov/android-image-fixes

Image loading is done through native imageView
This commit is contained in:
dtopuzov
2016-11-02 08:27:47 -07:00
committed by GitHub
5 changed files with 40 additions and 22 deletions

3
tests/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"typescript.tsdk": "./node_modules/typescript/lib"
}

View File

@@ -3,6 +3,8 @@ import * as TKUnit from"./TKUnit";
import { messageType } from "trace";
import { topmost, Frame } from "ui/frame";
import { TextView } from "ui/text-view";
import { Button } from "ui/button";
import { StackLayout } from "ui/layouts/stack-layout";
import * as platform from "platform";
import "./ui-test";
import fs = require("file-system");
@@ -183,9 +185,15 @@ function printRunTestStats() {
finalMessage += "\n" + "Test results: " + testFilePath;
let stack = new StackLayout();
let btn = new Button();
btn.text = "Rerun tests";
btn.on("tap", () => runAll(testsSelector));
stack.addChild(btn);
let messageContainer = new TextView();
messageContainer.text = finalMessage;
topmost().currentPage.content = messageContainer;
stack.addChild(messageContainer);
topmost().currentPage.content = stack;
}
function startLog(): void {
@@ -200,7 +208,9 @@ function log(): void {
TKUnit.write(testsName + " COMPLETED for " + duration + " BACKSTACK DEPTH: " + topmost().backStack.length, messageType.info);
}
let testsSelector: string
export var runAll = function (testSelector?: string) {
testsSelector = testSelector;
if (running) {
// TODO: We may schedule pending run requests
return;

View File

@@ -69,8 +69,8 @@ function runImageTest(done, image: ImageModule.Image, src: string) {
try {
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.assertFalse(image.isLoading, "Image.isLoading should be false.");
TKUnit.assertFalse(testModel.get("imageIsLoading"), "imageIsLoading on viewModel should be false.");
TKUnit.assertTrue(imageIsLoaded, "imageSource should be set.");
if (done) {
done(null);

View File

@@ -63,7 +63,7 @@ export function initImageCache(context: android.content.Context, mode = CacheMod
currentCacheMode = mode;
if (!imageFetcher) {
imageFetcher = new org.nativescript.widgets.image.Fetcher(context);
imageFetcher = org.nativescript.widgets.image.Fetcher.getInstance(context);
}
// Disable cache.
@@ -73,7 +73,8 @@ export function initImageCache(context: android.content.Context, mode = CacheMod
}
}
let params = new org.nativescript.widgets.image.Cache.CacheParams(context, "_imageCache");
let params = new org.nativescript.widgets.image.Cache.CacheParams();
params.memoryCacheEnabled = mode !== CacheMode.none;
params.setMemCacheSizePercent(memoryCacheSize); // Set memory cache to % of app memory
params.diskCacheEnabled = mode === CacheMode.diskAndMemory;
params.diskCacheSize = diskCacheSize;
@@ -145,7 +146,7 @@ export class Image extends imageCommon.Image {
}
else if (imageSource.isFileOrResourcePath(value)) {
if (value.indexOf(utils.RESOURCE_PREFIX) === 0) {
imageFetcher.loadImage(value, imageView, this.decodeWidth, this.decodeHeight, this.useCache, async, listener);
imageView.setUri(value, this.decodeWidth, this.decodeHeight, this.useCache, async, listener);
}
else {
let fileName = value;
@@ -153,12 +154,12 @@ export class Image extends imageCommon.Image {
fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
}
imageFetcher.loadImage(FILE_PREFIX + fileName, imageView, this.decodeWidth, this.decodeHeight, this.useCache, async, listener);
imageView.setUri(FILE_PREFIX + fileName, 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);
imageView.setUri(value, this.decodeWidth, this.decodeHeight, this.useCache, true, listener);
}
} else {
super._createImageSourceFromSrc();

View File

@@ -335,6 +335,9 @@
getRotationAngle(): number;
setRotationAngle(angle: number): void;
setUri(uri: string, decodeWidth: number, decodeHeight: number, useCache: boolean,
async: boolean, listener: image.Worker.IOnImageLoadedListener): void;
}
export class TabLayout extends android.widget.HorizontalScrollView {
@@ -385,7 +388,8 @@
}
export class Fetcher extends Worker {
constructor(context: android.content.Context);
private constructor();
public static getInstance(context: android.content.Context): Fetcher;
public addImageCache(cache: Cache): void;
public initCache(): void;
public clearCache(): void;
@@ -396,10 +400,10 @@
export namespace Cache {
export class CacheParams {
constructor(context: android.content.Context, diskCacheDirectoryName: string);
public setMemCacheSizePercent(percent: number): void;
public diskCacheEnabled: boolean;
public diskCacheSize: number;
public diskCacheEnabled: boolean;
public memoryCacheEnabled: boolean;
public setMemCacheSizePercent(percent: number): void;
}
}
}