|
@@ -12,6 +12,7 @@ import androidx.core.content.ContextCompat;
|
|
|
|
|
|
import com.compdfkit.forms.databinding.FormPdfSampleActivityBinding;
|
|
|
import com.compdfkit.tools.common.basic.activity.CBasicPDFActivity;
|
|
|
+import com.compdfkit.tools.common.pdf.config.FormsConfig;
|
|
|
import com.compdfkit.tools.common.utils.CFileUtils;
|
|
|
import com.compdfkit.tools.common.utils.CPermissionUtil;
|
|
|
import com.compdfkit.tools.common.utils.activitycontracts.CSelectPDFDocumentResultContract;
|
|
@@ -30,6 +31,7 @@ import com.compdfkit.ui.proxy.form.CPDFPushbuttonWidgetImpl;
|
|
|
import com.compdfkit.ui.reader.CPDFReaderView;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
|
|
|
public class PDFFormSampleActivity extends CBasicPDFActivity {
|
|
|
|
|
@@ -90,7 +92,7 @@ public class PDFFormSampleActivity extends CBasicPDFActivity {
|
|
|
} else if (cpdfBaseAnnot instanceof CPDFComboboxWidgetImpl) {
|
|
|
// When the ComboBox form is created, display an editing dialog for adding list data
|
|
|
CPDFAnnotationManager annotationManager = new CPDFAnnotationManager();
|
|
|
- annotationManager.showFormComboBoxEditFragment(getSupportFragmentManager(), cpdfBaseAnnot, cpdfPageView,true);
|
|
|
+ annotationManager.showFormComboBoxEditFragment(getSupportFragmentManager(), cpdfBaseAnnot, cpdfPageView, true);
|
|
|
} else if (cpdfBaseAnnot instanceof CPDFPushbuttonWidgetImpl) {
|
|
|
// When the PushButton form is created, display a dialog for editing the action method
|
|
|
CPDFAnnotationManager annotationManager = new CPDFAnnotationManager();
|
|
@@ -102,11 +104,13 @@ public class PDFFormSampleActivity extends CBasicPDFActivity {
|
|
|
}
|
|
|
|
|
|
private void initToolBarView() {
|
|
|
- binding.pdfToolBar.addMode(CPreviewMode.Form);
|
|
|
+ binding.pdfToolBar.addModes(Arrays.asList(CPreviewMode.Viewer,
|
|
|
+ CPreviewMode.Form));
|
|
|
+ binding.pdfToolBar.selectMode(CPreviewMode.Form);
|
|
|
binding.pdfToolBar.setPreviewModeChangeListener((mode) -> {
|
|
|
- if (mode == CPreviewMode.Viewer){
|
|
|
+ if (mode == CPreviewMode.Viewer) {
|
|
|
binding.pdfView.setViewMode(CPDFReaderView.ViewMode.VIEW);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
binding.pdfView.setViewMode(CPDFReaderView.ViewMode.FORM);
|
|
|
}
|
|
|
screenManager.changeWindowStatus(mode);
|
|
@@ -172,15 +176,15 @@ public class PDFFormSampleActivity extends CBasicPDFActivity {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void requestStoragePermissions(){
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
|
|
|
+ private void requestStoragePermissions() {
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
|
CPermissionUtil.openManageAllFileAppSettings(this);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
multiplePermissionResultLauncher.launch(STORAGE_PERMISSIONS, result -> {
|
|
|
if (CPermissionUtil.hasStoragePermissions(this)) {
|
|
|
selectDocument();
|
|
|
- }else {
|
|
|
- if (!CPermissionUtil.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)){
|
|
|
+ } else {
|
|
|
+ if (!CPermissionUtil.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
|
showPermissionsRequiredDialog();
|
|
|
}
|
|
|
}
|
|
@@ -190,6 +194,10 @@ public class PDFFormSampleActivity extends CBasicPDFActivity {
|
|
|
|
|
|
private void initFormToolbar() {
|
|
|
binding.formToolBar.initWithPDFView(binding.pdfView);
|
|
|
+ binding.formToolBar.setTools(Arrays.asList(
|
|
|
+ FormsConfig.FormsTools.Undo,
|
|
|
+ FormsConfig.FormsTools.Redo
|
|
|
+ ));
|
|
|
binding.formToolBar.setFragmentManager(getSupportFragmentManager());
|
|
|
}
|
|
|
|
|
@@ -213,7 +221,7 @@ public class PDFFormSampleActivity extends CBasicPDFActivity {
|
|
|
}
|
|
|
|
|
|
private void selectDocument() {
|
|
|
- if (binding.pdfView.getCPdfReaderView().getPDFDocument() == null){
|
|
|
+ if (binding.pdfView.getCPdfReaderView().getPDFDocument() == null) {
|
|
|
selectDocumentLauncher.launch(null);
|
|
|
return;
|
|
|
}
|
|
@@ -241,7 +249,8 @@ public class PDFFormSampleActivity extends CBasicPDFActivity {
|
|
|
|
|
|
@Override
|
|
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
|
|
- binding.pdfView.savePDF(null,e -> {});
|
|
|
+ binding.pdfView.savePDF(null, e -> {
|
|
|
+ });
|
|
|
super.onSaveInstanceState(outState);
|
|
|
}
|
|
|
|
|
@@ -249,7 +258,7 @@ public class PDFFormSampleActivity extends CBasicPDFActivity {
|
|
|
public void onBackPressed() {
|
|
|
if (binding.pdfView != null) {
|
|
|
binding.pdfView.savePDF((filePath, pdfUri) -> super.onBackPressed(), e -> super.onBackPressed());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
super.onBackPressed();
|
|
|
}
|
|
|
}
|