diff --git a/doric-android/doric/src/main/java/pub/doric/DoricContext.java b/doric-android/doric/src/main/java/pub/doric/DoricContext.java index cd647fad..d41b421d 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricContext.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricContext.java @@ -17,8 +17,11 @@ package pub.doric; import android.animation.AnimatorSet; import android.content.Context; +import android.content.Intent; import android.text.TextUtils; +import androidx.fragment.app.Fragment; + import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSONBuilder; @@ -258,4 +261,23 @@ public class DoricContext { public String getExtra() { return extra; } + + /** + * Use this to take effect of {@link #onActivityResult(int, int, Intent)} + */ + public void startActivityForResult(Intent intent, int requestCode) { + if (doricNavigator instanceof Fragment) { + ((Fragment) doricNavigator).startActivityForResult(intent, requestCode); + } + } + + /** + * To use this, + * you should use {@link #startActivityForResult(Intent, int)}. + */ + public void onActivityResult(int requestCode, int resultCode, Intent data) { + for (DoricJavaPlugin javaPlugin : mPluginMap.values()) { + javaPlugin.onActivityResult(requestCode, resultCode, data); + } + } } diff --git a/doric-android/doric/src/main/java/pub/doric/DoricPanel.java b/doric-android/doric/src/main/java/pub/doric/DoricPanel.java index b840d2a0..e1d07fdf 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricPanel.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricPanel.java @@ -24,6 +24,7 @@ import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.OnLifecycleEvent; +import android.content.Intent; import android.util.AttributeSet; import android.widget.FrameLayout; @@ -124,6 +125,12 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver { } } + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (mDoricContext != null) { + mDoricContext.onActivityResult(requestCode, resultCode, data); + } + } + public interface FrameChangedListener { void onFrameChanged(int width, int height); } diff --git a/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java b/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java index 7b256cf3..9137e8e5 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java @@ -15,6 +15,7 @@ */ package pub.doric; +import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -115,7 +116,7 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { @Override public void onResume() { super.onResume(); - if (!(getActivity() instanceof LifecycleOwner && doricPanel != null)) { + if (!(getActivity() instanceof LifecycleOwner) && doricPanel != null) { doricPanel.onActivityResume(); } } @@ -225,4 +226,8 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { }); } + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + doricPanel.onActivityResult(requestCode, resultCode, data); + } } diff --git a/doric-android/doric/src/main/java/pub/doric/plugin/DoricJavaPlugin.java b/doric-android/doric/src/main/java/pub/doric/plugin/DoricJavaPlugin.java index f991cdad..460b9f26 100644 --- a/doric-android/doric/src/main/java/pub/doric/plugin/DoricJavaPlugin.java +++ b/doric-android/doric/src/main/java/pub/doric/plugin/DoricJavaPlugin.java @@ -15,6 +15,8 @@ */ package pub.doric.plugin; +import android.content.Intent; + import pub.doric.DoricContext; import pub.doric.utils.DoricContextHolder; @@ -31,4 +33,11 @@ public abstract class DoricJavaPlugin extends DoricContextHolder { public void onTearDown() { } + + /** + * Called when use {@link DoricContext#startActivityForResult(Intent, int)} + */ + public void onActivityResult(int requestCode, int resultCode, Intent data) { + + } }