mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #3010 from NativeScript/hhristov/android-image-fixes
Image loading is done through native imageView
This commit is contained in:
3
tests/.vscode/settings.json
vendored
Normal file
3
tests/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"typescript.tsdk": "./node_modules/typescript/lib"
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
import * as TKUnit from"./TKUnit";
|
import * as TKUnit from "./TKUnit";
|
||||||
import {messageType} from "trace";
|
import { messageType } from "trace";
|
||||||
import {topmost, Frame} from "ui/frame";
|
import { topmost, Frame } from "ui/frame";
|
||||||
import {TextView} from "ui/text-view";
|
import { TextView } from "ui/text-view";
|
||||||
|
import { Button } from "ui/button";
|
||||||
|
import { StackLayout } from "ui/layouts/stack-layout";
|
||||||
import * as platform from "platform";
|
import * as platform from "platform";
|
||||||
import "./ui-test";
|
import "./ui-test";
|
||||||
import fs = require("file-system");
|
import fs = require("file-system");
|
||||||
@@ -132,14 +134,14 @@ function printRunTestStats() {
|
|||||||
var failedTestCount = 0;
|
var failedTestCount = 0;
|
||||||
var failedTestInfo = [];
|
var failedTestInfo = [];
|
||||||
|
|
||||||
let allTests = testsQueue.filter(t=> t.isTest);
|
let allTests = testsQueue.filter(t => t.isTest);
|
||||||
|
|
||||||
testFileContent.push("<testsuites>");
|
testFileContent.push("<testsuites>");
|
||||||
|
|
||||||
for (j = 0; j < allTests.length; j++) {
|
for (j = 0; j < allTests.length; j++) {
|
||||||
let testName = allTests[j].testName;
|
let testName = allTests[j].testName;
|
||||||
let duration = (allTests[j].duration / 1000).toFixed(2);
|
let duration = (allTests[j].duration / 1000).toFixed(2);
|
||||||
|
|
||||||
if (!allTests[j].isPassed) {
|
if (!allTests[j].isPassed) {
|
||||||
failedTestCount++;
|
failedTestCount++;
|
||||||
|
|
||||||
@@ -153,17 +155,17 @@ function printRunTestStats() {
|
|||||||
testCases.push(`<testcase classname="${platform.device.os}" name="${testName}" time="${duration}"></testcase>`);
|
testCases.push(`<testcase classname="${platform.device.os}" name="${testName}" time="${duration}"></testcase>`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var totalTime = (TKUnit.time() - startTime).toFixed(2);
|
var totalTime = (TKUnit.time() - startTime).toFixed(2);
|
||||||
|
|
||||||
testFileContent.push(`<testsuite name="NativeScript Tests" timestamp="${new Date()}" hostname="hostname" time="${totalTime}" errors="0" tests="${allTests.length}" skipped="0" failures="${failedTestCount}">`);
|
testFileContent.push(`<testsuite name="NativeScript Tests" timestamp="${new Date()}" hostname="hostname" time="${totalTime}" errors="0" tests="${allTests.length}" skipped="0" failures="${failedTestCount}">`);
|
||||||
|
|
||||||
testFileContent = testFileContent.concat(testCases);
|
testFileContent = testFileContent.concat(testCases);
|
||||||
|
|
||||||
let finalMessage = `\n=== ALL TESTS COMPLETE ===\n` +
|
let finalMessage = `\n=== ALL TESTS COMPLETE ===\n` +
|
||||||
`${(allTests.length - failedTestCount)} OK, ${failedTestCount} failed\n` +
|
`${(allTests.length - failedTestCount)} OK, ${failedTestCount} failed\n` +
|
||||||
`DURATION: ${totalTime} ms\n`;
|
`DURATION: ${totalTime} ms\n`;
|
||||||
TKUnit.write(finalMessage, messageType.info);
|
TKUnit.write(finalMessage, messageType.info);
|
||||||
|
|
||||||
for (j = 0; j < failedTestInfo.length; j++) {
|
for (j = 0; j < failedTestInfo.length; j++) {
|
||||||
let failureMessage = failedTestInfo[j];
|
let failureMessage = failedTestInfo[j];
|
||||||
@@ -183,9 +185,15 @@ function printRunTestStats() {
|
|||||||
|
|
||||||
finalMessage += "\n" + "Test results: " + testFilePath;
|
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();
|
let messageContainer = new TextView();
|
||||||
messageContainer.text = finalMessage;
|
messageContainer.text = finalMessage;
|
||||||
topmost().currentPage.content = messageContainer;
|
stack.addChild(messageContainer);
|
||||||
|
topmost().currentPage.content = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
function startLog(): void {
|
function startLog(): void {
|
||||||
@@ -200,7 +208,9 @@ function log(): void {
|
|||||||
TKUnit.write(testsName + " COMPLETED for " + duration + " BACKSTACK DEPTH: " + topmost().backStack.length, messageType.info);
|
TKUnit.write(testsName + " COMPLETED for " + duration + " BACKSTACK DEPTH: " + topmost().backStack.length, messageType.info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let testsSelector: string
|
||||||
export var runAll = function (testSelector?: string) {
|
export var runAll = function (testSelector?: string) {
|
||||||
|
testsSelector = testSelector;
|
||||||
if (running) {
|
if (running) {
|
||||||
// TODO: We may schedule pending run requests
|
// TODO: We may schedule pending run requests
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ function runImageTest(done, image: ImageModule.Image, src: string) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let imageIsLoaded = isIOS ? !!image.imageSource : true;
|
let imageIsLoaded = isIOS ? !!image.imageSource : true;
|
||||||
TKUnit.assertTrue(!image.isLoading, "Image.isLoading should be false.");
|
TKUnit.assertFalse(image.isLoading, "Image.isLoading should be false.");
|
||||||
TKUnit.assertTrue(!testModel.get("imageIsLoading"), "imageIsLoading on viewModel should be false.");
|
TKUnit.assertFalse(testModel.get("imageIsLoading"), "imageIsLoading on viewModel should be false.");
|
||||||
TKUnit.assertTrue(imageIsLoaded, "imageSource should be set.");
|
TKUnit.assertTrue(imageIsLoaded, "imageSource should be set.");
|
||||||
if (done) {
|
if (done) {
|
||||||
done(null);
|
done(null);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export function initImageCache(context: android.content.Context, mode = CacheMod
|
|||||||
|
|
||||||
currentCacheMode = mode;
|
currentCacheMode = mode;
|
||||||
if (!imageFetcher) {
|
if (!imageFetcher) {
|
||||||
imageFetcher = new org.nativescript.widgets.image.Fetcher(context);
|
imageFetcher = org.nativescript.widgets.image.Fetcher.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable cache.
|
// 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.setMemCacheSizePercent(memoryCacheSize); // Set memory cache to % of app memory
|
||||||
params.diskCacheEnabled = mode === CacheMode.diskAndMemory;
|
params.diskCacheEnabled = mode === CacheMode.diskAndMemory;
|
||||||
params.diskCacheSize = diskCacheSize;
|
params.diskCacheSize = diskCacheSize;
|
||||||
@@ -145,7 +146,7 @@ export class Image extends imageCommon.Image {
|
|||||||
}
|
}
|
||||||
else if (imageSource.isFileOrResourcePath(value)) {
|
else if (imageSource.isFileOrResourcePath(value)) {
|
||||||
if (value.indexOf(utils.RESOURCE_PREFIX) === 0) {
|
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 {
|
else {
|
||||||
let fileName = value;
|
let fileName = value;
|
||||||
@@ -153,12 +154,12 @@ export class Image extends imageCommon.Image {
|
|||||||
fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
|
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 {
|
else {
|
||||||
// For backwards compatibility http always use async loading.
|
// 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 {
|
} else {
|
||||||
super._createImageSourceFromSrc();
|
super._createImageSourceFromSrc();
|
||||||
|
|||||||
@@ -335,6 +335,9 @@
|
|||||||
|
|
||||||
getRotationAngle(): number;
|
getRotationAngle(): number;
|
||||||
setRotationAngle(angle: number): void;
|
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 {
|
export class TabLayout extends android.widget.HorizontalScrollView {
|
||||||
@@ -385,7 +388,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Fetcher extends Worker {
|
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 addImageCache(cache: Cache): void;
|
||||||
public initCache(): void;
|
public initCache(): void;
|
||||||
public clearCache(): void;
|
public clearCache(): void;
|
||||||
@@ -396,10 +400,10 @@
|
|||||||
|
|
||||||
export namespace Cache {
|
export namespace Cache {
|
||||||
export class CacheParams {
|
export class CacheParams {
|
||||||
constructor(context: android.content.Context, diskCacheDirectoryName: string);
|
|
||||||
public setMemCacheSizePercent(percent: number): void;
|
|
||||||
public diskCacheEnabled: boolean;
|
|
||||||
public diskCacheSize: number;
|
public diskCacheSize: number;
|
||||||
|
public diskCacheEnabled: boolean;
|
||||||
|
public memoryCacheEnabled: boolean;
|
||||||
|
public setMemCacheSizePercent(percent: number): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user