正在查看: 自健身 v3.3.4 应用的 PictureMultiCuttingActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 自健身 v3.3.4 应用的 PictureMultiCuttingActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.yalantis.ucrop;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AccelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.luck.picture.lib.config.PictureMimeType;
import com.yalantis.ucrop.callback.BitmapCropCallback;
import com.yalantis.ucrop.model.AspectRatio;
import com.yalantis.ucrop.model.CutInfo;
import com.yalantis.ucrop.util.FileUtils;
import com.yalantis.ucrop.util.SelectedStateListDrawable;
import com.yalantis.ucrop.view.GestureCropImageView;
import com.yalantis.ucrop.view.OverlayView;
import com.yalantis.ucrop.view.TransformImageView;
import com.yalantis.ucrop.view.UCropView;
import com.yalantis.ucrop.view.widget.AspectRatioTextView;
import com.yalantis.ucrop.view.widget.HorizontalProgressWheelView;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
public class PictureMultiCuttingActivity extends AppCompatActivity {
public static final int ALL = 3;
public static final Bitmap.CompressFormat DEFAULT_COMPRESS_FORMAT = Bitmap.CompressFormat.PNG;
public static final int DEFAULT_COMPRESS_QUALITY = 90;
public static final int NONE = 0;
public static final int ROTATE = 2;
private static final int ROTATE_WIDGET_SENSITIVITY_COEFFICIENT = 42;
public static final int SCALE = 1;
private static final int SCALE_WIDGET_SENSITIVITY_COEFFICIENT = 15000;
private static final int TABS_COUNT = 3;
private static final String TAG = "UCropActivity";
private PicturePhotoGalleryAdapter adapter;
private boolean circleDimmedLayer;
private int cutIndex;
private boolean isDragFrame;
private ArrayList<String> list;
private int mActiveWidgetColor;
private View mBlockingView;
private GestureCropImageView mGestureCropImageView;
private ViewGroup mLayoutAspectRatio;
private ViewGroup mLayoutRotate;
private ViewGroup mLayoutScale;
private int mLogoColor;
private OverlayView mOverlayView;
private int mRootViewBackgroundColor;
private boolean mShowBottomControls;
private int mStatusBarColor;
private TextView mTextViewRotateAngle;
private TextView mTextViewScalePercent;
private int mToolbarCancelDrawable;
private int mToolbarColor;
private int mToolbarCropDrawable;
private String mToolbarTitle;
private int mToolbarWidgetColor;
private UCropView mUCropView;
private ViewGroup mWrapperStateAspectRatio;
private ViewGroup mWrapperStateRotate;
private ViewGroup mWrapperStateScale;
private RecyclerView recyclerView;
private boolean rotateEnabled;
private boolean scaleEnabled;
private boolean mShowLoader = true;
private List<ViewGroup> mCropAspectRatioViews = new ArrayList();
private Bitmap.CompressFormat mCompressFormat = DEFAULT_COMPRESS_FORMAT;
private int mCompressQuality = 90;
private int[] mAllowedGestures = {1, 2, 3};
private List<CutInfo> cutInfos = new ArrayList();
private TransformImageView.TransformImageListener mImageListener = new TransformImageView.TransformImageListener() {
@Override
public void onRotate(float f) {
PictureMultiCuttingActivity.this.setAngleText(f);
}
@Override
public void onScale(float f) {
PictureMultiCuttingActivity.this.setScaleText(f);
}
@Override
public void onLoadComplete() {
PictureMultiCuttingActivity.this.mUCropView.animate().alpha(1.0f).setDuration(300L).setInterpolator(new AccelerateInterpolator());
PictureMultiCuttingActivity.this.mBlockingView.setClickable(false);
PictureMultiCuttingActivity.this.mShowLoader = false;
PictureMultiCuttingActivity.this.supportInvalidateOptionsMenu();
}
@Override
public void onLoadFailure(Exception exc) {
PictureMultiCuttingActivity.this.setResultError(exc);
PictureMultiCuttingActivity.this.closeActivity();
}
};
private final View.OnClickListener mStateClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (view.isSelected()) {
return;
}
PictureMultiCuttingActivity.this.setWidgetState(view.getId());
}
};
private void setAllowedGestures(int i) {
}
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.ucrop_picture_activity_multi_cutting);
Intent intent = getIntent();
ArrayList<String> stringArrayListExtra = getIntent().getStringArrayListExtra("com.yalantis.ucrop.cuts");
this.list = stringArrayListExtra;
if (stringArrayListExtra != null && stringArrayListExtra.size() > 0) {
Iterator<String> it = this.list.iterator();
while (it.hasNext()) {
this.cutInfos.add(new CutInfo(it.next(), false));
}
initData();
}
setupViews(intent);
setInitialState();
addBlockingView();
setImageData(intent);
}
private void initData() {
this.recyclerView = findViewById(R.id.recyclerView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(0);
this.recyclerView.setLayoutManager(linearLayoutManager);
Iterator<CutInfo> it = this.cutInfos.iterator();
while (it.hasNext()) {
it.next().setCut(false);
}
this.cutInfos.get(this.cutIndex).setCut(true);
PicturePhotoGalleryAdapter picturePhotoGalleryAdapter = new PicturePhotoGalleryAdapter(this, this.cutInfos);
this.adapter = picturePhotoGalleryAdapter;
this.recyclerView.setAdapter(picturePhotoGalleryAdapter);
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.ucrop_menu_activity, menu);
MenuItem findItem = menu.findItem(R.id.menu_loader);
Drawable icon = findItem.getIcon();
if (icon != null) {
try {
icon.mutate();
icon.setColorFilter(this.mToolbarWidgetColor, PorterDuff.Mode.SRC_ATOP);
findItem.setIcon(icon);
} catch (IllegalStateException e) {
Log.i(TAG, String.format("%s - %s", e.getMessage(), getString(R.string.ucrop_mutate_exception_hint)));
}
((Animatable) findItem.getIcon()).start();
}
MenuItem findItem2 = menu.findItem(R.id.menu_crop);
Drawable drawable = ContextCompat.getDrawable(this, this.mToolbarCropDrawable);
if (drawable != null) {
drawable.mutate();
drawable.setColorFilter(this.mToolbarWidgetColor, PorterDuff.Mode.SRC_ATOP);
findItem2.setIcon(drawable);
}
return true;
}
public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_crop).setVisible(!this.mShowLoader);
menu.findItem(R.id.menu_loader).setVisible(this.mShowLoader);
return super.onPrepareOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == R.id.menu_crop) {
cropAndSaveImage();
} else if (menuItem.getItemId() == 16908332) {
onBackPressed();
}
return super.onOptionsItemSelected(menuItem);
}
protected void onStop() {
super.onStop();
GestureCropImageView gestureCropImageView = this.mGestureCropImageView;
if (gestureCropImageView != null) {
gestureCropImageView.cancelAllAnimations();
}
}
private void setImageData(Intent intent) {
Uri uri = (Uri) intent.getParcelableExtra("com.yalantis.ucrop.InputUri");
Uri uri2 = (Uri) intent.getParcelableExtra("com.yalantis.ucrop.OutputUri");
processOptions(intent);
if (uri != null && uri2 != null) {
try {
if (FileUtils.isGif(uri.getPath())) {
this.mGestureCropImageView.setRotateEnabled(false);
this.mGestureCropImageView.setScaleEnabled(false);
} else {
this.mGestureCropImageView.setRotateEnabled(this.rotateEnabled);
this.mGestureCropImageView.setScaleEnabled(this.scaleEnabled);
}
this.mGestureCropImageView.setImageUri(uri, uri2);
return;
} catch (Exception e) {
setResultError(e);
closeActivity();
return;
}
}
setResultError(new NullPointerException(getString(R.string.ucrop_error_input_data_is_absent)));
closeActivity();
}
private void processOptions(Intent intent) {
String stringExtra = intent.getStringExtra("com.yalantis.ucrop.CompressionFormatName");
Bitmap.CompressFormat valueOf = !TextUtils.isEmpty(stringExtra) ? Bitmap.CompressFormat.valueOf(stringExtra) : null;
if (valueOf == null) {
valueOf = DEFAULT_COMPRESS_FORMAT;
}
this.mCompressFormat = valueOf;
this.mCompressQuality = intent.getIntExtra("com.yalantis.ucrop.CompressionQuality", 90);
int[] intArrayExtra = intent.getIntArrayExtra("com.yalantis.ucrop.AllowedGestures");
if (intArrayExtra != null && intArrayExtra.length == 3) {
this.mAllowedGestures = intArrayExtra;
}
this.mGestureCropImageView.setMaxBitmapSize(intent.getIntExtra("com.yalantis.ucrop.MaxBitmapSize", 0));
this.mGestureCropImageView.setMaxScaleMultiplier(intent.getFloatExtra("com.yalantis.ucrop.MaxScaleMultiplier", 10.0f));
this.mGestureCropImageView.setImageToWrapCropBoundsAnimDuration(intent.getIntExtra("com.yalantis.ucrop.ImageToCropBoundsAnimDuration", 500));
this.mOverlayView.setDragFrame(this.isDragFrame);
this.mOverlayView.setFreestyleCropEnabled(intent.getBooleanExtra("com.yalantis.ucrop.FreeStyleCrop", false));
this.circleDimmedLayer = intent.getBooleanExtra("com.yalantis.ucrop.CircleDimmedLayer", false);
this.mOverlayView.setDimmedColor(intent.getIntExtra("com.yalantis.ucrop.DimmedLayerColor", getResources().getColor(R.color.ucrop_color_default_dimmed)));
this.mOverlayView.setCircleDimmedLayer(this.circleDimmedLayer);
this.mOverlayView.setShowCropFrame(intent.getBooleanExtra("com.yalantis.ucrop.ShowCropFrame", true));
this.mOverlayView.setCropFrameColor(intent.getIntExtra("com.yalantis.ucrop.CropFrameColor", getResources().getColor(R.color.ucrop_color_default_crop_frame)));
this.mOverlayView.setCropFrameStrokeWidth(intent.getIntExtra("com.yalantis.ucrop.CropFrameStrokeWidth", getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_frame_stoke_width)));
this.mOverlayView.setShowCropGrid(intent.getBooleanExtra("com.yalantis.ucrop.ShowCropGrid", true));
this.mOverlayView.setCropGridRowCount(intent.getIntExtra("com.yalantis.ucrop.CropGridRowCount", 2));
this.mOverlayView.setCropGridColumnCount(intent.getIntExtra("com.yalantis.ucrop.CropGridColumnCount", 2));
this.mOverlayView.setCropGridColor(intent.getIntExtra("com.yalantis.ucrop.CropGridColor", getResources().getColor(R.color.ucrop_color_default_crop_grid)));
this.mOverlayView.setCropGridStrokeWidth(intent.getIntExtra("com.yalantis.ucrop.CropGridStrokeWidth", getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_grid_stoke_width)));
float floatExtra = intent.getFloatExtra("com.yalantis.ucrop.AspectRatioX", 0.0f);
float floatExtra2 = intent.getFloatExtra("com.yalantis.ucrop.AspectRatioY", 0.0f);
int intExtra = intent.getIntExtra("com.yalantis.ucrop.AspectRatioSelectedByDefault", 0);
ArrayList parcelableArrayListExtra = intent.getParcelableArrayListExtra("com.yalantis.ucrop.AspectRatioOptions");
if (floatExtra > 0.0f && floatExtra2 > 0.0f) {
ViewGroup viewGroup = this.mWrapperStateAspectRatio;
if (viewGroup != null) {
viewGroup.setVisibility(8);
}
this.mGestureCropImageView.setTargetAspectRatio(floatExtra / floatExtra2);
} else if (parcelableArrayListExtra != null && intExtra < parcelableArrayListExtra.size()) {
this.mGestureCropImageView.setTargetAspectRatio(((AspectRatio) parcelableArrayListExtra.get(intExtra)).getAspectRatioX() / ((AspectRatio) parcelableArrayListExtra.get(intExtra)).getAspectRatioY());
} else {
this.mGestureCropImageView.setTargetAspectRatio(0.0f);
}
int intExtra2 = intent.getIntExtra("com.yalantis.ucrop.MaxSizeX", 0);
int intExtra3 = intent.getIntExtra("com.yalantis.ucrop.MaxSizeY", 0);
if (intExtra2 <= 0 || intExtra3 <= 0) {
return;
}
this.mGestureCropImageView.setMaxResultImageSizeX(intExtra2);
this.mGestureCropImageView.setMaxResultImageSizeY(intExtra3);
}
private void setupViews(Intent intent) {
this.scaleEnabled = intent.getBooleanExtra("com.yalantis.ucrop.scale", false);
this.rotateEnabled = intent.getBooleanExtra("com.yalantis.ucrop.rotate", false);
this.mStatusBarColor = intent.getIntExtra("com.yalantis.ucrop.StatusBarColor", ContextCompat.getColor(this, R.color.ucrop_color_statusbar));
int intExtra = intent.getIntExtra("com.yalantis.ucrop.ToolbarColor", ContextCompat.getColor(this, R.color.ucrop_color_toolbar));
this.mToolbarColor = intExtra;
if (intExtra == -1) {
this.mToolbarColor = ContextCompat.getColor(this, R.color.ucrop_color_toolbar);
}
if (this.mStatusBarColor == -1) {
this.mStatusBarColor = ContextCompat.getColor(this, R.color.ucrop_color_statusbar);
}
this.mActiveWidgetColor = intent.getIntExtra("com.yalantis.ucrop.UcropColorWidgetActive", ContextCompat.getColor(this, R.color.ucrop_color_widget_active));
int intExtra2 = intent.getIntExtra("com.yalantis.ucrop.UcropToolbarWidgetColor", ContextCompat.getColor(this, R.color.ucrop_color_toolbar_widget));
this.mToolbarWidgetColor = intExtra2;
if (intExtra2 == -1) {
this.mToolbarWidgetColor = ContextCompat.getColor(this, R.color.ucrop_color_toolbar_widget);
}
this.mToolbarCancelDrawable = intent.getIntExtra("com.yalantis.ucrop.UcropToolbarCancelDrawable", R.drawable.ucrop_ic_cross);
this.mToolbarCropDrawable = intent.getIntExtra("com.yalantis.ucrop.UcropToolbarCropDrawable", R.drawable.ucrop_ic_done);
String stringExtra = intent.getStringExtra("com.yalantis.ucrop.UcropToolbarTitleText");
this.mToolbarTitle = stringExtra;
if (stringExtra == null) {
stringExtra = getResources().getString(R.string.ucrop_label_edit_photo);
}
this.mToolbarTitle = stringExtra;
this.mLogoColor = intent.getIntExtra("com.yalantis.ucrop.UcropLogoColor", ContextCompat.getColor(this, R.color.ucrop_color_default_logo));
this.mShowBottomControls = !intent.getBooleanExtra("com.yalantis.ucrop.HideBottomControls", false);
this.mRootViewBackgroundColor = intent.getIntExtra("com.yalantis.ucrop.UcropRootViewBackgroundColor", ContextCompat.getColor(this, R.color.ucrop_color_crop_background));
setupAppBar();
initiateRootViews();
if (this.mShowBottomControls) {
View.inflate(this, R.layout.ucrop_controls, (ViewGroup) findViewById(R.id.ucrop_mulit_photobox));
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.state_aspect_ratio);
this.mWrapperStateAspectRatio = viewGroup;
viewGroup.setOnClickListener(this.mStateClickListener);
ViewGroup viewGroup2 = (ViewGroup) findViewById(R.id.state_rotate);
this.mWrapperStateRotate = viewGroup2;
viewGroup2.setOnClickListener(this.mStateClickListener);
ViewGroup viewGroup3 = (ViewGroup) findViewById(R.id.state_scale);
this.mWrapperStateScale = viewGroup3;
viewGroup3.setOnClickListener(this.mStateClickListener);
this.mLayoutAspectRatio = (ViewGroup) findViewById(R.id.layout_aspect_ratio);
this.mLayoutRotate = (ViewGroup) findViewById(R.id.layout_rotate_wheel);
this.mLayoutScale = (ViewGroup) findViewById(R.id.layout_scale_wheel);
setupAspectRatioWidget(intent);
setupRotateWidget();
setupScaleWidget();
setupStatesWrapper();
}
}
private void setupAppBar() {
setStatusBarColor(this.mStatusBarColor);
Toolbar findViewById = findViewById(R.id.toolbar);
findViewById.setBackgroundColor(this.mToolbarColor);
findViewById.setTitleTextColor(this.mToolbarWidgetColor);
TextView textView = (TextView) findViewById.findViewById(R.id.toolbar_title);
textView.setTextColor(this.mToolbarWidgetColor);
textView.setText(this.mToolbarTitle);
Drawable mutate = ContextCompat.getDrawable(this, this.mToolbarCancelDrawable).mutate();
mutate.setColorFilter(this.mToolbarWidgetColor, PorterDuff.Mode.SRC_ATOP);
findViewById.setNavigationIcon(mutate);
setSupportActionBar(findViewById);
ActionBar supportActionBar = getSupportActionBar();
if (supportActionBar != null) {
supportActionBar.setDisplayShowTitleEnabled(false);
}
}
private void initiateRootViews() {
UCropView uCropView = (UCropView) findViewById(R.id.ucrop);
this.mUCropView = uCropView;
this.mGestureCropImageView = uCropView.getCropImageView();
this.mOverlayView = this.mUCropView.getOverlayView();
this.mGestureCropImageView.setTransformImageListener(this.mImageListener);
}
private void setupStatesWrapper() {
ImageView imageView = (ImageView) findViewById(R.id.image_view_state_scale);
ImageView imageView2 = (ImageView) findViewById(R.id.image_view_state_rotate);
ImageView imageView3 = (ImageView) findViewById(R.id.image_view_state_aspect_ratio);
imageView.setImageDrawable(new SelectedStateListDrawable(imageView.getDrawable(), this.mActiveWidgetColor));
imageView2.setImageDrawable(new SelectedStateListDrawable(imageView2.getDrawable(), this.mActiveWidgetColor));
imageView3.setImageDrawable(new SelectedStateListDrawable(imageView3.getDrawable(), this.mActiveWidgetColor));
}
private void setStatusBarColor(int i) {
Window window;
if (Build.VERSION.SDK_INT < 21 || (window = getWindow()) == null) {
return;
}
window.addFlags(Integer.MIN_VALUE);
window.setStatusBarColor(i);
}
private void setupAspectRatioWidget(Intent intent) {
int intExtra = intent.getIntExtra("com.yalantis.ucrop.AspectRatioSelectedByDefault", 0);
ArrayList parcelableArrayListExtra = intent.getParcelableArrayListExtra("com.yalantis.ucrop.AspectRatioOptions");
if (parcelableArrayListExtra == null || parcelableArrayListExtra.isEmpty()) {
intExtra = 2;
parcelableArrayListExtra = new ArrayList();
parcelableArrayListExtra.add(new AspectRatio(null, 1.0f, 1.0f));
parcelableArrayListExtra.add(new AspectRatio(null, 3.0f, 4.0f));
parcelableArrayListExtra.add(new AspectRatio(getString(R.string.ucrop_label_original).toUpperCase(), 0.0f, 0.0f));
parcelableArrayListExtra.add(new AspectRatio(null, 3.0f, 2.0f));
parcelableArrayListExtra.add(new AspectRatio(null, 16.0f, 9.0f));
}
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.layout_aspect_ratio);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, -1);
layoutParams.weight = 1.0f;
Iterator it = parcelableArrayListExtra.iterator();
while (it.hasNext()) {
AspectRatio aspectRatio = (AspectRatio) it.next();
FrameLayout frameLayout = (FrameLayout) getLayoutInflater().inflate(R.layout.ucrop_aspect_ratio, (ViewGroup) null);
frameLayout.setLayoutParams(layoutParams);
AspectRatioTextView aspectRatioTextView = (AspectRatioTextView) frameLayout.getChildAt(0);
aspectRatioTextView.setActiveColor(this.mActiveWidgetColor);
aspectRatioTextView.setAspectRatio(aspectRatio);
linearLayout.addView(frameLayout);
this.mCropAspectRatioViews.add(frameLayout);
}
this.mCropAspectRatioViews.get(intExtra).setSelected(true);
Iterator<ViewGroup> it2 = this.mCropAspectRatioViews.iterator();
while (it2.hasNext()) {
it2.next().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PictureMultiCuttingActivity.this.mGestureCropImageView.setTargetAspectRatio(((AspectRatioTextView) ((ViewGroup) view).getChildAt(0)).getAspectRatio(view.isSelected()));
PictureMultiCuttingActivity.this.mGestureCropImageView.setImageToWrapCropBounds();
if (view.isSelected()) {
return;
}
for (ViewGroup viewGroup : PictureMultiCuttingActivity.this.mCropAspectRatioViews) {
viewGroup.setSelected(viewGroup == view);
}
}
});
}
}
private void setupRotateWidget() {
this.mTextViewRotateAngle = (TextView) findViewById(R.id.text_view_rotate);
((HorizontalProgressWheelView) findViewById(R.id.rotate_scroll_wheel)).setScrollingListener(new HorizontalProgressWheelView.ScrollingListener() {
@Override
public void onScroll(float f, float f2) {
PictureMultiCuttingActivity.this.mGestureCropImageView.postRotate(f / 42.0f);
}
@Override
public void onScrollEnd() {
PictureMultiCuttingActivity.this.mGestureCropImageView.setImageToWrapCropBounds();
}
@Override
public void onScrollStart() {
PictureMultiCuttingActivity.this.mGestureCropImageView.cancelAllAnimations();
}
});
((HorizontalProgressWheelView) findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(this.mActiveWidgetColor);
findViewById(R.id.wrapper_reset_rotate).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PictureMultiCuttingActivity.this.resetRotation();
}
});
findViewById(R.id.wrapper_rotate_by_angle).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PictureMultiCuttingActivity.this.rotateByAngle(90);
}
});
}
private void setupScaleWidget() {
this.mTextViewScalePercent = (TextView) findViewById(R.id.text_view_scale);
((HorizontalProgressWheelView) findViewById(R.id.scale_scroll_wheel)).setScrollingListener(new HorizontalProgressWheelView.ScrollingListener() {
@Override
public void onScroll(float f, float f2) {
if (f > 0.0f) {
PictureMultiCuttingActivity.this.mGestureCropImageView.zoomInImage(PictureMultiCuttingActivity.this.mGestureCropImageView.getCurrentScale() + (f * ((PictureMultiCuttingActivity.this.mGestureCropImageView.getMaxScale() - PictureMultiCuttingActivity.this.mGestureCropImageView.getMinScale()) / 15000.0f)));
} else {
PictureMultiCuttingActivity.this.mGestureCropImageView.zoomOutImage(PictureMultiCuttingActivity.this.mGestureCropImageView.getCurrentScale() + (f * ((PictureMultiCuttingActivity.this.mGestureCropImageView.getMaxScale() - PictureMultiCuttingActivity.this.mGestureCropImageView.getMinScale()) / 15000.0f)));
}
}
@Override
public void onScrollEnd() {
PictureMultiCuttingActivity.this.mGestureCropImageView.setImageToWrapCropBounds();
}
@Override
public void onScrollStart() {
PictureMultiCuttingActivity.this.mGestureCropImageView.cancelAllAnimations();
}
});
((HorizontalProgressWheelView) findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(this.mActiveWidgetColor);
}
public void setAngleText(float f) {
TextView textView = this.mTextViewRotateAngle;
if (textView != null) {
textView.setText(String.format(Locale.getDefault(), "%.1f°", Float.valueOf(f)));
}
}
public void setScaleText(float f) {
TextView textView = this.mTextViewScalePercent;
if (textView != null) {
textView.setText(String.format(Locale.getDefault(), "%d%%", Integer.valueOf((int) (f * 100.0f))));
}
}
public void resetRotation() {
GestureCropImageView gestureCropImageView = this.mGestureCropImageView;
gestureCropImageView.postRotate(-gestureCropImageView.getCurrentAngle());
this.mGestureCropImageView.setImageToWrapCropBounds();
}
public void rotateByAngle(int i) {
this.mGestureCropImageView.postRotate(i);
this.mGestureCropImageView.setImageToWrapCropBounds();
}
private void setInitialState() {
if (this.mShowBottomControls) {
if (this.mWrapperStateAspectRatio.getVisibility() == 0) {
setWidgetState(R.id.state_aspect_ratio);
return;
} else {
setWidgetState(R.id.state_scale);
return;
}
}
setAllowedGestures(0);
}
public void setWidgetState(int i) {
if (this.mShowBottomControls) {
this.mWrapperStateAspectRatio.setSelected(i == R.id.state_aspect_ratio);
this.mWrapperStateRotate.setSelected(i == R.id.state_rotate);
this.mWrapperStateScale.setSelected(i == R.id.state_scale);
this.mLayoutAspectRatio.setVisibility(i == R.id.state_aspect_ratio ? 0 : 8);
this.mLayoutRotate.setVisibility(i == R.id.state_rotate ? 0 : 8);
this.mLayoutScale.setVisibility(i == R.id.state_scale ? 0 : 8);
if (i == R.id.state_scale) {
setAllowedGestures(0);
} else if (i == R.id.state_rotate) {
setAllowedGestures(1);
} else {
setAllowedGestures(2);
}
}
}
private void addBlockingView() {
if (this.mBlockingView == null) {
this.mBlockingView = new View(this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -1);
layoutParams.addRule(3, R.id.toolbar);
this.mBlockingView.setLayoutParams(layoutParams);
this.mBlockingView.setClickable(true);
}
((RelativeLayout) findViewById(R.id.ucrop_mulit_photobox)).addView(this.mBlockingView);
}
protected void cropAndSaveImage() {
this.mBlockingView.setClickable(true);
this.mShowLoader = true;
supportInvalidateOptionsMenu();
this.mGestureCropImageView.cropAndSaveImage(this.mCompressFormat, this.mCompressQuality, new BitmapCropCallback() {
@Override
public void onBitmapCropped(Uri uri, int i, int i2, int i3, int i4) {
PictureMultiCuttingActivity pictureMultiCuttingActivity = PictureMultiCuttingActivity.this;
pictureMultiCuttingActivity.setResultUri(uri, pictureMultiCuttingActivity.mGestureCropImageView.getTargetAspectRatio(), i, i2, i3, i4);
}
@Override
public void onCropFailure(Throwable th) {
PictureMultiCuttingActivity.this.setResultError(th);
PictureMultiCuttingActivity.this.closeActivity();
}
});
}
protected void setResultUri(Uri uri, float f, int i, int i2, int i3, int i4) {
try {
CutInfo cutInfo = this.cutInfos.get(this.cutIndex);
cutInfo.setCutPath(uri.getPath());
cutInfo.setCut(true);
cutInfo.setResultAspectRatio(f);
cutInfo.setOffsetX(i);
cutInfo.setOffsetY(i2);
cutInfo.setImageWidth(i3);
cutInfo.setImageHeight(i4);
int i5 = this.cutIndex + 1;
this.cutIndex = i5;
if (i5 >= this.cutInfos.size()) {
setResult(-1, new Intent().putExtra(UCropMulti.EXTRA_OUTPUT_URI_LIST, (Serializable) this.cutInfos));
closeActivity();
} else {
resetCutData();
}
} catch (Exception e) {
e.printStackTrace();
}
}
protected void resetCutData() {
setContentView(R.layout.ucrop_picture_activity_multi_cutting);
Intent intent = new Intent();
Bundle extras = getIntent().getExtras();
String path = this.cutInfos.get(this.cutIndex).getPath();
boolean isHttp = FileUtils.isHttp(path);
String lastImgType = getLastImgType(path);
extras.putParcelable("com.yalantis.ucrop.InputUri", isHttp ? Uri.parse(path) : Uri.fromFile(new File(path)));
extras.putParcelable("com.yalantis.ucrop.OutputUri", Uri.fromFile(new File(getCacheDir(), System.currentTimeMillis() + lastImgType)));
intent.putExtras(extras);
setupViews(intent);
setInitialState();
((RelativeLayout) findViewById(R.id.ucrop_mulit_photobox)).removeView(this.mBlockingView);
this.mBlockingView = null;
addBlockingView();
setImageData(intent);
initData();
int i = this.cutIndex;
if (i >= 5) {
this.recyclerView.scrollToPosition(i);
}
}
public static String getLastImgType(String str) {
String substring;
try {
int lastIndexOf = str.lastIndexOf(".");
if (lastIndexOf > 0) {
substring = str.substring(lastIndexOf, str.length());
switch (substring) {
case ".png":
case ".PNG":
case ".jpg":
case ".jpeg":
case ".JPEG":
case ".WEBP":
case ".bmp":
case ".BMP":
case ".webp":
return substring;
}
}
return PictureMimeType.PNG;
} catch (Exception e) {
e.printStackTrace();
return PictureMimeType.PNG;
}
}
protected void setResultError(Throwable th) {
setResult(96, new Intent().putExtra("com.yalantis.ucrop.Error", th));
}
protected void closeActivity() {
finish();
overridePendingTransition(0, R.anim.ucrop_close);
}
}