Jelajahi Sumber

PDFTool(Android) - 1.替换原选择文件保存位置界面

liuxiaolong 1 tahun lalu
induk
melakukan
2bfd4f5a35
15 mengubah file dengan 566 tambahan dan 99 penghapusan
  1. 38 0
      ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/directory/CFileDirectoryDatas.java
  2. 198 1
      ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/directory/CFileDirectoryDialog.java
  3. 23 0
      ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/directory/adapter/CFileDirectoryAdapter.java
  4. 86 0
      ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/directory/adapter/CFileDirectoryTitleAdapter.java
  5. 50 0
      ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/directory/bean/CFileDirectoryTitleBean.java
  6. 11 10
      ComPDFKit_Tools/src/main/java/com/compdfkit/tools/signature/importcert/create/CreateCertificateDigitalDialog.java
  7. 0 1
      ComPDFKit_Tools/src/main/java/com/compdfkit/tools/signature/info/CertDetailsDialog.java
  8. 16 8
      ComPDFKit_Tools/src/main/java/com/compdfkit/tools/signature/pdfproperties/pdfsign/CDigitalSignatureWidgetImpl.java
  9. 0 78
      ComPDFKit_Tools/src/main/java/com/compdfkit/tools/signature/pdfproperties/pdfsign/CSelectFolderEmptyDialog.java
  10. 5 0
      ComPDFKit_Tools/src/main/res/drawable/tools_ic_baseline_folder.xml
  11. 48 1
      ComPDFKit_Tools/src/main/res/layout/tools_file_directory_dialog.xml
  12. 47 0
      ComPDFKit_Tools/src/main/res/layout/tools_file_directory_list_item.xml
  13. 25 0
      ComPDFKit_Tools/src/main/res/layout/tools_file_directory_list_title_item.xml
  14. 18 0
      ComPDFKit_Tools/src/main/res/layout/tools_file_directory_list_title_separator_item.xml
  15. 1 0
      ComPDFKit_Tools/src/main/res/values/tools_strings.xml

+ 38 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/directory/CFileDirectoryDatas.java

