android:DoricJavaPlugin add onActivityResult support

This commit is contained in:
pengfei.zhou 2020-09-01 11:25:56 +08:00 committed by osborn
parent f6eb8632d6
commit 6484439852
4 changed files with 44 additions and 1 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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) {
}
}