Преглед на файлове

PDFTools(Android) - 1.自定义Form FieldName 2.综合demo模式切换

liuxiaolong преди 1 година
родител
ревизия
32024b0b7d

+ 12 - 2
compdfkit-demo/src/main/java/com/compdfkit/demo/MainActivity.java

@@ -26,6 +26,7 @@ import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
 import com.compdfkit.core.annotation.CPDFAnnotation;
+import com.compdfkit.core.annotation.form.CPDFWidget;
 import com.compdfkit.core.edit.CPDFEditManager;
 import com.compdfkit.demo.databinding.PdfSampleActivityBinding;
 import com.compdfkit.tools.common.activity.CBasicActivity;
@@ -150,7 +151,6 @@ public class MainActivity extends CBasicActivity {
         binding.pdfToolBar.selectMode(mode);
         binding.formToolBar.reset();
         resetContextMenu(binding.pdfView, mode);
-        binding.pdfView.setAllowAddAndEditAnnot(mode == CPreviewMode.Annotation || mode == CPreviewMode.Form);
         CPDFEditManager editManager = binding.pdfView.getCPdfReaderView().getEditManager();
         if (mode == CPreviewMode.Edit){
             if (editManager != null && !editManager.isEditMode()) {
@@ -161,11 +161,21 @@ public class MainActivity extends CBasicActivity {
                 editManager.endEdit();
             }
             switch (mode) {
+                case Viewer:
+                    binding.pdfView.getCPdfReaderView().setCurrentFocusedFormType(CPDFWidget.WidgetType.Widget_Unknown);
+                    binding.pdfView.getCPdfReaderView().setCurrentFocusedType(CPDFAnnotation.Type.UNKNOWN);
+                    binding.pdfView.getCPdfReaderView().setTouchMode(CPDFReaderView.TouchMode.BROWSE);
+                    binding.pdfView.setAllowAddAndEditAnnot(true);
+                    break;
                 case Annotation:
+                    binding.pdfView.setAllowAddAndEditAnnot(true);
                     binding.pdfView.resetAnnotationType();
                     break;
                 case Form:
-                    binding.pdfView.resetFormType();
+                    binding.pdfView.getCPdfReaderView().setCurrentFocusedFormType(CPDFWidget.WidgetType.Widget_Unknown);
+                    binding.pdfView.getCPdfReaderView().setCurrentFocusedType(CPDFAnnotation.Type.WIDGET);
+                    binding.pdfView.getCPdfReaderView().setTouchMode(CPDFReaderView.TouchMode.BROWSE);
+                    binding.pdfView.setAllowAddAndEditAnnot(true);
                     break;
                 default:break;
             }

BIN
compdfkit-repo/compdfkit-ui/ComPDFKit-UI.aar


+ 17 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfstyle/CPDFGlobalAnnotStyle.java

@@ -40,6 +40,7 @@ import com.compdfkit.ui.attribute.CPDFStrikeoutAttr;
 import com.compdfkit.ui.attribute.CPDFTextAttr;
 import com.compdfkit.ui.attribute.CPDFUnderlineAttr;
 import com.compdfkit.ui.attribute.IAttributeCallback;
+import com.compdfkit.ui.attribute.IAttributeUpdateCallback;
 import com.compdfkit.ui.attribute.form.CPDFCheckboxAttr;
 import com.compdfkit.ui.attribute.form.CPDFComboboxAttr;
 import com.compdfkit.ui.attribute.form.CPDFListboxAttr;
@@ -49,6 +50,8 @@ import com.compdfkit.ui.attribute.form.CPDFSignatureWidgetAttr;
 import com.compdfkit.ui.attribute.form.CPDFTextfieldAttr;
 import com.compdfkit.ui.reader.CPDFReaderView;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.LinkedHashSet;
 
 public class CPDFGlobalAnnotStyle extends CBasicOnStyleChangeListener implements CStyleProvider {
@@ -207,6 +210,7 @@ public class CPDFGlobalAnnotStyle extends CBasicOnStyleChangeListener implements
                     textFieldAttr.setBorderWidth(params.getBorderWidth());
                     textFieldAttr.setBorderColor(params.getLineColor());
                     textFieldAttr.setFillColor(params.getFillColor());
+                    textFieldAttr.setiAttributeUpdateCallback(() -> getDefaultFiledName("Text Field_"));
                     String textFieldFontName = CPDFTextAttribute.FontNameHelper.obtainFontName(params.getFontType(), params.isFontBold(), params.isFontItalic());
                     textFieldAttr.setTextAttribute(new CPDFTextAttribute(textFieldFontName, params.getFontSize(), params.getTextColor()));
                     textFieldAttr.setMultiline(params.isFormMultiLine());
@@ -233,6 +237,7 @@ public class CPDFGlobalAnnotStyle extends CBasicOnStyleChangeListener implements
                     checkboxAttr.setBorderColor(params.getLineColor());
                     checkboxAttr.setFillColor(params.getFillColor());
                     checkboxAttr.setChecked(params.isChecked());
+                    checkboxAttr.setiAttributeUpdateCallback(() -> getDefaultFiledName("Check Button_"));
                     break;
                 case FORM_RADIO_BUTTON:
                     CPDFRadiobuttonAttr radiobuttonAttr = attribute.getRadiobuttonAttr();
@@ -242,6 +247,7 @@ public class CPDFGlobalAnnotStyle extends CBasicOnStyleChangeListener implements
                     radiobuttonAttr.setBorderColor(params.getLineColor());
                     radiobuttonAttr.setFillColor(params.getFillColor());
                     radiobuttonAttr.setChecked(params.isChecked());
+                    radiobuttonAttr.setiAttributeUpdateCallback(() -> getDefaultFiledName("Radio Button_"));
                     break;
                 case FORM_LIST_BOX:
                     CPDFListboxAttr listBoxAttr = attribute.getListboxAttr();
@@ -250,6 +256,7 @@ public class CPDFGlobalAnnotStyle extends CBasicOnStyleChangeListener implements
                     listBoxAttr.setFillColor(params.getFillColor());
                     listBoxAttr.setBorderWidth(params.getBorderWidth());
                     listBoxAttr.setBorderColor(params.getLineColor());
+                    listBoxAttr.setiAttributeUpdateCallback(() -> getDefaultFiledName("List Choice_"));
                     break;
                 case FORM_COMBO_BOX:
                     CPDFComboboxAttr comboBoxAttr = attribute.getComboboxAttr();
@@ -258,6 +265,7 @@ public class CPDFGlobalAnnotStyle extends CBasicOnStyleChangeListener implements
                     comboBoxAttr.setFontColor(params.getTextColor());
                     comboBoxAttr.setBorderWidth(params.getBorderWidth());
                     comboBoxAttr.setBorderColor(params.getLineColor());
+                    comboBoxAttr.setiAttributeUpdateCallback(() -> getDefaultFiledName("Combox Choice_"));
                     break;
                 case FORM_PUSH_BUTTON:
                     CPDFPushButtonAttr pushButtonAttr = attribute.getPushButtonAttr();
@@ -267,6 +275,7 @@ public class CPDFGlobalAnnotStyle extends CBasicOnStyleChangeListener implements
                     pushButtonAttr.setFontColor(params.getTextColor());
                     pushButtonAttr.setFontSize(params.getFontSize());
                     pushButtonAttr.setButtonTitle(params.getFormDefaultValue());
+                    pushButtonAttr.setiAttributeUpdateCallback(() -> getDefaultFiledName("Push Button_"));
                     break;
                 case FORM_SIGNATURE_FIELDS:
                     CPDFSignatureWidgetAttr signatureWidgetAttr = attribute.getSignatureWidgetAttr();
@@ -274,6 +283,7 @@ public class CPDFGlobalAnnotStyle extends CBasicOnStyleChangeListener implements
                     signatureWidgetAttr.setBorderColor(params.getLineColor());
                     signatureWidgetAttr.setBorderStyle(CPDFWidget.BorderStyle.BS_Solid);
                     signatureWidgetAttr.setFillColor(params.getFillColor());
+                    signatureWidgetAttr.setiAttributeUpdateCallback(() -> getDefaultFiledName("Signature__"));
                     break;
                 default:
                     break;
@@ -457,4 +467,11 @@ public class CPDFGlobalAnnotStyle extends CBasicOnStyleChangeListener implements
         }
         return style;
     }
+
+    protected String getDefaultFiledName(String widgetType) {
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date = new Date(System.currentTimeMillis());
+        String dateStr = simpleDateFormat.format(date);
+        return String.format("%s%s", widgetType, dateStr);
+    }
 }