导航菜单

页面标题

页面副标题

大众借. v4.1.2 - PictureSelectActivity.java 源代码

正在查看: 大众借. v4.1.2 应用的 PictureSelectActivity.java JAVA 源代码文件

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


package com.wildma.pictureselector;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import androidx.core.app.ActivityCompat;
import com.wildma.pictureselector.PictureSelectDialog;
import java.io.File;

public class PictureSelectActivity extends Activity {
    public static final String CROP_HEIGHT = "crop_Height";
    public static final String CROP_WIDTH = "crop_width";
    public static final String ENABLE_CROP = "enable_crop";
    public static final String RATIO_HEIGHT = "ratio_Height";
    public static final String RATIO_WIDTH = "ratio_Width";
    private final int PERMISSION_CODE_FIRST = 20;
    private boolean isToast = true;
    private boolean mCropEnabled;
    private int mCropHeight;
    private int mCropWidth;
    private int mRatioHeight;
    private int mRatioWidth;
    private PictureSelectDialog mSelectPictureDialog;

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_picture_select);
        this.mCropEnabled = getIntent().getBooleanExtra(ENABLE_CROP, true);
        this.mCropWidth = getIntent().getIntExtra(CROP_WIDTH, 200);
        this.mCropHeight = getIntent().getIntExtra(CROP_HEIGHT, 200);
        this.mRatioWidth = getIntent().getIntExtra(RATIO_WIDTH, 1);
        this.mRatioHeight = getIntent().getIntExtra(RATIO_HEIGHT, 1);
        if (PermissionUtils.checkPermissionFirst(this, 20, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.CAMERA"})) {
            selectPicture();
        }
    }

    @Override
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        super.onRequestPermissionsResult(i, strArr, iArr);
        boolean z = true;
        for (int i2 = 0; i2 < strArr.length; i2++) {
            if (iArr[i2] == -1) {
                if (!ActivityCompat.shouldShowRequestPermissionRationale(this, strArr[i2]) && this.isToast) {
                    Toast.makeText(this, "请手动打开该应用需要的权限", 0).show();
                    this.isToast = false;
                }
                z = false;
            }
        }
        this.isToast = true;
        if (z) {
            Log.d("onRequestPermission", "onRequestPermissionsResult: 允许所有权限");
            selectPicture();
        } else {
            Log.d("onRequestPermission", "onRequestPermissionsResult: 有权限不允许");
            finish();
        }
    }

    public void selectPicture() {
        PictureSelectDialog pictureSelectDialog = new PictureSelectDialog(this, R.style.ActionSheetDialogStyle);
        this.mSelectPictureDialog = pictureSelectDialog;
        pictureSelectDialog.setOnItemClickListener(new PictureSelectDialog.OnItemClickListener() {
            @Override
            public void onItemClick(int i) {
                if (i == 1) {
                    PictureSelectUtils.getByCamera(PictureSelectActivity.this);
                    return;
                }
                if (i == 2) {
                    PictureSelectUtils.getByAlbum(PictureSelectActivity.this);
                } else if (i == 0) {
                    PictureSelectActivity.this.finish();
                    PictureSelectActivity.this.overridePendingTransition(0, R.anim.activity_out);
                }
            }
        });
    }

    @Override
    protected void onActivityResult(int i, int i2, Intent intent) {
        if (i2 == 0 && (i == 17 || i == 18 || i == 19)) {
            finish();
        }
        String onActivityResult = PictureSelectUtils.onActivityResult(this, i, i2, intent, this.mCropEnabled, this.mCropWidth, this.mCropHeight, this.mRatioWidth, this.mRatioHeight);
        if (TextUtils.isEmpty(onActivityResult)) {
            return;
        }
        PictureBean pictureBean = new PictureBean();
        pictureBean.setPath(onActivityResult);
        pictureBean.setCut(this.mCropEnabled);
        if (Build.VERSION.SDK_INT >= 29) {
            pictureBean.setUri(ImageUtils.getImageUri(this, onActivityResult));
        } else {
            pictureBean.setUri(Uri.fromFile(new File(onActivityResult)));
        }
        Intent intent2 = new Intent();
        intent2.putExtra(PictureSelector.PICTURE_RESULT, pictureBean);
        setResult(-1, intent2);
        finish();
    }
}