Skip to content

Commit

Permalink
Update Android Gradle
Browse files Browse the repository at this point in the history
Fix #1.
Bump Version.
  • Loading branch information
bthurlow committed Apr 26, 2016
1 parent 9e4dbbe commit 90cad4d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 46 deletions.
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
<!--
@Author: Brian Thurlow <bthurlow>
@Date: 03/29/2016 03:41:05 PM
@Last modified by: bthurlow
@Last modified time: 03/29/2016 04:24:04 PM
@Last modified by: Brian Thurlow
@Last modified time: 04/01/2016 11:52:29 AM
-->



# 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

iOS 8+

Android 17+

###Based on
### Based on

[TOCropViewController](https://github.com/TimOliver/TOCropViewController) for iOS

[uCrop](https://github.com/Yalantis/uCrop) for Android
Expand All @@ -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
<manifest>
<application>
Expand All @@ -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){
Expand All @@ -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){
Expand All @@ -72,13 +74,15 @@ cropper.show(picture,{width:300,height:300}).then(function(args){
```

### Options
* width:<number> The width of the image you would like returned.
* height:<number> 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<br/>Cancelled<br/>Error
image | ImageSource | `null` if there was an error or was cancelled<br/>`ImageSource` on success
12 changes: 8 additions & 4 deletions imagecropper.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -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");
Expand All @@ -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;
}
Expand Down
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion platforms/android/include.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ repositories {
jcenter()
}
dependencies {
compile 'com.yalantis:ucrop:1.3.+'
compile 'com.yalantis:ucrop:1.3.2'
}

0 comments on commit 90cad4d

Please sign in to comment.