Procházet zdrojové kódy

PDFTools(Android) - 1.Line、Arrow UI

liuxiaolong před 1 rokem
rodič
revize
3a3da7c561

+ 9 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/CAnnotStyleDialogFragment.java

@@ -28,10 +28,12 @@ import com.compdfkit.tools.annotation.pdfproperties.pdfannotstyle.adapter.CAnnot
 import com.compdfkit.tools.common.utils.CWrapHeightPageChangeCallback;
 import com.compdfkit.tools.annotation.pdfproperties.pdfannotstyle.viewmodel.CAnnotStyleViewModel;
 import com.compdfkit.tools.annotation.pdfproperties.pdfannotstyle.CAnnotStyle;
+import com.compdfkit.tools.common.utils.dialog.CDialogFragmentUtil;
 import com.compdfkit.tools.common.views.pdfproperties.basic.CBasicPropertiesFragment;
 import com.compdfkit.tools.common.views.pdfproperties.colorlist.CColorListView;
 import com.compdfkit.tools.common.views.pdfproperties.colorpicker.CColorPickerFragment;
 import com.compdfkit.tools.common.views.pdfproperties.colorpicker.widget.ColorPickerView;
+import com.google.android.material.bottomsheet.BottomSheetBehavior;
 import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
 
 import java.util.ArrayList;
@@ -77,6 +79,13 @@ public class CAnnotStyleDialogFragment extends BottomSheetDialogFragment impleme
         viewModel.setStyle(style);
     }
 
+    @Override
+    public void onStart() {
+        super.onStart();
+        BottomSheetBehavior<View> behavior = BottomSheetBehavior.from((View) getView().getParent());
+        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
+    }
+
     @Nullable
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

+ 8 - 2
compdfkit-tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfannotstyle/CAnnotStyle.java

