package ඓ.ᨨ.K.ඓ.ඓ;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import ඓ.ᨨ.K.ඓ.K.C0782;

/* renamed from: ඓ.ᨨ.K.ඓ.ඓ.ῲ  reason: contains not printable characters */
/* compiled from: MediaStoreCompat */
public class C0772 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public C0782 f3927;

    /* renamed from: ඓ  reason: contains not printable characters */
    public String f3928;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final WeakReference<Fragment> f3929 = null;

    /* renamed from: K  reason: contains not printable characters */
    public final WeakReference<Activity> f3930;

    /* renamed from: 㸾  reason: contains not printable characters */
    public Uri f3931;

    public C0772(Activity activity) {
        this.f3930 = new WeakReference<>(activity);
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2346(Context context, int i) {
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        if (intent.resolveActivity(context.getPackageManager()) != null) {
            File file = null;
            try {
                file = m2345();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (file != null) {
                this.f3928 = file.getAbsolutePath();
                this.f3931 = ((FileProvider.C0163) FileProvider.m603(this.f3930.get(), this.f3927.f3972)).m604(file);
                intent.putExtra("output", this.f3931);
                intent.addFlags(2);
                int i2 = Build.VERSION.SDK_INT;
                WeakReference<Fragment> weakReference = this.f3929;
                if (weakReference != null) {
                    weakReference.get().startActivityForResult(intent, i);
                } else {
                    this.f3930.get().startActivityForResult(intent, i);
                }
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final File m2345() throws IOException {
        File file;
        String format = String.format("JPEG_%s.jpg", new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()));
        if (this.f3927.f3973) {
            file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            if (!file.exists()) {
                file.mkdirs();
            }
        } else {
            file = this.f3930.get().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        }
        String str = this.f3927.f3971;
        if (str != null) {
            File file2 = new File(file, str);
            if (!file2.exists()) {
                file2.mkdirs();
            }
            file = file2;
        }
        File file3 = new File(file, format);
        int i = Build.VERSION.SDK_INT;
        if (!"mounted".equals(Environment.getExternalStorageState(file3))) {
            return null;
        }
        return file3;
    }
}
