Skip to content

Non square crop + Ti 6+ (Android) #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,43 @@

## Description

A cross platform image cropper for Titanium mobile.
A cross platform image cropper for Titanium mobile.

The iOS version uses [RSKImageCropper](https://github.com/ruslanskorb/RSKImageCropper) and the
The iOS version uses [RSKImageCropper](https://github.com/ruslanskorb/RSKImageCropper) and the
Android version uses [android-crop](https://github.com/jdamcd/android-crop).

## Usage

```js
var imageCropper = require('se.hyperlab.imagecropper');

imageCropper.open({
image: originalImage,
size: 960,
error: function (e) {
console.error('[CROPPING ERROR] ' + e);
},
success: function (e) {
someImageView.image = e.image;
}
});
if (OS_ANDROID){
imageCropper.open({
image: originalImage,
aspect_x: 1,
aspect_y: 2,
max_x: 300,
max_y: 300,
//size: 960, // for square images with aspect_x = aspect_y = 1
error: function (e) {
console.error('[CROPPING ERROR] ' + e);
},
success: function (e) {
someImageView.image = e.image;
}
});
} else {
imageCropper.open({
image: originalImage,
size: 960,
error: function (e) {
console.error('[CROPPING ERROR] ' + e);
},
success: function (e) {
someImageView.image = e.image;
}
});
}
```

You will also need to install and include the module in your `tiapp.xml` file.
Expand Down
Binary file not shown.
Binary file removed android/lib/android-crop-1.0.0-pre.jar
Binary file not shown.
Binary file added android/lib/android-crop-1.0.1.aar
Binary file not shown.
10 changes: 5 additions & 5 deletions android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.0.0
apiversion: 2
architectures: armeabi armeabi-v7a x86
version: 2.0.1
apiversion: 3
architectures: armeabi-v7a x86
description: TiImageCropper
author: Jonatan Lundin
license: MIT
Expand All @@ -13,8 +13,8 @@ copyright: Copyright (c) 2015 by Hyperlab AB
respackage: com.soundcloud.android.crop

# these should not be edited
name: TiImageCropper
name: tiimagecropper
moduleid: se.hyperlab.imagecropper
guid: 3f9278fb-c443-430a-8b6c-e7ee932b746c
platform: android
minsdk: 3.4.1.GA
minsdk: 6.0.0.GA
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

5 changes: 0 additions & 5 deletions android/platform/android/res/drawable/crop__texture.xml

This file was deleted.

19 changes: 0 additions & 19 deletions android/platform/android/res/layout/crop__activity_crop.xml

This file was deleted.

17 changes: 0 additions & 17 deletions android/platform/android/res/layout/crop__layout_done_cancel.xml

This file was deleted.

10 changes: 0 additions & 10 deletions android/platform/android/res/values-es/crop.xml

This file was deleted.

10 changes: 0 additions & 10 deletions android/platform/android/res/values-fr/crop.xml

This file was deleted.

10 changes: 0 additions & 10 deletions android/platform/android/res/values-ja/crop.xml

This file was deleted.

10 changes: 0 additions & 10 deletions android/platform/android/res/values-ko/crop.xml

This file was deleted.

6 changes: 0 additions & 6 deletions android/platform/android/res/values-land/crop.xml

This file was deleted.

6 changes: 0 additions & 6 deletions android/platform/android/res/values-large-v4/crop.xml

This file was deleted.

10 changes: 0 additions & 10 deletions android/platform/android/res/values-se/crop.xml

This file was deleted.

6 changes: 0 additions & 6 deletions android/platform/android/res/values-v21/crop.xml

This file was deleted.

10 changes: 0 additions & 10 deletions android/platform/android/res/values-zh/crop.xml

This file was deleted.

60 changes: 0 additions & 60 deletions android/platform/android/res/values/crop.xml

This file was deleted.

24 changes: 17 additions & 7 deletions android/src/se/hyperlab/imagecropper/TiImageCropperModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void onError(Activity activity, int requestCode, Exception e)
// Methods
@Kroll.method
public void open(KrollDict options) {
Activity activity = getTiContext().getTiApp().getCurrentActivity();
Activity activity = TiApplication.getInstance().getCurrentActivity();
TiActivitySupport support = (TiActivitySupport) activity;

successCallback = getCallback(options, "success");
Expand All @@ -118,15 +118,25 @@ public void open(KrollDict options) {

cropIntent.setData(source);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, destination);
cropIntent.putExtra("aspect_x", 1);
cropIntent.putExtra("aspect_y", 1);

if (options.containsKeyAndNotNull("size")) {
Log.i(LCAT, "Setting size to:" + options.getInt("size").toString());
cropIntent.putExtra("max_x", options.getInt("size"));
cropIntent.putExtra("max_y", options.getInt("size"));
cropIntent.putExtra("aspect_x", options.getInt("aspect_x"));
cropIntent.putExtra("aspect_y", options.getInt("aspect_y"));

if (options.containsKeyAndNotNull("max_y")) {
cropIntent.putExtra("max_y", options.getInt("max_y"));
}
if (options.containsKeyAndNotNull("max_x")) {
cropIntent.putExtra("max_x", options.getInt("max_x"));
}

// override with size for square images and backwards compatibility
if (options.containsKeyAndNotNull("size")) {
cropIntent.putExtra("max_x", options.getInt("size"));
cropIntent.putExtra("max_y", options.getInt("size"));

cropIntent.putExtra("aspect_x", 1);
cropIntent.putExtra("aspect_y", 1);
}
cropIntent.setClass(activity, CropImageActivity.class);

support.launchActivityForResult(cropIntent, Crop.REQUEST_CROP, this);
Expand Down