导航菜单

页面标题

页面副标题

ZG·三农 v1.1.5 - SystemPickerActivity.java 源代码

正在查看: ZG·三农 v1.1.5 应用的 SystemPickerActivity.java JAVA 源代码文件

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


package uts.sdk.modules.DCloudUniMedia;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.widget.RelativeLayout;
import androidx.activity.ComponentDialog$;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.PickVisualMediaRequest;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.fragment.app.FragmentActivity;
import io.dcloud.feature.uniapp.annotation.UniJSMethod;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import kotlin.jvm.internal.IntCompanionObject;

public class SystemPickerActivity extends FragmentActivity {
    public static final int DEFAULT_SELECTED_MAX_COUNT = Integer.MAX_VALUE;
    public static final String DOC_PATH = "doc_path";
    public static final String MAX_SELECT_COUNT = "max_select_count";
    public static final int PICKER_IMAGE = 100;
    public static final int PICKER_IMAGE_VIDEO = 101;
    public static final int PICKER_VIDEO = 102;
    public static final String SELECT_MODE = "select_mode";
    int activityOrientation = Integer.MAX_VALUE;
    private boolean copyToPrivacyPath = false;
    private String docPath;

    protected void onCreate(Bundle bundle) {
        ActivityResultContracts.PickVisualMedia.VisualMediaType visualMediaType;
        super.onCreate(bundle);
        setContentView(new RelativeLayout(this));
        if (getIntent().hasExtra("page_orientation")) {
            int intExtra = getIntent().getIntExtra("page_orientation", 1);
            this.activityOrientation = intExtra;
            setRequestedOrientation(intExtra);
        }
        this.copyToPrivacyPath = getIntent().getBooleanExtra("copy_privacy_path", false);
        this.docPath = getIntent().getStringExtra(DOC_PATH);
        int intExtra2 = getIntent().getIntExtra(SELECT_MODE, PICKER_IMAGE_VIDEO);
        int intExtra3 = getIntent().getIntExtra(MAX_SELECT_COUNT, Integer.MAX_VALUE);
        try {
            if (intExtra3 > ComponentDialog$.ExternalSyntheticApiModelOutline0.m()) {
                intExtra3 = ComponentDialog$.ExternalSyntheticApiModelOutline0.m();
            }
        } catch (Throwable unused) {
            if (intExtra3 > 100) {
                intExtra3 = 100;
            }
        }
        ActivityResultLauncher activityResultLauncher = null;
        switch (intExtra2) {
            case 100:
                visualMediaType = ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE;
                break;
            case PICKER_IMAGE_VIDEO:
                visualMediaType = ActivityResultContracts.PickVisualMedia.ImageAndVideo.INSTANCE;
                break;
            case PICKER_VIDEO:
                visualMediaType = ActivityResultContracts.PickVisualMedia.VideoOnly.INSTANCE;
                break;
            default:
                visualMediaType = null;
                break;
        }
        if (intExtra3 == 1) {
            activityResultLauncher = registerForActivityResult(new ActivityResultContracts.PickVisualMedia(), new ActivityResultCallback() {
                public final void onActivityResult(Object obj) {
                    SystemPickerActivity.this.m948xc81d2de2((Uri) obj);
                }
            });
        } else if (intExtra3 > 1) {
            activityResultLauncher = registerForActivityResult(new ActivityResultContracts.PickMultipleVisualMedia(intExtra3), new ActivityResultCallback() {
                public final void onActivityResult(Object obj) {
                    SystemPickerActivity.this.m949x5557df63((List) obj);
                }
            });
        }
        if (activityResultLauncher != null && visualMediaType != null) {
            activityResultLauncher.launch(new PickVisualMediaRequest.Builder().setMediaType(visualMediaType).build());
        } else {
            setResult(0);
            finish();
        }
    }

    void m948xc81d2de2(Uri uri) {
        if (uri != null) {
            onChooseFinish(uri);
        } else {
            setResult(0);
            finish();
        }
    }

    void m949x5557df63(List list) {
        if (list != null && !list.isEmpty()) {
            onChooseFinish((Uri[]) list.toArray(new Uri[0]));
        } else {
            setResult(0);
            finish();
        }
    }

    private void onChooseFinish(Uri... uriArr) {
        if (uriArr != null && uriArr.length > 0) {
            setTopAndBottomBarColor();
            compress(Arrays.asList(uriArr).iterator(), new ArrayList<>());
        } else {
            setResult(0);
            finish();
        }
    }

    private void compress(Iterator<Uri> it, final ArrayList<Media> arrayList) {
        String uri;
        while (it.hasNext()) {
            Uri next = it.next();
            getContentResolver().takePersistableUriPermission(next, 1);
            String type = getContentResolver().getType(next);
            if (this.copyToPrivacyPath && type != null && type.startsWith("image/")) {
                uri = this.docPath + System.currentTimeMillis() + UniJSMethod.NOT_SET + getFileName(next);
                if (!copyFile(next, uri, this)) {
                    uri = next.toString();
                }
            } else {
                uri = next.toString();
            }
            arrayList.add(makeMedia(uri));
        }
        runOnUiThread(new Runnable() {
            @Override
            public final void run() {
                SystemPickerActivity.this.m947x850f614b(arrayList);
            }
        });
    }

    void m947x850f614b(ArrayList arrayList) {
        Intent intent = new Intent();
        intent.putExtra("select_result", arrayList);
        setResult(-1, intent);
        finish();
    }

    private Media makeMedia(String str) {
        Media media = new Media(str, "name", System.currentTimeMillis(), 0, 0L, -1, "");
        new ArrayList().add(media);
        return media;
    }

    private void setTopAndBottomBarColor() {
        Window window = getWindow();
        window.addFlags(IntCompanionObject.MIN_VALUE);
        window.setStatusBarColor(Color.parseColor("#99000000"));
        window.setNavigationBarColor(Color.parseColor("#99000000"));
    }

    public void finish() {
        super.finish();
        overridePendingTransition(0, 0);
    }

    private java.lang.String getFileName(android.net.Uri r9) {
        throw new UnsupportedOperationException("Method not decompiled: uts.sdk.modules.DCloudUniMedia.SystemPickerActivity.getFileName(android.net.Uri):java.lang.String");
    }

    public boolean copyFile(Uri uri, String str, Context context) {
        try {
            File file = new File(str);
            if (!file.exists()) {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                if (file.exists()) {
                    file.createNewFile();
                }
            }
            InputStream openInputStream = context.getContentResolver().openInputStream(uri);
            FileOutputStream fileOutputStream = new FileOutputStream(str);
            byte[] bArr = new byte[1024];
            while (true) {
                int read = openInputStream.read(bArr);
                if (read != -1) {
                    fileOutputStream.write(bArr, 0, read);
                } else {
                    openInputStream.close();
                    fileOutputStream.close();
                    return true;
                }
            }
        } catch (Exception unused) {
            return false;
        }
    }
}