mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
namespaces removed (except Application)
This commit is contained in:
@ -1,73 +1,65 @@
|
||||
import app_module = require("Application/application");
|
||||
import types_module = require("Image/image_types");
|
||||
|
||||
export module tk {
|
||||
export module ui {
|
||||
export enum ImageType {
|
||||
PNG = 0,
|
||||
JPEG = 1,
|
||||
}
|
||||
export class Image {
|
||||
public android: any;
|
||||
|
||||
export class Image {
|
||||
public android: any;
|
||||
|
||||
constructor() {
|
||||
this.android = null;
|
||||
}
|
||||
|
||||
public loadFromResource(name: string): boolean {
|
||||
var androidApp = app_module.tk.ui.Application.current.android;
|
||||
var res = androidApp.context.getResources();
|
||||
if (res) {
|
||||
var identifier: number = res.getIdentifier(name, 'drawable', androidApp.packageName);
|
||||
if (0 < identifier) {
|
||||
this.android = android.graphics.BitmapFactory.decodeResource(res, identifier);
|
||||
return (this.android != null);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public loadFromFile(path: string): boolean {
|
||||
this.android = android.graphics.BitmapFactory.decodeFile(path, null);
|
||||
return (this.android != null);
|
||||
}
|
||||
|
||||
public loadFromData(data: any): boolean {
|
||||
this.android = android.graphics.BitmapFactory.decodeStream(data);
|
||||
return (this.android != null);
|
||||
}
|
||||
|
||||
public loadFromBitmap(source: any): boolean {
|
||||
this.android = source;
|
||||
return (this.android != null);
|
||||
}
|
||||
|
||||
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
|
||||
if (this.android) {
|
||||
var targetFormat = android.graphics.Bitmap.CompressFormat.PNG;
|
||||
switch (format) {
|
||||
case ImageType.JPEG:
|
||||
targetFormat = android.graphics.Bitmap.CompressFormat.JPEG;
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO add exception handling
|
||||
var outputStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(path));
|
||||
// FIXME compress is not found
|
||||
var res = this.android.compress(targetFormat, outputStream);
|
||||
outputStream.close();
|
||||
return res;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public getHeight(): number {
|
||||
return (this.android) ? this.android.getHeight() : NaN;
|
||||
}
|
||||
|
||||
public getWidth(): number {
|
||||
return (this.android) ? this.android.getWidth() : NaN;
|
||||
}
|
||||
}
|
||||
constructor() {
|
||||
this.android = null;
|
||||
}
|
||||
}
|
||||
|
||||
public loadFromResource(name: string): boolean {
|
||||
var androidApp = app_module.tk.ui.Application.current.android;
|
||||
var res = androidApp.context.getResources();
|
||||
if (res) {
|
||||
var identifier: number = res.getIdentifier(name, 'drawable', androidApp.packageName);
|
||||
if (0 < identifier) {
|
||||
this.android = android.graphics.BitmapFactory.decodeResource(res, identifier);
|
||||
return (this.android != null);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public loadFromFile(path: string): boolean {
|
||||
this.android = android.graphics.BitmapFactory.decodeFile(path, null);
|
||||
return (this.android != null);
|
||||
}
|
||||
|
||||
public loadFromData(data: any): boolean {
|
||||
this.android = android.graphics.BitmapFactory.decodeStream(data);
|
||||
return (this.android != null);
|
||||
}
|
||||
|
||||
public loadFromBitmap(source: any): boolean {
|
||||
this.android = source;
|
||||
return (this.android != null);
|
||||
}
|
||||
|
||||
public saveToFile(path: string, format: types_module.ImageType, quality?: number): boolean {
|
||||
if (this.android) {
|
||||
var targetFormat = android.graphics.Bitmap.CompressFormat.PNG;
|
||||
switch (format) {
|
||||
case types_module.ImageType.JPEG:
|
||||
targetFormat = android.graphics.Bitmap.CompressFormat.JPEG;
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO add exception handling
|
||||
var outputStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(path));
|
||||
// FIXME compress is not found
|
||||
var res = this.android.compress(targetFormat, outputStream);
|
||||
outputStream.close();
|
||||
return res;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public getHeight(): number {
|
||||
return (this.android) ? this.android.getHeight() : NaN;
|
||||
}
|
||||
|
||||
public getWidth(): number {
|
||||
return (this.android) ? this.android.getWidth() : NaN;
|
||||
}
|
||||
}
|
25
Image/image.d.ts
vendored
25
Image/image.d.ts
vendored
@ -1,19 +1,12 @@
|
||||
export declare module tk {
|
||||
export module ui {
|
||||
export enum ImageType {
|
||||
PNG = 0,
|
||||
JPEG = 1,
|
||||
}
|
||||
import types_module = require("Image/image_types");
|
||||
|
||||
export class Image {
|
||||
loadFromResource(name: string): boolean;
|
||||
loadFromFile(path: string): boolean;
|
||||
loadFromData(data: any): boolean;
|
||||
loadFromBitmap(source: any): boolean;
|
||||
saveToFile(path: string, format: ImageType, quality?: number): boolean;
|
||||
export declare class Image {
|
||||
loadFromResource(name: string): boolean;
|
||||
loadFromFile(path: string): boolean;
|
||||
loadFromData(data: any): boolean;
|
||||
loadFromBitmap(source: any): boolean;
|
||||
saveToFile(path: string, format: types_module.ImageType, quality?: number): boolean;
|
||||
|
||||
getHeight(): number;
|
||||
getWidth(): number;
|
||||
}
|
||||
}
|
||||
getHeight(): number;
|
||||
getWidth(): number;
|
||||
}
|
@ -1,64 +1,57 @@
|
||||
export module tk {
|
||||
export module ui {
|
||||
export enum ImageType {
|
||||
PNG = 0,
|
||||
JPEG = 1,
|
||||
}
|
||||
import types_module = require("Image/image_types");
|
||||
|
||||
export class Image {
|
||||
public ios: any;
|
||||
export class Image {
|
||||
public ios: any;
|
||||
|
||||
constructor() {
|
||||
this.ios = null;
|
||||
}
|
||||
|
||||
public loadFromResource(name: string): boolean {
|
||||
this.ios = UIKit.UIImage.imageNamed(name);
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public loadFromFile(path: string): boolean {
|
||||
this.ios = UIKit.UIImage.imageWithContentsOfFile(path);
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public loadFromData(data: any): boolean {
|
||||
this.ios = UIKit.UIImage.imageWithData(data);
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public loadFromBitmap(source: any): boolean {
|
||||
this.ios = source;
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
|
||||
if (null == this.ios) {
|
||||
return false;
|
||||
}
|
||||
var res = false;
|
||||
var data = null;
|
||||
switch (format) {
|
||||
case ImageType.JPEG:
|
||||
data = UIKit.UIImageJPEGRepresentation(this.ios, ('undefined' == typeof quality) ? 1.0 : quality);
|
||||
break;
|
||||
case ImageType.PNG:
|
||||
data = UIKit.UIImagePNGRepresentation(this.ios);
|
||||
break;
|
||||
}
|
||||
if (null != data) {
|
||||
res = data.writeToFileAtomically(path, true);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public getHeight(): number {
|
||||
return (this.ios) ? this.ios.size().height : NaN;
|
||||
}
|
||||
|
||||
public getWidth(): number {
|
||||
return (this.ios) ? this.ios.size().width : NaN;
|
||||
}
|
||||
}
|
||||
constructor() {
|
||||
this.ios = null;
|
||||
}
|
||||
}
|
||||
|
||||
public loadFromResource(name: string): boolean {
|
||||
this.ios = UIKit.UIImage.imageNamed(name);
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public loadFromFile(path: string): boolean {
|
||||
this.ios = UIKit.UIImage.imageWithContentsOfFile(path);
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public loadFromData(data: any): boolean {
|
||||
this.ios = UIKit.UIImage.imageWithData(data);
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public loadFromBitmap(source: any): boolean {
|
||||
this.ios = source;
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public saveToFile(path: string, format: types_module.ImageType, quality?: number): boolean {
|
||||
if (null == this.ios) {
|
||||
return false;
|
||||
}
|
||||
var res = false;
|
||||
var data = null;
|
||||
switch (format) {
|
||||
case types_module.ImageType.JPEG:
|
||||
data = UIKit.UIImageJPEGRepresentation(this.ios, ('undefined' == typeof quality) ? 1.0 : quality);
|
||||
break;
|
||||
case types_module.ImageType.PNG:
|
||||
data = UIKit.UIImagePNGRepresentation(this.ios);
|
||||
break;
|
||||
}
|
||||
if (null != data) {
|
||||
res = data.writeToFileAtomically(path, true);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public getHeight(): number {
|
||||
return (this.ios) ? this.ios.size().height : NaN;
|
||||
}
|
||||
|
||||
public getWidth(): number {
|
||||
return (this.ios) ? this.ios.size().width : NaN;
|
||||
}
|
||||
}
|
4
Image/image_types.ts
Normal file
4
Image/image_types.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum ImageType {
|
||||
PNG = 0,
|
||||
JPEG = 1,
|
||||
}
|
Reference in New Issue
Block a user