public class

Utils

extends Object
java.lang.Object
   ↳ com.pdftron.pdf.utils.Utils

Class Overview

A general utility class

Summary

Constants
double INTERSECTION_EPSILON
int MAX_NUM_DUPLICATED_FILES
int URI_TYPE_DOCUMENT The URI is a document.
int URI_TYPE_FILE The URI is a file.
int URI_TYPE_TREE The URI is a file tree.
int URI_TYPE_UNKNOWN The URI is unknown.
double vertex_dist_epsilon
Public Constructors
Utils()
Public Methods
static Bitmap adjustAlpha(Bitmap bitmap, int alpha)
Adjusts alpha channel of a bitmap
static int adjustAlphaColor(int color, float factor)
Adjusts alpha color.
static boolean applyDayNight(AppCompatActivity activity)
Apply day night mode.
static ExternalFileInfo buildExternalFile(Context context, Uri uri)
Returns an external file info from the specified URI
static RectF buildPageBoundBoxOnClient(PDFViewCtrl pdfViewCtrl, int pageNum)
Computes the page bounding box of PDFView in the client space.
static boolean cacheFileExists(Context context, String cacheFileName)
Checks whether the cache file exists.
static double calcDistance(double x1, double y1, double x2, double y2)
static com.pdftron.pdf.Point calcIntersection(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy)
static double calcLinePointDistance(double x1, double y1, double x2, double y2, double x, double y)
static void closeQuietly(PDFDoc doc)
Closes the PDF doc quietly
static void closeQuietly(PDFDoc doc, SecondaryFileFilter filter)
Closes the PDFDoc and file filter proper quietly
static void closeQuietly(FDFDoc doc)
Closes the FDF doc quietly
static void closeQuietly(SecondaryFileFilter filter)
Closes the file filter proper quietly
static ColorPt color2ColorPt(int color)
Converts an integer color to a color point
static int colorPt2color(ColorPt colorPt)
Converts a color point to an integer color
static float convDp2Pix(Context context, float dp)
Converts density independent pixels to physical pixels.
static Bitmap convDrawableToBitmap(Drawable drawable)
Converts a drawable to a bitmap
static File convExternalContentUriToFile(Context activity, Uri beamUri)
Converts external content URI to a file
static LinkedHashMap<String, String> convJSONToMap(String jsonString)
static JSONObject convMapToJSON(LinkedHashMap<String, String> item)
static float convPix2Dp(Context context, float pix)
Converts physical pixels to density independent pixels.
static com.pdftron.pdf.Rect convertFromPageRectToScreenRect(PDFViewCtrl pdfViewCtrl, com.pdftron.pdf.Rect rect, int pageNum)
Converts a rect in page space to screen space
static com.pdftron.pdf.Rect convertFromPageRectToScrollViewerRect(PDFViewCtrl pdfViewCtrl, com.pdftron.pdf.Rect rect, int pageNum)
Converts a rect in page space to scroll view space
static void copy(File src, File dst)
static long copyLarge(RandomAccessFile inputFile, OutputStream output, byte[] buffer)
Copies a large file.
static long copyLarge(RandomAccessFile inputFile, OutputStream output)
Copies a large file.
static File copyResourceToLocal(Context context, int resId, String name, String ext)
Copies the specified resource file into the temp folder with provided name.
static String copyResourceToTempFolder(Context context, int resId, boolean force, String resourceName)
Copies the specified resource file into the temp folder.
static Intent createGenericShareIntent(Activity activity, Uri uri)
Returns a generic share intent for the specified URI
static Intent createGenericShareIntents(Activity activity, ArrayList<Uri> uris)
Returns a generic share intent for the specified URIs
static StateListDrawable createImageDrawableSelector(Context context, int resourceId, int color)
Creates a state image drawable (enable/disable) from a resource id with specified color and the transparency factor when disabled.
static StateListDrawable createImageDrawableSelector(Context context, int resourceId, int color, int disableOpacity)
Creates a state image drawable (enable/disable) from a resource id with specified color and the transparency factor when disabled.
static Intent createShareIntent(Activity activity, File file)
Returns a generic share intent for the specified file
static Intent createShareIntents(Activity activity, ArrayList<FileInfo> files)
Returns a generic share intent for the specified files
static String decryptIt(Context context, String value)
Decrypts the specified value
static void deleteCacheFile(Context context, String cacheFileName)
Deletes the cache file.
static duplicateInDownload(ContentResolver cr, Uri uri, String title)
Returns an Single for a duplicating file in the "Downloads" folder On subscribe: Duplicates a file in "Download" folder

