Skip to content

Commit

Permalink
#35 Display crop box coordinates and size
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Sep 21, 2022
1 parent c4fc088 commit e132a43
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import androidx.core.app.ActivityCompat;
Expand Down Expand Up @@ -271,6 +272,7 @@ private void copyExtra(Intent outIntent, Bundle extras, String... extraIds) {
protected static final String IMAGE_JPEG_MIME = "image/jpeg";

protected CropImageView uCropView = null;
protected TextView txtStatus = null;
private ImageProcessor mSpectrum;

// #7: workaround rotation change while picker is open causes Activity re-create without
Expand All @@ -283,11 +285,34 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crop);
uCropView = findViewById(R.id.ucrop);
txtStatus = findViewById(R.id.status);

uCropView.setOnSetCropOverlayMovedListener(new CropImageView.OnSetCropOverlayMovedListener() {
@Override
public void onCropOverlayMoved(Rect rect) {
onUpdateCropping();
}
});
mSpectrum = new ImageProcessor();

}

private void onUpdateCropping() {
String cropInfo = toString(getCropRect());
txtStatus.setText(cropInfo);
Log.d(TAG, getInstanceNo4Debug() + "onUpdateCropping(crop=" + cropInfo + ")");
}

public String toString(Rect r) {
StringBuilder sb = new StringBuilder();

sb
.append('(').append(r.left).append(',').append(r.top).append(") .. (")
.append(r.right).append(',').append(r.bottom).append(") => [")
.append(r.width()).append('x').append(r.height()).append(']');
return sb.toString();
}

protected void finishIfMainMethod(int idMenuMainMethod) {
if (this.idMenuMainMethod == idMenuMainMethod) {
finish();
Expand All @@ -304,9 +329,6 @@ protected void SetImageUriAndLastCropArea(Uri uri, Bundle savedInstanceState) {

protected void SetImageUriAndLastCropArea(Uri uri, Rect crop) {
try {

/*
*/
if (LOAD_ASYNC) {
uCropView.setImageUriAsync(uri);
} else {
Expand Down Expand Up @@ -604,6 +626,17 @@ public void setRotation(int rotation) {
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_rotate, menu);
// getMenuInflater().inflate(R.menu.menu_aspect_ratio, menu);

/*
Format 3:4:
9x11,10x13,11x15,13x17,20x27,30x40
Format 2:3:
9x13,10x15,11x17,13x18,20x30,30x45
Format 9:16:
9x15,10x18
*/

return true;
}

Expand Down
9 changes: 7 additions & 2 deletions app/src/main/res/layout/activity_crop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
android:orientation="vertical"
tools:context=".CropAreasEditActivity"
>

<TextView
android:id="@+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="(1521,481) .. (1792,831)" />

<net.realify.lib.androidimagecropper.CropImageView
android:id="@+id/ucrop"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cropBackgroundColor="#88AA66CC"
Expand Down
3 changes: 2 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/10.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
todo
New Feature [#35 Display crop box coordinates and size](https://github.com/k3b/LosslessJpgCrop/issues/35)
?? #15 predefined crop size

0 comments on commit e132a43

Please sign in to comment.