diff --git a/README.md b/README.md index 8cb053c..5038a19 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ ## 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 @@ -12,16 +12,33 @@ Android version uses [android-crop](https://github.com/jdamcd/android-crop). ```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. diff --git a/android/dist/se.hyperlab.imagecropper-android-2.0.1.zip b/android/dist/se.hyperlab.imagecropper-android-2.0.1.zip new file mode 100644 index 0000000..afa1bdc Binary files /dev/null and b/android/dist/se.hyperlab.imagecropper-android-2.0.1.zip differ diff --git a/android/lib/android-crop-1.0.0-pre.jar b/android/lib/android-crop-1.0.0-pre.jar deleted file mode 100644 index 8582bb6..0000000 Binary files a/android/lib/android-crop-1.0.0-pre.jar and /dev/null differ diff --git a/android/lib/android-crop-1.0.1.aar b/android/lib/android-crop-1.0.1.aar new file mode 100644 index 0000000..2f42f76 Binary files /dev/null and b/android/lib/android-crop-1.0.1.aar differ diff --git a/android/manifest b/android/manifest index 91f830c..648129a 100644 --- a/android/manifest +++ b/android/manifest @@ -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 @@ -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 diff --git a/android/platform/android/res/drawable-hdpi-v4/crop__divider.9.png b/android/platform/android/res/drawable-hdpi-v4/crop__divider.9.png deleted file mode 100644 index 0279e17..0000000 Binary files a/android/platform/android/res/drawable-hdpi-v4/crop__divider.9.png and /dev/null differ diff --git a/android/platform/android/res/drawable-hdpi-v4/crop__ic_cancel.png b/android/platform/android/res/drawable-hdpi-v4/crop__ic_cancel.png deleted file mode 100644 index cde36e1..0000000 Binary files a/android/platform/android/res/drawable-hdpi-v4/crop__ic_cancel.png and /dev/null differ diff --git a/android/platform/android/res/drawable-hdpi-v4/crop__ic_done.png b/android/platform/android/res/drawable-hdpi-v4/crop__ic_done.png deleted file mode 100644 index 58bf972..0000000 Binary files a/android/platform/android/res/drawable-hdpi-v4/crop__ic_done.png and /dev/null differ diff --git a/android/platform/android/res/drawable-mdpi-v4/crop__divider.9.png b/android/platform/android/res/drawable-mdpi-v4/crop__divider.9.png deleted file mode 100644 index 0279e17..0000000 Binary files a/android/platform/android/res/drawable-mdpi-v4/crop__divider.9.png and /dev/null differ diff --git a/android/platform/android/res/drawable-mdpi-v4/crop__ic_cancel.png b/android/platform/android/res/drawable-mdpi-v4/crop__ic_cancel.png deleted file mode 100644 index 9f4c3d6..0000000 Binary files a/android/platform/android/res/drawable-mdpi-v4/crop__ic_cancel.png and /dev/null differ diff --git a/android/platform/android/res/drawable-mdpi-v4/crop__ic_done.png b/android/platform/android/res/drawable-mdpi-v4/crop__ic_done.png deleted file mode 100644 index cf5fab3..0000000 Binary files a/android/platform/android/res/drawable-mdpi-v4/crop__ic_done.png and /dev/null differ diff --git a/android/platform/android/res/drawable-v21/crop__selectable_background.xml b/android/platform/android/res/drawable-v21/crop__selectable_background.xml deleted file mode 100644 index 369a4c6..0000000 --- a/android/platform/android/res/drawable-v21/crop__selectable_background.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/android/platform/android/res/drawable-xhdpi-v4/crop__divider.9.png b/android/platform/android/res/drawable-xhdpi-v4/crop__divider.9.png deleted file mode 100644 index 65061c0..0000000 Binary files a/android/platform/android/res/drawable-xhdpi-v4/crop__divider.9.png and /dev/null differ diff --git a/android/platform/android/res/drawable-xhdpi-v4/crop__ic_cancel.png b/android/platform/android/res/drawable-xhdpi-v4/crop__ic_cancel.png deleted file mode 100644 index ca7d159..0000000 Binary files a/android/platform/android/res/drawable-xhdpi-v4/crop__ic_cancel.png and /dev/null differ diff --git a/android/platform/android/res/drawable-xhdpi-v4/crop__ic_done.png b/android/platform/android/res/drawable-xhdpi-v4/crop__ic_done.png deleted file mode 100644 index b891571..0000000 Binary files a/android/platform/android/res/drawable-xhdpi-v4/crop__ic_done.png and /dev/null differ diff --git a/android/platform/android/res/drawable-xhdpi-v4/crop__tile.png b/android/platform/android/res/drawable-xhdpi-v4/crop__tile.png deleted file mode 100644 index b0b0044..0000000 Binary files a/android/platform/android/res/drawable-xhdpi-v4/crop__tile.png and /dev/null differ diff --git a/android/platform/android/res/drawable/crop__selectable_background.xml b/android/platform/android/res/drawable/crop__selectable_background.xml deleted file mode 100644 index 3b87c19..0000000 --- a/android/platform/android/res/drawable/crop__selectable_background.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/android/platform/android/res/drawable/crop__texture.xml b/android/platform/android/res/drawable/crop__texture.xml deleted file mode 100644 index fa80dc3..0000000 --- a/android/platform/android/res/drawable/crop__texture.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - \ No newline at end of file diff --git a/android/platform/android/res/layout/crop__activity_crop.xml b/android/platform/android/res/layout/crop__activity_crop.xml deleted file mode 100644 index aabcaae..0000000 --- a/android/platform/android/res/layout/crop__activity_crop.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/android/platform/android/res/layout/crop__layout_done_cancel.xml b/android/platform/android/res/layout/crop__layout_done_cancel.xml deleted file mode 100644 index 9f02b75..0000000 --- a/android/platform/android/res/layout/crop__layout_done_cancel.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/android/platform/android/res/values-es/crop.xml b/android/platform/android/res/values-es/crop.xml deleted file mode 100644 index a183dc4..0000000 --- a/android/platform/android/res/values-es/crop.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - CANCELAR - ACEPTAR - No hay imágenes disponibles - Guardando imagen… - Por favor espere… - \ No newline at end of file diff --git a/android/platform/android/res/values-fr/crop.xml b/android/platform/android/res/values-fr/crop.xml deleted file mode 100644 index 7fe4afa..0000000 --- a/android/platform/android/res/values-fr/crop.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - ANNULER - ACCEPTER - Aucune image disponible - Enregistrement de l\'image… - Veuillez patienter… - \ No newline at end of file diff --git a/android/platform/android/res/values-ja/crop.xml b/android/platform/android/res/values-ja/crop.xml deleted file mode 100644 index c015912..0000000 --- a/android/platform/android/res/values-ja/crop.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - キャンセル - 決定 - 画像が見つかりません - 保存中… - お待ちください… - \ No newline at end of file diff --git a/android/platform/android/res/values-ko/crop.xml b/android/platform/android/res/values-ko/crop.xml deleted file mode 100644 index a032bed..0000000 --- a/android/platform/android/res/values-ko/crop.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - 취소 - 확인 - 이미지가 존재하지 않습니다. - 사진을 저장중입니다… - 잠시만 기다려주세요… - \ No newline at end of file diff --git a/android/platform/android/res/values-land/crop.xml b/android/platform/android/res/values-land/crop.xml deleted file mode 100644 index 342e088..0000000 --- a/android/platform/android/res/values-land/crop.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - 48dp - \ No newline at end of file diff --git a/android/platform/android/res/values-large-v4/crop.xml b/android/platform/android/res/values-large-v4/crop.xml deleted file mode 100644 index a7b3939..0000000 --- a/android/platform/android/res/values-large-v4/crop.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - 64dp - \ No newline at end of file diff --git a/android/platform/android/res/values-se/crop.xml b/android/platform/android/res/values-se/crop.xml deleted file mode 100644 index 9691b4f..0000000 --- a/android/platform/android/res/values-se/crop.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - AVBRYT - SPARA - Inga tillgängliga bildkällor - Sparar bild… - Vänta lite… - diff --git a/android/platform/android/res/values-v21/crop.xml b/android/platform/android/res/values-v21/crop.xml deleted file mode 100644 index 7f8be59..0000000 --- a/android/platform/android/res/values-v21/crop.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - #aaaaaa - \ No newline at end of file diff --git a/android/platform/android/res/values-zh/crop.xml b/android/platform/android/res/values-zh/crop.xml deleted file mode 100644 index d3ed293..0000000 --- a/android/platform/android/res/values-zh/crop.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - 取消 - 完成 - 无效的图片 - 正在保存照片… - 请等待… - \ No newline at end of file diff --git a/android/platform/android/res/values/crop.xml b/android/platform/android/res/values/crop.xml deleted file mode 100644 index 026eb71..0000000 --- a/android/platform/android/res/values/crop.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - #f3f3f3 - #666666 - #77000000 - #1a000000 - - - - 56dp - - - CANCEL - DONE - No image sources available - Saving picture… - Please wait… - - - - - - - - \ No newline at end of file diff --git a/android/src/se/hyperlab/imagecropper/TiImageCropperModule.java b/android/src/se/hyperlab/imagecropper/TiImageCropperModule.java index 42e4578..461a172 100644 --- a/android/src/se/hyperlab/imagecropper/TiImageCropperModule.java +++ b/android/src/se/hyperlab/imagecropper/TiImageCropperModule.java @@ -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"); @@ -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);