what-the-bank/sources/io/flutter/plugins/imagepicker/ImagePickerPlugin.java

413 lines
17 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package io.flutter.plugins.imagepicker;
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import androidx.lifecycle.DefaultLifecycleObserver;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
import java.io.File;
import o.InterfaceC16541pFg;
import o.wdQ;
/* loaded from: classes6.dex */
public class ImagePickerPlugin implements MethodChannel.MethodCallHandler, FlutterPlugin, ActivityAware {
private static final int CAMERA_DEVICE_FRONT = 1;
private static final int CAMERA_DEVICE_REAR = 0;
private static final String CHANNEL = "plugins.flutter.io/image_picker_android";
static final String METHOD_CALL_IMAGE = "pickImage";
static final String METHOD_CALL_MULTI_IMAGE = "pickMultiImage";
private static final String METHOD_CALL_RETRIEVE = "retrieve";
static final String METHOD_CALL_VIDEO = "pickVideo";
private static final int SOURCE_CAMERA = 0;
private static final int SOURCE_GALLERY = 1;
private ActivityState activityState;
private FlutterPlugin.FlutterPluginBinding pluginBinding;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes6.dex */
public class LifeCycleObserver implements Application.ActivityLifecycleCallbacks, DefaultLifecycleObserver {
final ImagePickerPlugin this$0;
private final Activity thisActivity;
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityCreated(Activity activity, Bundle bundle) {
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityPaused(Activity activity) {
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityResumed(Activity activity) {
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityStarted(Activity activity) {
}
@Override // androidx.lifecycle.DefaultLifecycleObserver, o.InterfaceC15806ikR
public void onCreate(InterfaceC16541pFg interfaceC16541pFg) {
}
@Override // androidx.lifecycle.DefaultLifecycleObserver, o.InterfaceC15806ikR
public void onPause(InterfaceC16541pFg interfaceC16541pFg) {
}
@Override // androidx.lifecycle.DefaultLifecycleObserver, o.InterfaceC15806ikR
public void onResume(InterfaceC16541pFg interfaceC16541pFg) {
}
@Override // androidx.lifecycle.DefaultLifecycleObserver, o.InterfaceC15806ikR
public void onStart(InterfaceC16541pFg interfaceC16541pFg) {
}
LifeCycleObserver(ImagePickerPlugin imagePickerPlugin, Activity activity) {
this.this$0 = imagePickerPlugin;
this.thisActivity = activity;
}
@Override // androidx.lifecycle.DefaultLifecycleObserver, o.InterfaceC15806ikR
public void onStop(InterfaceC16541pFg interfaceC16541pFg) {
onActivityStopped(this.thisActivity);
}
@Override // androidx.lifecycle.DefaultLifecycleObserver, o.InterfaceC15806ikR
public void onDestroy(InterfaceC16541pFg interfaceC16541pFg) {
onActivityDestroyed(this.thisActivity);
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityDestroyed(Activity activity) {
if (this.thisActivity != activity || activity.getApplicationContext() == null) {
return;
}
((Application) activity.getApplicationContext()).unregisterActivityLifecycleCallbacks(this);
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityStopped(Activity activity) {
if (this.thisActivity == activity) {
this.this$0.activityState.getDelegate().saveStateBeforeResult();
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes6.dex */
public class ActivityState {
private Activity activity;
private ActivityPluginBinding activityBinding;
private Application application;
private MethodChannel channel;
private ImagePickerDelegate delegate;
private wdQ lifecycle;
private LifeCycleObserver observer;
final ImagePickerPlugin this$0;
ActivityState(ImagePickerPlugin imagePickerPlugin, Application application, Activity activity, BinaryMessenger binaryMessenger, MethodChannel.MethodCallHandler methodCallHandler, PluginRegistry.Registrar registrar, ActivityPluginBinding activityPluginBinding) {
this.this$0 = imagePickerPlugin;
this.application = application;
this.activity = activity;
this.activityBinding = activityPluginBinding;
this.delegate = imagePickerPlugin.constructDelegate(activity);
MethodChannel methodChannel = new MethodChannel(binaryMessenger, ImagePickerPlugin.CHANNEL);
this.channel = methodChannel;
methodChannel.setMethodCallHandler(methodCallHandler);
LifeCycleObserver lifeCycleObserver = new LifeCycleObserver(imagePickerPlugin, activity);
this.observer = lifeCycleObserver;
if (registrar != null) {
application.registerActivityLifecycleCallbacks(lifeCycleObserver);
registrar.addActivityResultListener(this.delegate);
registrar.addRequestPermissionsResultListener(this.delegate);
} else {
activityPluginBinding.addActivityResultListener(this.delegate);
activityPluginBinding.addRequestPermissionsResultListener(this.delegate);
wdQ activityLifecycle = FlutterLifecycleAdapter.getActivityLifecycle(activityPluginBinding);
this.lifecycle = activityLifecycle;
activityLifecycle.e(this.observer);
}
}
ActivityState(ImagePickerPlugin imagePickerPlugin, ImagePickerDelegate imagePickerDelegate, Activity activity) {
this.this$0 = imagePickerPlugin;
this.activity = activity;
this.delegate = imagePickerDelegate;
}
void release() {
ActivityPluginBinding activityPluginBinding = this.activityBinding;
if (activityPluginBinding != null) {
activityPluginBinding.removeActivityResultListener(this.delegate);
this.activityBinding.removeRequestPermissionsResultListener(this.delegate);
this.activityBinding = null;
}
wdQ wdq = this.lifecycle;
if (wdq != null) {
wdq.a(this.observer);
this.lifecycle = null;
}
MethodChannel methodChannel = this.channel;
if (methodChannel != null) {
methodChannel.setMethodCallHandler(null);
this.channel = null;
}
Application application = this.application;
if (application != null) {
application.unregisterActivityLifecycleCallbacks(this.observer);
this.application = null;
}
this.activity = null;
this.observer = null;
this.delegate = null;
}
ImagePickerDelegate getDelegate() {
return this.delegate;
}
Activity getActivity() {
return this.activity;
}
}
public static void registerWith(PluginRegistry.Registrar registrar) {
if (registrar.activity() == null) {
return;
}
Activity activity = registrar.activity();
new ImagePickerPlugin().setup(registrar.messenger(), registrar.context() != null ? (Application) registrar.context().getApplicationContext() : null, activity, registrar, null);
}
public ImagePickerPlugin() {
}
ImagePickerPlugin(ImagePickerDelegate imagePickerDelegate, Activity activity) {
this.activityState = new ActivityState(this, imagePickerDelegate, activity);
}
@Override // io.flutter.embedding.engine.plugins.activity.ActivityAware
public void onAttachedToActivity(ActivityPluginBinding activityPluginBinding) {
setup(this.pluginBinding.getBinaryMessenger(), (Application) this.pluginBinding.getApplicationContext(), activityPluginBinding.getActivity(), null, activityPluginBinding);
}
@Override // io.flutter.embedding.engine.plugins.activity.ActivityAware
public void onDetachedFromActivity() {
tearDown();
}
@Override // io.flutter.embedding.engine.plugins.activity.ActivityAware
public void onDetachedFromActivityForConfigChanges() {
onDetachedFromActivity();
}
@Override // io.flutter.embedding.engine.plugins.activity.ActivityAware
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding activityPluginBinding) {
onAttachedToActivity(activityPluginBinding);
}
private void setup(BinaryMessenger binaryMessenger, Application application, Activity activity, PluginRegistry.Registrar registrar, ActivityPluginBinding activityPluginBinding) {
this.activityState = new ActivityState(this, application, activity, binaryMessenger, this, registrar, activityPluginBinding);
}
private void tearDown() {
ActivityState activityState = this.activityState;
if (activityState != null) {
activityState.release();
this.activityState = null;
}
}
final ImagePickerDelegate constructDelegate(Activity activity) {
ImagePickerCache imagePickerCache = new ImagePickerCache(activity);
File cacheDir = activity.getCacheDir();
return new ImagePickerDelegate(activity, cacheDir, new ImageResizer(cacheDir, new ExifDataCopier()), imagePickerCache);
}
/* loaded from: classes6.dex */
static class MethodResultWrapper implements MethodChannel.Result {
private Handler handler = new Handler(Looper.getMainLooper());
private MethodChannel.Result methodResult;
MethodResultWrapper(MethodChannel.Result result) {
this.methodResult = result;
}
@Override // io.flutter.plugin.common.MethodChannel.Result
public void success(Object obj) {
this.handler.post(new Runnable(this, obj) { // from class: io.flutter.plugins.imagepicker.ImagePickerPlugin.MethodResultWrapper.1
final MethodResultWrapper this$0;
final Object val$result;
{
this.this$0 = this;
this.val$result = obj;
}
@Override // java.lang.Runnable
public void run() {
this.this$0.methodResult.success(this.val$result);
}
});
}
@Override // io.flutter.plugin.common.MethodChannel.Result
public void error(String str, String str2, Object obj) {
this.handler.post(new Runnable(this, str, str2, obj) { // from class: io.flutter.plugins.imagepicker.ImagePickerPlugin.MethodResultWrapper.2
final MethodResultWrapper this$0;
final String val$errorCode;
final Object val$errorDetails;
final String val$errorMessage;
{
this.this$0 = this;
this.val$errorCode = str;
this.val$errorMessage = str2;
this.val$errorDetails = obj;
}
@Override // java.lang.Runnable
public void run() {
this.this$0.methodResult.error(this.val$errorCode, this.val$errorMessage, this.val$errorDetails);
}
});
}
@Override // io.flutter.plugin.common.MethodChannel.Result
public void notImplemented() {
this.handler.post(new Runnable(this) { // from class: io.flutter.plugins.imagepicker.ImagePickerPlugin.MethodResultWrapper.3
final MethodResultWrapper this$0;
{
this.this$0 = this;
}
@Override // java.lang.Runnable
public void run() {
this.this$0.methodResult.notImplemented();
}
});
}
}
/* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
@Override // io.flutter.plugin.common.MethodChannel.MethodCallHandler
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
char c;
CameraDevice cameraDevice;
ActivityState activityState = this.activityState;
if (activityState == null || activityState.getActivity() == null) {
result.error("no_activity", "image_picker plugin requires a foreground activity.", null);
return;
}
MethodResultWrapper methodResultWrapper = new MethodResultWrapper(result);
ImagePickerDelegate delegate = this.activityState.getDelegate();
if (methodCall.argument("cameraDevice") != null) {
if (((Integer) methodCall.argument("cameraDevice")).intValue() == 1) {
cameraDevice = CameraDevice.FRONT;
} else {
cameraDevice = CameraDevice.REAR;
}
delegate.setCameraDevice(cameraDevice);
}
String str = methodCall.method;
str.hashCode();
switch (str.hashCode()) {
case -1708939613:
if (str.equals(METHOD_CALL_MULTI_IMAGE)) {
c = 0;
break;
}
c = 65535;
break;
case -1457314374:
if (str.equals(METHOD_CALL_IMAGE)) {
c = 1;
break;
}
c = 65535;
break;
case -1445424934:
if (str.equals(METHOD_CALL_VIDEO)) {
c = 2;
break;
}
c = 65535;
break;
case -310034372:
if (str.equals(METHOD_CALL_RETRIEVE)) {
c = 3;
break;
}
c = 65535;
break;
default:
c = 65535;
break;
}
if (c == 0) {
delegate.chooseMultiImageFromGallery(methodCall, methodResultWrapper);
return;
}
if (c == 1) {
int intValue = ((Integer) methodCall.argument("source")).intValue();
if (intValue == 0) {
delegate.takeImageWithCamera(methodCall, methodResultWrapper);
return;
} else {
if (intValue == 1) {
delegate.chooseImageFromGallery(methodCall, methodResultWrapper);
return;
}
throw new IllegalArgumentException("Invalid image source: ".concat(String.valueOf(intValue)));
}
}
if (c != 2) {
if (c == 3) {
delegate.retrieveLostImage(methodResultWrapper);
return;
} else {
StringBuilder sb = new StringBuilder("Unknown method ");
sb.append(methodCall.method);
throw new IllegalArgumentException(sb.toString());
}
}
int intValue2 = ((Integer) methodCall.argument("source")).intValue();
if (intValue2 == 0) {
delegate.takeVideoWithCamera(methodCall, methodResultWrapper);
} else {
if (intValue2 == 1) {
delegate.chooseVideoFromGallery(methodCall, methodResultWrapper);
return;
}
throw new IllegalArgumentException("Invalid video source: ".concat(String.valueOf(intValue2)));
}
}
@Override // io.flutter.embedding.engine.plugins.FlutterPlugin
public void onDetachedFromEngine(FlutterPlugin.FlutterPluginBinding flutterPluginBinding) {
this.pluginBinding = null;
}
@Override // io.flutter.embedding.engine.plugins.FlutterPlugin
public void onAttachedToEngine(FlutterPlugin.FlutterPluginBinding flutterPluginBinding) {
this.pluginBinding = flutterPluginBinding;
}
final ActivityState getActivityState() {
return this.activityState;
}
}