Browse Source

PDFTools(Android) - 1.Bug修复

liuxiaolong 1 year ago
parent
commit
9a67b3cfe8

+ 2 - 2
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfannotationbar/CAnnotationToolbar.java

@@ -233,7 +233,7 @@ public class CAnnotationToolbar extends FrameLayout {
             if (pdfView != null) {
                 pdfView.getCPdfReaderView().getUndoManager().undo();
             }
-        } catch (CPDFUndoFailedException e) {
+        } catch (Exception e) {
         }
     }
 
@@ -242,7 +242,7 @@ public class CAnnotationToolbar extends FrameLayout {
             if (pdfView != null) {
                 pdfView.getCPdfReaderView().getUndoManager().redo();
             }
-        } catch (CPDFRedoFailedException e) {
+        } catch (Exception e) {
 
         }
     }

+ 11 - 6
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/contextmenu/impl/CEditImageContextMenuView.java

@@ -16,6 +16,7 @@ import com.compdfkit.tools.common.contextmenu.CPDFContextMenuHelper;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuEditImageProvider;
 import com.compdfkit.tools.common.contextmenu.provider.ContextMenuMultipleLineView;
 import com.compdfkit.tools.common.contextmenu.provider.ContextMenuView;
+import com.compdfkit.tools.common.utils.CToastUtil;
 import com.compdfkit.tools.common.views.pdfproperties.pdfstyle.CAnnotStyle;
 import com.compdfkit.tools.common.views.pdfproperties.pdfstyle.CStyleDialogFragment;
 import com.compdfkit.tools.common.views.pdfproperties.pdfstyle.CStyleType;
@@ -64,12 +65,16 @@ public class CEditImageContextMenuView implements ContextMenuEditImageProvider {
             }
         } );
         menuView.addItem(R.string.tools_context_menu_image_extract, 1,v -> {
-            String sdPath = pageView.getContext().getFilesDir().getAbsolutePath();
-            File file = new File(sdPath, System.currentTimeMillis() + ".png");
-            pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.EXTRACT_IMAGE, file.getAbsolutePath());
-            helper.dismissContextMenu();
-            Toast.makeText(pageView.getContext(), R.string.tools_export_success, Toast.LENGTH_LONG).show();
-        } );
+            try{
+                String sdPath = pageView.getContext().getFilesDir().getAbsolutePath();
+                File file = new File(sdPath, System.currentTimeMillis() + ".png");
+                pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.EXTRACT_IMAGE, file.getAbsolutePath());
+                helper.dismissContextMenu();
+                Toast.makeText(pageView.getContext(), R.string.tools_export_success, Toast.LENGTH_LONG).show();
+            }catch (Exception e){
+                CToastUtil.showLongToast(pageView.getContext(), R.string.tools_page_edit_extract_fail);
+            }
+                    } );
         menuView.addSecondView();
         View view = LayoutInflater.from(pageView.getContext()).inflate(R.layout.tools_context_menu_image_item_layout, null);
         view.setOnClickListener(v-> {

+ 2 - 2
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/utils/activitycontracts/CImageResultContracts.java

@@ -54,11 +54,11 @@ public class CImageResultContracts extends ActivityResultContract<CImageResultCo
             intent.setType("image/*");
             return intent;
         } else {
-            Intent intentCamera = new Intent();
+            Intent intentCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                 intentCamera.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
             }
-            intentCamera.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
+            intentCamera.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
             File file = new File(context.getFilesDir(), "compdfkit" + File.separator + "temp" + File.separator +"camera_" + CDateUtil.getDataTime(CDateUtil.NORMAL_DATE_FORMAT) + ".png");
             file.getParentFile().mkdirs();
             cameraUri = CFileUtils.getUriBySystem(context, file);

+ 10 - 4
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/pdfstyle/manager/provider/CEditSelectionsProvider.java

@@ -15,6 +15,8 @@ import com.compdfkit.core.annotation.CPDFTextAttribute;
 import com.compdfkit.core.edit.CPDFEditArea;
 import com.compdfkit.core.edit.CPDFEditImageArea;
 import com.compdfkit.core.edit.CPDFEditTextArea;
+import com.compdfkit.tools.R;
+import com.compdfkit.tools.common.utils.CToastUtil;
 import com.compdfkit.tools.common.views.pdfproperties.pdfstyle.CAnnotStyle;
 import com.compdfkit.tools.common.views.pdfproperties.pdfstyle.CStyleType;
 import com.compdfkit.ui.edit.CPDFEditSelections;
@@ -135,10 +137,14 @@ public class CEditSelectionsProvider implements CStyleProvider {
                         }
                         break;
                     case Export:
-                        if (pageView != null) {
-                            String sdPath = pageView.getContext().getFilesDir().getAbsolutePath();
-                            File file = new File(sdPath, System.currentTimeMillis() + ".png");
-                            pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.EXTRACT_IMAGE, file.getAbsolutePath());
+                        try {
+                            if (pageView != null) {
+                                String sdPath = pageView.getContext().getFilesDir().getAbsolutePath();
+                                File file = new File(sdPath, System.currentTimeMillis() + ".png");
+                                pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.EXTRACT_IMAGE, file.getAbsolutePath());
+                            }
+                        }catch (Exception e){
+                            CToastUtil.showLongToast(pageView.getContext(), R.string.tools_page_edit_extract_fail);
                         }
                         break;
                     default:

+ 49 - 35
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/docseditor/pdfpageeditinsert/CInsertBlankPageDialogFragment.java

@@ -1,6 +1,7 @@
 package com.compdfkit.tools.docseditor.pdfpageeditinsert;
 
 import android.annotation.SuppressLint;
+import android.os.Build;
 import android.os.Bundle;
 import android.text.Editable;
 import android.text.TextUtils;
@@ -45,14 +46,17 @@ public class CInsertBlankPageDialogFragment extends BottomSheetDialogFragment im
     private RadioButton rbToPageLocationAfter;
     private AppCompatEditText etInputPageIndex;
 
+    private RadioGroup rgInsertTo;
+
     private CPageEditBar.OnEditDoneCallback onEditDoneCallback;
 
     private int pageIndex;
-    public static CInsertBlankPageDialogFragment newInstance(){
+
+    public static CInsertBlankPageDialogFragment newInstance() {
         return new CInsertBlankPageDialogFragment();
     }
 
-    public void initWithPDFView(CPDFViewCtrl pdfView){
+    public void initWithPDFView(CPDFViewCtrl pdfView) {
         this.pdfView = pdfView;
     }
 
@@ -65,9 +69,9 @@ public class CInsertBlankPageDialogFragment extends BottomSheetDialogFragment im
     @Override
     public void onStart() {
         super.onStart();
-        if (!CViewUtils.isLandScape(getContext())){
+        if (!CViewUtils.isLandScape(getContext())) {
             CDialogFragmentUtil.setDimAmount(getDialog(), 0F);
-        }else {
+        } else {
             CDialogFragmentUtil.setDimAmount(getDialog(), 0.2F);
         }
         BottomSheetBehavior<View> behavior = BottomSheetBehavior.from((View) getView().getParent());
@@ -91,19 +95,25 @@ public class CInsertBlankPageDialogFragment extends BottomSheetDialogFragment im
         rbToPageLocationBefore = rootView.findViewById(R.id.rb_tools_edit_page_insert_location_before);
         rbToPageLocationAfter = rootView.findViewById(R.id.rb_tools_edit_page_insert_location_after);
         etInputPageIndex = rootView.findViewById(R.id.et_tool_edit_page_enterpage);
-
-        rbHomePage.setOnClickListener(this);
-        rbLastPage.setOnClickListener(this);
-        rbToPageLocationBefore.setOnClickListener(this);
-        rbToPageLocationAfter.setOnClickListener(this);
-        etInputPageIndex.setOnFocusChangeListener((view, b) -> {
-            if (b) {
+        rgInsertTo = rootView.findViewById(R.id.rp_tools_edit_page_insertpage_location);
+        etInputPageIndex.setOnFocusChangeListener((view, focus) -> {
+            if (!focus) {
+                CViewUtils.hideKeyboard(etInputPageIndex);
+            }else {
+                if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1){
+                    if (rbHomePage.isChecked() || rbLastPage.isChecked()) {
+                        rbToPageLocationBefore.setChecked(true);
+                        CViewUtils.showKeyboard(etInputPageIndex);
+                    }
+                }
+            }
+        });
+        etInputPageIndex.setOnClickListener(v -> {
+            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
                 if (rbHomePage.isChecked() || rbLastPage.isChecked()) {
                     rbToPageLocationBefore.setChecked(true);
                     CViewUtils.showKeyboard(etInputPageIndex);
                 }
-            } else {
-                CViewUtils.hideKeyboard(etInputPageIndex);
             }
         });
         etInputPageIndex.addTextChangedListener(new TextWatcher() {
@@ -137,6 +147,28 @@ public class CInsertBlankPageDialogFragment extends BottomSheetDialogFragment im
         ivDirectionH.setOnClickListener(this);
         ivRightArrow.setOnClickListener(this);
 
+        rgInsertTo.setOnCheckedChangeListener((group, checkedId) -> {
+            if (checkedId == R.id.rb_tools_edit_page_insert_location_homepage) {
+                etInputPageIndex.clearFocus();
+                updateDoneBtnStatus();
+            } else if (checkedId == R.id.rb_tools_edit_page_insert_location_lastpage) {
+                etInputPageIndex.clearFocus();
+                updateDoneBtnStatus();
+            } else if (checkedId == R.id.rb_tools_edit_page_insert_location_before) {
+                if (!etInputPageIndex.isFocused()) {
+                    etInputPageIndex.requestFocus();
+                    CViewUtils.showKeyboard(etInputPageIndex);
+                }
+                updateDoneBtnStatus();
+            } else if (checkedId == R.id.rb_tools_edit_page_insert_location_after) {
+                if (!etInputPageIndex.isFocused()) {
+                    etInputPageIndex.requestFocus();
+                    CViewUtils.showKeyboard(etInputPageIndex);
+                }
+                updateDoneBtnStatus();
+            }
+        });
+
         return rootView;
     }
 
@@ -173,7 +205,7 @@ public class CInsertBlankPageDialogFragment extends BottomSheetDialogFragment im
             }
         }
         int pageCount = document.getPageCount();
-        if (pageIndex > pageCount){
+        if (pageIndex > pageCount) {
             CToastUtil.showLongToast(getContext(), R.string.tools_page_choose_skip_input_error);
             return;
         }
@@ -211,7 +243,7 @@ public class CInsertBlankPageDialogFragment extends BottomSheetDialogFragment im
             return;
         }
         for (int i = 0; i < sizeArr.length; i++) {
-            RadioButton radio = (RadioButton)LayoutInflater.from(getContext()).inflate(R.layout.tools_pageedit_pagesize_item, null);
+            RadioButton radio = (RadioButton) LayoutInflater.from(getContext()).inflate(R.layout.tools_pageedit_pagesize_item, null);
             RadioGroup.LayoutParams layoutParams =
                     new RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, CDimensUtils.dp2px(getContext(), 50));
             radio.setLayoutParams(layoutParams);
@@ -223,9 +255,9 @@ public class CInsertBlankPageDialogFragment extends BottomSheetDialogFragment im
             radio.setText(sizeArr[i]);
             radio.setTag(sizeValueArr[i]);
             radio.setOnClickListener(view -> {
-                tvCurPageSize.setText(((RadioButton)view).getText());
+                tvCurPageSize.setText(((RadioButton) view).getText());
             });
-            rgPageSize.addView(radio,i);
+            rgPageSize.addView(radio, i);
         }
     }
 
@@ -257,24 +289,6 @@ public class CInsertBlankPageDialogFragment extends BottomSheetDialogFragment im
             } else {
                 clPagesize.setVisibility(View.GONE);
             }
-        } else if (id == R.id.rb_tools_edit_page_insert_location_homepage) {
-            etInputPageIndex.clearFocus();
-            updateDoneBtnStatus();
-        } else if (id == R.id.rb_tools_edit_page_insert_location_lastpage) {
-            etInputPageIndex.clearFocus();
-            updateDoneBtnStatus();
-        } else if (id == R.id.rb_tools_edit_page_insert_location_before) {
-            if (!etInputPageIndex.isFocused()) {
-                etInputPageIndex.requestFocus();
-                CViewUtils.showKeyboard(etInputPageIndex);
-            }
-            updateDoneBtnStatus();
-        } else if (id == R.id.rb_tools_edit_page_insert_location_after) {
-            if (!etInputPageIndex.isFocused()) {
-                etInputPageIndex.requestFocus();
-                CViewUtils.showKeyboard(etInputPageIndex);
-            }
-            updateDoneBtnStatus();
         }
     }
 

+ 55 - 38
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/docseditor/pdfpageeditinsert/CInsertPdfPageDialogFragment.java

@@ -5,6 +5,7 @@ import static com.compdfkit.core.document.CPDFDocument.PDFDocumentError.PDFDocum
 
 import android.content.Intent;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
 import android.text.Editable;
 import android.text.TextUtils;
@@ -13,6 +14,7 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.RadioButton;
+import android.widget.RadioGroup;
 import android.widget.Toast;
 
 import androidx.activity.result.ActivityResultLauncher;
@@ -47,6 +49,9 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
     private CPDFViewCtrl pdfView;
     private AppCompatTextView tvFilename;
     private AppCompatImageView ivFileNameRight;
+
+    private RadioGroup rgPageRange;
+
     private RadioButton rbFromPageLocationAll;
     private RadioButton rbFromPageLocationOdd;
     private RadioButton rbFromPageLocationEven;
@@ -57,6 +62,9 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
     private RadioButton rbToPageLocationLast;
     private RadioButton rbToPageLocationBefore;
     private RadioButton rbToPageLocationAfter;
+
+    private RadioGroup rgInsertTo;
+
     private AppCompatEditText etToInputPageIndex;
 
     private CPageEditBar.OnEditDoneCallback onEditDoneCallback;
