Class Signature
-
- All Implemented Interfaces:
-
android.os.Parcelable
public abstract class Signature implements Parcelable
Represents a single signature (or signature item). To create an InkAnnotation or from this signature use the toInkAnnotation and toStampAnnotation methods. You can check the signature annotation type through getAnnotationType.
-
-
Field Summary
Fields Modifier and Type Field Description public final static long
ID_NOT_SET
public final static int
BITMAP_NOT_SET
-
Constructor Summary
Constructors Constructor Description Signature()
-
Method Summary
Modifier and Type Method Description static Signature
create(@NonNull() Bitmap bitmap, @NonNull() RectF rect, @Nullable() BiometricSignatureData biometricSignatureData, float drawWidthRatio)
Creates the Signature. static Signature
create(@ColorInt() int inkColor, float lineWidthPdf, @NonNull() List<List<PointF>> lines, @Nullable() BiometricSignatureData biometricSignatureData, float drawWidthRatio)
Creates the Signature. static Signature
fromJson(@NonNull() JSONObject signatureJson)
Creates a signature object by parsing the provided JSON object. static Signature
fromJson(long id, @NonNull() JSONObject signatureJson)
Creates a signature object by parsing the provided JSON object. JSONObject
toJson()
Converts a signature into a JSON object. abstract AnnotationType
getAnnotationType()
Gets the annotation type of the signature, which can either be InkAnnotation or StampAnnotation. abstract long
getId()
Signature id number used in signature database. abstract int
getInkColor()
Gets color used for signature ink. abstract float
getLineWidth()
Gets signature line width. abstract List<List<PointF>>
getLines()
Access list of signature lines. abstract BiometricSignatureData
getBiometricData()
Gets the biometric data that was collected with this signature. abstract float
getSignatureDrawWidthRatio()
Gets the ratio of signature width to width of the drawing view used when drawing the signature. abstract int
getBitmapIdentifier()
Gets the bitmap identifier used for rendering the image signature, or BITMAP_NOT_SET if the signature is not represented by a bitmap. Bitmap
getBitmap()
Gets the bitmap used for rendering the image signature, or null
if the signature is not an image signature.abstract RectF
getStampRect()
Bounding rectangle for this signature's bitmap. InkAnnotation
toInkAnnotation(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @NonNull() PointF touchPoint)
Builds ink annotation from signature data. InkAnnotation
toInkAnnotation(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @NonNull() RectF targetRect)
Builds ink annotation from signature data. InkAnnotation
toInkAnnotation(@IntRange(from = 0) int pageIndex)
Builds ink annotation from signature data. StampAnnotation
toStampAnnotation(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @NonNull() PointF touchPoint)
Builds stamp annotation from signature data. StampAnnotation
toStampAnnotation(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @NonNull() RectF targetRect)
Builds stamp annotation from signature data. StampAnnotation
toStampAnnotation(@IntRange(from = 0) int pageIndex)
Builds stamp annotation from signature data. RectF
getBoundingBox()
Returns bounding box of the signature data in pdf coordinates. static Bitmap
textToBitmap(@NonNull() String text, @NonNull() Font font, @ColorInt() int color, @FloatRange(from = 0) float scaleFactor, @NonNull() DisplayMetrics displayMetrics)
Creates a bitmap from text that the user typed and a font the user chose. -
-
Method Detail
-
create
static Signature create(@NonNull() Bitmap bitmap, @NonNull() RectF rect, @Nullable() BiometricSignatureData biometricSignatureData, float drawWidthRatio)
Creates the Signature. Intended for internal usage only.
-
create
static Signature create(@ColorInt() int inkColor, float lineWidthPdf, @NonNull() List<List<PointF>> lines, @Nullable() BiometricSignatureData biometricSignatureData, float drawWidthRatio)
Creates the Signature. Intended for internal usage only.
-
fromJson
static Signature fromJson(@NonNull() JSONObject signatureJson)
Creates a signature object by parsing the provided JSON object. The JSON object you provide should be initially obtained via toJson.
- Parameters:
signatureJson
- JSON object to parse.- Returns:
Signature created from the provided JSON object.
-
fromJson
static Signature fromJson(long id, @NonNull() JSONObject signatureJson)
Creates a signature object by parsing the provided JSON object. The JSON object you provide should be initially obtained via toJson. This method also allows you to specify an id which will be assigned to the signature created from the given JSON. This id will also be assigned by the framework when retrieving the signatures from the default storage.
- Parameters:
id
- Id to be assigned to the signature.signatureJson
- JSON object to parse.- Returns:
Signature created from the provided JSON object.
-
toJson
@NonNull() JSONObject toJson()
Converts a signature into a JSON object. You can use that JSON object to recreate the signature later on via fromJson.
- Returns:
A JSON object representing a converted signature.
-
getAnnotationType
@NonNull() abstract AnnotationType getAnnotationType()
Gets the annotation type of the signature, which can either be InkAnnotation or StampAnnotation. Useful for getting the correct type through toInkAnnotation and toStampAnnotation.
- Returns:
The AnnotationType of the signature. This can either be INK or STAMP.
-
getId
abstract long getId()
Signature id number used in signature database. If not set, the default value is ID_NOT_SET.
- Returns:
Id number assigned from the database.
-
getInkColor
@ColorInt() abstract int getInkColor()
Gets color used for signature ink.
- Returns:
Color of the signature ink.
-
getLineWidth
abstract float getLineWidth()
Gets signature line width.
- Returns:
Width of signature ink lines in pdf points.
-
getLines
abstract List<List<PointF>> getLines()
Access list of signature lines.
- Returns:
List of lines consisting from pdf points.
-
getBiometricData
@Nullable() abstract BiometricSignatureData getBiometricData()
Gets the biometric data that was collected with this signature. May return
null
if no biometric data was created.- Returns:
The BiometricSignatureData that was collected with this signature, or
null
if no biometric data was collected.
-
getSignatureDrawWidthRatio
abstract float getSignatureDrawWidthRatio()
Gets the ratio of signature width to width of the drawing view used when drawing the signature.
This size is used in toAnnotation to auto-size annotation around touched point so that the largest signatures cover 1/4 of the page and smaller less.
-
getBitmapIdentifier
abstract int getBitmapIdentifier()
Gets the bitmap identifier used for rendering the image signature, or BITMAP_NOT_SET if the signature is not represented by a bitmap.
- Returns:
Bitmap identifier representing the image signature.
-
getBitmap
@WorkerThread()@Nullable() Bitmap getBitmap()
Gets the bitmap used for rendering the image signature, or
null
if the signature is not an image signature.NOTE: The returned bitmap is kept in memory in a hash map but this method is meant to be used as an auxiliary method for adding the signature to the document. The bitmap may be destroyed when the app is in background and the system kills the process because needs to release memory resources. This method does not guarantee persistence, to implement this kind of use case it's better to rely on a database, or a cache mechanism that stores the bitmap in the local storage.
- Returns:
Bitmap used for rendering the image signature, or
null
if the signature is not an image signature.
-
getStampRect
@Nullable() abstract RectF getStampRect()
Bounding rectangle for this signature's bitmap.
- Returns:
RectF encompassing this signature's image.
-
toInkAnnotation
@NonNull() InkAnnotation toInkAnnotation(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @NonNull() PointF touchPoint)
Builds ink annotation from signature data.
- Parameters:
document
- Target document where the annotation will be added to.pageIndex
- Target page index indocument
where the annotation will be added to.touchPoint
- Point where the annotation should be created.- Returns:
Ink annotation representing this signature, or null if class is not an ink signature.
-
toInkAnnotation
@NonNull() InkAnnotation toInkAnnotation(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @NonNull() RectF targetRect)
Builds ink annotation from signature data.
- Parameters:
document
- Target document where the annotation will be added to.pageIndex
- Target page index indocument
where the annotation will be added to.targetRect
- Rect on the page into which the annotation should be fitted.- Returns:
Ink annotation representing this signature, or null if class is not an ink signature.
-
toInkAnnotation
@NonNull() InkAnnotation toInkAnnotation(@IntRange(from = 0) int pageIndex)
Builds ink annotation from signature data. This method does not set annotation's bounding box. If you want to create a stamp annotation with bounding box around certain touch point, use toInkAnnotation instead.
- Parameters:
pageIndex
- Target page index where the annotation will be added to.- Returns:
Ink annotation representing this signature, or null if class is not an ink signature.
-
toStampAnnotation
@NonNull() StampAnnotation toStampAnnotation(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @NonNull() PointF touchPoint)
Builds stamp annotation from signature data.
- Parameters:
document
- Target document where the annotation will be added to.pageIndex
- Target page index indocument
where the annotation will be added to.touchPoint
- Point where the annotation should be created.- Returns:
Stamp annotation representing this signature, or null if class is not an image signature.
-
toStampAnnotation
@NonNull() StampAnnotation toStampAnnotation(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @NonNull() RectF targetRect)
Builds stamp annotation from signature data.
- Parameters:
document
- Target document where the annotation will be added to.pageIndex
- Target page index indocument
where the annotation will be added to.targetRect
- Rect on the page into which the annotation should be fitted.- Returns:
Stamp annotation representing this signature, or null if class is not an image signature.
-
toStampAnnotation
@NonNull() StampAnnotation toStampAnnotation(@IntRange(from = 0) int pageIndex)
Builds stamp annotation from signature data. If you want to create a stamp annotation with a specific bounding box around certain touch point, use toStampAnnotation instead.
- Parameters:
pageIndex
- Target page index where the annotation will be added to.- Returns:
Stamp annotation representing this signature, or null if class is not an image signature.
-
getBoundingBox
@NonNull() RectF getBoundingBox()
Returns bounding box of the signature data in pdf coordinates. The bounding box will always have its
left
andbottom
values equal0
.- Returns:
Rect enclosing all lines of this signature. Always starts at (0,0) (bottom left corner).
-
textToBitmap
@NonNull() static Bitmap textToBitmap(@NonNull() String text, @NonNull() Font font, @ColorInt() int color, @FloatRange(from = 0) float scaleFactor, @NonNull() DisplayMetrics displayMetrics)
Creates a bitmap from text that the user typed and a font the user chose.
- Parameters:
text
- The text to be displayed.font
- The font to use to show the text.color
- The color to render the text.scaleFactor
- A factor, always positive, by which to scale the bitmap size.displayMetrics
- DisplayMetrics instance.- Returns:
a bitmap from text that the user typed and a font the user chose.
-
-
-
-