Browse Source

PDFTool(Android) - 1.修复跳转弹窗暗色模式问题 2.更改导出图片路径到外部目录

liuxiaolong 1 year ago
parent
commit
d59ab59ced

+ 1 - 0
.gitignore

@@ -17,3 +17,4 @@ local.properties
 /ComPDFKit_Repo/build/
 /ComPDFKit_Repo/compdfkit/build/
 /ComPDFKit_Repo/compdfkit-ui/build/
+secring.gpg

+ 5 - 2
ComPDFKit_Tools/build.gradle

@@ -1,6 +1,7 @@
 plugins {
     id 'com.android.library'
 }
+apply from: '../compdfkit-tools-mavencentral.gradle'
 
 def getProductName() {
     return "ComPDFKitDemo"
@@ -40,8 +41,8 @@ android {
 dependencies {
 
     api fileTree(include: ['*.jar'], dir: 'libs')
-    api project(path:':ComPDFKit_Repo:compdfkit')
-    api project(path:':ComPDFKit_Repo:compdfkit-ui')
+//    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'
 
@@ -51,5 +52,7 @@ dependencies {
     implementation 'com.google.android.material:material:1.8.0'
     implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
     implementation 'com.google.android.flexbox:flexbox:3.0.0'
+    api 'com.compdf:compdfkit:1.9.1-SNAPSHOT'
+    api 'com.compdf:compdfkit-ui:1.9.1-SNAPSHOT'
 
 }

+ 33 - 26
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/contextmenu/impl/CEditImageContextMenuView.java

@@ -5,18 +5,22 @@ import static com.compdfkit.ui.contextmenu.CPDFContextMenuShowHelper.ReplaceEdit
 import android.content.Context;
 import android.content.Intent;
 import android.graphics.RectF;
+import android.os.Environment;
+import android.provider.MediaStore;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.Toast;
 
 import androidx.fragment.app.FragmentActivity;
 
+import com.compdfkit.core.document.CPDFSdk;
 import com.compdfkit.tools.R;
 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.utils.image.CBitmapUtil;
 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;
@@ -47,13 +51,13 @@ public class CEditImageContextMenuView implements ContextMenuEditImageProvider {
                 }
             }
             helper.dismissContextMenu();
-        } );
+        });
         menuView.addItem(R.string.tools_edit_image_property_rotate_left, 0, v -> {
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.ROTATE, -90.0f);
-        } );
+        });
         menuView.addItem(R.string.tools_edit_image_property_rotate_right, 0, v -> {
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.ROTATE, 90.0f);
-        } );
+        });
         menuView.addItem(R.string.tools_context_menu_image_replace, 1, v -> {
             if (helper.getReaderView().getContext() instanceof FragmentActivity) {
                 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
@@ -63,21 +67,24 @@ public class CEditImageContextMenuView implements ContextMenuEditImageProvider {
                 ((FragmentActivity) context).startActivityForResult(intent, ReplaceEditImageArea);
                 helper.dismissContextMenu();
             }
-        } );
-        menuView.addItem(R.string.tools_context_menu_image_extract, 1,v -> {
-            try{
-                String sdPath = pageView.getContext().getFilesDir().getAbsolutePath();
-                File file = new File(sdPath, System.currentTimeMillis() + ".png");
+        });
+        menuView.addItem(R.string.tools_context_menu_image_extract, 1, v -> {
+            try {
+                Context context = pageView.getContext();
+                String sdPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
+                File file = new File(sdPath, "ComPDFKit" + File.separator + System.currentTimeMillis() + ".png");
                 pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.EXTRACT_IMAGE, file.getAbsolutePath());
+                MediaStore.Images.Media.insertImage(context.getContentResolver(),
+                        file.getAbsolutePath(), file.getName(), "description");
                 helper.dismissContextMenu();
                 Toast.makeText(pageView.getContext(), R.string.tools_export_success, Toast.LENGTH_LONG).show();
-            }catch (Exception e){
+            } 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-> {
+        view.setOnClickListener(v -> {
             menuView.showSecondView(false);
         });
         menuView.addItemToSecondView(view);
@@ -93,33 +100,33 @@ public class CEditImageContextMenuView implements ContextMenuEditImageProvider {
         menuView.addItemToSecondView(R.string.tools_context_menu_transparacy_100, v -> {
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.TRANCPARENCY, 1f);
         });
-        menuView.addItem(R.string.tools_context_menu_image_transparancy,1, v -> {
+        menuView.addItem(R.string.tools_context_menu_image_transparancy, 1, v -> {
             menuView.showSecondView(true);
-        } );
-        menuView.addItem(R.string.tools_context_menu_image_horizental_mirror, 1,v -> {
+        });
+        menuView.addItem(R.string.tools_context_menu_image_horizental_mirror, 1, v -> {
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.HORIZENTAL_MIRROR, null);
-        } );
-        menuView.addItem(R.string.tools_context_menu_image_vertical_mirror, 2,v -> {
+        });
+        menuView.addItem(R.string.tools_context_menu_image_vertical_mirror, 2, v -> {
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.VERTICLE_MIRROR, null);
-        } );
+        });
         menuView.addItem(R.string.tools_crop, 2, v -> {
             pageView.setCropCallback(rect -> {
             });
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.ENTER_CROP, null);
             helper.dismissContextMenu();
-        } );
-        menuView.addItem(R.string.tools_delete, 2,v -> {
+        });
+        menuView.addItem(R.string.tools_delete, 2, v -> {
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.DELETE, null);
             helper.dismissContextMenu();
-        } );
-        menuView.addItem(R.string.tools_context_menu_image_copy, 2,v -> {
+        });
+        menuView.addItem(R.string.tools_context_menu_image_copy, 2, v -> {
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.COPY, null);
             helper.dismissContextMenu();
-        } );
-        menuView.addItem(R.string.tools_context_menu_image_cut, 2,v -> {
+        });
+        menuView.addItem(R.string.tools_context_menu_image_cut, 2, v -> {
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.CUT, null);
             helper.dismissContextMenu();
-        } );
+        });
         return menuView;
     }
 