If "Download" has already a file with the same name, it will pick up a different name
static String encryptIt(Context context, String value)
Encrypts the specified value
static int findMinIndex(double[] numbers)
static int getAccentColor(Context context)
Returns the accent color defined in android attribute.
static AlertDialog.Builder getAlertDialogBuilder(Context context, int messageId, int titleId)
Creates an alert dialog builder.
static AlertDialog.Builder getAlertDialogBuilder(Context context, String message, String title)
Creates an alert dialog builder.
static AlertDialog.Builder getAlertDialogNoTitleBuilder(Context context, int messageId)
Creates an alert dialog builder.
static String[] getAllGoogleDocsSupportedTypes()
static Rect getBBox(ArrayList<Point> pagePoints)
static int getBackgroundColor(Context context)
Returns the background color defined in android attribute.
static String getBidiString(String str)
Converts the specified string to Bidi.
static Bitmap getBitmapByVecDrawable(VectorDrawable vectorDrawable)
static Bitmap getBitmapFromImageUri(Context context, Uri imageUri, String backupFilepath)
Returns real path from the specified image URI.
static String getByteCount(long bytes)
Returns the number of bytes in string format
static Rect getCachedBBox(JSONObject obj)
static String getCachedContents(JSONObject obj)
static String getColorHexString(int color)
Gets color value in hex format (#0xFFFFFF)
static ContentResolver getContentResolver(Context context)
A helper to get getContentResolver().
static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs)
Gets the value of the data column for this Uri.
static String getDateTimeFormatFromField(String fieldValue, boolean isDate)
static String getDeviceName()
static String getDisplayNameFromImageUri(Context context, Uri imageUri, String backupFilepath)
Returns the display name from the image URI
static void getDisplaySize(Context context, Point outSize)
Gets the size of the display, in pixels.
static Drawable getDrawable(Context context, int drawableRes)
Helper to get a drawable from drawable resource.
static Drawable getDrawableWithTint(Context context, int drawableId, int tintColor)
static String getExtension(String filename)
Returns file extension in lower case, or empty string if input is null
static File getExternalFilesDir(Context context, String type)
static File[] getExternalFilesDirs(Context context, String type)
static String getFileNameNotInUse(ExternalFileInfo folder, String original)
Returns a file path in the specified path that is not used.
static String getFileNameNotInUse(String original)
Returns a file path in the specified path that is not used.
static ArrayList<String> getFileNamesFromPortfolio(Context context, Uri fileUri, String password)
static ArrayList<String> getFileNamesFromPortfolio(File file, String password)
Given a portfolio PDF document (ie, with embedded files), returns a list of the embedded files.
static ArrayList<String> getFileNamesFromPortfolio(PDFDoc doc)
static Bookmark getFirstBookmark(PDFDoc pdfDoc)
Returns the first bookmark in a certain document.
static String getFontFileName(String fontFilePath)
Gets font file name
static int getForegroundColor(Context context)
Returns the foreground color defined in android attribute.
static long getFreeDiskStorage()
Gets the free disk storage size
static String getLocaleDigits(String input)
Returns digits based on the Locale.
static com.pdftron.pdf.Rect getPageRect(PDFViewCtrl pdfViewCtrl, int pageNum)
static String getPassword(Context context, String filepath)
Returns password if it is saved in PdfViewCtrlTabsManager.
static int getPostProcessedColor(PDFViewCtrl pdfViewCtrl, int color)
convert color to post processed color in pdf
static int getPrimaryColor(Context context)
Returns the primary color defined in android attribute.
static int getPrimaryDarkColor(Context context)
Returns the primary dark color defined in android attribute.
static String getReadableByteUnit(long bytes, boolean si)
static Long getReadableByteValue(long bytes, boolean si)
static String getRealPathFromImageURI(Context context, Uri imageUri)
Returns real path from the specified image URI.
static String getRealPathFromURI(Context context, Uri uri)
Gets a file path from a Uri.
static int getRealScreenHeight(Context context)
Returns the real screen height without subtracting any window decor or applying any compatibility scale factors.
static int getRealScreenWidth(Context context)
Returns the real screen width without subtracting any window decor or applying any compatibility scale factors.
static int getResourceColor(Context context, String name)
A helper to get color identifier.
static int getResourceDrawable(Context context, String name)
A helper to get drawable identifier.
static int getResourceRaw(Context context, String name)
A helper to get raw identifier.
static Resources getResources(Context context)
A helper to get getResources().
static int getScreenHeight(Context context)
Returns the screen height.
static com.pdftron.pdf.Rect getScreenRectInPageSpace(PDFViewCtrl pdfViewCtrl, int pageNum)
static int getScreenWidth(Context context)
Returns the screen width.
static int getThemeAttrColor(Context context, int attr)
static String getUriDisplayName(Context context, Uri contentUri)
Returns the display name of the specified URI
static String getUriDocumentPath(Uri uri)
Returns the URI document path.
static String getUriExtension(ContentResolver contentResolver, Uri uri)
Returns the file extension of the specified URI
static long getUriFileSize(ContentResolver contentResolver, Uri uri)
Returns the file size of the specified URI
static Uri getUriForFile(Context context, File file)
Return the URI for the specified file
static String getUriTreePath(Uri uri)
Returns the URI tree path.
static int getUriType(Uri uri)
Returns the URI type
static String getValidFilename(String filename)
Return a valid file name from the specified file name.
static String getValidTitle(Context context, Uri fileUri)
Return a valid title from the specified URI
static void handleEmptyPopup(PDFViewCtrl pdfViewCtrl, Markup markup)
Handles an empty popup
static void handlePdfFromImageFailed(Context context, Map imageIntent)
Handles when trying to create PDF from an image fails.
static boolean hasEnoughStorageToSave(long fileSize)
static boolean hasFileAttachments(PDFDoc doc)
static boolean hasRightToLeftChar(String str)
Checks whether the specified string has any right-to-left characters.
static boolean hasStoragePermission(Context context)
Checks whether the app has the storage permission.
static void hideSoftKeyboard(Context context, View view)
Hides soft keyboard.
static String humanReadableByteCount(long bytes, boolean si)
Gets a human readable format of a byte size.
static boolean isAnnotationHandlerToolMode(ToolManager.ToolMode toolMode)
Gets whether a tool mode is one of the handler tool modes.
static boolean isAppInstalledOnDevice(Context context, String uri)
Checks whether the specified app is installed on the device.
static boolean isChromebook(Context context)
static boolean isColorDark(int color)
Checks whether the given color is considered as dark.
static boolean isColorDark(int color, float threshold)
Checks whether the given color is considered as dark.
static boolean isDeviceNightMode(Context context)
Returns whether the current device UI mode is night.
static boolean isDoNotRequestThumbFile(ContentResolver cr, String fileUriString)
Checks whether should request thumbnail file
static boolean isDoNotRequestThumbFile(String filePath)
static boolean isDocModified(PDFDoc pdfDoc)
Checks whether the file is modified.
static boolean isExtensionHandled(String extension)
Checks whether the specified extension is handled.
static boolean isImageCopied(Context context)
static boolean isImageFile(String filePath)
Checks whether the specified file is an image file.
static boolean isImageFile(ContentResolver cr, Uri fileUri)
Checks whether the specified URI is an image file.
static boolean isItemInList(String item, String[] array)
This method ignores case
static boolean isJellyBeanMR1()
Checks if this device is running Jelly Bean MR1 or higher.
static boolean isJellyBeanMR2()
Checks if this device is running Jelly Bean MR2 or higher.
static boolean isKitKat()
Checks if this device is running KitKat or higher.
static boolean isKitKatOnly()
Checks if this device is running KitKat only.
static boolean isLandscape(Context context)
Checks if the device is in landscape mode.
static boolean isLargeScreen(Context context)
Checks if the screen size is large.
static boolean isLargeScreenWidth(Context context)
Checks if the screen width is large.
static boolean isLeftToRightString(String str)
Checks whether the specified string is left-to-right.
static boolean isLollipop()
Checks if this device is running Lollipop or higher.
static boolean isLollipopMR1()
Checks if this device is running Lollipop MR1 or higher.
static boolean isMarshmallow()
Checks if this device is running Marshmallow or higher.
static boolean isMimeTypeHandled(String mimeType)
Checks whether the specified mime type is handled.
static boolean isNotPdf(String filePath)
Checks whether the specified file is non-PDF file.
static boolean isNotPdf(ContentResolver cr, Uri fileUri)
Checks whether the specified URI is non-PDF file.
static boolean isNougat()
Checks if this device is running Nougat or higher.
static boolean isNullOrEmpty(String string)
Checks whether the string is null or empty.
static boolean isOfficeDocument(ContentResolver cr, Uri fileUri)
Checks whether the specified URI is an office document.
static boolean isOfficeDocument(String filePath)
Checks whether the specified file is an office document.
static boolean isOreo()
Checks if this device is running Oreo or higher.
static boolean isPie()
static boolean isPortrait(Context context)
Checks if the device is in portrait mode.
static boolean isRightToLeftString(String str)
Checks whether the specified string is right-to-left.
static boolean isRtlLayout(Context context)
Checks whether the layout direction is right-to-left.
static boolean isSamePoint(double ax, double ay, double bx, double by)
static boolean isScreenTooNarrow(Context context)
Check whether the screen is too narrow.
static boolean isSdCardFile(Context context, File file)
Checks whether the specified file is stored in a SD card.
static boolean isSystemLanguagePersianArabic()
static boolean isTablet(Context context)
Checks if the device is a tablet.
static boolean isTextCopy(Annot annot)
Determines if the note is copied from annotated text.
static boolean isTwoColorSimilar(int color1, int color2, float threshold)
Checks whether two colors are close to each other by CIE76 computation
static boolean isUriSeekable(Context context, Uri uri)
static void manageOOM(Context context, PDFViewCtrl pdfViewCtrl)
Frees up memory when out-of-memory happens.
static void manageOOM(PDFViewCtrl pdfViewCtrl)
Frees up memory when out-of-memory happens.
static void manageOOM(Context context)
Frees up memory when out-of-memory happens.
static HashMap<String, String> parseDefaults(Context context, int xmlRes)
static void removeTextCopy(Annot annot)
Removes the text copy tag from the annotation's SDF Obj.
static Bitmap replace9PatchColor(Bitmap inputBmp, int fromColor, int toColor)
Replaces a color with another when the input bitmap is a 9-path.
static void requestStoragePermissions(Activity activity, View layout, int requestCode)
Requests the user for the storage permission.
static JSONObject retrieveToolCache(Context context, String cacheFileName)
Retrieves the tool cache.
static void safeNotifyDataSetChanged(RecyclerView.Adapter adapter)
A helper to safely call RecyclerView.Adapter#notifyDataSetChanged()
static void safeNotifyItemChanged(RecyclerView.Adapter adapter, int position)
A helper to safely call RecyclerView.Adapter#notifyItemChanged(int)
static void safeRemoveItemDecoration(RecyclerView recyclerView, RecyclerView.ItemDecoration itemDecoration)
A helper to safely call RecyclerView.Adapter#removeItemDecoration(RecyclerView.ItemDecoration)
static void safeShowAlertDialog(Context context, CharSequence message, String title)
Shows an alert dialog.
static void safeShowAlertDialog(Context context, int messageId, int titleId)
Shows an alert dialog.
static void setTextCopy(Annot annot)
Adds the text copy tag to the annotation's SDF Obj which is used to determine if the note is copied from annotated text
static void shareGenericFile(Activity activity, Uri file)
Shares a URI.
static void shareGenericFiles(Activity activity, ArrayList<Uri> files)
Shares URIs.
static void sharePdfFile(Activity activity, File file)
Shares a PDF file.
static void sharePdfFiles(Activity activity, ArrayList<FileInfo> files)
Shares PDF files.
static void showAlertDialog(Activity activity, CharSequence message, String title)
Shows an alert dialog.
static void showAlertDialog(Activity activity, int messageId, int titleId)
Shows an alert dialog.
static void showAlertDialogWithLink(Context context, String message, String title)
Shows an alert dialog.
static void showSoftKeyboard(Context context, View view)
Shows soft keyboard.
static void snapPointToRect(PointF point, RectF rect)
Snaps a point to the specified rectangle
static Bitmap tint(Bitmap bitmap, int color)
Tints a bitmap to a new color.
static int toolbarIconMaxCount(Context context)
static void unlockQuietly(PDFDoc doc)
Unlocks the PDF doc write lock quietly
static void unlockReadQuietly(PDFDoc doc)
Unlocks the PDF doc read lock quietly
static boolean uriHasReadPermission(Context context, Uri uri)
Checks whether the specified URI has read permission.
static boolean uriHasReadWritePermission(Context context, Uri uri)
Checks whether the specified URI has read/write permission.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final double INTERSECTION_EPSILON