@@ -128,6 +136,7 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
         tvFilename = rootView.findViewById(R.id.iv_tool_insert_page_filename);
 
         ivFileNameRight = rootView.findViewById(R.id.iv_tool_insert_page_right);
+        rgPageRange = rootView.findViewById(R.id.rp_tools_edit_page_insertpage_from_location);
         rbFromPageLocationAll = rootView.findViewById(R.id.rb_tools_edit_page_insert_location_from_all);
         rbFromPageLocationOdd = rootView.findViewById(R.id.rb_tools_edit_page_insert_location_from_odd);
         rbFromPageLocationEven = rootView.findViewById(R.id.rb_tools_edit_page_insert_location_from_even);
@@ -138,27 +147,43 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
         rbToPageLocationBefore = rootView.findViewById(R.id.rb_tools_edit_page_insert_location_before);
         rbToPageLocationAfter = rootView.findViewById(R.id.rb_tools_edit_page_insert_location_after);
         etToInputPageIndex = rootView.findViewById(R.id.et_tool_edit_page_enterpage);
-
-        rbFromPageLocationAll.setOnClickListener(this);
-        rbFromPageLocationOdd.setOnClickListener(this);
-        rbFromPageLocationEven.setOnClickListener(this);
-        rbFromPageLocationSpecify.setOnClickListener(this);
-
-        rbToPageLocationHome.setOnClickListener(this);
-        rbToPageLocationLast.setOnClickListener(this);
-        rbToPageLocationBefore.setOnClickListener(this);
-        rbToPageLocationAfter.setOnClickListener(this);
+        rgInsertTo = rootView.findViewById(R.id.rp_tools_edit_page_insertpage_location);
 
         etFromInputPageIndex.setOnFocusChangeListener((view, b) -> {
             if (b) {
+                if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
+                    if (!rbFromPageLocationSpecify.isChecked()) {
+                        rbFromPageLocationSpecify.setChecked(true);
+                        CViewUtils.showKeyboard(etFromInputPageIndex);
+                    }
+                }
+            } else {
+                CViewUtils.hideKeyboard(etFromInputPageIndex);
+            }
+        });
+        etFromInputPageIndex.setOnClickListener(v -> {
+            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
                 if (!rbFromPageLocationSpecify.isChecked()) {
                     rbFromPageLocationSpecify.setChecked(true);
                     CViewUtils.showKeyboard(etFromInputPageIndex);
                 }
-            } else {
-                CViewUtils.hideKeyboard(etFromInputPageIndex);
             }
         });
