Browse Source

PDFTools(Android) - 1.Circle Shape UI及交互

liuxiaolong 1 year ago
parent
commit
5622fa7311

+ 3 - 1
compdfkit-tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfannotstyle/CAnnotStyle.java

@@ -372,7 +372,6 @@ public class CAnnotStyle {
             case STRIKEOUT:
                 titleResId = R.string.tools_annot_strikeout;
                 break;
-
             case UNDERLINE:
                 titleResId = R.string.tools_annot_underline;
                 break;
@@ -385,6 +384,9 @@ public class CAnnotStyle {
             case SQUARE:
                 titleResId = R.string.tools_annot_square;
                 break;
+            case CIRCLE:
+                titleResId = R.string.tools_annot_circle;
+                break;
             default:
                 titleResId = R.string.tools_menu_pdfview;
                 break;

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

@@ -42,8 +42,8 @@ public class CPropertiesFragmentDatas {
                 list.addAll(inkFragments(style));
                 break;
             case SQUARE:
+            case CIRCLE:
                 list.addAll(squareFragments(style));
-
                 break;
             default:
                break;

+ 19 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfannotstyle/manager/CAnnotStyleManager.java

@@ -18,6 +18,7 @@ import com.compdfkit.tools.annotation.pdfproperties.pdfannotstyle.CAnnotStyle;
 import com.compdfkit.tools.common.views.pdfannotationbar.bean.CAnnotationType;
 import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl;
 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.CPDFSquareAttr;
@@ -95,6 +96,15 @@ public class CAnnotStyleManager implements CAnnotStyle.OnAnnotStyleChangeListene
                     squareAttr.setBorderWidth(params.getBorderWidth());
                     squareAttr.setBorderStyle(params.getBorderStyle());
                     break;
+                case CIRCLE:
+                    CPDFCircleAttr circleAttr = attribute.getCircleAttr();
+                    circleAttr.setBgColor(params.getFillColor());
+                    circleAttr.setBgAlpha(params.getFillColorOpacity());
+                    circleAttr.setLineColor(params.getLineColor());
+                    circleAttr.setLineAlpha(params.getLineColorOpacity());
+                    circleAttr.setBorderWidth(params.getBorderWidth());
+                    circleAttr.setBorderStyle(params.getBorderStyle());
+                    break;
                 default:
                     break;
             }
@@ -208,6 +218,15 @@ public class CAnnotStyleManager implements CAnnotStyle.OnAnnotStyleChangeListene
                 style.setBorderWidth(squareAttr.getBorderWidth());
                 style.setBorderStyle(squareAttr.getBorderStyle());
                 break;
+            case CIRCLE:
+                CPDFCircleAttr circleAttr = attribute.getCircleAttr();
+                style.setFillColor(circleAttr.getBgColor());
+                style.setFillColorOpacity(circleAttr.getBgAlpha());
+                style.setLineColor(circleAttr.getLineColor());
+                style.setLineColorOpacity(circleAttr.getLineAlpha());
+                style.setBorderWidth(circleAttr.getBorderWidth());
+                style.setBorderStyle(circleAttr.getBorderStyle());
+                break;
             default:
                 break;
         }

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

@@ -65,6 +65,7 @@ public class CShapeStyleFragment extends CBasicPropertiesFragment {
         super.onViewCreated(view, savedInstanceState);
         CAnnotStyle cAnnotStyle = viewModel.getStyle();
         if (cAnnotStyle != null) {
+            stylePreviewView.setAnnotType(cAnnotStyle.getType());
             stylePreviewView.setColor(cAnnotStyle.getFillColor());
             stylePreviewView.setColorOpacity(cAnnotStyle.getFillColorOpacity());
             stylePreviewView.setBorderWidth((int) cAnnotStyle.getBorderWidth());

+ 43 - 14
compdfkit-tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/preview/CAnnotShapePreviewView.java

@@ -5,8 +5,8 @@ import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.DashPathEffect;
 import android.graphics.Paint;
-import android.graphics.Path;
 import android.graphics.Rect;
+import android.graphics.RectF;
 import android.util.AttributeSet;
 import android.view.View;
 
@@ -89,9 +89,16 @@ public class CAnnotShapePreviewView extends CBasicAnnotPreviewView {
     }
 
     @Override
-    public void setDashedSpace(int dashedSpace) {
+    public void setDashedGsp(int dashedGap) {
         if (shapeView != null) {
-            shapeView.setDashGap(dashedSpace);
+            shapeView.setDashGap(dashedGap);
+        }
+    }
+
+    @Override
+    public void setShapeType(CShapeView.ShapeType shapeType){
+        if (shapeView != null){
+            shapeView.setShapeType(shapeType);
         }
     }
 
@@ -99,7 +106,7 @@ public class CAnnotShapePreviewView extends CBasicAnnotPreviewView {
 
         enum ShapeType {
             SQUARE,
-            OVAL,
+            CIRCLE,
             LINE,
             ARROW,
         }
@@ -121,14 +128,16 @@ public class CAnnotShapePreviewView extends CBasicAnnotPreviewView {
 
         private int borderWidth = 0;
 
-        private Rect squareRect = new Rect();
+        private RectF borderRectF = new RectF();
 
-        private Rect fillSquareRect = new Rect();
+        private RectF fillRectF = new RectF();
 
         private int mDashWidth = 8;
 
         private int mDashGap = 0;
 
+        private Rect sizeRect = new Rect();
+
         public CShapeView(Context context) {
             this(context, null);
         }
@@ -206,7 +215,10 @@ public class CAnnotShapePreviewView extends CBasicAnnotPreviewView {
             invalidate();
         }
 
-        private Rect sizeRect = new Rect();
+        public void setShapeType(ShapeType shapeType) {
+            this.shapeType = shapeType;
+            invalidate();
+        }
 
         @Override
         protected void onDraw(Canvas canvas) {
@@ -221,14 +233,31 @@ public class CAnnotShapePreviewView extends CBasicAnnotPreviewView {
                             (int) (left + width),
                             getHeight());
 
-                    fillSquareRect.set(sizeRect.left + borderWidth, sizeRect.top + borderWidth, sizeRect.right - borderWidth, sizeRect.bottom - borderWidth);
-                    canvas.drawRect(fillSquareRect, fillPaint);
+                    fillRectF.set(sizeRect.left + borderWidth, sizeRect.top + borderWidth, sizeRect.right - borderWidth, sizeRect.bottom - borderWidth);
+                    canvas.drawRect(fillRectF, fillPaint);
+
+                    borderRectF.set(fillRectF.left - (borderWidth / 2F),
+                            fillRectF.top - (borderWidth / 2F),
+                            fillRectF.right + (borderWidth / 2F),
+                            fillRectF.bottom + (borderWidth / 2F));
+                    canvas.drawRect(borderRectF, borderPaint);
+                    break;
+
+                case CIRCLE:
+                    float circleWidth = getHeight();
+                    float circleLeft = (float) getWidth() / 2F - (circleWidth / 2);
+                    sizeRect.set((int) circleLeft,
+                            0,
+                            (int) (circleLeft + circleWidth),
+                            getHeight());
+                    fillRectF.set(sizeRect.left + borderWidth, sizeRect.top + borderWidth, sizeRect.right - borderWidth, sizeRect.bottom - borderWidth);
+                    canvas.drawOval(fillRectF, fillPaint);
+                    borderRectF.set(fillRectF.left - (borderWidth / 2F),
+                            fillRectF.top - (borderWidth / 2F),
+                            fillRectF.right + (borderWidth / 2F),
+                            fillRectF.bottom + (borderWidth / 2F));
+                    canvas.drawOval(borderRectF, borderPaint);
 
-                    squareRect.set(fillSquareRect.left - (borderWidth / 2),
-                            fillSquareRect.top - (borderWidth / 2),
-                            fillSquareRect.right + (borderWidth / 2),
-                            fillSquareRect.bottom + (borderWidth / 2));
-                    canvas.drawRect(squareRect, borderPaint);
                     break;
                 default:
                     break;

+ 3 - 1
compdfkit-tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/preview/CBasicAnnotPreviewView.java

@@ -43,5 +43,7 @@ import androidx.annotation.Nullable;
 
      public void setBorderColorOpacity(@IntRange(from = 0, to = 255) int colorOpacity){}
 
-     public void setDashedSpace(int dashedSpace){}
+     public void setDashedGsp(int dashedSpace){}
+
+     public void setShapeType(CAnnotShapePreviewView.CShapeView.ShapeType shapeType){}
 }

+ 6 - 1
compdfkit-tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/preview/CStylePreviewView.java

@@ -88,7 +88,7 @@ public class CStylePreviewView extends FrameLayout {
 
     public void setDashedSpaceWidth(int dashedSpace){
         if(previewView != null){
-            previewView.setDashedSpace(dashedSpace);
+            previewView.setDashedGsp(dashedSpace);
         }
     }
 
@@ -112,6 +112,11 @@ public class CStylePreviewView extends FrameLayout {
                 break;
             case SQUARE:
                 previewView = new CAnnotShapePreviewView(getContext());
+                previewView.setShapeType(CAnnotShapePreviewView.CShapeView.ShapeType.SQUARE);
+                break;
+            case CIRCLE:
+                previewView = new CAnnotShapePreviewView(getContext());
+                previewView.setShapeType(CAnnotShapePreviewView.CShapeView.ShapeType.CIRCLE);
                 break;
             default:
                 break;

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

@@ -85,6 +85,7 @@
     <string name="tools_annot_squiggly">Squiggly</string>
     <string name="tools_annot_ink">Ink</string>
     <string name="tools_annot_square">Square</string>
+    <string name="tools_annot_circle">Circle</string>