|
@@ -22,6 +22,7 @@ import androidx.fragment.app.FragmentActivity;
|
|
import androidx.fragment.app.FragmentContainerView;
|
|
import androidx.fragment.app.FragmentContainerView;
|
|
|
|
|
|
|
|
|
|
|
|
+import com.compdfkit.flutter.compdfkit_flutter.plugin.CPDFViewCtrlPlugin;
|
|
import com.compdfkit.tools.common.pdf.CPDFConfigurationUtils;
|
|
import com.compdfkit.tools.common.pdf.CPDFConfigurationUtils;
|
|
import com.compdfkit.tools.common.pdf.CPDFDocumentFragment;
|
|
import com.compdfkit.tools.common.pdf.CPDFDocumentFragment;
|
|
import com.compdfkit.tools.common.pdf.config.CPDFConfiguration;
|
|
import com.compdfkit.tools.common.pdf.config.CPDFConfiguration;
|
|
@@ -33,7 +34,7 @@ import io.flutter.plugin.common.MethodCall;
|
|
import io.flutter.plugin.common.MethodChannel;
|
|
import io.flutter.plugin.common.MethodChannel;
|
|
import io.flutter.plugin.platform.PlatformView;
|
|
import io.flutter.plugin.platform.PlatformView;
|
|
|
|
|
|
-public class CPDFViewCtrlFlutter implements PlatformView, MethodChannel.MethodCallHandler {
|
|
|
|
|
|
+public class CPDFViewCtrlFlutter implements PlatformView {
|
|
|
|
|
|
public static final String LOG_TAG = "ComPDFKit-Plugin";
|
|
public static final String LOG_TAG = "ComPDFKit-Plugin";
|
|
private FragmentContainerView fragmentContainerView;
|
|
private FragmentContainerView fragmentContainerView;
|
|
@@ -44,7 +45,7 @@ public class CPDFViewCtrlFlutter implements PlatformView, MethodChannel.MethodCa
|
|
|
|
|
|
private int viewId;
|
|
private int viewId;
|
|
|
|
|
|
- private MethodChannel methodChannel;
|
|
|
|
|
|
+ private CPDFViewCtrlPlugin methodChannel;
|
|
|
|
|
|
public CPDFViewCtrlFlutter(Context context, BinaryMessenger binaryMessenger, int viewId, Map<String, Object> creationParams) {
|
|
public CPDFViewCtrlFlutter(Context context, BinaryMessenger binaryMessenger, int viewId, Map<String, Object> creationParams) {
|
|
this.binaryMessenger = binaryMessenger;
|
|
this.binaryMessenger = binaryMessenger;
|
|
@@ -54,10 +55,10 @@ public class CPDFViewCtrlFlutter implements PlatformView, MethodChannel.MethodCa
|
|
Log.e(LOG_TAG, "CPDFViewCtrlFlutter:Create CPDFDocumentFragment");
|
|
Log.e(LOG_TAG, "CPDFViewCtrlFlutter:Create CPDFDocumentFragment");
|
|
initCPDFViewCtrl(context, creationParams);
|
|
initCPDFViewCtrl(context, creationParams);
|
|
|
|
|
|
- String channelName = "com.compdfkit.flutter.ui.pdfviewer." + viewId;
|
|
|
|
- Log.e(LOG_TAG, "CPDFViewCtrlFlutter: create MethodChannel:" + channelName);
|
|
|
|
- methodChannel = new MethodChannel(binaryMessenger, channelName);
|
|
|
|
- methodChannel.setMethodCallHandler(this);
|
|
|
|
|
|
+ methodChannel = new CPDFViewCtrlPlugin(context, binaryMessenger, viewId);
|
|
|
|
+ methodChannel.setDocumentFragment(documentFragment);
|
|
|
|
+ methodChannel.register();
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -87,20 +88,12 @@ public class CPDFViewCtrlFlutter implements PlatformView, MethodChannel.MethodCa
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void onViewDetachedFromWindow(@NonNull View v) {
|
|
public void onViewDetachedFromWindow(@NonNull View v) {
|
|
- documentFragment.pdfView.savePDF((s, uri) -> {
|
|
|
|
- Log.e(LOG_TAG, "CPDFViewCtrlFlutter: pdfView.savePDF Success");
|
|
|
|
- detachedFragment(context);
|
|
|
|
- }, e -> {
|
|
|
|
- Log.e(LOG_TAG, "CPDFViewCtrlFlutter: pdfView.savePDF Fail");
|
|
|
|
- e.printStackTrace();
|
|
|
|
- detachedFragment(context);
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
|
|
+ detachedFragment(context);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- private void detachedFragment(Context context){
|
|
|
|
|
|
+ private void detachedFragment(Context context) {
|
|
Log.e(LOG_TAG, "CPDFViewCtrlFlutter: Detached CPDFDocumentFragment from window");
|
|
Log.e(LOG_TAG, "CPDFViewCtrlFlutter: Detached CPDFDocumentFragment from window");
|
|
FragmentActivity fragmentActivity = getFragmentActivity(context);
|
|
FragmentActivity fragmentActivity = getFragmentActivity(context);
|
|
if (fragmentActivity != null) {
|
|
if (fragmentActivity != null) {
|
|
@@ -153,18 +146,4 @@ public class CPDFViewCtrlFlutter implements PlatformView, MethodChannel.MethodCa
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
|
|
|
|
- Log.e(LOG_TAG, "CPDFViewCtrlFlutter:onMethodCall:" + call.method);
|
|
|
|
- switch (call.method) {
|
|
|
|
- case "pdfviewer":
|
|
|
|
- result.success("rick");
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- Log.e(LOG_TAG, "CPDFViewCtrlFlutter:onMethodCall:notImplemented");
|
|
|
|
- result.notImplemented();
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|