Browse Source

PDFTool(Android) - v2.0.3.p0 新增截取功能

liuxiaolong 8 months ago
parent
commit
4e5b11d205

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


BIN
ComPDFKit_Repo/compdfkit/ComPDFKit.aar


+ 2 - 4
ComPDFKit_Tools/build.gradle

@@ -43,10 +43,8 @@ android {
 dependencies {
 
     api fileTree(include: ['*.jar'], dir: 'libs')
-//    api project(path:':ComPDFKit_Repo:compdfkit')
-//    api project(path:':ComPDFKit_Repo:compdfkit-ui')
-    api ('com.compdf:compdfkit:2.0.1')
-    api ('com.compdf:compdfkit-ui:2.0.1')
+    api project(path:':ComPDFKit_Repo:compdfkit')
+    api project(path:':ComPDFKit_Repo:compdfkit-ui')
     api 'com.github.bumptech.glide:glide:4.15.1'
     annotationProcessor 'com.github.bumptech.glide:compiler:4.15.1'
     api 'androidx.documentfile:documentfile:1.0.1'

+ 2 - 1
ComPDFKit_Tools/src/main/assets/tools_default_configuration.json

@@ -35,7 +35,8 @@
       "security",
       "flattened",
       "share",
-      "openDocument"
+      "openDocument",
+      "snip"
     ]
   },
   "annotationsConfig": {

+ 4 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/basic/fragment/CBasicPDFFragment.java

@@ -27,6 +27,7 @@ import com.compdfkit.tools.annotation.pdfproperties.pdfnote.CPDFtextAnnotImpl;
 import com.compdfkit.tools.common.contextmenu.CPDFContextMenuHelper;
 import com.compdfkit.tools.common.contextmenu.impl.CEditImageContextMenuView;
 import com.compdfkit.tools.common.contextmenu.impl.CEditTextContextMenuView;
+import com.compdfkit.tools.common.contextmenu.impl.CScreenShotContextMenuView;
 import com.compdfkit.tools.common.contextmenu.impl.CSearchReplaceContextMenuView;
 import com.compdfkit.tools.common.contextmenu.impl.CSignatureContextMenuView;
 import com.compdfkit.tools.common.utils.CFileUtils;
@@ -57,6 +58,7 @@ public class CBasicPDFFragment extends CPermissionFragment {
                 pdfView.getCPdfReaderView().setContextMenuShowListener(
                         new CPDFContextMenuHelper.Builder()
                                 .setSelectContentMenu(new CopyContextMenuView())
+                                .setScreenShotContextMenu(new CScreenShotContextMenuView())
                                 .create(pdfView));
                 break;
             case Annotation:
@@ -70,6 +72,7 @@ public class CBasicPDFFragment extends CPermissionFragment {
                                 .setEditTextContentMenu(new CEditTextContextMenuView())
                                 .setEditImageContentMenu(new CEditImageContextMenuView())
                                 .setSearchReplaceContextMenu(new CSearchReplaceContextMenuView())
+                                .setScreenShotContextMenu(new CScreenShotContextMenuView())
                                 .create(pdfView));
                 break;
             case Form:
@@ -82,6 +85,7 @@ public class CBasicPDFFragment extends CPermissionFragment {
                 pdfView.getCPdfReaderView().setContextMenuShowListener(
                         new CPDFContextMenuHelper.Builder()
                                 .setSignatureContextMenu(new CSignatureContextMenuView())
+                                .setScreenShotContextMenu(new CScreenShotContextMenuView())
                                 .create(pdfView));
                 break;
             default:

+ 18 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/contextmenu/CPDFContextMenuHelper.java

@@ -9,6 +9,7 @@
 
 package com.compdfkit.tools.common.contextmenu;
 
+import android.graphics.Bitmap;
 import android.graphics.PointF;
 import android.graphics.RectF;
 import android.os.Bundle;
@@ -32,6 +33,7 @@ import com.compdfkit.tools.common.contextmenu.impl.CLongPressContextMenuView;
 import com.compdfkit.tools.common.contextmenu.impl.CMarkupContextMenuView;
 import com.compdfkit.tools.common.contextmenu.impl.CPushButtonContextMenuView;
 import com.compdfkit.tools.common.contextmenu.impl.CRadioButtonContextMenuView;
+import com.compdfkit.tools.common.contextmenu.impl.CScreenShotContextMenuView;
 import com.compdfkit.tools.common.contextmenu.impl.CSearchReplaceContextMenuView;
 import com.compdfkit.tools.common.contextmenu.impl.CSelectContentContextMenuView;
 import com.compdfkit.tools.common.contextmenu.impl.CShapeContextMenuView;
@@ -52,6 +54,7 @@ import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuListBoxProvi
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuLongPressProvider;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuMarkupProvider;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuRadioButtonProvider;
+import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuScreenShotProvider;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuSearchReplaceProvider;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuSelectContentProvider;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuSoundContentProvider;
@@ -287,6 +290,14 @@ public class CPDFContextMenuHelper extends CPDFContextMenuShowHelper {
         return super.getSearchReplaceContentView(cpdfPageView, layoutInflater);
     }
 
+    @Override
+    public View getScreenShotContentView(CPDFPageView cpdfPageView, LayoutInflater layoutInflater, RectF rectF) {
+        if (helperParams.screenShotProvider != null){
+            return helperParams.screenShotProvider.getScreenShotContentView(this, cpdfPageView, layoutInflater, rectF);
+        }
+        return super.getScreenShotContentView(cpdfPageView, layoutInflater, rectF);
+    }
+
     @Override
     public void dismissContextMenu() {
         if (popupWindow != null) {
@@ -451,6 +462,11 @@ public class CPDFContextMenuHelper extends CPDFContextMenuShowHelper {
             return this;
         }
 
+        public Builder setScreenShotContextMenu(ContextMenuScreenShotProvider screenShotProvider){
+            this.params.screenShotProvider = screenShotProvider;
+            return this;
+        }
+
         public CPDFContextMenuHelper create(CPDFViewCtrl pdfView){
             return new CPDFContextMenuHelper(pdfView, params);
         }
@@ -466,6 +482,7 @@ public class CPDFContextMenuHelper extends CPDFContextMenuShowHelper {
             params.stampProvider = new CStampContextMenuView();
             params.linkProvider = new CLinkContextMenuView();
             params.searchReplaceProvider = new CSearchReplaceContextMenuView();
+            params.screenShotProvider = new CScreenShotContextMenuView();
             return this;
         }
 
@@ -478,6 +495,7 @@ public class CPDFContextMenuHelper extends CPDFContextMenuShowHelper {
             params.formSignatureProvider = new CSignatureContextMenuView();
             params.pushButtonProvider = new CPushButtonContextMenuView();
             params.selectContentProvider = new CopyContextMenuView();
+            params.screenShotProvider = new CScreenShotContextMenuView();
             return this;
         }
     }

+ 3 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/contextmenu/ContextMenuProviderParams.java

@@ -24,6 +24,7 @@ import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuLongPressPro
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuMarkupProvider;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuPushButtonProvider;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuRadioButtonProvider;
+import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuScreenShotProvider;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuSearchReplaceProvider;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuSelectContentProvider;
 import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuShapeProvider;
@@ -70,4 +71,6 @@ class ContextMenuProviderParams {
     public ContextMenuPushButtonProvider pushButtonProvider;
 
     public ContextMenuSearchReplaceProvider searchReplaceProvider;
+
+    public ContextMenuScreenShotProvider screenShotProvider;
 }

+ 52 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/contextmenu/impl/CScreenShotContextMenuView.java

@@ -0,0 +1,52 @@
+/**
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+ *
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+ * This notice may not be removed from this file.
+ */
+
+package com.compdfkit.tools.common.contextmenu.impl;
+
+
+import android.graphics.RectF;
+import android.view.LayoutInflater;
+import android.view.View;
+
+
+import com.compdfkit.tools.R;
+import com.compdfkit.tools.common.contextmenu.CPDFContextMenuHelper;
+import com.compdfkit.tools.common.contextmenu.interfaces.ContextMenuScreenShotProvider;
+import com.compdfkit.tools.common.contextmenu.provider.ContextMenuView;
+import com.compdfkit.tools.common.utils.CFileUtils;
+import com.compdfkit.tools.common.utils.date.CDateUtil;
+import com.compdfkit.tools.common.utils.image.CImageUtil;
+import com.compdfkit.ui.reader.CPDFPageView;
+import com.compdfkit.ui.reader.CPDFReaderView;
+
+import java.io.File;
+
+public class CScreenShotContextMenuView implements ContextMenuScreenShotProvider {
+
+
+    @Override
+    public View getScreenShotContentView(CPDFContextMenuHelper helper, CPDFPageView pageView, LayoutInflater inflater, RectF rectF) {
+        ContextMenuView menuView = new ContextMenuView(pageView.getContext());
+        menuView.addItem(R.string.tools_exit, v -> {
+            pageView.clearScreenShotRect();
+            helper.getReaderView().setTouchMode(CPDFReaderView.TouchMode.BROWSE);
+            helper.dismissContextMenu();
+        });
+        menuView.addItem(R.string.tools_share, v -> {
+            String fileName = "screenshot_"+ CDateUtil.getDataTime(CDateUtil.NORMAL_DATE_FORMAT)+".png";
+            String screenShotFilePath = CImageUtil.saveBitmap(pageView.getContext(), fileName, pageView.getScreenshotBitmap());
+            CFileUtils.shareFile(menuView.getContext(), pageView.getContext().getString(R.string.tools_share), "image/*", new File(screenShotFilePath));
+            helper.getReaderView().setTouchMode(CPDFReaderView.TouchMode.BROWSE);
+            pageView.clearScreenShotRect();
+            helper.dismissContextMenu();
+        });
+        return menuView;
+    }
+
+}

+ 26 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/contextmenu/interfaces/ContextMenuScreenShotProvider.java

@@ -0,0 +1,26 @@
+/**
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+ *
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+ * This notice may not be removed from this file.
+ */
+
+package com.compdfkit.tools.common.contextmenu.interfaces;
+
+
+import android.graphics.Bitmap;
+import android.graphics.RectF;
+import android.view.LayoutInflater;
+import android.view.View;
+
+import com.compdfkit.tools.common.contextmenu.CPDFContextMenuHelper;
+import com.compdfkit.ui.proxy.CPDFInkAnnotImpl;
+import com.compdfkit.ui.reader.CPDFPageView;
+
+public interface ContextMenuScreenShotProvider {
+
+    View getScreenShotContentView(CPDFContextMenuHelper helper, CPDFPageView pageView, LayoutInflater inflater, RectF rectF);
+
+}

+ 23 - 1
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/pdf/CPDFDocumentFragment.java

@@ -16,8 +16,8 @@ import static com.compdfkit.tools.contenteditor.CEditToolbar.SELECT_AREA_TEXT;
 
 import android.Manifest;
 import android.content.Context;
-import android.content.Intent;
 import android.content.res.Configuration;
+import android.graphics.Color;
 import android.graphics.Paint;
 import android.net.Uri;
 import android.os.Build;
@@ -40,6 +40,7 @@ import androidx.core.content.ContextCompat;
 import com.compdfkit.core.annotation.CPDFAnnotation;
 import com.compdfkit.core.annotation.form.CPDFSignatureWidget;
 import com.compdfkit.core.document.CPDFDocument;
+import com.compdfkit.core.edit.CPDFEditConfig;
 import com.compdfkit.core.edit.CPDFEditManager;
 import com.compdfkit.core.edit.CPDFEditPage;
 import com.compdfkit.core.page.CPDFPage;
@@ -490,6 +491,16 @@ public class CPDFDocumentFragment extends CBasicPDFFragment {
         }
         editToolBar.initWithPDFView(pdfView);
         editToolBar.setEditMode(false);
+        CPDFEditConfig editConfig = pdfView.getCPdfReaderView()
+                .getEditManager()
+                .getEditConfigBuilder()
+                    .setScreenshotRectColor(Color.TRANSPARENT)
+                    .setScreenshotBorderColor(ContextCompat.getColor(getContext(), R.color.tools_color_accent))
+                    .setScreenshotBorderDash(new float[]{8.0F, 4F})
+                    .build();
+
+        pdfView.getCPdfReaderView().getEditManager().updateEditConfig(editConfig);
+
         editToolBar.setEditPropertyBtnClickListener((view) -> {
             int type = pdfView.getCPdfReaderView().getSelectAreaType();
             CStyleType styleType = CStyleType.UNKNOWN;
@@ -630,6 +641,17 @@ public class CPDFDocumentFragment extends CBasicPDFFragment {
                             }
                         });
                         break;
+                    case Snip:
+                        menuWindow.addItem(R.drawable.tools_ic_snap, R.string.tools_snap, v -> {
+                            CPDFReaderView readerView = pdfView.getCPdfReaderView();
+                            readerView.setTouchMode(CPDFReaderView.TouchMode.SCREENSHOT);
+//                            readerView.setScreenShotLisener((cpdfPageView, bitmap) -> {
+//                                Log.e("ComPDFKit", "截屏:bitmap:(" + bitmap.getWidth() + " * " + bitmap.getHeight() + ")");
+//                                readerView.setTouchMode(CPDFReaderView.TouchMode.BROWSE);
+////                                CImageUtil.saveBitmap(getContext(), bitmap);
+//                            });
+                        });
+                        break;
                     default:
                         break;
                 }

+ 3 - 1
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/pdf/config/ToolbarConfig.java

@@ -70,7 +70,9 @@ public class ToolbarConfig implements Serializable {
         Share,
         OpenDocument,
 
-        Flattened;
+        Flattened,
+
+        Snip;
 
         public static MenuAction fromString(String str) {
             try {

+ 21 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/utils/image/CImageUtil.java

@@ -9,10 +9,16 @@
 
 package com.compdfkit.tools.common.utils.image;
 
+import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.view.View;
 
+import com.compdfkit.tools.common.utils.CFileUtils;
+import com.compdfkit.tools.common.utils.date.CDateUtil;
+
+import java.io.File;
+
 public class CImageUtil {
 
 
@@ -24,5 +30,20 @@ public class CImageUtil {
         return CBitmapUtil.cropTransparent(bitmap);
     }
 
+    public static String saveBitmap(Context context, String fileName, Bitmap bitmap){
+        if (bitmap == null){
+            return null;
+        }
+        File file = new File(context.getFilesDir(), CFileUtils.CACHE_FOLDER);
+        file.mkdirs();
+        File bitmapFile =  new File(file, fileName);
+        boolean success = CBitmapUtil.saveBitmapToFile(bitmap,bitmapFile, 100, Bitmap.CompressFormat.PNG);
+        if (success){
+            return bitmapFile.getAbsolutePath();
+        }else {
+            return null;
+        }
+    }
+
 
 }

+ 10 - 0
ComPDFKit_Tools/src/main/res/drawable/tools_ic_snap.xml

@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="20dp"
+    android:height="20dp"
+    android:viewportWidth="20"
+    android:viewportHeight="20">
+  <path
+      android:pathData="M6.114,2.471H2V6.578H6.114V2.471ZM18,2.471H13.886V6.578H18V2.471ZM6.114,13.422H2V17.529H6.114V13.422ZM18,13.422H13.886V17.529H18V13.422ZM9.086,5.209V3.84H7.257V5.209H9.086ZM12.743,5.209V3.84H10.915V5.209H12.743ZM4.743,9.087H3.371V7.262H4.743V9.087ZM4.743,12.738H3.371V10.913H4.743V12.738ZM15.257,9.087H16.628V7.262H15.257V9.087ZM15.257,12.738H16.628V10.913H15.257V12.738ZM9.086,14.791V16.16H7.257V14.791H9.086ZM12.743,14.791V16.16H10.915V14.791H12.743Z"
+      android:fillColor="#43474D"
+      android:fillType="evenOdd"/>
+</vector>

+ 2 - 0
ComPDFKit_Tools/src/main/res/values-zh-rCN/tools_strings.xml

@@ -489,5 +489,7 @@
     <string name="tools_font_style_italic">斜体</string>
     <string name="tools_font_style_bold_italic">加粗&amp;斜体</string>
 
+    <string name="tools_exit">退出</string>
+    <string name="tools_snap">截取</string>
 
 </resources>

+ 4 - 0
ComPDFKit_Tools/src/main/res/values/tools_strings.xml

@@ -495,4 +495,8 @@
     <string name="tools_font_style_italic">Italic</string>
     <string name="tools_font_style_bold_italic">Bold&amp;Italic</string>
 
+    <string name="tools_snap">Snap</string>
+
+    <string name="tools_exit">Exit</string>
+
 </resources>

+ 3 - 3
config.gradle

@@ -3,10 +3,10 @@ ext {
             COMPILESDK: 33,
             MINSDK: 21,
             TARGETSDK: 33,
-            VERSIONCODE: 1011
+            VERSIONCODE: 1012
     ]
     sdk = [
-            COMPDFKIT_SDK_VERSION : "2.0.1",
-            COMPDFKIT_SDK_BUILD_TAG : "build_beta_2.0.1_f95eee300_202404241139"
+            COMPDFKIT_SDK_VERSION : "2.0.3",
+            COMPDFKIT_SDK_BUILD_TAG : "build_beta_2.0.3_f95eee300_202404241139"
     ]
 }