Constant Value: 1.0E-30

public static final int MAX_NUM_DUPLICATED_FILES

Constant Value: 100 (0x00000064)

public static final int URI_TYPE_DOCUMENT

The URI is a document.

Constant Value: 2 (0x00000002)

public static final int URI_TYPE_FILE

The URI is a file.

Constant Value: 1 (0x00000001)

public static final int URI_TYPE_TREE

The URI is a file tree.

Constant Value: 3 (0x00000003)

public static final int URI_TYPE_UNKNOWN

The URI is unknown.

Constant Value: 0 (0x00000000)

public static final double vertex_dist_epsilon

Constant Value: 1.0E-8

Public Constructors

public Utils ()

Public Methods

public static Bitmap adjustAlpha (Bitmap bitmap, int alpha)

Adjusts alpha channel of a bitmap

Parameters
bitmap The input bitmap
alpha The alpha
Returns
  • The output bitmap after adjusting the alpha channel of the bitmap

public static int adjustAlphaColor (int color, float factor)

Adjusts alpha color.

Parameters
color The color
factor The factor for adjustment
Returns
  • The adjusted color

public static boolean applyDayNight (AppCompatActivity activity)

Apply day night mode.

Returns
  • true if the night mode was applied, false otherwise

public static ExternalFileInfo buildExternalFile (Context context, Uri uri)

