Skip to content

Commit

Permalink
com.naver.android.helloyako.imagecrop.view.ImageCropView
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Apr 11, 2019
1 parent e411cb4 commit f76dde1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 46 deletions.
15 changes: 9 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:$support'
implementation fileTree(include: ['*.jar'], dir: 'libs')
// implementation "com.android.support:appcompat-v7:$support"
implementation "com.android.support:support-v4:$support"
implementation "com.android.support:support-annotations:$support"

implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

// implements lossless croppig
// implementation 'com.facebook.spectrum:spectrum-default:1.0.0'
// implementation 'com.facebook.spectrum:spectrum-default:1.0.0'
implementation 'com.facebook.spectrum:spectrum-core:1.0.0'
implementation 'com.facebook.spectrum:spectrum-jpeg:1.0.0'

// the cropping gui
implementation project(':ucrop')
// implementation project(':ucrop')
// implementation 'com.github.yalantis:ucrop:2.2.3'
// implementation 'com.edmodo:cropper:1.0.1'
implementation "com.naver.android.helloyako:imagecropview:1.2.2"
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package de.k3b.android.lossless_jpg_crop;

import android.Manifest;
import android.app.ActionBar;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.RectF;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.yalantis.ucrop.model.ImageState;
import com.yalantis.ucrop.view.GestureCropImageView;
import com.yalantis.ucrop.view.OverlayView;
import com.yalantis.ucrop.view.UCropView;
import com.naver.android.helloyako.imagecrop.view.ImageCropView;

import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -32,9 +28,6 @@ public class MainActivity extends BaseActivity {
private static final int REQUEST_SAVE_PICTURE = 2;
private static final int REQUEST_SAVE_PICTURE_PERMISSION = 102;

private GestureCropImageView mImageView;
private OverlayView mCropView;

private ImageProcessor mSpectrum;

@Override
Expand All @@ -51,37 +44,18 @@ protected void onCreate(Bundle savedInstanceState) {
pickFromGallery();
} else {
try {
UCropView uCropView = findViewById(R.id.ucrop);

mImageView = uCropView.getCropImageView();
ImageCropView uCropView = findViewById(R.id.ucrop);

mImageView.setImageUri(uri, null);
mImageView.setRotateEnabled(false);

mCropView = uCropView.getOverlayView();
mCropView.setShowCropFrame(true);
mCropView.setShowCropGrid(true);
mCropView.setDimmedColor(Color.TRANSPARENT);
mCropView.setFreestyleCropMode(OverlayView.FREESTYLE_CROP_MODE_ENABLE);
InputStream stream = getContentResolver().openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(stream);

uCropView.setImageBitmap(bitmap);
} catch (Exception e) {
Log.e(TAG, "setImageUri", e);
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}

/*
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(new File(getIntent().getData().getPath()).getAbsolutePath(), options);
*/

final ActionBar actionBar = this.getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getString(R.string.app_name)); // , options.outWidth, options.outHeight));
}

}

@Override
Expand Down Expand Up @@ -146,7 +120,7 @@ private void saveCroppedImage() {
see BitmapLoadTask.resize() for new details
curent workaround: load visible image with full bitmap instead of uri
**/
debug(imageUri, mImageView.getRelativeCroppingRectangleF());
// debug(imageUri, mImageView.getRelativeCroppingRectangleF());
/*
if (imageUri != null && imageUri.getScheme().equals("file")) {
try {
Expand All @@ -171,7 +145,7 @@ private void debug(Uri imageUri, RectF currentCropImageState) {
* Callback received when a permissions request has been completed.
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_GET_PICTURE_PERMISSION:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,30 @@
tools:context=".MainActivity"
>

<!--
<com.yalantis.ucrop.view.UCropView
android:id="@+id/ucrop"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.edmodo.cropper.CropImageView
android:id="@+id/ucrop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
-->

<com.naver.android.helloyako.imagecrop.view.ImageCropView
xmlns:imagecrop="http://schemas.android.com/apk/res-auto"
android:id="@+id/ucrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
imagecrop:outsideLayerColor="#99000000"
imagecrop:setInnerGridMode="on"
imagecrop:gridInnerStroke="1dp"
imagecrop:gridInnerColor="#66ffffff"
imagecrop:setOuterGridMode="on"
imagecrop:gridOuterStroke="1dp"
imagecrop:gridOuterColor="#ffffff"/>

</LinearLayout>
3 changes: 0 additions & 3 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include ':app', ':ucrop'
// include ':app', ':ucrop'
include ':app'

0 comments on commit f76dde1

Please sign in to comment.