mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-04 02:28:18 +00:00
Image editor: added resizing
This commit is contained in:
parent
f2064227f5
commit
c027660d77
3 changed files with 100 additions and 2 deletions
|
@ -23,10 +23,17 @@ import static android.app.Activity.RESULT_OK;
|
|||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.Size;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ProgressBar;
|
||||
|
@ -34,6 +41,7 @@ import android.widget.ProgressBar;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
|
||||
import com.canhub.cropper.CropImageOptions;
|
||||
import com.canhub.cropper.CropImageView;
|
||||
|
@ -45,16 +53,24 @@ import java.io.IOException;
|
|||
import java.io.OutputStream;
|
||||
|
||||
public class FragmentDialogEditImage extends FragmentDialogBase {
|
||||
private int resize = 0;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
Bundle args = getArguments();
|
||||
|
||||
if (savedInstanceState != null)
|
||||
resize = savedInstanceState.getInt("fair:resize", 0);
|
||||
|
||||
final int[] resizeValues = getResources().getIntArray(R.array.resizeValues);
|
||||
|
||||
Context context = getContext();
|
||||
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_edit_image, null);
|
||||
ImageButton ibRotate = dview.findViewById(R.id.ibRotate);
|
||||
ImageButton ibFlipHorizontally = dview.findViewById(R.id.ibFlipHorizontally);
|
||||
ImageButton ibFlipVertically = dview.findViewById(R.id.ibFlipVertically);
|
||||
ImageButton ibResize = dview.findViewById(R.id.ibResize);
|
||||
ImageButton ibCancel = dview.findViewById(R.id.ibCancel);
|
||||
ImageButton ibSave = dview.findViewById(R.id.ibSave);
|
||||
CropImageView civ = dview.findViewById(R.id.civ);
|
||||
|
@ -85,6 +101,51 @@ public class FragmentDialogEditImage extends FragmentDialogBase {
|
|||
}
|
||||
});
|
||||
|
||||
ibResize.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, FragmentDialogEditImage.this, v);
|
||||
|
||||
Size expected = civ.expectedImageSize();
|
||||
int s = (expected == null
|
||||
? Integer.MAX_VALUE
|
||||
: Math.max(expected.getWidth(), expected.getHeight()));
|
||||
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilderEx("---");
|
||||
if (resize == 0)
|
||||
ssb.setSpan(new StyleSpan(Typeface.BOLD), 0, ssb.length(), 0);
|
||||
popupMenu.getMenu().add(Menu.NONE, 1, 1, ssb)
|
||||
.setIntent(new Intent().putExtra("size", 0));
|
||||
|
||||
int order = 1;
|
||||
for (int size : resizeValues) {
|
||||
if (size > s)
|
||||
break;
|
||||
order++;
|
||||
ssb = new SpannableStringBuilderEx(getString(R.string.title_add_resize_pixels, size));
|
||||
if (size == resize)
|
||||
ssb.setSpan(new StyleSpan(Typeface.BOLD), 0, ssb.length(), 0);
|
||||
popupMenu.getMenu().add(Menu.NONE, order, order, ssb)
|
||||
.setIntent(new Intent().putExtra("size", size));
|
||||
}
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
Intent intent = item.getIntent();
|
||||
if (intent == null)
|
||||
return false;
|
||||
|
||||
resize = intent.getIntExtra("size", 0);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
popupMenu.show();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ibCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -117,7 +178,7 @@ public class FragmentDialogEditImage extends FragmentDialogBase {
|
|||
if (attachment == null)
|
||||
return null;
|
||||
|
||||
Bitmap bm = civ.getCroppedImage();
|
||||
Bitmap bm = civ.getCroppedImage(resize, resize, CropImageView.RequestSizeOptions.RESIZE_INSIDE);
|
||||
if (bm == null)
|
||||
return null;
|
||||
|
||||
|
@ -202,4 +263,10 @@ public class FragmentDialogEditImage extends FragmentDialogBase {
|
|||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
outState.putInt("fair:resize", resize);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
}
|
||||
|
|
15
app/src/main/res/drawable/twotone_aspect_ratio_24.xml
Normal file
15
app/src/main/res/drawable/twotone_aspect_ratio_24.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M3,19.01h18V4.99H3v14.02zM14,15h3v-3h2v5h-5v-2zM5,7h5v2H7v3H5V7z"
|
||||
android:strokeAlpha="0.3"
|
||||
android:fillAlpha="0.3"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19.01L3,19.01L3,4.99h18v14.02zM7,9h3L10,7L5,7v5h2zM19,12h-2v3h-3v2h5z"/>
|
||||
</vector>
|
|
@ -62,6 +62,22 @@
|
|||
app:srcCompat="@drawable/twotone_swap_vert_24"
|
||||
app:tint="?attr/colorAccent" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibResize"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/title_add_image_resize"
|
||||
android:scaleType="fitCenter"
|
||||
android:tooltipText="@string/title_add_image_resize"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/ibFlipVertically"
|
||||
app:layout_constraintTop_toBottomOf="@id/civ"
|
||||
app:srcCompat="@drawable/twotone_aspect_ratio_24"
|
||||
app:tint="?attr/colorAccent" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibCancel"
|
||||
android:layout_width="36dp"
|
||||
|
@ -73,7 +89,7 @@
|
|||
android:scaleType="fitCenter"
|
||||
android:tooltipText="@android:string/cancel"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/ibFlipVertically"
|
||||
app:layout_constraintStart_toEndOf="@id/ibResize"
|
||||
app:layout_constraintTop_toBottomOf="@id/civ"
|
||||
app:srcCompat="@drawable/twotone_close_24" />
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue