Bläddra i källkod

ComPDFKit Demo(Android) - 1.大纲Dialog 2.公共ToolBar

liuxiaolong 1 år sedan
förälder
incheckning
61a0ffcf1f

+ 16 - 3
compdfkit-tools/src/main/java/com/compdfkit/tools/CPDFOutlineDialogFragment.java

@@ -1,13 +1,13 @@
 /**
  * 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;
+package com.compdfkit.tools.pdfoutline;
 
 
 import android.os.Bundle;
@@ -18,16 +18,29 @@ import android.view.ViewGroup;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
+import com.compdfkit.tools.R;
+import com.compdfkit.tools.utils.dialog.DialogFragmentUtil;
+import com.google.android.material.bottomsheet.BottomSheetBehavior;
 import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
 
 public class CPDFOutlineDialogFragment extends BottomSheetDialogFragment {
 
+    @Override
+    public void onStart() {
+        super.onStart();
+        BottomSheetBehavior<View> behavior = BottomSheetBehavior.from((View) getView().getParent());
+        DialogFragmentUtil.setBottomSheetDialogFragmentFullScreen(getDialog(), behavior);
+    }
+
     @Nullable
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
-        return super.onCreateView(inflater, container, savedInstanceState);
+        return inflater.inflate(R.layout.tools_cpdf_outline_dialog_fragment, container, false);
     }
 
+    @Override
+    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
 
+    }
 
 }

+ 38 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/utils/dialog/DialogFragmentUtil.java

@@ -0,0 +1,38 @@
+/**
+ * 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.utils.dialog;
+
+import android.app.Dialog;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.FrameLayout;
+
+import androidx.annotation.Nullable;
+
+import com.google.android.material.bottomsheet.BottomSheetBehavior;
+
+
+public class DialogFragmentUtil {
+
+
+    public static void setBottomSheetDialogFragmentFullScreen(@Nullable Dialog dialog, BottomSheetBehavior<View> behavior) {
+        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
+        if (dialog == null) {
+            return;
+        }
+        FrameLayout bottomSheet =
+                dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet);
+        ViewGroup.LayoutParams layoutParams = bottomSheet.getLayoutParams();
+        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
+        bottomSheet.setLayoutParams(layoutParams);
+    }
+
+}

+ 93 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/utils/view/CToolBar.java

@@ -0,0 +1,93 @@
+/**
+ * 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.utils.view;
+
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Color;
+import android.graphics.drawable.Drawable;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.content.res.AppCompatResources;
+import androidx.appcompat.widget.AppCompatImageView;
+import androidx.appcompat.widget.AppCompatTextView;
+
+import com.compdfkit.tools.R;
+
+public class CToolBar extends FrameLayout {
+
+    private AppCompatTextView tvToolBarTitle;
+    private AppCompatImageView ivToolBarBackBtn;
+
+    public CToolBar(@NonNull Context context) {
+        super(context);
+        initToolBar(context, null);
+    }
+
+    public CToolBar(@NonNull Context context, @Nullable AttributeSet attrs) {
+        super(context, attrs);
+        initToolBar(context, attrs);
+    }
+
+    public CToolBar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+
+    private void initToolBar(Context context, @Nullable AttributeSet attrs) {
+        LayoutInflater.from(getContext()).inflate(R.layout.tools_ctool_bar, this);
+        setBackgroundColor(Color.WHITE);
+        setElevation(8);
+        tvToolBarTitle = findViewById(R.id.tv_tool_bar_title);
+        ivToolBarBackBtn = findViewById(R.id.iv_tool_bar_back);
+        initAttributes(context, attrs);
+    }
+
+    private void initAttributes(Context context, @Nullable AttributeSet attrs) {
+        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Tools_CToolBar);
+        if (typedArray != null) {
+            String toolBarTitle = typedArray.getString(R.styleable.Tools_CToolBar_tools_toolbar_title);
+            if (!TextUtils.isEmpty(toolBarTitle)) {
+                tvToolBarTitle.setText(toolBarTitle);
+            }
+            Drawable backIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_CToolBar_tools_toolbar_back_icon, R.drawable.tools_ic_back);
+            if (backIconDrawable != null) {
+                ivToolBarBackBtn.setImageDrawable(backIconDrawable);
+            }
+            typedArray.recycle();
+        }
+    }
+
+    private Drawable loadImageFromAttributes(TypedArray typedArray, int index, int defValue){
+        Drawable drawable = null;
+        try {
+            int resId = typedArray.getResourceId(index, defValue);
+            if (resId != -1){
+                drawable = AppCompatResources.getDrawable(getContext(), resId);
+            }
+            return drawable;
+        }catch (Exception e){
+            return null;
+        }
+    }
+
+
+    public void setBackBtnClickListener(OnClickListener clickListener){
+        ivToolBarBackBtn.setOnClickListener(clickListener);
+    }
+
+
+
+}

+ 13 - 30
compdfkit-tools/src/main/res/layout/tools_cpdf_outline_dialog_fragment.xml

@@ -3,42 +3,25 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools">
+    >
 
 
-    <androidx.constraintlayout.widget.ConstraintLayout
+    <com.compdfkit.tools.utils.view.CToolBar
+        android:id="@+id/tool_bar"
         android:layout_width="match_parent"
         android:layout_height="?android:attr/actionBarSize"
+        app:tools_toolbar_title="Outline"
         app:layout_constraintTop_toTopOf="parent"
-        >
-
-        <androidx.appcompat.widget.AppCompatImageView
-            android:id="@+id/iv_tool_bar_search"
-            android:layout_width="0dp"
-            android:layout_height="match_parent"
-            android:layout_margin="10dp"
-            android:padding="4dp"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintDimensionRatio="1:1"
-            app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="parent"
-            app:srcCompat="@drawable/tools_ic_back" />
-
-        <androidx.appcompat.widget.AppCompatTextView
-            android:id="@+id/tv_tool_bar_title"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:textColor="@android:color/black"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="parent"
-            android:textSize="16sp"
-            android:text="Outline" />
-
-
-    </androidx.constraintlayout.widget.ConstraintLayout>
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"/>
 
+    <androidx.recyclerview.widget.RecyclerView
+        android:layout_width="match_parent"
+        app:layout_constraintTop_toBottomOf="@id/tool_bar"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        android:layout_height="300dp"/>
 
 
 

+ 37 - 0
compdfkit-tools/src/main/res/layout/tools_ctool_bar.xml

@@ -0,0 +1,37 @@
+<?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"
+    tools:layout_height="?android:attr/actionBarSize">
+
+
+    <androidx.appcompat.widget.AppCompatTextView
+        android:id="@+id/tv_tool_bar_title"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textColor="@android:color/black"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        android:textSize="16sp"
+        tools:text="PDF View" />
+
+    <androidx.appcompat.widget.AppCompatImageView
+        android:id="@+id/iv_tool_bar_back"
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:layout_margin="10dp"
+        android:padding="4dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintDimensionRatio="1:1"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:srcCompat="@drawable/tools_ic_back" />
+
+
+
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 6 - 1
compdfkit-tools/src/main/res/values/tools_attrs.xml

@@ -1,12 +1,17 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
 
+    <attr name="tools_toolbar_title" format="string"/>
 
     <declare-styleable name="Tools_CPDFToolBar">
-        <attr name="tools_toolbar_title" format="string"/>
+        <attr name="tools_toolbar_title"/>
         <attr name="tools_toolbar_search_icon" format="reference"/>
         <attr name="tools_toolbar_outline_icon" format="reference"/>
         <attr name="tools_toolbar_more_icon" format="reference"/>
     </declare-styleable>
 
+    <declare-styleable name="Tools_CToolBar">
+        <attr name="tools_toolbar_title"/>
+        <attr name="tools_toolbar_back_icon" format="reference"/>
+    </declare-styleable>
 </resources>

+ 3 - 0
viewer-ctrl-demo/src/main/java/com/compdfkit/demo/viewer/MainActivity.java

@@ -6,6 +6,7 @@ import android.os.Bundle;
 import android.widget.Toast;
 
 import com.compdfkit.demo.viewer.databinding.ViewerActivityMainBinding;
+import com.compdfkit.tools.pdfoutline.CPDFOutlineDialogFragment;
 import com.compdfkit.tools.task.CExtractAssetFileTask;
 
 public class MainActivity extends AppCompatActivity {
@@ -37,6 +38,8 @@ public class MainActivity extends AppCompatActivity {
         binding.pdfToolBar.setOutlineBtnClickListener(v -> {
             //open outline
             Toast.makeText(this, "outline", Toast.LENGTH_SHORT).show();
+            CPDFOutlineDialogFragment cpdfOutlineDialogFragment = new CPDFOutlineDialogFragment();
+            cpdfOutlineDialogFragment.show(getSupportFragmentManager(), "outline");
 
         });
         binding.pdfToolBar.setMoreBtnClickListener(v -> {