@@ -0,0 +1,38 @@
+/**
+ * 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.views.directory;
+
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+public class CFileDirectoryDatas {
+
+
+    public static List<File> getDirectories(String rootDir){
+        List<File> list = new ArrayList<>();
+        File file = new File(rootDir);
+        File[] files = file.listFiles(pathname -> !pathname.isHidden() && pathname.isDirectory());
+        if (files == null || files.length == 0){
+            return list;
+        }else {
+            Collections.addAll(list, files);
+            Collections.sort(list, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
+            return list;
+        }
+    }
+
+
+}

+ 198 - 1
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/directory/CFileDirectoryDialog.java

@@ -1,12 +1,67 @@
 package com.compdfkit.tools.common.views.directory;
 
 
+import android.app.Dialog;
+import android.os.Bundle;
+import android.os.Environment;
+import android.text.TextUtils;
 import android.view.View;
 
+import androidx.activity.ComponentDialog;
+import androidx.activity.OnBackPressedCallback;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.widget.AppCompatButton;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.compdfkit.tools.R;
 import com.compdfkit.tools.common.basic.fragment.CBasicBottomSheetDialogFragment;
+import com.compdfkit.tools.common.utils.threadpools.SimpleBackgroundTask;
+import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
+import com.compdfkit.tools.common.views.CToolBar;
+import com.compdfkit.tools.common.views.directory.adapter.CFileDirectoryAdapter;
+import com.compdfkit.tools.common.views.directory.adapter.CFileDirectoryTitleAdapter;
+import com.compdfkit.tools.common.views.directory.bean.CFileDirectoryTitleBean;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
 
 public class CFileDirectoryDialog extends CBasicBottomSheetDialogFragment {
 
+    public static final String EXTRA_ROOT_DIR = "extra_root_dir";
+
+    public static final String EXTRA_TITLE = "extra_title";
+
+    public static final String EXTRA_CONFIRM_BUTTON_TITLE = "extra_confirm_button_title";
+
+    private CToolBar toolBar;
+
+    private RecyclerView rvFolderTitle;
+
+    private RecyclerView rvFolderList;
+
+    private AppCompatButton btnConfirm;
+
+    private CFileDirectoryTitleAdapter titleAdapter;
+
+    private CFileDirectoryAdapter directoryAdapter;
+
+    private COnSelectFolderListener selectFolderListener;
+
+    private OnBackPressedCallback callback;
+
+    public static CFileDirectoryDialog newInstance(String rootDir, String title, String confirmBtnTitle) {
+        Bundle args = new Bundle();
+        args.putString(EXTRA_ROOT_DIR, rootDir);
+        args.putString(EXTRA_TITLE, title);
+        args.putString(EXTRA_CONFIRM_BUTTON_TITLE, confirmBtnTitle);
+        CFileDirectoryDialog fragment = new CFileDirectoryDialog();
+        fragment.setArguments(args);
+        return fragment;
+    }
+
     @Override
     protected boolean fullScreen() {
         return true;
@@ -17,18 +72,160 @@ public class CFileDirectoryDialog extends CBasicBottomSheetDialogFragment {
         return false;
     }
 
+    @Override
+    protected float dimAmount() {
+        return CViewUtils.isLandScape(getContext()) ? 0.2F : 0F;
+    }
+
     @Override
     protected int layoutId() {
-        return 0;
+        return R.layout.tools_file_directory_dialog;
+    }
+
+    @NonNull
+    @Override
+    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
+        Dialog dialog = super.onCreateDialog(savedInstanceState);
+        if (dialog instanceof ComponentDialog) {
+            ComponentDialog componentDialog = (ComponentDialog) dialog;
+            callback = new OnBackPressedCallback(true) {
+                @Override
+                public void handleOnBackPressed() {
+                    String dir = titleAdapter.getLastFolder();
+                    if (!TextUtils.isEmpty(dir) && titleAdapter.list.size() != 1) {
+                        titleAdapter.toupperLevel();
+                        String upperLevelDir = titleAdapter.getLastFolder();
+                        refreshDirectories(upperLevelDir);
+                    } else {
+                        dismiss();
+                    }
+                }
+            };
+            componentDialog.getOnBackPressedDispatcher().addCallback(callback);
+        }
+        return dialog;
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        if (getDialog() != null) {
+            getDialog().setCancelable(false);
+        }
     }
 
     @Override
     protected void onCreateView(View rootView) {
+        toolBar = rootView.findViewById(R.id.tool_bar);
+        rvFolderTitle = rootView.findViewById(R.id.rv_folder_title);
+        rvFolderList = rootView.findViewById(R.id.recycler_view);
+        btnConfirm = rootView.findViewById(R.id.btn_ok);
+        btnConfirm.setOnClickListener(v -> {
+            String dir = titleAdapter.getLastFolder();
+            if (selectFolderListener != null) {
+                if (!TextUtils.isEmpty(dir)){
+                    selectFolderListener.folder(dir);
 
+                }else {
+                    selectFolderListener.folder(getNormalFolder());
+                }
+            }
+            dismiss();
+        });
     }
 
     @Override
     protected void onViewCreate() {
+        toolBar.setBackBtnClickListener(v -> {
+            dismiss();
+        });
+        if (getArguments() != null) {
+            String title = getArguments().getString(EXTRA_TITLE);
+            if (!TextUtils.isEmpty(title)){
+                toolBar.setTitle(title);
+            }
+            String confirmButtonTitle = getArguments().getString(EXTRA_CONFIRM_BUTTON_TITLE);
+            if (!TextUtils.isEmpty(confirmButtonTitle)){
+                btnConfirm.setText(confirmButtonTitle);
+            }
+        }
+
+        initFolderTitleList();
+        initDirectoriesList();
+    }
+
+    private void initFolderTitleList() {
+        titleAdapter = new CFileDirectoryTitleAdapter();
+        rvFolderTitle.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
+        rvFolderTitle.setAdapter(titleAdapter);
+        titleAdapter.setList(createTitleList());
+        titleAdapter.setOnItemClickListener((adapter, view, position) -> {
+            CFileDirectoryTitleBean item = titleAdapter.list.get(position);
+            if (!item.isSeparator()) {
+                titleAdapter.removeRange(position);
+                refreshDirectories(item.getFile().getAbsolutePath());
+            }
+        });
+    }
+
+    private void initDirectoriesList() {
+        directoryAdapter = new CFileDirectoryAdapter();
+        rvFolderList.setLayoutManager(new LinearLayoutManager(getContext()));
+        rvFolderList.setAdapter(directoryAdapter);
+        directoryAdapter.setOnItemClickListener((adapter, view, position) -> {
+            File childDirectory = directoryAdapter.list.get(position);
+            applyTitleList(childDirectory);
+        });
+        String rootDir = createTitleList().get(0).getFile().getAbsolutePath();
+        refreshDirectories(rootDir);
+    }
+
+    private List<CFileDirectoryTitleBean> createTitleList() {
+        String rootDir = Environment.getExternalStorageDirectory().getAbsolutePath();
+        if (getArguments() != null && !TextUtils.isEmpty(getArguments().getString(EXTRA_ROOT_DIR))) {
+            rootDir = getArguments().getString(EXTRA_ROOT_DIR);
+        }
+        List<CFileDirectoryTitleBean> list = new ArrayList<>();
+        list.add(new CFileDirectoryTitleBean(new File(rootDir)));
+        return list;
+    }
+
+    private void applyTitleList(File childFile) {
+        List<CFileDirectoryTitleBean> list = new ArrayList<>();
+        list.add(CFileDirectoryTitleBean.separator());
+        list.add(new CFileDirectoryTitleBean(childFile));
+        titleAdapter.addList(list);
+        rvFolderTitle.smoothScrollToPosition(titleAdapter.list.size() - 1);
+        refreshDirectories(childFile.getAbsolutePath());
+    }
 
+
+    private void refreshDirectories(String rootDir){
+        new SimpleBackgroundTask<List<File>>(getContext()){
+
+            @Override
+            protected List<File> onRun() {
+                return CFileDirectoryDatas.getDirectories(rootDir);
+            }
+
+            @Override
+            protected void onSuccess(List<File> result) {
+                directoryAdapter.setList(result);
+            }
+        }.execute();
     }
+
+    private String getNormalFolder(){
+        return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
+    }
+
+    public void setSelectFolderListener(COnSelectFolderListener selectFolderListener) {
+        this.selectFolderListener = selectFolderListener;
+    }
+
+    public interface COnSelectFolderListener{
+        void folder(String dir);
+    }
+
+
 }

+ 23 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/directory/adapter/CFileDirectoryAdapter.java

@@ -0,0 +1,23 @@
+package com.compdfkit.tools.common.views.directory.adapter;
+
+import android.content.Context;
+import android.view.ViewGroup;
+
+import com.compdfkit.tools.R;
+import com.compdfkit.tools.common.utils.adapter.CBaseQuickAdapter;
+import com.compdfkit.tools.common.utils.adapter.CBaseQuickViewHolder;
+
+import java.io.File;
+
+
+public class CFileDirectoryAdapter extends CBaseQuickAdapter<File, CBaseQuickViewHolder> {
+    @Override
+    protected CBaseQuickViewHolder onCreateViewHolder(Context context, ViewGroup parent, int viewType) {
+        return new CBaseQuickViewHolder(R.layout.tools_file_directory_list_item, parent);
+    }
+
+    @Override
+    protected void onBindViewHolder(CBaseQuickViewHolder holder, int position, File item) {
+        holder.setText(R.id.tv_name, item.getName());
+    }
+}

+ 86 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/directory/adapter/CFileDirectoryTitleAdapter.java

@@ -0,0 +1,86 @@
+/**
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+ * <p>
+ * 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.views.directory.adapter;
+
+import android.content.Context;
+import android.os.Environment;
+import android.view.ViewGroup;
+
+import com.compdfkit.tools.R;
+import com.compdfkit.tools.common.utils.adapter.CBaseQuickAdapter;
+import com.compdfkit.tools.common.utils.adapter.CBaseQuickViewHolder;
+import com.compdfkit.tools.common.views.directory.bean.CFileDirectoryTitleBean;
+
+import java.io.File;
+
+
+public class CFileDirectoryTitleAdapter extends CBaseQuickAdapter<CFileDirectoryTitleBean, CBaseQuickViewHolder> {
+
+    public static final int ITEM_TITLE = 0;
+
+    public static final int ITEM_TITLE_SEPARATOR = 1;
+
+    @Override
+    protected CBaseQuickViewHolder onCreateViewHolder(Context context, ViewGroup parent, int viewType) {
+        if (viewType == ITEM_TITLE) {
+            return new CBaseQuickViewHolder(R.layout.tools_file_directory_list_title_item, parent);
+        } else {
+            return new CBaseQuickViewHolder(R.layout.tools_file_directory_list_title_separator_item, parent);
+        }
+    }
+
+    @Override
+    public int getItemViewType(int position) {
+        return list.get(position).isSeparator() ?
+                ITEM_TITLE_SEPARATOR : ITEM_TITLE;
+    }
+
+    @Override
+    protected void onBindViewHolder(CBaseQuickViewHolder holder, int position, CFileDirectoryTitleBean item) {
+        if (item.isSeparator()) {
+
+        } else {
+            File file = item.getFile();
+            if (file.getAbsolutePath().equalsIgnoreCase(Environment.getExternalStorageDirectory().getAbsolutePath())){
+                holder.setText(R.id.tv_name, "SD Card");
+            }else {
+                holder.setText(R.id.tv_name, item.getFile().getName());
+            }
+        }
+    }
+
+    public void removeRange(int startPosition){
+        for (int i = list.size() - 1; i > startPosition; i--) {
+            list.remove(i);
+            notifyItemRemoved(i);
+        }
+    }
+
+    public void toupperLevel(){
+        for (int i = list.size() - 1; i >= 0; i--) {
+            CFileDirectoryTitleBean bean = list.get(i);
+            if (!bean.isSeparator() && i != list.size() -1){
+                removeRange(i);
+                return;
+            }
+        }
+    }
+
+
+    public String getLastFolder(){
+        for (int i = list.size() - 1; i >= 0; i--) {
+            CFileDirectoryTitleBean bean = list.get(i);
+            if (!bean.isSeparator()){
+                return bean.getFile().getAbsolutePath();
+            }
+        }
+        return "";
+    }
+}

+ 50 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/directory/bean/CFileDirectoryTitleBean.java

@@ -0,0 +1,50 @@
+/**
+ * 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.views.directory.bean;
+
+import java.io.File;
+
+
+public class CFileDirectoryTitleBean {
+
+    public CFileDirectoryTitleBean() {
+    }
+
+    public CFileDirectoryTitleBean(File file){
+        this.file = file;
+    }
+
+    public static CFileDirectoryTitleBean separator(){
+        CFileDirectoryTitleBean bean = new CFileDirectoryTitleBean();
+        bean.setSeparator(true);
+        return bean;
+    }
+
+
+    private File file;
+
+    private boolean isSeparator;
+
+    public File getFile() {
+        return file;
+    }
+
+    public void setFile(File file) {
+        this.file = file;
+    }
+
+    public boolean isSeparator() {
+        return isSeparator;
+    }
+
+    public void setSeparator(boolean separator) {
+        isSeparator = separator;
+    }
+}

+ 11 - 10
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/signature/importcert/create/CreateCertificateDigitalDialog.java

@@ -40,6 +40,7 @@ import com.compdfkit.tools.common.utils.CFileUtils;
 import com.compdfkit.tools.common.utils.CToastUtil;
 import com.compdfkit.tools.common.utils.threadpools.CThreadPoolUtils;
 import com.compdfkit.tools.common.utils.view.CEditText;
+import com.compdfkit.tools.common.views.directory.CFileDirectoryDialog;
 import com.compdfkit.tools.signature.CertificateDigitalDatas;
 import com.compdfkit.tools.signature.interfaces.COnSelectCertFileListener;
 
@@ -92,15 +93,6 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
 
     private String fileName = "";
 
-    private ActivityResultLauncher<Intent> selectDirLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
-        if (result.getData() != null && result.getData().getData() != null) {
-            Uri uri = result.getData().getData();
-            CFileUtils.takeUriPermission(getContext(), result.getData().getData());
-            customSavePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + uri.getPath().replace("/tree/primary:", "");
-            tvSaveAddress.setText(getSaveAddress() + File.separator + fileName);
-        }
-    });
-
     public static CreateCertificateDigitalDialog newInstance() {
         Bundle args = new Bundle();
         CreateCertificateDigitalDialog fragment = new CreateCertificateDigitalDialog();
@@ -211,7 +203,16 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
         } else if (v.getId() == R.id.iv_tool_bar_close) {
             dismiss();
         } else if (v.getId() == R.id.tv_save_address) {
-            selectDirLauncher.launch(CFileUtils.selectSystemDir(true));
+            CFileDirectoryDialog directoryDialog = CFileDirectoryDialog.newInstance(
+                    Environment.getExternalStorageDirectory().getAbsolutePath(),
+                    getContext().getString(R.string.tools_select_folder),
+                    getContext().getString(R.string.tools_save_to_this_directory)
+            );
+            directoryDialog.setSelectFolderListener(dir -> {
+                customSavePath = dir;
+                tvSaveAddress.setText(getSaveAddress() + File.separator + fileName);
+            });
+            directoryDialog.show(getChildFragmentManager(), "directoryDialog");
         } else if (v.getId() == R.id.btn_save) {
             String name = etName.getText();
             String grantor = etOrganizationUnit.getText();

+ 0 - 1
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/signature/info/CertDetailsDialog.java

@@ -43,7 +43,6 @@ public class CertDetailsDialog extends CBasicBottomSheetDialogFragment {
 
     private COnDialogDismissListener dialogDismissListener;
 
-
     public static CertDetailsDialog newInstance(CPDFSignature signature) {
         Bundle args = new Bundle();
         CertDetailsDialog fragment = new CertDetailsDialog();

+ 16 - 8
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/signature/pdfproperties/pdfsign/CDigitalSignatureWidgetImpl.java

@@ -9,7 +9,9 @@
 
 package com.compdfkit.tools.signature.pdfproperties.pdfsign;
 
+import android.content.Context;
 import android.graphics.Bitmap;
+import android.os.Environment;
 
 import androidx.fragment.app.FragmentActivity;
 
@@ -20,6 +22,7 @@ import com.compdfkit.core.signature.CPDFSignature;
 import com.compdfkit.tools.R;
 import com.compdfkit.tools.common.utils.CToastUtil;
 import com.compdfkit.tools.common.utils.image.CBitmapUtil;
+import com.compdfkit.tools.common.views.directory.CFileDirectoryDialog;
 import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl;
 import com.compdfkit.tools.signature.CertificateDigitalDatas;
 import com.compdfkit.tools.signature.importcert.create.CPDFSelectDigitalSignatureDialog;
@@ -46,24 +49,29 @@ public class CDigitalSignatureWidgetImpl extends CPDFSignatureWidgetImpl {
             }
             return;
         }
-
         CPDFSelectDigitalSignatureDialog dialog = CPDFSelectDigitalSignatureDialog.newInstance();
         dialog.setCertDigitalSignListener((certFilePath, certPassword, signImagePath) -> {
             CPDFCertInfo certInfo = CertificateDigitalDatas.getCertInfo(certFilePath, certPassword);
             CDigitalSignStylePreviewDialog previewDialog = CDigitalSignStylePreviewDialog.newInstance(signImagePath, certInfo.getSubject().getCommonName());
             previewDialog.setResultDigitalSignListener((digitalSignImagePath, styleData) -> {
                 try {
-                    // set sign image
-                    Bitmap bitmap = CBitmapUtil.decodeBitmap(digitalSignImagePath);
-                    ((CPDFSignatureWidget) pdfAnnotation).updateApWithBitmap(bitmap, CPDFImageScaleType.SCALETYPE_fitCenter);
-                    refresh();
 
-                    CSelectFolderEmptyDialog selectFolderEmptyDialog = CSelectFolderEmptyDialog.newInstance();
-                    selectFolderEmptyDialog.setSelectFolderListener(dir -> {
+                    Context context = readerView.getContext();
+                    CFileDirectoryDialog directoryDialog = CFileDirectoryDialog.newInstance(
+                            Environment.getExternalStorageDirectory().getAbsolutePath(),
+                            context.getString(R.string.tools_select_folder),
+                            context.getString(R.string.tools_save_to_this_directory)
+                    );
+                    directoryDialog.setSelectFolderListener(dir -> {
+                        // set sign image
+                        Bitmap bitmap = CBitmapUtil.decodeBitmap(digitalSignImagePath);
+                        ((CPDFSignatureWidget) pdfAnnotation).updateApWithBitmap(bitmap, CPDFImageScaleType.SCALETYPE_fitCenter);
+                        refresh();
+
                         signDocument(cpdfSignatureWidget, styleData, certFilePath, certPassword, dir);
                     });
                     if (readerView.getContext() instanceof FragmentActivity) {
-                        selectFolderEmptyDialog.show(((FragmentActivity) readerView.getContext()).getSupportFragmentManager(), "selectFolderDialog");
+                        directoryDialog.show(((FragmentActivity) readerView.getContext()).getSupportFragmentManager(), "selectFolderDialog");
                     }
                 } catch (Exception e) {
                     e.printStackTrace();

+ 0 - 78
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/signature/pdfproperties/pdfsign/CSelectFolderEmptyDialog.java

@@ -1,78 +0,0 @@
-/**
- * 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.signature.pdfproperties.pdfsign;
-
-
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Environment;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.activity.result.ActivityResultLauncher;
-import androidx.activity.result.contract.ActivityResultContracts;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.fragment.app.DialogFragment;
-
-import com.compdfkit.tools.R;
-import com.compdfkit.tools.common.utils.CFileUtils;
-
-import java.io.File;
-
-public class CSelectFolderEmptyDialog extends DialogFragment {
-
-    private COnSelectFolderListener selectFolderListener;
-
-    private ActivityResultLauncher<Intent> selectDirLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
-        if (result.getData() != null && result.getData().getData() != null) {
-            Uri uri = result.getData().getData();
-            CFileUtils.takeUriPermission(getContext(), result.getData().getData());
-            String customSavePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + uri.getPath().replace("/tree/primary:", "");
-            if (selectFolderListener != null) {
-                selectFolderListener.folder(customSavePath);
-            }
-            dismiss();
-        }else {
-            dismiss();
-        }
-    });
-
-    public static CSelectFolderEmptyDialog newInstance() {
-
-        Bundle args = new Bundle();
-
-        CSelectFolderEmptyDialog fragment = new CSelectFolderEmptyDialog();
-        fragment.setArguments(args);
-        return fragment;
-    }
-
-    @Nullable
-    @Override
-    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
-        return inflater.inflate(R.layout.tools_sign_select_folder_empty_dialog, container,false);
-    }
-
-    @Override
-    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
-        super.onViewCreated(view, savedInstanceState);
-        selectDirLauncher.launch(CFileUtils.selectSystemDir(true));
-    }
-
-    public void setSelectFolderListener(COnSelectFolderListener selectFolderListener) {
-        this.selectFolderListener = selectFolderListener;
-    }
-
-    protected interface COnSelectFolderListener{
-        void folder(String dir);
-    }
-}

+ 5 - 0
ComPDFKit_Tools/src/main/res/drawable/tools_ic_baseline_folder.xml

@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:tint="#000000"
+    android:viewportHeight="24" android:viewportWidth="24"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="@android:color/white" android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
+</vector>

+ 48 - 1
ComPDFKit_Tools/src/main/res/layout/tools_file_directory_dialog.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
 
@@ -8,12 +9,58 @@
         android:id="@+id/tool_bar"
         android:layout_width="match_parent"
         android:layout_height="?attr/actionBarSize"
+        android:elevation="4dp"
         android:title="@string/tools_select_folder"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        app:layout_constraintTop_toTopOf="parent" >
 
+    </com.compdfkit.tools.common.views.CToolBar>
 
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/rv_folder_title"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:background="@color/tools_reader_setting_head_bg_color"
+        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
+        app:layout_constraintEnd_toEndOf="parent"
+        android:paddingHorizontal="8dp"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@id/tool_bar"
+        tools:listitem="@layout/tools_file_directory_list_title_item" />
 
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recycler_view"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        app:layout_constraintBottom_toTopOf="@id/btn_ok"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintVertical_bias="0"
+        app:layout_constrainedHeight="true"
+        app:layout_constraintTop_toBottomOf="@id/rv_folder_title"
+        tools:listitem="@layout/tools_file_directory_list_item" />
+
+
+    <androidx.appcompat.widget.AppCompatButton
+        android:id="@+id/btn_ok"
+        android:layout_width="match_parent"
+        android:layout_height="40dp"
+        android:layout_marginHorizontal="16dp"
+        android:layout_marginBottom="16dp"
+        android:background="@drawable/tools_sign_cert_info_btn_bg"
+        android:foreground="@drawable/tools_common_btn_corner_ripple"
+        android:gravity="center"
+        android:text="@string/tools_page_edit_toolbar_done"
+        android:textAllCaps="false"
+        android:textColor="@color/tools_color_accent"
+        android:textSize="16sp"
+        android:textStyle="bold"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@id/recycler_view"
+        app:layout_constraintVertical_bias="1" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 47 - 0
ComPDFKit_Tools/src/main/res/layout/tools_file_directory_list_item.xml

@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="60dp"
+    android:background="@drawable/tools_common_btn_rectangle_ripple">
+
+    <androidx.appcompat.widget.AppCompatImageView
+        android:id="@+id/iv_image"
+        android:layout_width="24dp"
+        android:layout_height="24dp"
+        android:layout_marginStart="24dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:srcCompat="@drawable/tools_ic_baseline_folder"
+        app:tint="@color/tools_text_color_secondary" />
+
+    <androidx.appcompat.widget.AppCompatTextView
+        android:id="@+id/tv_name"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="16dp"
+        android:ellipsize="start"
+        android:singleLine="true"
+        android:layout_marginEnd="8dp"
+        android:textSize="16sp"
+        android:textColor="@color/tools_text_color_primary"
+        app:layout_constrainedWidth="true"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0"
+        app:layout_constraintStart_toEndOf="@id/iv_image"
+        app:layout_constraintTop_toTopOf="parent"
+        tools:text="Folder" />
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1px"
+        android:background="@color/tools_item_dividing_line_color"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 25 - 0
ComPDFKit_Tools/src/main/res/layout/tools_file_directory_list_title_item.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="wrap_content"
+    android:layout_height="30dp"
+    android:background="@drawable/tools_common_btn_rectangle_ripple">
+
+    <androidx.appcompat.widget.AppCompatTextView
+        android:id="@+id/tv_name"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="8dp"
+        android:layout_marginEnd="8dp"
+        android:ellipsize="start"
+        android:singleLine="true"
+        android:textColor="@color/tools_text_color_primary"
+        app:layout_constrainedWidth="true"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        tools:text="Folder" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 18 - 0
ComPDFKit_Tools/src/main/res/layout/tools_file_directory_list_title_separator_item.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="wrap_content"
+    android:layout_height="30dp"
+    >
+
+    <androidx.appcompat.widget.AppCompatImageView
+        android:layout_width="24dp"
+        android:layout_height="24dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:srcCompat="@drawable/tools_ic_grey_arrow" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

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

@@ -417,5 +417,6 @@
     <string name="tools_trust">Trust</string>
     <string name="tools_add_to_trusted_cert">Add to Trusted Certificates</string>
     <string name="tools_select_folder">Select folder</string>
+    <string name="tools_save_to_this_directory">Save to this directory</string>
 
 </resources>