|
@@ -7,18 +7,21 @@
|
|
|
* This notice may not be removed from this file.
|
|
|
*/
|
|
|
|
|
|
-package com.compdfkit.tools.annotation.pdfproperties.pdfattr;
|
|
|
+package com.compdfkit.tools.annotation.pdfproperties.pdfannotstyle;
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.graphics.Color;
|
|
|
import android.os.Parcel;
|
|
|
import android.os.Parcelable;
|
|
|
+import android.util.Log;
|
|
|
|
|
|
import androidx.annotation.ColorInt;
|
|
|
import androidx.annotation.ColorRes;
|
|
|
import androidx.annotation.FloatRange;
|
|
|
import androidx.annotation.IntRange;
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
|
import com.compdfkit.core.annotation.CPDFLineAnnotation;
|
|
@@ -27,23 +30,26 @@ import com.compdfkit.core.annotation.CPDFTextAttribute;
|
|
|
import com.compdfkit.tools.R;
|
|
|
import com.compdfkit.tools.common.views.pdfannotationbar.bean.CAnnotationType;
|
|
|
|
|
|
-public class CAnnotStyle implements Parcelable ,Cloneable{
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class CAnnotStyle implements Parcelable, Cloneable {
|
|
|
|
|
|
private CAnnotationType type;
|
|
|
|
|
|
private int color = Color.BLACK;
|
|
|
|
|
|
- private int colorAlpha = 255;
|
|
|
+ private int colorOpacity = 255;
|
|
|
|
|
|
private float borderWidth;
|
|
|
|
|
|
private int lineColor = Color.BLACK;
|
|
|
|
|
|
- private int lineColorAlpha = 255;
|
|
|
+ private int lineColorOpacity = 255;
|
|
|
|
|
|
private int fillColor = Color.BLACK;
|
|
|
|
|
|
- private int fillAlpha = 255;
|
|
|
+ private int fillColorOpacity = 255;
|
|
|
|
|
|
private CPDFLineAnnotation.LineType startLineType;
|
|
|
|
|
@@ -55,7 +61,7 @@ public class CAnnotStyle implements Parcelable ,Cloneable{
|
|
|
|
|
|
private int textColor = Color.BLACK;
|
|
|
|
|
|
- private int textColorAlpha = 255;
|
|
|
+ private int textColorOpacity = 255;
|
|
|
|
|
|
private int fontSize;
|
|
|
|
|
@@ -71,22 +77,24 @@ public class CAnnotStyle implements Parcelable ,Cloneable{
|
|
|
|
|
|
private CPDFStampAnnotation.TextStampColor textStampColor;
|
|
|
|
|
|
+ private List<OnAnnotStyleChangeListener> styleChangeListenerList = new ArrayList<>();
|
|
|
+
|
|
|
public CAnnotStyle(CAnnotationType type) {
|
|
|
this.type = type;
|
|
|
}
|
|
|
|
|
|
protected CAnnotStyle(Parcel in) {
|
|
|
color = in.readInt();
|
|
|
- colorAlpha = in.readInt();
|
|
|
+ colorOpacity = in.readInt();
|
|
|
borderWidth = in.readFloat();
|
|
|
lineColor = in.readInt();
|
|
|
- lineColorAlpha = in.readInt();
|
|
|
+ lineColorOpacity = in.readInt();
|
|
|
fillColor = in.readInt();
|
|
|
- fillAlpha = in.readInt();
|
|
|
+ fillColorOpacity = in.readInt();
|
|
|
fontBold = in.readByte() != 0;
|
|
|
fontItalic = in.readByte() != 0;
|
|
|
textColor = in.readInt();
|
|
|
- textColorAlpha = in.readInt();
|
|
|
+ textColorOpacity = in.readInt();
|
|
|
fontSize = in.readInt();
|
|
|
imagePath = in.readString();
|
|
|
textStampContent = in.readString();
|
|
@@ -96,16 +104,16 @@ public class CAnnotStyle implements Parcelable ,Cloneable{
|
|
|
@Override
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
|
|
dest.writeInt(color);
|
|
|
- dest.writeInt(colorAlpha);
|
|
|
+ dest.writeInt(colorOpacity);
|
|
|
dest.writeFloat(borderWidth);
|
|
|
dest.writeInt(lineColor);
|
|
|
- dest.writeInt(lineColorAlpha);
|
|
|
+ dest.writeInt(lineColorOpacity);
|
|
|
dest.writeInt(fillColor);
|
|
|
- dest.writeInt(fillAlpha);
|
|
|
+ dest.writeInt(fillColorOpacity);
|
|
|
dest.writeByte((byte) (fontBold ? 1 : 0));
|
|
|
dest.writeByte((byte) (fontItalic ? 1 : 0));
|
|
|
dest.writeInt(textColor);
|
|
|
- dest.writeInt(textColorAlpha);
|
|
|
+ dest.writeInt(textColorOpacity);
|
|
|
dest.writeInt(fontSize);
|
|
|
dest.writeString(imagePath);
|
|
|
dest.writeString(textStampContent);
|
|
@@ -133,28 +141,26 @@ public class CAnnotStyle implements Parcelable ,Cloneable{
|
|
|
return type;
|
|
|
}
|
|
|
|
|
|
- public void setType(CAnnotationType type) {
|
|
|
- this.type = type;
|
|
|
- }
|
|
|
-
|
|
|
public int getColor() {
|
|
|
return color;
|
|
|
}
|
|
|
|
|
|
public void setColor(@ColorInt int color) {
|
|
|
+ boolean update = color != this.color;
|
|
|
this.color = color;
|
|
|
+ Log.e("CAnnotStyle", "setColor(" + color + ", update:" + update + ")");
|
|
|
+ updateColorListener(this.color, update);
|
|
|
}
|
|
|
|
|
|
- public void setColor(Context context, @ColorRes int colorRes) {
|
|
|
- this.color = ContextCompat.getColor(context, colorRes);
|
|
|
+ public int getColorOpacity() {
|
|
|
+ return colorOpacity;
|
|
|
}
|
|
|
|
|
|
- public int getColorAlpha() {
|
|
|
- return colorAlpha;
|
|
|
- }
|
|
|
-
|
|
|
- public void setColorAlpha(@IntRange(from = 0, to = 255) int colorAlpha) {
|
|
|
- this.colorAlpha = colorAlpha;
|
|
|
+ public void setColorOpacity(@IntRange(from = 0, to = 255) int colorOpacity) {
|
|
|
+ boolean update = colorOpacity != this.colorOpacity;
|
|
|
+ this.colorOpacity = colorOpacity;
|
|
|
+ Log.e("CAnnotStyle", "setColorOpacity(" + colorOpacity + ", update:" + update + ")");
|
|
|
+ updateColorOpacity(this.colorOpacity, update);
|
|
|
}
|
|
|
|
|
|
public float getBorderWidth() {
|
|
@@ -177,12 +183,12 @@ public class CAnnotStyle implements Parcelable ,Cloneable{
|
|
|
this.lineColor = ContextCompat.getColor(context, colorRes);
|
|
|
}
|
|
|
|
|
|
- public int getLineColorAlpha() {
|
|
|
- return lineColorAlpha;
|
|
|
+ public int getLineColorOpacity() {
|
|
|
+ return lineColorOpacity;
|
|
|
}
|
|
|
|
|
|
- public void setLineColorAlpha(@IntRange(from = 0, to = 255) int lineColorAlpha) {
|
|
|
- this.lineColorAlpha = lineColorAlpha;
|
|
|
+ public void setLineColorOpacity(@IntRange(from = 0, to = 255) int lineColorAlpha) {
|
|
|
+ this.lineColorOpacity = lineColorAlpha;
|
|
|
}
|
|
|
|
|
|
public int getFillColor() {
|
|
@@ -197,12 +203,12 @@ public class CAnnotStyle implements Parcelable ,Cloneable{
|
|
|
this.fillColor = ContextCompat.getColor(context, colorRes);
|
|
|
}
|
|
|
|
|
|
- public int getFillAlpha() {
|
|
|
- return fillAlpha;
|
|
|
+ public int getFillColorOpacity() {
|
|
|
+ return fillColorOpacity;
|
|
|
}
|
|
|
|
|
|
- public void setFillAlpha(@IntRange(from = 0, to = 255) int fillAlpha) {
|
|
|
- this.fillAlpha = fillAlpha;
|
|
|
+ public void setFillColorOpacity(@IntRange(from = 0, to = 255) int fillColorOpacity) {
|
|
|
+ this.fillColorOpacity = fillColorOpacity;
|
|
|
}
|
|
|
|
|
|
public CPDFLineAnnotation.LineType getStartLineType() {
|
|
@@ -249,12 +255,12 @@ public class CAnnotStyle implements Parcelable ,Cloneable{
|
|
|
this.textColor = ContextCompat.getColor(context, colorRes);
|
|
|
}
|
|
|
|
|
|
- public int getTextColorAlpha() {
|
|
|
- return textColorAlpha;
|
|
|
+ public int getTextColorOpacity() {
|
|
|
+ return textColorOpacity;
|
|
|
}
|
|
|
|
|
|
- public void setTextColorAlpha(@IntRange(from = 0, to = 255) int textColorAlpha) {
|
|
|
- this.textColorAlpha = textColorAlpha;
|
|
|
+ public void setTextColorOpacity(@IntRange(from = 0, to = 255) int textColorOpacity) {
|
|
|
+ this.textColorOpacity = textColorOpacity;
|
|
|
}
|
|
|
|
|
|
public int getFontSize() {
|
|
@@ -313,6 +319,66 @@ public class CAnnotStyle implements Parcelable ,Cloneable{
|
|
|
this.textStampColor = textStampColor;
|
|
|
}
|
|
|
|
|
|
+ @NonNull
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "CAnnotStyle{" +
|
|
|
+ "type:" + type + "," +
|
|
|
+ "color" + color + "," +
|
|
|
+ "colorOpacity" + colorOpacity + "," +
|
|
|
+ "borderWidth" + borderWidth + "," +
|
|
|
+ "lineColor" + lineColor + "," +
|
|
|
+ "lineColorOpacity" + lineColorOpacity + "," +
|
|
|
+ "fillColor" + fillColor + "," +
|
|
|
+ "fillColorOpacity" + fillColorOpacity + "," +
|
|
|
+ "startLineType" + (startLineType != null ? startLineType.name() : "empty") + "," +
|
|
|
+ "endLineType" + (endLineType != null ? endLineType.name() : "empty") + "," +
|
|
|
+ "fontBold" + fontBold + "," +
|
|
|
+ "fontItalic" + fontItalic + "," +
|
|
|
+ "textColor" + textColor + "," +
|
|
|
+ "textColorOpacity" + textColorOpacity + "," +
|
|
|
+ "fontSize" + fontSize + "," +
|
|
|
+ "fontType" + (fontType != null ? fontType.name() : "empty") + "," +
|
|
|
+ "imagePath" + imagePath + "," +
|
|
|
+ "textStampContent" + textStampContent + "," +
|
|
|
+ "textStampDate" + textStampDate + "," +
|
|
|
+ "textStampShape" + (textStampShape != null ? textStampShape.name() : "empty") + "," +
|
|
|
+ "textStampColor" + (textStampColor != null ? textStampColor.name() : "empty") + ",";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int hashCode() {
|
|
|
+ int result = this.borderWidth != 0.0F ? Float.floatToIntBits(this.borderWidth) : 0;
|
|
|
+ result = 31 * result + this.color;
|
|
|
+ result = 31 * result + (this.colorOpacity != 0.0F ? Float.floatToIntBits(this.colorOpacity) : 0);
|
|
|
+ result = 31 * result + this.lineColor;
|
|
|
+ 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.startLineType != null ? this.startLineType.hashCode() : 0);
|
|
|
+ result = 31 * result + (this.endLineType != null ? this.endLineType.hashCode() : 0);
|
|
|
+ result = 31 * result + this.textColor;
|
|
|
+ result = 31 * result + (this.textColorOpacity != 0.0F ? Float.floatToIntBits(this.textColorOpacity) : 0);
|
|
|
+ result = 31 * result + (this.fontSize != 0.0F ? Float.floatToIntBits(this.fontSize) : 0);
|
|
|
+ result = 31 * result + (this.fontType != null ? this.fontType.hashCode() : 0);
|
|
|
+ result = 31 * result + (this.imagePath != null ? this.imagePath.hashCode() : 0);
|
|
|
+ result = 31 * result + (this.textStampContent != null ? this.textStampContent.hashCode() : 0);
|
|
|
+ result = 31 * result + (this.textStampDate != null ? this.textStampDate.hashCode() : 0);
|
|
|
+ result = 31 * result + (this.type != null ? type.hashCode() : 0);
|
|
|
+ result = 31 * result + (this.textStampShape != null ? this.textStampShape.hashCode() : 0);
|
|
|
+ result = 31 * result + (this.textStampColor != null ? this.textStampColor.hashCode() : 0);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean equals(@Nullable Object obj) {
|
|
|
+ if (obj instanceof CAnnotStyle) {
|
|
|
+ return obj.toString().equals(this.toString());
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public int getAnnotTypeTitleResId() {
|
|
|
int titleResId = 0;
|
|
|
switch (type) {
|
|
@@ -338,4 +404,41 @@ public class CAnnotStyle implements Parcelable ,Cloneable{
|
|
|
}
|
|
|
return titleResId;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private void updateColorListener(@ColorInt int color, boolean update) {
|
|
|
+ if (styleChangeListenerList != null && update) {
|
|
|
+ for (OnAnnotStyleChangeListener onAnnotStyleChangeListener : styleChangeListenerList) {
|
|
|
+ onAnnotStyleChangeListener.onChangeAnnotColor(color);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateColorOpacity(int colorOpacity, boolean update) {
|
|
|
+ if (styleChangeListenerList != null && update) {
|
|
|
+ for (OnAnnotStyleChangeListener onAnnotStyleChangeListener : styleChangeListenerList) {
|
|
|
+ onAnnotStyleChangeListener.onChangeAnnotColorOpacity(colorOpacity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addStyleChangeListener(OnAnnotStyleChangeListener styleChangeListener) {
|
|
|
+ this.styleChangeListenerList.add(styleChangeListener);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addStyleChangeListener(List<OnAnnotStyleChangeListener> styleChangeListener) {
|
|
|
+ this.styleChangeListenerList.addAll(styleChangeListener);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void removeStyleChangeListener(OnAnnotStyleChangeListener styleChangeListener) {
|
|
|
+ this.styleChangeListenerList.remove(styleChangeListener);
|
|
|
+ }
|
|
|
+
|
|
|
+ public interface OnAnnotStyleChangeListener {
|
|
|
+
|
|
|
+ void onChangeAnnotColor(@ColorInt int color);
|
|
|
+
|
|
|
+ void onChangeAnnotColorOpacity(@ColorInt int opacity);
|
|
|
+ }
|
|
|
+
|
|
|
}
|