|
@@ -24,6 +24,7 @@ import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
|
+import com.compdfkit.core.annotation.CPDFBorderStyle;
|
|
|
import com.compdfkit.core.annotation.CPDFLineAnnotation;
|
|
|
import com.compdfkit.core.annotation.CPDFStampAnnotation;
|
|
|
import com.compdfkit.core.annotation.CPDFTextAttribute;
|
|
@@ -33,7 +34,7 @@ import com.compdfkit.tools.common.views.pdfannotationbar.bean.CAnnotationType;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
-public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
+public class CAnnotStyle {
|
|
|
|
|
|
private CAnnotationType type;
|
|
|
|
|
@@ -53,6 +54,8 @@ public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
|
|
|
private int fillColorOpacity = 255;
|
|
|
|
|
|
+ private CPDFBorderStyle borderStyle = new CPDFBorderStyle(CPDFBorderStyle.Style.Border_Solid, 10, new float[]{8.0F, 9F});
|
|
|
+
|
|
|
private CPDFLineAnnotation.LineType startLineType;
|
|
|
|
|
|
private CPDFLineAnnotation.LineType endLineType;
|
|
@@ -85,59 +88,6 @@ public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
this.type = type;
|
|
|
}
|
|
|
|
|
|
- protected CAnnotStyle(Parcel in) {
|
|
|
- color = in.readInt();
|
|
|
- colorOpacity = in.readInt();
|
|
|
- borderWidth = in.readFloat();
|
|
|
- lineColor = in.readInt();
|
|
|
- lineColorOpacity = in.readInt();
|
|
|
- fillColor = in.readInt();
|
|
|
- fillColorOpacity = in.readInt();
|
|
|
- fontBold = in.readByte() != 0;
|
|
|
- fontItalic = in.readByte() != 0;
|
|
|
- textColor = in.readInt();
|
|
|
- textColorOpacity = in.readInt();
|
|
|
- fontSize = in.readInt();
|
|
|
- imagePath = in.readString();
|
|
|
- textStampContent = in.readString();
|
|
|
- textStampDate = in.readString();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void writeToParcel(Parcel dest, int flags) {
|
|
|
- dest.writeInt(color);
|
|
|
- dest.writeInt(colorOpacity);
|
|
|
- dest.writeFloat(borderWidth);
|
|
|
- dest.writeInt(lineColor);
|
|
|
- dest.writeInt(lineColorOpacity);
|
|
|
- dest.writeInt(fillColor);
|
|
|
- dest.writeInt(fillColorOpacity);
|
|
|
- dest.writeByte((byte) (fontBold ? 1 : 0));
|
|
|
- dest.writeByte((byte) (fontItalic ? 1 : 0));
|
|
|
- dest.writeInt(textColor);
|
|
|
- dest.writeInt(textColorOpacity);
|
|
|
- dest.writeInt(fontSize);
|
|
|
- dest.writeString(imagePath);
|
|
|
- dest.writeString(textStampContent);
|
|
|
- dest.writeString(textStampDate);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int describeContents() {
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- public static final Creator<CAnnotStyle> CREATOR = new Creator<CAnnotStyle>() {
|
|
|
- @Override
|
|
|
- public CAnnotStyle createFromParcel(Parcel in) {
|
|
|
- return new CAnnotStyle(in);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public CAnnotStyle[] newArray(int size) {
|
|
|
- return new CAnnotStyle[size];
|
|
|
- }
|
|
|
- };
|
|
|
|
|
|
public CAnnotationType getType() {
|
|
|
return type;
|
|
@@ -189,19 +139,21 @@ public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
}
|
|
|
|
|
|
public void setLineColor(@ColorInt int lineColor) {
|
|
|
+ boolean update = lineColor != this.lineColor;
|
|
|
this.lineColor = lineColor;
|
|
|
- }
|
|
|
-
|
|
|
- public void setLineColor(Context context, @ColorRes int colorRes) {
|
|
|
- this.lineColor = ContextCompat.getColor(context, colorRes);
|
|
|
+ Log.e("CAnnotStyle", "setLineColor(" + lineColor + ", update:" + update + ")");
|
|
|
+ updateLineColor(lineColor, update);
|
|
|
}
|
|
|
|
|
|
public int getLineColorOpacity() {
|
|
|
return lineColorOpacity;
|
|
|
}
|
|
|
|
|
|
- public void setLineColorOpacity(@IntRange(from = 0, to = 255) int lineColorAlpha) {
|
|
|
- this.lineColorOpacity = lineColorAlpha;
|
|
|
+ public void setLineColorOpacity(@IntRange(from = 0, to = 255) int lineColorOpacity) {
|
|
|
+ boolean update = lineColorOpacity != this.lineColorOpacity;
|
|
|
+ this.lineColorOpacity = lineColorOpacity;
|
|
|
+ Log.e("CAnnotStyle", "setLineColorOpacity(" + lineColorOpacity + ", update:" + update + ")");
|
|
|
+ updateLineColorOpacity(lineColorOpacity, update);
|
|
|
}
|
|
|
|
|
|
public int getFillColor() {
|
|
@@ -209,19 +161,33 @@ public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
}
|
|
|
|
|
|
public void setFillColor(@ColorInt int fillColor) {
|
|
|
+ boolean update = fillColor != this.fillColor;
|
|
|
this.fillColor = fillColor;
|
|
|
+ Log.e("CAnnotStyle", "setFillColor(" + fillColor + ", update:" + update + ")");
|
|
|
+ updateFillColor(fillColor, update);
|
|
|
}
|
|
|
|
|
|
- public void setFillColor(Context context, @ColorRes int colorRes) {
|
|
|
- this.fillColor = ContextCompat.getColor(context, colorRes);
|
|
|
- }
|
|
|
|
|
|
public int getFillColorOpacity() {
|
|
|
return fillColorOpacity;
|
|
|
}
|
|
|
|
|
|
public void setFillColorOpacity(@IntRange(from = 0, to = 255) int fillColorOpacity) {
|
|
|
+ boolean update = fillColorOpacity != this.fillColorOpacity;
|
|
|
this.fillColorOpacity = fillColorOpacity;
|
|
|
+ Log.e("CAnnotStyle", "setFillColorOpacity(" + fillColor + ", update:" + update + ")");
|
|
|
+ updateFillColorOpacity(fillColorOpacity, update);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setBorderStyle(CPDFBorderStyle borderStyle) {
|
|
|
+ boolean update = borderStyle.equals(this.borderStyle);
|
|
|
+ this.borderStyle = borderStyle;
|
|
|
+ Log.e("CAnnotStyle", "setBorderStyle(" + borderStyle + ", update:" + update + ")");
|
|
|
+ updateBorderStyle(borderStyle, update);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CPDFBorderStyle getBorderStyle() {
|
|
|
+ return borderStyle;
|
|
|
}
|
|
|
|
|
|
public CPDFLineAnnotation.LineType getStartLineType() {
|
|
@@ -344,6 +310,7 @@ public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
"lineColorOpacity" + lineColorOpacity + "," +
|
|
|
"fillColor" + fillColor + "," +
|
|
|
"fillColorOpacity" + fillColorOpacity + "," +
|
|
|
+ "borderStyle" + (borderStyle != null ? borderStyle.toString() : "empty") + "," +
|
|
|
"startLineType" + (startLineType != null ? startLineType.name() : "empty") + "," +
|
|
|
"endLineType" + (endLineType != null ? endLineType.name() : "empty") + "," +
|
|
|
"fontBold" + fontBold + "," +
|
|
@@ -368,6 +335,7 @@ public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
result = 31 * result + (this.lineColorOpacity != 0.0F ? Float.floatToIntBits(this.lineColorOpacity) : 0);
|
|
|
result = 31 * result + this.fillColor;
|
|
|
result = 31 * result + (this.fillColorOpacity != 0.0F ? Float.floatToIntBits(this.fillColorOpacity) : 0);
|
|
|
+ result = 31 * result + (this.borderStyle != null ? this.borderStyle.hashCode() : 0);
|
|
|
result = 31 * result + (this.startLineType != null ? this.startLineType.hashCode() : 0);
|
|
|
result = 31 * result + (this.endLineType != null ? this.endLineType.hashCode() : 0);
|
|
|
result = 31 * result + this.textColor;
|
|
@@ -414,6 +382,9 @@ public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
case INK:
|
|
|
titleResId = R.string.tools_annot_ink;
|
|
|
break;
|
|
|
+ case SQUARE:
|
|
|
+ titleResId = R.string.tools_annot_square;
|
|
|
+ break;
|
|
|
default:
|
|
|
titleResId = R.string.tools_menu_pdfview;
|
|
|
break;
|
|
@@ -446,6 +417,46 @@ public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void updateLineColor(int color, boolean update) {
|
|
|
+ if (styleChangeListenerList != null && update) {
|
|
|
+ for (OnAnnotStyleChangeListener onAnnotStyleChangeListener : styleChangeListenerList) {
|
|
|
+ onAnnotStyleChangeListener.onChangeAnnotLineColor(color);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateLineColorOpacity(int opacity, boolean update) {
|
|
|
+ if (styleChangeListenerList != null && update) {
|
|
|
+ for (OnAnnotStyleChangeListener onAnnotStyleChangeListener : styleChangeListenerList) {
|
|
|
+ onAnnotStyleChangeListener.onChangeAnnotLineColorOpacity(opacity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateFillColor(int color, boolean update) {
|
|
|
+ if (styleChangeListenerList != null && update) {
|
|
|
+ for (OnAnnotStyleChangeListener onAnnotStyleChangeListener : styleChangeListenerList) {
|
|
|
+ onAnnotStyleChangeListener.onChangeAnnotFillColor(color);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateFillColorOpacity(int opacity, boolean update) {
|
|
|
+ if (styleChangeListenerList != null && update) {
|
|
|
+ for (OnAnnotStyleChangeListener onAnnotStyleChangeListener : styleChangeListenerList) {
|
|
|
+ onAnnotStyleChangeListener.onChangeAnnotFillColorOpacity(opacity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateBorderStyle(CPDFBorderStyle style, boolean update) {
|
|
|
+ if (styleChangeListenerList != null && update) {
|
|
|
+ for (OnAnnotStyleChangeListener onAnnotStyleChangeListener : styleChangeListenerList) {
|
|
|
+ onAnnotStyleChangeListener.onChangeAnnotBorderStyle(style);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void addStyleChangeListener(OnAnnotStyleChangeListener styleChangeListener) {
|
|
|
this.styleChangeListenerList.add(styleChangeListener);
|
|
|
}
|
|
@@ -458,13 +469,24 @@ public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
this.styleChangeListenerList.remove(styleChangeListener);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public interface OnAnnotStyleChangeListener {
|
|
|
|
|
|
void onChangeAnnotColor(@ColorInt int color);
|
|
|
|
|
|
- void onChangeAnnotColorOpacity(@ColorInt int opacity);
|
|
|
+ void onChangeAnnotColorOpacity(int opacity);
|
|
|
|
|
|
void onChangeAnnotBorderWidth(float borderWidth);
|
|
|
+
|
|
|
+ void onChangeAnnotLineColor(@ColorInt int color);
|
|
|
+
|
|
|
+ void onChangeAnnotLineColorOpacity(int opacity);
|
|
|
+
|
|
|
+ void onChangeAnnotFillColor(@ColorInt int color);
|
|
|
+
|
|
|
+ void onChangeAnnotFillColorOpacity(int opacity);
|
|
|
+
|
|
|
+ void onChangeAnnotBorderStyle(CPDFBorderStyle style);
|
|
|
}
|
|
|
|
|
|
}
|