@@ -132,11 +139,11 @@ public class CEditImageContextMenuView implements ContextMenuEditImageProvider {
         menuView.addItem(R.string.tools_context_menu_image_crop_done, v -> {
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.CROP, null);
             helper.dismissContextMenu();
-        } );
+        });
         menuView.addItem(R.string.tools_context_menu_image_crop_cancel, v -> {
             pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.EXIT_CROP, null);
             helper.dismissContextMenu();
-        } );
+        });
         return menuView;
     }
 }

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

@@ -9,6 +9,9 @@
 
 package com.compdfkit.tools.common.views.pdfproperties.pdfstyle.manager.provider;
 
+import android.content.Context;
+import android.os.Environment;
+import android.provider.MediaStore;
 import android.text.TextUtils;
 
 import com.compdfkit.core.annotation.CPDFTextAttribute;
@@ -141,9 +144,12 @@ public class CEditSelectionsProvider implements CStyleProvider {
                     case Export:
                         try {
                             if (pageView != null) {
-                                String sdPath = pageView.getContext().getFilesDir().getAbsolutePath();
-                                File file = new File(sdPath, System.currentTimeMillis() + ".png");
+                                Context context = pageView.getContext();
+                                String sdPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
+                                File file = new File(sdPath, "ComPDFKit" + File.separator + System.currentTimeMillis() + ".png");
                                 pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.EXTRACT_IMAGE, file.getAbsolutePath());
+                                MediaStore.Images.Media.insertImage(context.getContentResolver(),
+                                        file.getAbsolutePath(), file.getName(), "description");
                             }
                         }catch (Exception e){
                             CToastUtil.showLongToast(pageView.getContext(), R.string.tools_page_edit_extract_fail);

+ 3 - 2
ComPDFKit_Tools/src/main/res/layout/tools_common_input_dialog.xml

@@ -4,6 +4,7 @@
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="center"
+    android:background="@color/tools_color_background"
     android:orientation="vertical">
 
     <LinearLayout
@@ -20,7 +21,7 @@
             android:layout_marginStart="24dp"
             android:layout_marginTop="24dp"
             android:visibility="gone"
-            android:textColor="?android:attr/textColorPrimary"
+            android:textColor="@color/tools_text_color_primary"
             android:textSize="16sp"
             android:textStyle="bold"
             tools:text="Title" />
@@ -33,7 +34,7 @@
             android:gravity="center_vertical|start"
             android:layout_marginStart="24dp"
             android:layout_marginTop="24dp"
-            android:textColor="?android:attr/textColorPrimary"
+            android:textColor="@color/tools_text_color_primary"
             android:textSize="16sp"
             tools:text="Jump to" />
 

+ 3 - 1
PDFViewer/build.gradle

@@ -51,6 +51,8 @@ dependencies {
     implementation 'androidx.appcompat:appcompat:1.6.1'
     implementation 'com.google.android.material:material:1.8.0'
     implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
-    implementation project(':ComPDFKit_Tools')
     implementation 'pub.devrel:easypermissions:3.0.0'
+    api 'com.compdf:compdfkit:1.9.1-SNAPSHOT'
+    api 'com.compdf:compdfkit-ui:1.9.1-SNAPSHOT'
+    api project(path: ':ComPDFKit_Tools')
 }

+ 87 - 0
compdfkit-mavencentral.gradle

@@ -0,0 +1,87 @@
+apply plugin: 'maven-publish'
+apply plugin: 'signing'
+
+def PUBLISH_VERSION = '1.9.1-SNAPSHOT'
+def PUBLISH_GROUP_ID = 'com.compdf'
+def PUBLISH_ARTIFACT_ID = 'compdfkit'
+
+ext["signing.keyId"] = '' //签名的密钥后8位
+ext["signing.password"] = ''  //签名设置的密码
+ext["signing.secretKeyRingFile"] = '' //生成的secring.gpg文件目录
+ext["ossrhUsername"] = ''  //sonatype用户名
+ext["ossrhPassword"] = ''  //sonatype密码
+
+task sourceJar(type: Jar) {
+    from android.sourceSets.main.java.srcDirs
+    classifier "source"
+}
+
+File secretPropsFile = project.rootProject.file('local.properties')
+if (secretPropsFile.exists()) {
+    println "Found secret props file, loading props"
+    Properties p = new Properties()
+    p.load(new FileInputStream(secretPropsFile))
+    p.each { name, value ->
+        ext[name] = value
+    }
+} else {
+    println "No props file, loading env vars"
+}
+
+afterEvaluate {
+    publishing {
+        publications {
+            release(MavenPublication) {
+                println("publish-maven Log-------> PUBLISH_GROUP_ID: $PUBLISH_GROUP_ID; PUBLISH_ARTIFACT_ID: $PUBLISH_ARTIFACT_ID; PUBLISH_VERSION: $PUBLISH_VERSION")
+                groupId PUBLISH_GROUP_ID
+                artifactId PUBLISH_ARTIFACT_ID
+                version = PUBLISH_VERSION
+                artifact("$buildDir/outputs/aar/ComPDFKit.aar")
+//                artifact(sourceJar)
+                pom {
+                    name = PUBLISH_ARTIFACT_ID
+                    url = 'https://www.compdf.com/'
+                    developers {
+                        developer {
+                            id = 'compdfkit'
+                            name = 'compdfkit' //你的sonatype用户名
+                            email = 'youna@compdf.com' //你的sonatype注册邮箱
+                        }
+                    }
+                    withXml{
+                        def dependenciesNode = asNode().appendNode('dependencies')
+                        //Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
+                        configurations.implementation.allDependencies.each {
+                            if(it.group != null && (it.name != null || "unspecified".equals(it.name)) && it.version != null)
+                            {
+                                def dependencyNode = dependenciesNode.appendNode('dependency')
+                                dependencyNode.appendNode('groupId', it.group)
+                                dependencyNode.appendNode('artifactId', it.name)
+                                dependencyNode.appendNode('version', it.version)
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        repositories {
+            maven {
+                name = PUBLISH_ARTIFACT_ID
+//                def releasesRepoUrl = layout.buildDirectory.dir('repos/releases')
+//                def snapshotsRepoUrl = layout.buildDirectory.dir('repos/snapshots')
+                def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
+                def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
+                println("publish version:${PUBLISH_VERSION}")
+                url = PUBLISH_VERSION.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
+
+                credentials {
+                    username ossrhUsername
+                    password ossrhPassword
+                }
+            }
+        }
+    }
+}
+signing {
+    sign publishing.publications
+}

+ 87 - 0
compdfkit-tools-mavencentral.gradle

@@ -0,0 +1,87 @@
+apply plugin: 'maven-publish'
+apply plugin: 'signing'
+
+def PUBLISH_VERSION = '1.9.1-SNAPSHOT'
+def PUBLISH_GROUP_ID = 'com.compdf'
+def PUBLISH_ARTIFACT_ID = 'compdfkit-tools'
+
+ext["signing.keyId"] = '' //签名的密钥后8位
+ext["signing.password"] = ''  //签名设置的密码
+ext["signing.secretKeyRingFile"] = '' //生成的secring.gpg文件目录
+ext["ossrhUsername"] = ''  //sonatype用户名
+ext["ossrhPassword"] = ''  //sonatype密码
+
+task sourceJar(type: Jar) {
+    from android.sourceSets.main.java.srcDirs
+    classifier "source"
+}
+
+File secretPropsFile = project.rootProject.file('local.properties')
+if (secretPropsFile.exists()) {
+    println "Found secret props file, loading props"
+    Properties p = new Properties()
+    p.load(new FileInputStream(secretPropsFile))
+    p.each { name, value ->
+        ext[name] = value
+    }
+} else {
+    println "No props file, loading env vars"
+}
+
+afterEvaluate {
+    publishing {
+        publications {
+            release(MavenPublication) {
+                println("publish-maven Log-------> PUBLISH_GROUP_ID: $PUBLISH_GROUP_ID; PUBLISH_ARTIFACT_ID: $PUBLISH_ARTIFACT_ID; PUBLISH_VERSION: $PUBLISH_VERSION")
+                groupId PUBLISH_GROUP_ID
+                artifactId PUBLISH_ARTIFACT_ID
+                version = PUBLISH_VERSION
+                artifact("$buildDir/outputs/aar/ComPDFKit_Tools-release.aar")
+//                artifact(sourceJar)
+                pom {
+                    name = PUBLISH_ARTIFACT_ID
+                    url = 'https://www.compdf.com/'
+                    developers {
+                        developer {
+                            id = 'compdfkit'
+                            name = 'compdfkit' //你的sonatype用户名
+                            email = 'youna@compdf.com' //你的sonatype注册邮箱
+                        }
+                    }
+                    withXml{
+                        def dependenciesNode = asNode().appendNode('dependencies')
+                        //Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
+                        configurations.implementation.allDependencies.each {
+                            if(it.group != null && (it.name != null || "unspecified".equals(it.name)) && it.version != null)
+                            {
+                                def dependencyNode = dependenciesNode.appendNode('dependency')
+                                dependencyNode.appendNode('groupId', it.group)
+                                dependencyNode.appendNode('artifactId', it.name)
+                                dependencyNode.appendNode('version', it.version)
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        repositories {
+            maven {
+                name = PUBLISH_ARTIFACT_ID
+//                def releasesRepoUrl = layout.buildDirectory.dir('repos/releases')
+//                def snapshotsRepoUrl = layout.buildDirectory.dir('repos/snapshots')
+                def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
+                def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
+                println("publish version:${PUBLISH_VERSION}")
+                url = PUBLISH_VERSION.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
+
+                credentials {
+                    username ossrhUsername
+                    password ossrhPassword
+                }
+            }
+        }
+    }
+}
+signing {
+    sign publishing.publications
+}

+ 87 - 0
compdfkit-ui-mavencentral.gradle

@@ -0,0 +1,87 @@
+apply plugin: 'maven-publish'
+apply plugin: 'signing'
+
+def PUBLISH_VERSION = '1.9.1-SNAPSHOT'
+def PUBLISH_GROUP_ID = 'com.compdf'
+def PUBLISH_ARTIFACT_ID = 'compdfkit-ui'
+
+ext["signing.keyId"] = '' //签名的密钥后8位
+ext["signing.password"] = ''  //签名设置的密码
+ext["signing.secretKeyRingFile"] = '' //生成的secring.gpg文件目录
+ext["ossrhUsername"] = ''  //sonatype用户名
+ext["ossrhPassword"] = ''  //sonatype密码
+
+task sourceJar(type: Jar) {
+    from android.sourceSets.main.java.srcDirs
+    classifier "source"
+}
+
+File secretPropsFile = project.rootProject.file('local.properties')
+if (secretPropsFile.exists()) {
+    println "Found secret props file, loading props"
+    Properties p = new Properties()
+    p.load(new FileInputStream(secretPropsFile))
+    p.each { name, value ->
+        ext[name] = value
+    }
+} else {
+    println "No props file, loading env vars"
+}
+
+afterEvaluate {
+    publishing {
+        publications {
+            release(MavenPublication) {
+                println("publish-maven Log-------> PUBLISH_GROUP_ID: $PUBLISH_GROUP_ID; PUBLISH_ARTIFACT_ID: $PUBLISH_ARTIFACT_ID; PUBLISH_VERSION: $PUBLISH_VERSION")
+                groupId PUBLISH_GROUP_ID
+                artifactId PUBLISH_ARTIFACT_ID
+                version = PUBLISH_VERSION
+                artifact("$buildDir/outputs/aar/ComPDFKit-UI.aar")
+//                artifact(sourceJar)
+                pom {
+                    name = PUBLISH_ARTIFACT_ID
+                    url = 'https://www.compdf.com/'
+                    developers {
+                        developer {
+                            id = 'compdfkit'
+                            name = 'compdfkit' //你的sonatype用户名
+                            email = 'youna@compdf.com' //你的sonatype注册邮箱
+                        }
+                    }
+                    withXml{
+                        def dependenciesNode = asNode().appendNode('dependencies')
+                        //Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
+                        configurations.implementation.allDependencies.each {
+                            if(it.group != null && (it.name != null || "unspecified".equals(it.name)) && it.version != null)
+                            {
+                                def dependencyNode = dependenciesNode.appendNode('dependency')
+                                dependencyNode.appendNode('groupId', it.group)
+                                dependencyNode.appendNode('artifactId', it.name)
+                                dependencyNode.appendNode('version', it.version)
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        repositories {
+            maven {
+                name = PUBLISH_ARTIFACT_ID
+//                def releasesRepoUrl = layout.buildDirectory.dir('repos/releases')
+//                def snapshotsRepoUrl = layout.buildDirectory.dir('repos/snapshots')
+                def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
+                def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
+                println("publish version:${PUBLISH_VERSION}")
+                url = PUBLISH_VERSION.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
+
+                credentials {
+                    username ossrhUsername
+                    password ossrhPassword
+                }
+            }
+        }
+    }
+}
+signing {
+    sign publishing.publications
+}

BIN
secring.gpg


+ 7 - 0
settings.gradle

@@ -1,5 +1,8 @@
 pluginManagement {
     repositories {
+        maven {
+            url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
+        }
         google()
         mavenCentral()
         gradlePluginPortal()
@@ -8,8 +11,12 @@ pluginManagement {
 dependencyResolutionManagement {
     repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
     repositories {
+        maven {
+            url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
+        }
         google()
         mavenCentral()
+
     }
 }
 rootProject.name = "compdfkit_android_demo"