Returns an external file info from the specified URI

Parameters
context The context
uri The URI
Returns
  • The external file info

public static RectF buildPageBoundBoxOnClient (PDFViewCtrl pdfViewCtrl, int pageNum)

Computes the page bounding box of PDFView in the client space.

Parameters
pdfViewCtrl The PDFViewCtrl
pageNum The page number
Returns
  • The rectangle of PDFView in the client space

public static boolean cacheFileExists (Context context, String cacheFileName)

Checks whether the cache file exists.

Parameters
context The context
cacheFileName The cache file name
Returns
  • true if the cache file exists

public static double calcDistance (double x1, double y1, double x2, double y2)

public static com.pdftron.pdf.Point calcIntersection (double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy)

public static double calcLinePointDistance (double x1, double y1, double x2, double y2, double x, double y)

public static void closeQuietly (PDFDoc doc)

Closes the PDF doc quietly

Parameters
doc The PDF doc

public static void closeQuietly (PDFDoc doc, SecondaryFileFilter filter)

Closes the PDFDoc and file filter proper quietly

Parameters
doc the PDFDoc
filter the SecondaryFileFilter

public static void closeQuietly (FDFDoc doc)

Closes the FDF doc quietly

Parameters
doc The FDF doc

public static void closeQuietly (SecondaryFileFilter filter)

Closes the file filter proper quietly

Parameters
filter the SecondaryFileFilter

public static ColorPt color2ColorPt (int color)

Converts an integer color to a color point

Parameters
color The color as integer
Returns
  • The color as ColorPt

public static int colorPt2color (ColorPt colorPt)

Converts a color point to an integer color

Parameters
colorPt The color as ColorPt
Returns
  • The color as integer

public static float convDp2Pix (Context context, float dp)

Converts density independent pixels to physical pixels.

public static Bitmap convDrawableToBitmap (Drawable drawable)

Converts a drawable to a bitmap

Parameters
drawable The drawable
Returns
  • The bitmap

public static File convExternalContentUriToFile (Context activity, Uri beamUri)

Converts external content URI to a file

Parameters
activity The activity
beamUri The URI
Returns
  • The file

public static LinkedHashMap<String, String> convJSONToMap (String jsonString)

public static JSONObject convMapToJSON (LinkedHashMap<String, String> item)

public static float convPix2Dp (Context context, float pix)

Converts physical pixels to density independent pixels.

public static com.pdftron.pdf.Rect convertFromPageRectToScreenRect (PDFViewCtrl pdfViewCtrl, com.pdftron.pdf.Rect rect, int pageNum)

Converts a rect in page space to screen space

Parameters
pdfViewCtrl The PDFViewCtrl
rect The rectangle in page space
pageNum The page number
Returns
  • The rectangle in screen space
Throws
PDFNet exception
PDFNetException

public static com.pdftron.pdf.Rect convertFromPageRectToScrollViewerRect (PDFViewCtrl pdfViewCtrl, com.pdftron.pdf.Rect rect, int pageNum)

Converts a rect in page space to scroll view space

Parameters
pdfViewCtrl The PDFViewCtrl
rect The rectangle in page space
pageNum The page number
Returns
  • The rectangle in scroll view space
Throws
PDFNet exception
PDFNetException

public static void copy (File src, File dst)

Throws
IOException

public static long copyLarge (RandomAccessFile inputFile, OutputStream output, byte[] buffer)

Copies a large file.

Parameters
inputFile The input file
output The output stream
buffer A helper buffer
Returns
  • The number of copied bytes
Throws
IOException IO exception

public static long copyLarge (RandomAccessFile inputFile, OutputStream output)

Copies a large file.

Parameters
inputFile The input file
output The output stream
Returns
  • The number of copied bytes
Throws
IOException IO exception

public static File copyResourceToLocal (Context context, int resId, String name, String ext)

Copies the specified resource file into the temp folder with provided name. If file already exists, it will be overridden.

Parameters
context The context
resId The resource ID to be copied
name The name of resource and will be used as name of the output file
ext The extension of resource and will be used as extension of the output file
Returns
  • The file path of copied resource file

public static String copyResourceToTempFolder (Context context, int resId, boolean force, String resourceName)

Copies the specified resource file into the temp folder.

Parameters
context The context
resId The resource ID to be copied
force True to overwrite the existing resource file
resourceName The name of resource
Returns
  • The file path of copied resource file
Throws
PDFNet exception
PDFNetException

public static Intent createGenericShareIntent (Activity activity, Uri uri)

Returns a generic share intent for the specified URI

Parameters
activity The activity
uri The URI
Returns
  • The intent

public static Intent createGenericShareIntents (Activity activity, ArrayList<Uri> uris)

Returns a generic share intent for the specified URIs

Parameters
activity The activity
uris A list of URIs
Returns
  • The intent

public static StateListDrawable createImageDrawableSelector (Context context, int resourceId, int color)

