导航菜单

页面标题

页面副标题

Bhakti v5.4.0 - CropImageActivity.java 源代码

正在查看: Bhakti v5.4.0 应用的 CropImageActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.canhub.cropper;

import H5.b;
import Kp.J;
import Kp.V;
import L8.n;
import W7.sD.tdGaoHZiSbko;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.util.Pair;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.app.AppCompatActivity;
import com.canhub.cropper.CropImageView;
import io.w0;
import j.c;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.concurrent.CancellationException;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;
import l.e;
import m.g;
import o7.I;
import o7.L;
import o7.d;
import o7.l;
import o7.o;
import o7.p;
import o7.s;
import o7.u;
import o7.v;
import o7.z;
import p7.a;
import t8.AbstractC0002i;

@Metadata
public class CropImageActivity extends AppCompatActivity implements z, v {

    @Deprecated
    public static final String BUNDLE_KEY_TMP_URI = "bundle_key_tmp_uri";
    private static final o Companion = new o();
    private a binding;
    private s cropImageOptions;
    private Uri cropImageUri;
    private CropImageView cropImageView;
    private Uri latestTmpUri;
    private final c pickImageGallery;
    private final c takePicture;

    public CropImageActivity() {
        c registerForActivityResult = registerForActivityResult(new n(3), new o7.n(this, 0));
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult, "registerForActivityResul…mageResult(uri)\n        }");
        this.pickImageGallery = registerForActivityResult;
        c registerForActivityResult2 = registerForActivityResult(new n(8), new o7.n(this, 1));
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult2, "registerForActivityResul…ckImageResult(null)\n    }");
        this.takePicture = registerForActivityResult2;
    }

    private final Uri getTmpFileUri() {
        File createTempFile = File.createTempFile("tmp_image_file", ".png", getCacheDir());
        createTempFile.createNewFile();
        createTempFile.deleteOnExit();
        Intrinsics.checkNotNullExpressionValue(createTempFile, "tmpFile");
        return AbstractC0002i.C(this, createTempFile);
    }

    private final void openCamera() {
        Uri tmpFileUri = getTmpFileUri();
        this.latestTmpUri = tmpFileUri;
        this.takePicture.a(tmpFileUri);
    }

    public final void openSource(a aVar) {
        int i = p.a[aVar.ordinal()];
        if (i == 1) {
            openCamera();
        } else {
            if (i != 2) {
                return;
            }
            this.pickImageGallery.a("image/*");
        }
    }

    public static final void pickImageGallery$lambda$0(CropImageActivity cropImageActivity, Uri uri) {
        Intrinsics.checkNotNullParameter(cropImageActivity, "this$0");
        cropImageActivity.onPickImageResult(uri);
    }

    private final void setCustomizations() {
        CharSequence string;
        s sVar = this.cropImageOptions;
        if (sVar == null) {
            Intrinsics.m("cropImageOptions");
            throw null;
        }
        a aVar = this.binding;
        if (aVar == null) {
            Intrinsics.m("binding");
            throw null;
        }
        aVar.a.setBackgroundColor(sVar.W0);
        m.a supportActionBar = getSupportActionBar();
        if (supportActionBar != null) {
            s sVar2 = this.cropImageOptions;
            if (sVar2 == null) {
                Intrinsics.m("cropImageOptions");
                throw null;
            }
            if (sVar2.v0.length() > 0) {
                s sVar3 = this.cropImageOptions;
                if (sVar3 == null) {
                    Intrinsics.m("cropImageOptions");
                    throw null;
                }
                string = sVar3.v0;
            } else {
                string = getResources().getString(L.crop_image_activity_title);
            }
            setTitle(string);
            supportActionBar.o(true);
            s sVar4 = this.cropImageOptions;
            if (sVar4 == null) {
                Intrinsics.m("cropImageOptions");
                throw null;
            }
            Integer num = sVar4.X0;
            if (num != null) {
                supportActionBar.l(new ColorDrawable(num.intValue()));
            }
            s sVar5 = this.cropImageOptions;
            if (sVar5 == null) {
                Intrinsics.m("cropImageOptions");
                throw null;
            }
            Integer num2 = sVar5.Y0;
            if (num2 != null) {
                int intValue = num2.intValue();
                SpannableString spannableString = new SpannableString(getTitle());
                spannableString.setSpan(new ForegroundColorSpan(intValue), 0, spannableString.length(), 33);
                setTitle(spannableString);
            }
            s sVar6 = this.cropImageOptions;
            if (sVar6 == null) {
                Intrinsics.m("cropImageOptions");
                throw null;
            }
            Integer num3 = sVar6.Z0;
            if (num3 != null) {
                int intValue2 = num3.intValue();
                try {
                    Drawable drawable = getDrawable(e.abc_ic_ab_back_material);
                    if (drawable != null) {
                        drawable.setColorFilter(new PorterDuffColorFilter(intValue2, PorterDuff.Mode.SRC_ATOP));
                    }
                    supportActionBar.p(drawable);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static final boolean showImageSourceDialog$lambda$14(CropImageActivity cropImageActivity, DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
        Intrinsics.checkNotNullParameter(cropImageActivity, "this$0");
        if (i == 4 && keyEvent.getAction() == 1) {
            cropImageActivity.onBackPressed();
        }
        return true;
    }

    public static final void showImageSourceDialog$lambda$15(Function1 function1, DialogInterface dialogInterface, int i) {
        Intrinsics.checkNotNullParameter(function1, "$openSource");
        function1.invoke(i == 0 ? a.CAMERA : a.GALLERY);
    }

    private final void showIntentChooser() {
        throw new UnsupportedOperationException("Method not decompiled: com.canhub.cropper.CropImageActivity.showIntentChooser():void");
    }

    public static final void takePicture$lambda$1(CropImageActivity cropImageActivity, Boolean bool) {
        Intrinsics.checkNotNullParameter(cropImageActivity, "this$0");
        Intrinsics.checkNotNullExpressionValue(bool, "it");
        cropImageActivity.onPickImageResult(bool.booleanValue() ? cropImageActivity.latestTmpUri : null);
    }

    public void cropImage() {
        s sVar = this.cropImageOptions;
        if (sVar == null) {
            Intrinsics.m("cropImageOptions");
            throw null;
        }
        if (sVar.E0) {
            setResult(null, null, 1);
            return;
        }
        CropImageView cropImageView = this.cropImageView;
        if (cropImageView != null) {
            Bitmap.CompressFormat compressFormat = sVar.z0;
            Intrinsics.checkNotNullParameter(compressFormat, "saveCompressFormat");
            CropImageView.d dVar = sVar.D0;
            Intrinsics.checkNotNullParameter(dVar, "options");
            if (cropImageView.o0 == null) {
                throw new IllegalArgumentException("mOnCropImageCompleteListener is not set");
            }
            Intrinsics.checkNotNullParameter(dVar, "options");
            Intrinsics.checkNotNullParameter(compressFormat, "saveCompressFormat");
            Bitmap bitmap = cropImageView.i;
            if (bitmap != null) {
                WeakReference weakReference = cropImageView.y0;
                d dVar2 = weakReference != null ? (d) weakReference.get() : null;
                if (dVar2 != null) {
                    dVar2.M.cancel((CancellationException) null);
                }
                Pair pair = (cropImageView.q0 > 1 || dVar == CropImageView.d.SAMPLING) ? new Pair(Integer.valueOf(bitmap.getWidth() * cropImageView.q0), Integer.valueOf(bitmap.getHeight() * cropImageView.q0)) : new Pair(0, 0);
                Integer num = (Integer) pair.first;
                Integer num2 = (Integer) pair.second;
                Context context = cropImageView.getContext();
                Intrinsics.checkNotNullExpressionValue(context, "context");
                WeakReference weakReference2 = new WeakReference(cropImageView);
                Uri uri = cropImageView.p0;
                float[] cropPoints = cropImageView.getCropPoints();
                int i = cropImageView.k;
                Intrinsics.checkNotNullExpressionValue(num, "orgWidth");
                int intValue = num.intValue();
                Intrinsics.checkNotNullExpressionValue(num2, "orgHeight");
                int intValue2 = num2.intValue();
                CropOverlayView cropOverlayView = cropImageView.f374b;
                Intrinsics.e(cropOverlayView);
                boolean z = cropOverlayView.m0;
                int aspectRatioX = cropOverlayView.getAspectRatioX();
                int aspectRatioY = cropOverlayView.getAspectRatioY();
                CropImageView.d dVar3 = CropImageView.d.NONE;
                int i2 = dVar != dVar3 ? sVar.B0 : 0;
                int i3 = dVar != dVar3 ? sVar.C0 : 0;
                boolean z2 = cropImageView.p;
                int i4 = i2;
                boolean z3 = cropImageView.r;
                Uri uri2 = sVar.y0;
                if (uri2 == null) {
                    uri2 = cropImageView.z0;
                }
                WeakReference weakReference3 = new WeakReference(new d(context, weakReference2, uri, bitmap, cropPoints, i, intValue, intValue2, z, aspectRatioX, aspectRatioY, i4, i3, z2, z3, dVar, compressFormat, sVar.A0, uri2));
                cropImageView.y0 = weakReference3;
                Object obj = weakReference3.get();
                Intrinsics.e(obj);
                d dVar4 = (d) obj;
                dVar4.M = Kp.p.w(dVar4, V.a, (J) null, new o7.c(dVar4, (pp.c) null), 2);
                cropImageView.h();
            }
        }
    }

    public Intent getResultIntent(Uri uri, Exception exc, int i) {
        CropImageView cropImageView = this.cropImageView;
        Uri imageUri = cropImageView != null ? cropImageView.getImageUri() : null;
        CropImageView cropImageView2 = this.cropImageView;
        float[] cropPoints = cropImageView2 != null ? cropImageView2.getCropPoints() : null;
        CropImageView cropImageView3 = this.cropImageView;
        Rect cropRect = cropImageView3 != null ? cropImageView3.getCropRect() : null;
        CropImageView cropImageView4 = this.cropImageView;
        int rotatedDegrees = cropImageView4 != null ? cropImageView4.getRotatedDegrees() : 0;
        CropImageView cropImageView5 = this.cropImageView;
        Rect wholeImageRect = cropImageView5 != null ? cropImageView5.getWholeImageRect() : null;
        Intrinsics.e(cropPoints);
        Parcelable lVar = new l(imageUri, uri, exc, cropPoints, cropRect, wholeImageRect, rotatedDegrees, i);
        Intent intent = new Intent();
        intent.putExtras(getIntent());
        intent.putExtra("CROP_IMAGE_EXTRA_RESULT", lVar);
        return intent;
    }

    public void onBackPressed() {
        super/*androidx.activity.ComponentActivity*/.onBackPressed();
        setResultCancel();
    }

    public boolean onCreateOptionsMenu(android.view.Menu r11) {
        throw new UnsupportedOperationException("Method not decompiled: com.canhub.cropper.CropImageActivity.onCreateOptionsMenu(android.view.Menu):boolean");
    }

    public void onCropImageComplete(CropImageView cropImageView, u uVar) {
        Intrinsics.checkNotNullParameter(cropImageView, "view");
        Intrinsics.checkNotNullParameter(uVar, "result");
        setResult(uVar.b, uVar.c, uVar.h);
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        Intrinsics.checkNotNullParameter(menuItem, "item");
        int itemId = menuItem.getItemId();
        if (itemId == I.crop_image_menu_crop) {
            cropImage();
        } else if (itemId == I.ic_rotate_left_24) {
            s sVar = this.cropImageOptions;
            if (sVar == null) {
                Intrinsics.m("cropImageOptions");
                throw null;
            }
            rotateImage(-sVar.K0);
        } else if (itemId == I.ic_rotate_right_24) {
            s sVar2 = this.cropImageOptions;
            if (sVar2 == null) {
                Intrinsics.m("cropImageOptions");
                throw null;
            }
            rotateImage(sVar2.K0);
        } else if (itemId == I.ic_flip_24_horizontally) {
            CropImageView cropImageView = this.cropImageView;
            if (cropImageView != null) {
                cropImageView.p = !cropImageView.p;
                cropImageView.a(cropImageView.getWidth(), cropImageView.getHeight(), true, false);
            }
        } else if (itemId == I.ic_flip_24_vertically) {
            CropImageView cropImageView2 = this.cropImageView;
            if (cropImageView2 != null) {
                cropImageView2.r = !cropImageView2.r;
                cropImageView2.a(cropImageView2.getWidth(), cropImageView2.getHeight(), true, false);
            }
        } else {
            if (itemId != 16908332) {
                return super/*android.app.Activity*/.onOptionsItemSelected(menuItem);
            }
            setResultCancel();
        }
        return true;
    }

    public void onPickImageResult(Uri uri) {
        if (uri == null) {
            setResultCancel();
            return;
        }
        this.cropImageUri = uri;
        CropImageView cropImageView = this.cropImageView;
        if (cropImageView != null) {
            cropImageView.setImageUriAsync(uri);
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        Intrinsics.checkNotNullParameter(bundle, "outState");
        super/*androidx.activity.ComponentActivity*/.onSaveInstanceState(bundle);
        bundle.putString(BUNDLE_KEY_TMP_URI, String.valueOf(this.latestTmpUri));
    }

    public void onSetImageUriComplete(CropImageView cropImageView, Uri uri, Exception exc) {
        CropImageView cropImageView2;
        CropImageView cropImageView3;
        Intrinsics.checkNotNullParameter(cropImageView, "view");
        Intrinsics.checkNotNullParameter(uri, "uri");
        if (exc != null) {
            setResult(null, exc, 1);
            return;
        }
        s sVar = this.cropImageOptions;
        if (sVar == null) {
            Intrinsics.m("cropImageOptions");
            throw null;
        }
        Rect rect = sVar.F0;
        if (rect != null && (cropImageView3 = this.cropImageView) != null) {
            if (sVar == null) {
                Intrinsics.m("cropImageOptions");
                throw null;
            }
            cropImageView3.setCropRect(rect);
        }
        s sVar2 = this.cropImageOptions;
        if (sVar2 == null) {
            Intrinsics.m("cropImageOptions");
            throw null;
        }
        int i = sVar2.G0;
        if (i > 0 && (cropImageView2 = this.cropImageView) != null) {
            if (sVar2 == null) {
                Intrinsics.m("cropImageOptions");
                throw null;
            }
            cropImageView2.setRotatedDegrees(i);
        }
        s sVar3 = this.cropImageOptions;
        if (sVar3 == null) {
            Intrinsics.m("cropImageOptions");
            throw null;
        }
        if (sVar3.P0) {
            cropImage();
        }
    }

    public void onStart() {
        super.onStart();
        CropImageView cropImageView = this.cropImageView;
        if (cropImageView != null) {
            cropImageView.setOnSetImageUriCompleteListener(this);
        }
        CropImageView cropImageView2 = this.cropImageView;
        if (cropImageView2 != null) {
            cropImageView2.setOnCropImageCompleteListener(this);
        }
    }

    public void onStop() {
        super.onStop();
        CropImageView cropImageView = this.cropImageView;
        if (cropImageView != null) {
            cropImageView.setOnSetImageUriCompleteListener(null);
        }
        CropImageView cropImageView2 = this.cropImageView;
        if (cropImageView2 != null) {
            cropImageView2.setOnCropImageCompleteListener(null);
        }
    }

    public void rotateImage(int i) {
        CropImageView cropImageView = this.cropImageView;
        if (cropImageView != null) {
            cropImageView.e(i);
        }
    }

    public void setCropImageView(CropImageView cropImageView) {
        Intrinsics.checkNotNullParameter(cropImageView, "cropImageView");
        this.cropImageView = cropImageView;
    }

    public void setResult(Uri uri, Exception exc, int i) {
        setResult(exc != null ? 204 : -1, getResultIntent(uri, exc, i));
        finish();
    }

    public void setResultCancel() {
        setResult(0);
        finish();
    }

    public void showImageSourceDialog(Function1<? super a, Unit> function1) {
        Intrinsics.checkNotNullParameter(function1, "openSource");
        g gVar = new g(this);
        m.d dVar = gVar.a;
        dVar.j = false;
        dVar.k = new w0(this, 1);
        dVar.d = dVar.a.getText(L.pick_image_chooser_title);
        String[] strArr = {getString(L.pick_image_camera), getString(L.pick_image_gallery)};
        T8.g gVar2 = new T8.g(function1, 2);
        dVar.l = strArr;
        dVar.n = gVar2;
        gVar.create().show();
    }

    public void updateMenuItemIconColor(Menu menu, int i, int i2) {
        Drawable icon;
        Intrinsics.checkNotNullParameter(menu, "menu");
        MenuItem findItem = menu.findItem(i);
        if (findItem == null || (icon = findItem.getIcon()) == null) {
            return;
        }
        try {
            icon.mutate();
            X1.a aVar = X1.a.SRC_ATOP;
            ColorFilter colorFilter = null;
            if (Build.VERSION.SDK_INT >= 29) {
                Object o = b.o(aVar);
                if (o != null) {
                    colorFilter = b.c(i2, o);
                }
            } else {
                PorterDuff.Mode G2 = c3.c.G(aVar);
                if (G2 != null) {
                    colorFilter = new PorterDuffColorFilter(i2, G2);
                }
            }
            icon.setColorFilter(colorFilter);
            findItem.setIcon(icon);
        } catch (Exception e) {
            Log.w("AIC", "Failed to update menu item color", e);
        }
    }

    public void updateMenuItemTextColor(Menu menu, int i, int i2) {
        Intrinsics.checkNotNullParameter(menu, "menu");
        MenuItem findItem = menu.findItem(i);
        CharSequence title = findItem.getTitle();
        if (title == null || !(!StringsKt.H(title))) {
            return;
        }
        try {
            SpannableString spannableString = new SpannableString(title);
            spannableString.setSpan(new ForegroundColorSpan(i2), 0, spannableString.length(), 33);
            findItem.setTitle(spannableString);
        } catch (Exception e) {
            Log.w("AIC", "Failed to update menu item color", e);
        }
    }

    public void onCreate(Bundle bundle) {
        Uri uri;
        s sVar;
        super/*androidx.fragment.app.FragmentActivity*/.onCreate(bundle);
        a inflate = a.inflate(getLayoutInflater());
        Intrinsics.checkNotNullExpressionValue(inflate, "inflate(layoutInflater)");
        this.binding = inflate;
        Uri uri2 = null;
        if (inflate != null) {
            setContentView(inflate.a);
            a aVar = this.binding;
            if (aVar != null) {
                CropImageView cropImageView = aVar.b;
                Intrinsics.checkNotNullExpressionValue(cropImageView, "binding.cropImageView");
                setCropImageView(cropImageView);
                Bundle bundleExtra = getIntent().getBundleExtra("CROP_IMAGE_EXTRA_BUNDLE");
                if (bundleExtra != null) {
                    uri = (Uri) bundleExtra.getParcelable("CROP_IMAGE_EXTRA_SOURCE");
                } else {
                    uri = null;
                }
                this.cropImageUri = uri;
                if (bundleExtra != null) {
                    sVar = (s) bundleExtra.getParcelable(tdGaoHZiSbko.wplfckrVA);
                } else {
                    sVar = null;
                }
                if (sVar == null) {
                    sVar = new s();
                }
                this.cropImageOptions = sVar;
                if (bundle == null) {
                    Uri uri3 = this.cropImageUri;
                    if (uri3 != null && !uri3.equals(Uri.EMPTY)) {
                        CropImageView cropImageView2 = this.cropImageView;
                        if (cropImageView2 != null) {
                            cropImageView2.setImageUriAsync(this.cropImageUri);
                        }
                    } else {
                        s sVar2 = this.cropImageOptions;
                        if (sVar2 != null) {
                            if (sVar2.Q0) {
                                showIntentChooser();
                            } else {
                                boolean z = sVar2.a;
                                if (z && sVar2.b) {
                                    showImageSourceDialog(new Zp.u(1, this, CropImageActivity.class, "openSource", "openSource(Lcom/canhub/cropper/CropImageActivity$Source;)V", 0, 9));
                                } else if (z) {
                                    this.pickImageGallery.a("image/*");
                                } else if (sVar2.b) {
                                    openCamera();
                                } else {
                                    finish();
                                }
                            }
                        } else {
                            Intrinsics.m("cropImageOptions");
                            throw null;
                        }
                    }
                } else {
                    String string = bundle.getString(BUNDLE_KEY_TMP_URI);
                    if (string != null) {
                        uri2 = Uri.parse(string);
                        Intrinsics.checkNotNullExpressionValue(uri2, "parse(this)");
                    }
                    this.latestTmpUri = uri2;
                }
                setCustomizations();
                return;
            }
            Intrinsics.m("binding");
            throw null;
        }
        Intrinsics.m("binding");
        throw null;
    }
}