+        rgPageRange.setOnCheckedChangeListener((group, checkedId) -> {
+            if (checkedId == R.id.rb_tools_edit_page_insert_location_from_all) {
+                etFromInputPageIndex.clearFocus();
+            } else if (checkedId == R.id.rb_tools_edit_page_insert_location_from_odd) {
+                etFromInputPageIndex.clearFocus();
+            } else if (checkedId == R.id.rb_tools_edit_page_insert_location_from_even) {
+                etFromInputPageIndex.clearFocus();
+            } else if (checkedId == R.id.rb_tools_edit_page_insert_location_from_specify) {
+                if (!etFromInputPageIndex.isFocused()) {
+                    etFromInputPageIndex.requestFocus();
+                    CViewUtils.showKeyboard(etFromInputPageIndex);
+                }
+            }
+            updateDoneBtnStatus();
+        });
         etFromInputPageIndex.addTextChangedListener(new TextWatcher() {
             @Override
             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@@ -186,6 +211,24 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
                 CViewUtils.hideKeyboard(etToInputPageIndex);
             }
         });
+        rgInsertTo.setOnCheckedChangeListener((group, checkedId) -> {
+            if (checkedId == R.id.rb_tools_edit_page_insert_location_homepage) {
+                etToInputPageIndex.clearFocus();
+            } else if (checkedId == R.id.rb_tools_edit_page_insert_location_lastpage) {
+                etToInputPageIndex.clearFocus();
+            } else if (checkedId == R.id.rb_tools_edit_page_insert_location_before) {
+                if (!etToInputPageIndex.isFocused()) {
+                    etToInputPageIndex.requestFocus();
+                    CViewUtils.showKeyboard(etToInputPageIndex);
+                }
+            } else if (checkedId == R.id.rb_tools_edit_page_insert_location_after) {
+                if (!etToInputPageIndex.isFocused()) {
+                    etToInputPageIndex.requestFocus();
+                    CViewUtils.showKeyboard(etToInputPageIndex);
+                }
+            }
+            updateDoneBtnStatus();
+        });
         etToInputPageIndex.addTextChangedListener(new TextWatcher() {
             @Override
             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@@ -390,33 +433,7 @@ public class CInsertPdfPageDialogFragment extends BottomSheetDialogFragment impl
         int id = view.getId();
         if (id == R.id.iv_tool_insert_page_right) {
             selectDocumentLauncher.launch(CFileUtils.getContentIntent());
-        } else if (id == R.id.rb_tools_edit_page_insert_location_from_all) {
-            etFromInputPageIndex.clearFocus();
-        } else if (id == R.id.rb_tools_edit_page_insert_location_from_odd) {
-            etFromInputPageIndex.clearFocus();
-        } else if (id == R.id.rb_tools_edit_page_insert_location_from_even) {
-            etFromInputPageIndex.clearFocus();
-        } else if (id == R.id.rb_tools_edit_page_insert_location_from_specify) {
-            if (!etFromInputPageIndex.isFocused()) {
-                etFromInputPageIndex.requestFocus();
-                CViewUtils.showKeyboard(etFromInputPageIndex);
-            }
-        } else if (id == R.id.rb_tools_edit_page_insert_location_homepage) {
-            etToInputPageIndex.clearFocus();
-        } else if (id == R.id.rb_tools_edit_page_insert_location_lastpage) {
-            etToInputPageIndex.clearFocus();
-        } else if (id == R.id.rb_tools_edit_page_insert_location_before) {
-            if (!etToInputPageIndex.isFocused()) {
-                etToInputPageIndex.requestFocus();
-                CViewUtils.showKeyboard(etToInputPageIndex);
-            }
-        } else if (id == R.id.rb_tools_edit_page_insert_location_after) {
-            if (!etToInputPageIndex.isFocused()) {
-                etToInputPageIndex.requestFocus();
-                CViewUtils.showKeyboard(etToInputPageIndex);
-            }
         }
-        updateDoneBtnStatus();
     }
 
     public void setOnEditDoneCallback(CPageEditBar.OnEditDoneCallback callback) {