Creates a state image drawable (enable/disable) from a resource id with specified color and the transparency factor when disabled.

Parameters
context The context
resourceId The input resource id
color The tint color
Returns
  • The state image drawable

public static StateListDrawable createImageDrawableSelector (Context context, int resourceId, int color, int disableOpacity)

Creates a state image drawable (enable/disable) from a resource id with specified color and the transparency factor when disabled.

Parameters
context The context
resourceId The input resource id
color The tint color
disableOpacity The transparency when the drawable is disabled
Returns
  • The state image drawable

public static Intent createShareIntent (Activity activity, File file)

Returns a generic share intent for the specified file

Parameters
activity The activity
file The file
Returns
  • The intent

public static Intent createShareIntents (Activity activity, ArrayList<FileInfo> files)

Returns a generic share intent for the specified files

Parameters
activity The activity
files A list of files
Returns
  • The intent

public static String decryptIt (Context context, String value)

Decrypts the specified value

Parameters
context The context
value The value
Returns
  • The decrypted value

public static void deleteCacheFile (Context context, String cacheFileName)

Deletes the cache file.

Parameters
context The context
cacheFileName The cache file name

public static duplicateInDownload (ContentResolver cr, Uri uri, String title)

Returns an Single for a duplicating file in the "Downloads" folder On subscribe: Duplicates a file in "Download" folder

If "Download" has already a file with the same name, it will pick up a different name

Parameters
cr Content resolver for the uri
uri The URI of a file
title The title of the file
Returns
  • Observable for duplicating files locally

public static String encryptIt (Context context, String value)

Encrypts the specified value

Parameters
context The context
value The value
Returns
  • The encrypted value

public static int findMinIndex (double[] numbers)

public static int getAccentColor (Context context)

Returns the accent color defined in android attribute.

Parameters
context The context
Returns
  • The accent color defined in android attribute

public static AlertDialog.Builder getAlertDialogBuilder (Context context, int messageId, int titleId)

Creates an alert dialog builder.

Parameters
context The context
messageId The id of the message
Returns
  • The dialog builder

public static AlertDialog.Builder getAlertDialogBuilder (Context context, String message, String title)

Creates an alert dialog builder.

Parameters
context The context
message The message of the dialog
title The title of the dialog
Returns
  • The dialog builder

public static AlertDialog.Builder getAlertDialogNoTitleBuilder (Context context, int messageId)

Creates an alert dialog builder.

Parameters
context The context
messageId The id of the message
Returns
  • The dialog builder

public static String[] getAllGoogleDocsSupportedTypes ()

public static Rect getBBox (ArrayList<Point> pagePoints)

public static int getBackgroundColor (Context context)

Returns the background color defined in android attribute.

Parameters
context The context
Returns
  • The background color defined in android attribute

public static String getBidiString (String str)

Converts the specified string to Bidi.

Parameters
str The string
Returns
  • The Bidi string

public static Bitmap getBitmapByVecDrawable (VectorDrawable vectorDrawable)

public static Bitmap getBitmapFromImageUri (Context context, Uri imageUri, String backupFilepath)

Returns real path from the specified image URI.

Parameters
context The context
imageUri The image URI
backupFilepath The backup file path
Returns
  • The bitmap from the specified image URI

public static String getByteCount (long bytes)

Returns the number of bytes in string format

Parameters
bytes The number of bytes
Returns
  • The number of bytes in string format

public static Rect getCachedBBox (JSONObject obj)

public static String getCachedContents (JSONObject obj)

public static String getColorHexString (int color)