@@ -56,9 +56,9 @@ public class CAnnotStyle {
 
     private CPDFBorderStyle borderStyle = new CPDFBorderStyle(CPDFBorderStyle.Style.Border_Solid, 10, new float[]{8.0F, 9F});
 
-    private CPDFLineAnnotation.LineType startLineType;
+    private CPDFLineAnnotation.LineType startLineType = CPDFLineAnnotation.LineType.LINETYPE_NONE;
 
-    private CPDFLineAnnotation.LineType endLineType;
+    private CPDFLineAnnotation.LineType endLineType = CPDFLineAnnotation.LineType.LINETYPE_NONE;
 
     private boolean fontBold;
 
@@ -387,6 +387,12 @@ public class CAnnotStyle {
             case CIRCLE:
                 titleResId = R.string.tools_annot_circle;
                 break;
+            case LINE:
+                titleResId = R.string.tools_annot_line;
+                break;
+            case ARROW:
+                titleResId = R.string.tools_annot_arrow;
+                break;
             default:
                 titleResId = R.string.tools_menu_pdfview;
                 break;

+ 2 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfannotstyle/data/CPropertiesFragmentDatas.java

@@ -43,6 +43,8 @@ public class CPropertiesFragmentDatas {
                 break;
             case SQUARE:
             case CIRCLE:
+            case LINE:
+            case ARROW:
                 list.addAll(squareFragments(style));
                 break;
             default:

+ 25 - 2
compdfkit-tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfannotstyle/manager/CAnnotStyleManager.java

@@ -21,6 +21,7 @@ import com.compdfkit.ui.attribute.CPDFAnnotAttribute;
 import com.compdfkit.ui.attribute.CPDFCircleAttr;
 import com.compdfkit.ui.attribute.CPDFHighlightAttr;
 import com.compdfkit.ui.attribute.CPDFInkAttr;
+import com.compdfkit.ui.attribute.CPDFLineAttr;
 import com.compdfkit.ui.attribute.CPDFSquareAttr;
 import com.compdfkit.ui.attribute.CPDFSquigglyAttr;
 import com.compdfkit.ui.attribute.CPDFStrikeoutAttr;
@@ -28,8 +29,6 @@ import com.compdfkit.ui.attribute.CPDFUnderlineAttr;
 import com.compdfkit.ui.attribute.IAttributeCallback;
 import com.compdfkit.ui.attribute.form.CPDFTextfieldAttr;
 
-import java.util.HashMap;
-import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 
 public class CAnnotStyleManager implements CAnnotStyle.OnAnnotStyleChangeListener {
@@ -105,6 +104,17 @@ public class CAnnotStyleManager implements CAnnotStyle.OnAnnotStyleChangeListene
                     circleAttr.setBorderWidth(params.getBorderWidth());
                     circleAttr.setBorderStyle(params.getBorderStyle());
                     break;
+                case LINE:
+                case ARROW:
+                    CPDFLineAttr lineAttr = attribute.getLineAttr();
+                    lineAttr.setLineColor(params.getLineColor());
+                    lineAttr.setLineAlpha(params.getLineColorOpacity());
+                    lineAttr.setFillColor(params.getFillColor());
+                    lineAttr.setFillAlpha(params.getFillColorOpacity());
+                    lineAttr.setBorderWidth(params.getBorderWidth());
+                    lineAttr.setBorderStyle(params.getBorderStyle());
+                    lineAttr.setLineType(params.getStartLineType(), params.getEndLineType());
+                    break;
                 default:
                     break;
             }
@@ -226,6 +236,19 @@ public class CAnnotStyleManager implements CAnnotStyle.OnAnnotStyleChangeListene
                 style.setLineColorOpacity(circleAttr.getLineAlpha());
                 style.setBorderWidth(circleAttr.getBorderWidth());
                 style.setBorderStyle(circleAttr.getBorderStyle());
+                break;
+            case LINE:
+            case ARROW:
+                CPDFLineAttr lineAttr = attribute.getLineAttr();
+                style.setLineColor(lineAttr.getLineColor());
+                style.setLineColorOpacity(lineAttr.getLineAlpha());
+                style.setFillColor(lineAttr.getFillColor());
+                style.setFillColorOpacity(lineAttr.getFillAlpha());
+                style.setBorderStyle(lineAttr.getBorderStyle());
+                style.setBorderWidth(lineAttr.getBorderWidth());
+                style.setStartLineType(lineAttr.getHeadType());
+                style.setEndLineType(lineAttr.getTailType());
+
                 break;
             default:
                 break;

+ 16 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfshape/CShapeStyleFragment.java

@@ -18,10 +18,12 @@ import android.view.ViewGroup;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.constraintlayout.widget.ConstraintLayout;
 
 import com.compdfkit.core.annotation.CPDFBorderStyle;
 import com.compdfkit.tools.R;
 import com.compdfkit.tools.annotation.pdfproperties.pdfannotstyle.CAnnotStyle;
+import com.compdfkit.tools.common.views.pdfannotationbar.bean.CAnnotationType;
 import com.compdfkit.tools.common.views.pdfproperties.basic.CBasicPropertiesFragment;
 import com.compdfkit.tools.common.views.pdfproperties.colorlist.CColorListView;
 import com.compdfkit.tools.common.views.pdfproperties.colorpicker.widget.ColorPickerView;
@@ -43,6 +45,10 @@ public class CShapeStyleFragment extends CBasicPropertiesFragment {
 
     private CSliderBar dashedSliderBar;
 
+    private ConstraintLayout clStartLineType;
+
+    private ConstraintLayout clTailLineType;
+
     public static CShapeStyleFragment newInstance() {
         return new CShapeStyleFragment();
     }
@@ -57,6 +63,8 @@ public class CShapeStyleFragment extends CBasicPropertiesFragment {
         opacitySliderBar = rootView.findViewById(R.id.slider_bar);
         borderWidthSliderBar = rootView.findViewById(R.id.slider_bar_border_width);
         dashedSliderBar = rootView.findViewById(R.id.dashed_slider_bar);
+        clStartLineType = rootView.findViewById(R.id.cl_start_line_type);
+        clTailLineType = rootView.findViewById(R.id.cl_tail_line_type);
         return rootView;
     }
 
@@ -79,7 +87,15 @@ public class CShapeStyleFragment extends CBasicPropertiesFragment {
 
             opacitySliderBar.setProgress(cAnnotStyle.getLineColorOpacity());
             dashedSliderBar.setProgress((int) cAnnotStyle.getBorderStyle().getDashArr()[1]);
+
+            if (cAnnotStyle.getType() == CAnnotationType.ARROW || cAnnotStyle.getType() == CAnnotationType.LINE){
+                fillColorListView.setVisibility(View.GONE);
+                borderColorListView.setTitle(R.string.tools_color);
+                clStartLineType.setVisibility(View.VISIBLE);
+                clTailLineType.setVisibility(View.VISIBLE);
+            }
         }
+
         viewModel.addStyleChangeListener(this);
 
         opacitySliderBar.setChangeListener((opacity, percentageValue) -> updateColorOpacity(opacity));

+ 15 - 1
compdfkit-tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/colorlist/CColorListView.java

@@ -18,6 +18,7 @@ import android.widget.LinearLayout;
 
 import androidx.annotation.ColorInt;
 import androidx.annotation.Nullable;
+import androidx.annotation.StringRes;
 import androidx.appcompat.widget.AppCompatTextView;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
@@ -47,6 +48,7 @@ public class CColorListView extends LinearLayout {
     private OnColorPickerClickListener colorPickerClickListener;
 
     private int colorListResId = R.array.tools_annot_markup_colors;
+    private AppCompatTextView tvTitle;
 
     public CColorListView(Context context) {
         this(context, null);
@@ -77,7 +79,7 @@ public class CColorListView extends LinearLayout {
     private void init(Context context){
         inflate(context, R.layout.tools_color_list_view_layout, this);
         RecyclerView rvColor = findViewById(R.id.rv_color);
-        AppCompatTextView tvTitle = findViewById(R.id.tv_color_title);
+        tvTitle = findViewById(R.id.tv_color_title);
         if (!showTitle){
             tvTitle.setVisibility(GONE);
         }
@@ -134,6 +136,18 @@ public class CColorListView extends LinearLayout {
         }
     }
 
+    public void setTitle(@StringRes int titleResId){
+        if (tvTitle != null) {
+            tvTitle.setText(titleResId);
+        }
+    }
+
+    public void setTitle(String title){
+        if (tvTitle != null) {
+            tvTitle.setText(title);
+        }
+    }
+
     public void setOnColorSelectListener(COnColorSelectListener onColorSelectListener) {
         this.onColorSelectListener = onColorSelectListener;
     }

+ 12 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/preview/CAnnotShapePreviewView.java

@@ -15,6 +15,8 @@ import androidx.annotation.IntRange;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
+import com.compdfkit.core.annotation.CPDFBorderStyle;
+
 /**
  * @classname:
  * @author: LiuXiaoLong
@@ -257,6 +259,16 @@ public class CAnnotShapePreviewView extends CBasicAnnotPreviewView {
                             fillRectF.right + (borderWidth / 2F),
                             fillRectF.bottom + (borderWidth / 2F));
                     canvas.drawOval(borderRectF, borderPaint);
+                    break;
+                case LINE:
+                    float lineWidth = getHeight();
+                    float startX = (float) getWidth() / 2F - (lineWidth / 2);
+                    float startY = (getHeight() / 2F) + borderWidth;
+                    float stopX = startX + getHeight();
+                    float stopY = (getHeight() / 2F) + borderWidth;
+                    canvas.drawLine(startX, startY, stopX, stopY, borderPaint);
+                    break;
+                case ARROW:
 
                     break;
                 default:

+ 16 - 8
compdfkit-tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/preview/CStylePreviewView.java

@@ -62,32 +62,32 @@ public class CStylePreviewView extends FrameLayout {
         }
     }
 
-    public void setColorOpacity(int colorOpacity){
-        if (previewView != null){
+    public void setColorOpacity(int colorOpacity) {
+        if (previewView != null) {
             previewView.setColorOpacity(colorOpacity);
         }
     }
 
-    public void setBorderWidth(int width){
-        if (previewView != null){
+    public void setBorderWidth(int width) {
+        if (previewView != null) {
             previewView.setBorderWidth(width);
         }
     }
 
-    public void setBorderColor(@ColorInt int color){
+    public void setBorderColor(@ColorInt int color) {
         if (previewView != null) {
             previewView.setBorderColor(color);
         }
     }
 
-    public void setBorderColorOpacity(int opacity){
+    public void setBorderColorOpacity(int opacity) {
         if (previewView != null) {
             previewView.setBorderColorOpacity(opacity);
         }
     }
 
-    public void setDashedSpaceWidth(int dashedSpace){
-        if(previewView != null){
+    public void setDashedSpaceWidth(int dashedSpace) {
+        if (previewView != null) {
             previewView.setDashedGsp(dashedSpace);
         }
     }
@@ -118,6 +118,14 @@ public class CStylePreviewView extends FrameLayout {
                 previewView = new CAnnotShapePreviewView(getContext());
                 previewView.setShapeType(CAnnotShapePreviewView.CShapeView.ShapeType.CIRCLE);
                 break;
+            case LINE:
+                previewView = new CAnnotShapePreviewView(getContext());
+                previewView.setShapeType(CAnnotShapePreviewView.CShapeView.ShapeType.LINE);
+                break;
+            case ARROW:
+                previewView = new CAnnotShapePreviewView(getContext());
+                previewView.setShapeType(CAnnotShapePreviewView.CShapeView.ShapeType.ARROW);
+                break;
             default:
                 break;
         }

+ 34 - 28
compdfkit-tools/src/main/res/layout/tools_properties_markup_style_fragment.xml

@@ -1,37 +1,43 @@
 <?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"
+<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:paddingBottom="16dp"
-    >
+    android:layout_height="match_parent">
 
 
-    <com.compdfkit.tools.common.views.pdfproperties.preview.CStylePreviewView
-        android:id="@+id/style_preview"
+    <androidx.constraintlayout.widget.ConstraintLayout
+        xmlns:app="http://schemas.android.com/apk/res-auto"
         android:layout_width="match_parent"
-        android:layout_height="80dp"
-        app:tools_annot_type="highlight"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        android:layout_height="match_parent"
+        android:paddingBottom="16dp">
 
 
-    <com.compdfkit.tools.common.views.pdfproperties.colorlist.CColorListView
-        android:id="@+id/color_list_view"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@id/style_preview" />
+        <com.compdfkit.tools.common.views.pdfproperties.preview.CStylePreviewView
+            android:id="@+id/style_preview"
+            android:layout_width="match_parent"
+            android:layout_height="80dp"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            app:tools_annot_type="highlight" />
 
-    <com.compdfkit.tools.common.views.pdfproperties.sliderbar.CSliderBar
-        android:id="@+id/slider_bar"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:max="255"
-        android:layout_marginTop="8dp"
-        app:layout_constraintTop_toBottomOf="@id/color_list_view"
-        app:tools_slider_bar_value_show_type="percentage" />
 
-</androidx.constraintlayout.widget.ConstraintLayout>
+        <com.compdfkit.tools.common.views.pdfproperties.colorlist.CColorListView
+            android:id="@+id/color_list_view"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@id/style_preview" />
+
+        <com.compdfkit.tools.common.views.pdfproperties.sliderbar.CSliderBar
+            android:id="@+id/slider_bar"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="8dp"
+            android:max="255"
+            app:layout_constraintTop_toBottomOf="@id/color_list_view"
+            app:tools_slider_bar_value_show_type="percentage" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+</androidx.core.widget.NestedScrollView>

+ 22 - 20
compdfkit-tools/src/main/res/layout/tools_properties_note_style_fragment.xml

@@ -1,27 +1,29 @@
 <?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"
+<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:paddingBottom="16dp">
+    android:layout_height="wrap_content">
 
-
-    <com.compdfkit.tools.common.views.pdfproperties.preview.CStylePreviewView
-        android:id="@+id/style_preview"
+    <androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
         android:layout_width="match_parent"
-        android:layout_height="80dp"
-        app:tools_annot_type="text"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        android:layout_height="wrap_content"
+        android:paddingBottom="16dp">
 
+        <com.compdfkit.tools.common.views.pdfproperties.preview.CStylePreviewView
+            android:id="@+id/style_preview"
+            android:layout_width="match_parent"
+            android:layout_height="80dp"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            app:tools_annot_type="text" />
 
-    <com.compdfkit.tools.common.views.pdfproperties.colorlist.CColorListView
-        android:id="@+id/color_list_view"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@id/style_preview" />
+        <com.compdfkit.tools.common.views.pdfproperties.colorlist.CColorListView
+            android:id="@+id/color_list_view"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@id/style_preview" />
 
-</androidx.constraintlayout.widget.ConstraintLayout>
+    </androidx.constraintlayout.widget.ConstraintLayout>
+</androidx.core.widget.NestedScrollView>

+ 63 - 0
compdfkit-tools/src/main/res/layout/tools_properties_shape_style_fragment.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:id="@+id/cl_rootView"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
@@ -64,4 +65,66 @@
         app:tools_slider_bar_value_show_type="source"
         app:tools_title="@string/tools_dashed_setting" />
 
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/cl_start_line_type"
+        android:layout_width="match_parent"
+        android:layout_height="60dp"
+        android:visibility="gone"
+        app:layout_constraintTop_toBottomOf="@id/dashed_slider_bar">
+
+        <androidx.appcompat.widget.AppCompatTextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="16dp"
+            android:text="@string/tools_annot_start_line_style"
+            android:textColor="?android:attr/textColorPrimary"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+        <androidx.appcompat.widget.AppCompatImageView
+            android:id="@+id/iv_start_line_style"
+            android:layout_width="45dp"
+            android:layout_height="45dp"
+            android:layout_marginEnd="16dp"
+            android:padding="8dp"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            app:srcCompat="@drawable/tools_ic_right_arrow" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/cl_tail_line_type"
+        android:layout_width="match_parent"
+        android:layout_height="60dp"
+        android:visibility="gone"
+        app:layout_constraintTop_toBottomOf="@id/cl_start_line_type">
+
+        <androidx.appcompat.widget.AppCompatTextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="16dp"
+            android:text="@string/tools_annot_tail_line_style"
+            android:textColor="?android:attr/textColorPrimary"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+        <androidx.appcompat.widget.AppCompatImageView
+            android:id="@+id/iv_tail_line_style"
+            android:layout_width="45dp"
+            android:layout_height="45dp"
+            android:layout_marginEnd="16dp"
+            android:padding="8dp"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            app:srcCompat="@drawable/tools_ic_right_arrow" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
 </androidx.constraintlayout.widget.ConstraintLayout>

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

@@ -86,6 +86,10 @@
     <string name="tools_annot_ink">Ink</string>
     <string name="tools_annot_square">Square</string>
     <string name="tools_annot_circle">Circle</string>
+    <string name="tools_annot_line">Line</string>
+    <string name="tools_annot_arrow">Arrow</string>
+    <string name="tools_annot_start_line_style">Start Line Style</string>
+    <string name="tools_annot_tail_line_style">Tail Line Style</string>