diff --git a/README.md b/README.md index 5201d34..d105dd6 100755 --- a/README.md +++ b/README.md @@ -1,17 +1,13 @@ - - # A {N} Image Cropping Plugin -[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](http://choosealicense.com/licenses/mit/) -[![npm](https://img.shields.io/npm/v/nativescript-imagecropper.svg)](https://www.npmjs.com/package/nativescript-imagecropper) -[![npm](https://img.shields.io/npm/dt/nativescript-imagecropper.svg?label=npm%20downloads)](https://www.npmjs.com/package/nativescript-imagecropper) -[![GitHub release](https://img.shields.io/github/release/bthurlow/nativescript-imagecropper.svg)](https://github.com/bthurlow/nativescript-imagecropper) + +[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](http://choosealicense.com/licenses/mit/) [![npm](https://img.shields.io/npm/v/nativescript-imagecropper.svg)](https://www.npmjs.com/package/nativescript-imagecropper) [![npm](https://img.shields.io/npm/dt/nativescript-imagecropper.svg?label=npm%20downloads)](https://www.npmjs.com/package/nativescript-imagecropper) [![GitHub release](https://img.shields.io/github/release/bthurlow/nativescript-imagecropper.svg)](https://github.com/bthurlow/nativescript-imagecropper) ## Notes @@ -19,7 +15,8 @@ iOS 8+ Android 17+ -###Based on +### Based on + [TOCropViewController](https://github.com/TimOliver/TOCropViewController) for iOS [uCrop](https://github.com/Yalantis/uCrop) for Android @@ -28,11 +25,12 @@ Android 17+ Run `tns plugin add nativescript-imagecropper` -## Android Install Notes +### Android Install Notes This plugin is designed according to {N} 2.0 Specs. For Android, you will need to modify the AndroidManifest.xml file. Add the following to the AndroidManifest.xml + ```xml @@ -44,12 +42,15 @@ Add the following to the AndroidManifest.xml ### Usage To use the image cropping module you must first require it. + ```js var icModule = require("nativescript-imagecropper"); ``` + ### Methods -show(ImageSource): Returns a cropped ImageSource +`show(ImageSource)`: Returns a cropped ImageSource + ```js var cropper = new icModule.ImageCropper(); cropper.show(picture).then(function(args){ @@ -60,7 +61,8 @@ cropper.show(picture).then(function(args){ }); ``` -show(ImageSource,Options): Returns a cropped and resized ImageSource +`show(ImageSource,Options)`: Returns a cropped and resized ImageSource + ```js var cropper = new icModule.ImageCropper(); cropper.show(picture,{width:300,height:300}).then(function(args){ @@ -72,13 +74,15 @@ cropper.show(picture,{width:300,height:300}).then(function(args){ ``` ### Options -* width: The width of the image you would like returned. -* height: The height of the image you would like returned. + +Option | Type | Description +------ | ------ | ------------------------------------------------ +width | number | The width of the image you would like returned. +height | number | The height of the image you would like returned. ### Returned Result Arguments -* response: string; - * Success - * Cancelled - * Error -* image: ImageSource; - * Returns null if there was an error or was cancelled. + +Argument | Type | Result(s) +-------- | ----------- | -------------------------------------------------------------------------- +response | string | Success
Cancelled
Error +image | ImageSource | `null` if there was an error or was cancelled
`ImageSource` on success diff --git a/imagecropper.android.ts b/imagecropper.android.ts index bcd854e..001e694 100644 --- a/imagecropper.android.ts +++ b/imagecropper.android.ts @@ -49,12 +49,11 @@ export class ImageCropper{ var sourcePath:android.net.Uri = android.net.Uri.parse("file://"+sourcePathTemp); //Fix our path that comes from {N} file-system. var destinationPath:android.net.Uri = android.net.Uri.parse("file://"+destinationPathTemp); //Fix our path that comes from {N} file-system. - application.android.on(application.AndroidApplication.activityResultEvent,onResult); - function onResult(args){ var requestCode = args.requestCode; var resultCode = args.resultCode; var data = args.intent; + // var _that = this; if(resultCode == android.app.Activity.RESULT_OK && requestCode == UCrop.REQUEST_CROP){ var resultUri:android.net.Uri = UCrop.getOutput(data); @@ -90,6 +89,8 @@ export class ImageCropper{ } }; + application.android.on(application.AndroidApplication.activityResultEvent,onResult); + if(_options && _options.width && _options.height){ var gcd = this._gcd(_options.width,_options.height); // console.log("gcd:" + gcd.toString()); @@ -106,14 +107,14 @@ export class ImageCropper{ } } else{ - application.android.off(application.AndroidApplication.activityResultEvent, onResult); + // application.android.off(application.AndroidApplication.activityResultEvent, this.onResult); reject({ response:"Error", image:null }); } } catch(e){ - application.android.off(application.AndroidApplication.activityResultEvent, onResult); + // application.android.off(application.AndroidApplication.activityResultEvent, this.onResult); reject({ response:"Error", image:null @@ -129,6 +130,7 @@ export class ImageCropper{ return this._gcd(height, width % height); } } + private _storeImageSource(image:imageSource.ImageSource):string{ var folder:fs.Folder = fs.knownFolders.temp(); var path = fs.path.join(folder.path,"temp.jpg"); @@ -140,11 +142,13 @@ export class ImageCropper{ return null; } } + private _cleanFiles():void{ //Clear Temp var folder:fs.Folder = fs.knownFolders.temp(); folder.clear(); } + private _getContext():android.app.Activity{ return application.android.foregroundActivity; } diff --git a/package.json b/package.json index 35841fa..26c5c64 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,26 @@ { - "name":"nativescript-imagecropper", - "version":"0.0.4", - "description":"A image cropper based on TOCropViewController for iOS and uCrop for Android", - "main":"imagecropper.js", - "nativescript":{ - "platforms":{ - "android":"1.4.0", - "ios":"1.4.0" + "name": "nativescript-imagecropper", + "version": "0.0.5", + "description": "A image cropper based on TOCropViewController for iOS and uCrop for Android", + "main": "imagecropper.js", + "nativescript": { + "platforms": { + "android": "1.4.0", + "ios": "1.4.0" } }, - "scripts":{ + "scripts": { "build": "tsc", "preparedemo": "npm run build && cd demo && tns plugin remove nativescript-imagecropper && tns plugin add .. && tns install", "setup": "cd demo && npm install && cd .. && npm run build && cd demo && tns plugin add .. && cd ..", "demo.ios": "npm run preparedemo; cd demo; tns deploy ios --emulator --justlaunch", - "demo.android": "npm run preparedemo && cd demo && tns run android" + "demo.android": "npm run preparedemo && cd demo && tns run android" }, - "repository":{ - "type":"git", - "url":"https://github.com/bthurlow/nativescript-imagecropper" + "repository": { + "type": "git", + "url": "https://github.com/bthurlow/nativescript-imagecropper" }, - "keywords":[ + "keywords": [ "NativeScript", "image", "crop", @@ -29,14 +29,14 @@ "TOCropViewController", "uCrop" ], - "author":"bthurlow", - "bugs":{ - "url":"https://github.com/bthurlow/nativescript-imagecropper/issues" + "author": "bthurlow", + "bugs": { + "url": "https://github.com/bthurlow/nativescript-imagecropper/issues" }, "license": "MIT", - "homepage":"https://github.com/bthurlow/nativescript-imagecropper", - "readmeFilename":"README.md", - "devDependencies":{ - "typescript":"^1.8.7" + "homepage": "https://github.com/bthurlow/nativescript-imagecropper", + "readmeFilename": "README.md", + "devDependencies": { + "typescript": "^1.8.7" } } diff --git a/platforms/android/include.gradle b/platforms/android/include.gradle index 79513cc..d9f9fc1 100644 --- a/platforms/android/include.gradle +++ b/platforms/android/include.gradle @@ -2,5 +2,5 @@ repositories { jcenter() } dependencies { - compile 'com.yalantis:ucrop:1.3.+' + compile 'com.yalantis:ucrop:1.3.2' }