Gets color value in hex format (#0xFFFFFF)

Parameters
color color
Returns
  • hex format string

public static ContentResolver getContentResolver (Context context)

A helper to get getContentResolver().

public static String getDataColumn (Context context, Uri uri, String selection, String[] selectionArgs)

Gets the value of the data column for this Uri. This is useful for MediaStore Uris, and other file-based ContentProviders.

Parameters
context The context.
uri The Uri to query.
selection (Optional) Filter used in the query.
selectionArgs (Optional) Selection arguments used in the query.
Returns
  • The value of the _data column, which is typically a file path.

public static String getDateTimeFormatFromField (String fieldValue, boolean isDate)

public static String getDeviceName ()

public static String getDisplayNameFromImageUri (Context context, Uri imageUri, String backupFilepath)

Returns the display name from the image URI

Parameters
context The context
imageUri The URI
backupFilepath The backup file path
Returns
  • The display name from the image URI

public static void getDisplaySize (Context context, Point outSize)

Gets the size of the display, in pixels.

Parameters
context the Context
outSize A Point object to receive the size information

public static Drawable getDrawable (Context context, int drawableRes)

Helper to get a drawable from drawable resource.

Parameters
context The context
drawableRes The drawable resource
Returns
  • Drawable

public static Drawable getDrawableWithTint (Context context, int drawableId, int tintColor)

public static String getExtension (String filename)

Returns file extension in lower case, or empty string if input is null

public static File getExternalFilesDir (Context context, String type)

A helper to get getExternalFilesDir(String).

public static File[] getExternalFilesDirs (Context context, String type)

public static String getFileNameNotInUse (ExternalFileInfo folder, String original)

Returns a file path in the specified path that is not used.

Parameters
folder The folder in external storage
original The original file name
Returns
  • The file path that is not used

public static String getFileNameNotInUse (String original)

Returns a file path in the specified path that is not used.

Parameters
original The original file path
Returns
  • The file path that is not used

public static ArrayList<String> getFileNamesFromPortfolio (Context context, Uri fileUri, String password)

public static ArrayList<String> getFileNamesFromPortfolio (File file, String password)

Given a portfolio PDF document (ie, with embedded files), returns a list of the embedded files.

Parameters
file the PDF document
password the password to open this document if secured
Returns
  • a list of file names of the embedded files

public static ArrayList<String> getFileNamesFromPortfolio (PDFDoc doc)

public static Bookmark getFirstBookmark (PDFDoc pdfDoc)

Returns the first bookmark in a certain document.

Parameters
pdfDoc The PDF Doc
Returns
  • The first bookmark in the given document; null if the document doesn't have a valid bookmark

public static String getFontFileName (String fontFilePath)

Gets font file name

Parameters
fontFilePath font file path
Returns
  • font file name

public static int getForegroundColor (Context context)

Returns the foreground color defined in android attribute.

Parameters
context The context
Returns
  • The foreground color defined in android attribute

public static long getFreeDiskStorage ()

Gets the free disk storage size

public static String getLocaleDigits (String input)

Returns digits based on the Locale.

Parameters
input The digits in string format
Returns
  • The digits based on the Locale

public static com.pdftron.pdf.Rect getPageRect (PDFViewCtrl pdfViewCtrl, int pageNum)

public static String getPassword (Context context, String filepath)

Returns password if it is saved in PdfViewCtrlTabsManager.

Parameters
context The Context
filepath The file path
Returns
  • The password saved for the specified file

public static int getPostProcessedColor (PDFViewCtrl pdfViewCtrl, int color)

convert color to post processed color in pdf

Parameters
pdfViewCtrl The PDFViewCtrl
color The color to be post processed
Returns
  • The post processed color

public static int getPrimaryColor (Context context)

Returns the primary color defined in android attribute.

Parameters
context The context
Returns
  • The primary color defined in android attribute

public static int getPrimaryDarkColor (Context context)

Returns the primary dark color defined in android attribute.

Parameters
context The context
Returns
  • The primary dark color defined in android attribute

public static String getReadableByteUnit (long bytes, boolean si)

public static Long getReadableByteValue (long bytes, boolean si)

public static String getRealPathFromImageURI (Context context, Uri imageUri)

Returns real path from the specified image URI.

Parameters
context The context
imageUri The image URI
Returns
  • The real path from the specified image URI

public static String getRealPathFromURI (Context context, Uri uri)

Gets a file path from a Uri. This will get the the path for Storage Access Framework Documents, as well as the _data field for the MediaStore and other file-based ContentProviders.

Parameters
context The context.
uri The Uri to query.

reference http://stackoverflow.com/a/20559175

Note: there is also another version of this function in QuadOverImageView package (FileUtils.java)

public static int getRealScreenHeight (Context context)

Returns the real screen height without subtracting any window decor or applying any compatibility scale factors.

Parameters
context The context
Returns
  • The real screen height

public static int getRealScreenWidth (Context context)

Returns the real screen width without subtracting any window decor or applying any compatibility scale factors.

Parameters
context The context
Returns
  • The real screen width

public static int getResourceColor (Context context, String name)

A helper to get color identifier.

public static int getResourceDrawable (Context context, String name)

A helper to get drawable identifier.

public static int getResourceRaw (Context context, String name)

A helper to get raw identifier.

public static Resources getResources (Context context)

A helper to get getResources().

public static int getScreenHeight (Context context)

Returns the screen height. Value returned by this method does not necessarily represent the actual screen height (native resolution) of the display.

Parameters
context The context
Returns
  • The screen height

public static com.pdftron.pdf.Rect getScreenRectInPageSpace (PDFViewCtrl pdfViewCtrl, int pageNum)

public static int getScreenWidth (Context context)

Returns the screen width. Value returned by this method does not necessarily represent the actual screen width (native resolution) of the display.

Parameters
context The context
Returns
  • The screen width

public static int getThemeAttrColor (Context context, int attr)

public static String getUriDisplayName (Context context, Uri contentUri)

Returns the display name of the specified URI

Parameters
context The context
contentUri The content URI
Returns
  • The display name of the specified URI

public static String getUriDocumentPath (Uri uri)

Returns the URI document path.

Parameters
uri The URI
Returns
  • The document path

public static String getUriExtension (ContentResolver contentResolver, Uri uri)

Returns the file extension of the specified URI

Parameters
contentResolver The content resolver
uri The URI
Returns
  • The file extension of the specified URI

public static long getUriFileSize (ContentResolver contentResolver, Uri uri)

Returns the file size of the specified URI

Parameters
contentResolver The content resolver
uri The URI
Returns
  • The file size of the specified URI

public static Uri getUriForFile (Context context, File file)

Return the URI for the specified file

Parameters
context The context
file The file
Returns
  • The URI

public static String getUriTreePath (Uri uri)

Returns the URI tree path.

Parameters
uri The URI
Returns
  • The tree path

public static int getUriType (Uri uri)

Returns the URI type

Parameters
uri The URI
Returns

public static String getValidFilename (String filename)

Return a valid file name from the specified file name.

Parameters
filename The file name
Returns
  • A valid file name

public static String getValidTitle (Context context, Uri fileUri)

Return a valid title from the specified URI

Parameters
context The context
fileUri The uri of the document
Returns
  • A valid title

public static void handleEmptyPopup (PDFViewCtrl pdfViewCtrl, Markup markup)

Handles an empty popup

Parameters
pdfViewCtrl The PDFViewCtrl
markup The markup

public static void handlePdfFromImageFailed (Context context, Map imageIntent)

Handles when trying to create PDF from an image fails. It remove any cached memory if any and show a toast

Parameters
context The context
imageIntent The internal image intent map obtained from readImageIntent(Intent, Context, Uri)

public static boolean hasEnoughStorageToSave (long fileSize)

public static boolean hasFileAttachments (PDFDoc doc)

public static boolean hasRightToLeftChar (String str)

Checks whether the specified string has any right-to-left characters.

Parameters
str The string
Returns
  • True if the specified string has any right-to-left characters

public static boolean hasStoragePermission (Context context)

Checks whether the app has the storage permission.

Parameters
context The context
Returns
  • True if the app has the storage permission

public static void hideSoftKeyboard (Context context, View view)

Hides soft keyboard.

Parameters
context The context
view The view

public static String humanReadableByteCount (long bytes, boolean si)

Gets a human readable format of a byte size.

See http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java

Parameters
bytes the number of bytes
si true for SI units or false for binary units
Returns
  • the human readable format of the byte size.

public static boolean isAnnotationHandlerToolMode (ToolManager.ToolMode toolMode)

Gets whether a tool mode is one of the handler tool modes.

Parameters
toolMode the tool mode
Returns
  • whether the tool mode is one of the handler tool modes

public static boolean isAppInstalledOnDevice (Context context, String uri)

Checks whether the specified app is installed on the device.

Parameters
context The context
uri The app URI
Returns
  • True if the specified app is installed on the device

public static boolean isChromebook (Context context)

public static boolean isColorDark (int color)

Checks whether the given color is considered as dark.

Parameters
color The color
Returns
  • True if the given color is considered as dark

public static boolean isColorDark (int color, float threshold)

Checks whether the given color is considered as dark.

Parameters
color The color
threshold threshold value to determine if the color is dark
Returns
  • True if the given color is considered as dark

public static boolean isDeviceNightMode (Context context)

Returns whether the current device UI mode is night.

Parameters
context The context
Returns
  • True if the current device UI mode is night

public static boolean isDoNotRequestThumbFile (ContentResolver cr, String fileUriString)

Checks whether should request thumbnail file

Parameters
cr The content resolver
fileUriString The URI
Returns
  • True if not request thumbnail file

public static boolean isDoNotRequestThumbFile (String filePath)

public static boolean isDocModified (PDFDoc pdfDoc)

Checks whether the file is modified.

Parameters
pdfDoc The PDF doc
Returns
  • True if the file is modified

public static boolean isExtensionHandled (String extension)

Checks whether the specified extension is handled.

Parameters
extension The extension
Returns
  • True if the specified extension is handled

public static boolean isImageCopied (Context context)

public static boolean isImageFile (String filePath)

Checks whether the specified file is an image file.

Parameters
filePath The file path
Returns
  • True if the specified file is an image file

public static boolean isImageFile (ContentResolver cr, Uri fileUri)

Checks whether the specified URI is an image file.

Parameters
cr The content resolver
fileUri The URI
Returns
  • True if the specified URI is an image file

public static boolean isItemInList (String item, String[] array)

This method ignores case

public static boolean isJellyBeanMR1 ()

Checks if this device is running Jelly Bean MR1 or higher.

Returns
  • true if Jelly Bean MR1 or higher, false otherwise.

public static boolean isJellyBeanMR2 ()

Checks if this device is running Jelly Bean MR2 or higher.

Returns
  • true if Jelly Bean MR2 or higher, false otherwise.

public static boolean isKitKat ()

Checks if this device is running KitKat or higher.

Returns
  • true if KitKat or higher, false otherwise.

public static boolean isKitKatOnly ()

Checks if this device is running KitKat only.

Returns
  • true if KitKat, false otherwise.

public static boolean isLandscape (Context context)

Checks if the device is in landscape mode.

Parameters
context The context
Returns
  • True if the device is in landscape mode

public static boolean isLargeScreen (Context context)

Checks if the screen size is large.

Parameters
context The context
Returns
  • True if the screen size is large

public static boolean isLargeScreenWidth (Context context)

Checks if the screen width is large.

Parameters
context The context
Returns
  • True if the screen size is large

public static boolean isLeftToRightString (String str)

Checks whether the specified string is left-to-right.

Parameters
str The string
Returns
  • True if the specified string is left-to-right

public static boolean isLollipop ()

Checks if this device is running Lollipop or higher.

Returns
  • true if Lollipop or higher, false otherwise.

public static boolean isLollipopMR1 ()

Checks if this device is running Lollipop MR1 or higher.

Returns
  • true if Lollipop MR1 or higher, false otherwise.

public static boolean isMarshmallow ()

Checks if this device is running Marshmallow or higher.

Returns
  • true if Marshmallow or higher, false otherwise.

public static boolean isMimeTypeHandled (String mimeType)

Checks whether the specified mime type is handled.

Parameters
mimeType The mime type
Returns
  • True if the specified mime type is handled

public static boolean isNotPdf (String filePath)

Checks whether the specified file is non-PDF file.

Parameters
filePath The file path
Returns
  • True if the specified file is non-PDF file

public static boolean isNotPdf (ContentResolver cr, Uri fileUri)

Checks whether the specified URI is non-PDF file.

Parameters
cr The content resolver
fileUri The URI
Returns
  • True if the specified URI is non-PDF file

public static boolean isNougat ()

Checks if this device is running Nougat or higher.

Returns
  • true if Nougat or higher, false otherwise.

public static boolean isNullOrEmpty (String string)

Checks whether the string is null or empty.

Parameters
string the string to be checked against
Returns
  • true if the string is null or empty, false otherwise

public static boolean isOfficeDocument (ContentResolver cr, Uri fileUri)

Checks whether the specified URI is an office document.

Parameters
cr The content resolver
fileUri The URI
Returns
  • True if the specified URI is an office document

public static boolean isOfficeDocument (String filePath)

Checks whether the specified file is an office document.

Parameters
filePath The file path
Returns
  • True if the specified file is an office document

public static boolean isOreo ()

Checks if this device is running Oreo or higher.

Returns
  • true if Oreo or higher, false otherwise.

public static boolean isPie ()

public static boolean isPortrait (Context context)

Checks if the device is in portrait mode.

Parameters
context The context
Returns
  • True if the device is in portrait mode

public static boolean isRightToLeftString (String str)

Checks whether the specified string is right-to-left.

Parameters
str The string
Returns
  • True if the specified string is right-to-left

public static boolean isRtlLayout (Context context)

Checks whether the layout direction is right-to-left.

Parameters
context The context
Returns
  • True if the layout direction is right-to-left

public static boolean isSamePoint (double ax, double ay, double bx, double by)

public static boolean isScreenTooNarrow (Context context)

Check whether the screen is too narrow.

Parameters
context The context
Returns
  • True if the screen is too narrow

public static boolean isSdCardFile (Context context, File file)

Checks whether the specified file is stored in a SD card.

Parameters
context The context
file The file
Returns
  • True if the specified file is stored in a SD card

public static boolean isSystemLanguagePersianArabic ()

Returns
  • True if the system language is Persian/Arabic

public static boolean isTablet (Context context)

Checks if the device is a tablet.

Parameters
context The context
Returns
  • True if the device is a tablet

public static boolean isTextCopy (Annot annot)

Determines if the note is copied from annotated text.

Parameters
annot The annotation
Returns
  • True if the note is copied from annotated text; False otherwise

public static boolean isTwoColorSimilar (int color1, int color2, float threshold)

Checks whether two colors are close to each other by CIE76 computation

Parameters
color1 The first color to compare
color2 The second color to compare
threshold If the distance of two colors is lower than the threshold, then they are considered as closed color
Returns
  • true if two colors are close to each other, false otherwise

public static boolean isUriSeekable (Context context, Uri uri)

public static void manageOOM (Context context, PDFViewCtrl pdfViewCtrl)

Frees up memory when out-of-memory happens.

Parameters
context The context
pdfViewCtrl The PDFViewCtrl

public static void manageOOM (PDFViewCtrl pdfViewCtrl)

Frees up memory when out-of-memory happens.

Parameters
pdfViewCtrl The PDFViewCtrl

public static void manageOOM (Context context)

Frees up memory when out-of-memory happens.

Parameters
context The context

public static HashMap<String, String> parseDefaults (Context context, int xmlRes)

public static void removeTextCopy (Annot annot)

Removes the text copy tag from the annotation's SDF Obj. See {setTextCopy(Annot)}.

Parameters
annot The annotation

public static Bitmap replace9PatchColor (Bitmap inputBmp, int fromColor, int toColor)

Replaces a color with another when the input bitmap is a 9-path.

Parameters
inputBmp The input 9-patch bitmap
fromColor The color to be replaced from
toColor The color to be replaced to
Returns
  • The output bitmap after replacing the color

public static void requestStoragePermissions (Activity activity, View layout, int requestCode)

Requests the user for the storage permission.

Parameters
activity The activity
requestCode The request code

public static JSONObject retrieveToolCache (Context context, String cacheFileName)

Retrieves the tool cache.

Parameters
context The context
cacheFileName The cache file name
Returns
  • The JSON object

public static void safeNotifyDataSetChanged (RecyclerView.Adapter adapter)

A helper to safely call RecyclerView.Adapter#notifyDataSetChanged()

public static void safeNotifyItemChanged (RecyclerView.Adapter adapter, int position)

A helper to safely call RecyclerView.Adapter#notifyItemChanged(int)

public static void safeRemoveItemDecoration (RecyclerView recyclerView, RecyclerView.ItemDecoration itemDecoration)

A helper to safely call RecyclerView.Adapter#removeItemDecoration(RecyclerView.ItemDecoration)

public static void safeShowAlertDialog (Context context, CharSequence message, String title)

Shows an alert dialog. /\p> Note: always call showAlertDialog(Activity, CharSequence, String) instead unless you are sure it is running on the UI thread, for example inside onPostExecute, onClick, etc

Parameters
context The context
message The message
title The title

public static void safeShowAlertDialog (Context context, int messageId, int titleId)

Shows an alert dialog. /\p> Note: always call showAlertDialog(Activity, int, int) instead unless you are sure it is running on the UI thread, for example inside onPostExecute, onClick, etc

Parameters
context The context
messageId The ID of the message
titleId The ID of the title

public static void setTextCopy (Annot annot)

Adds the text copy tag to the annotation's SDF Obj which is used to determine if the note is copied from annotated text

Parameters
annot The annotation

public static void shareGenericFile (Activity activity, Uri file)

Shares a URI.

Parameters
activity The activity
file The file

public static void shareGenericFiles (Activity activity, ArrayList<Uri> files)

Shares URIs.

Parameters
activity The activity
files A list of URIs

public static void sharePdfFile (Activity activity, File file)

Shares a PDF file.

Parameters
activity The activity
file The file

public static void sharePdfFiles (Activity activity, ArrayList<FileInfo> files)

Shares PDF files.

Parameters
activity The activity
files A list of files

public static void showAlertDialog (Activity activity, CharSequence message, String title)

Shows an alert dialog.

Parameters
activity The activity
message The message
title The title

public static void showAlertDialog (Activity activity, int messageId, int titleId)

Shows an alert dialog.

Parameters
activity The activity
messageId The ID of the message
titleId The ID of the title

public static void showAlertDialogWithLink (Context context, String message, String title)

Shows an alert dialog.

Parameters
context The context
message The message
title The title

public static void showSoftKeyboard (Context context, View view)

Shows soft keyboard.

Parameters
context The context
view The view

public static void snapPointToRect (PointF point, RectF rect)

Snaps a point to the specified rectangle

Parameters
point The resulted point snapped to the rectangle
rect The rectangle

public static Bitmap tint (Bitmap bitmap, int color)

Tints a bitmap to a new color.

Parameters
bitmap The input bitmap
color The tinting color
Returns
  • The output bitmap after tinting the bitmap

public static int toolbarIconMaxCount (Context context)

public static void unlockQuietly (PDFDoc doc)

Unlocks the PDF doc write lock quietly

Parameters
doc The PDF doc

public static void unlockReadQuietly (PDFDoc doc)

Unlocks the PDF doc read lock quietly

Parameters
doc The PDF doc

public static boolean uriHasReadPermission (Context context, Uri uri)

Checks whether the specified URI has read permission.

Parameters
context The context
uri The URI
Returns
  • True if the specified URI has read permission

public static boolean uriHasReadWritePermission (Context context, Uri uri)

Checks whether the specified URI has read/write permission.

Parameters
context The context
uri The URI
Returns
  • True if the specified URI has read/write permission