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
Fields
public static boolean CHECK_ALL_FILES_ACCESS_PERMISSION
public static boolean FORCE_PRE_ANDROID_Q
public static boolean sShowAlertDialog
public static boolean sTEST_MODE
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 double angleBetweenTwoPointsWithPivot(double point1X, double point1Y, double point2X, double point2Y, double pivotX, double pivotY)
static boolean applyDayNight(Context context, AppCompatDelegate delegate)
Apply day night mode.
static boolean applyDayNight(AppCompatActivity activity)
Apply day night mode.
static void applyPrimaryTextTintToButton(ImageView imageView)
static void applySecondaryTextTintToButton(ImageView imageView)
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 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 String capitalize(String s)
Capitalizes the first letter of the given string.
static void closeDocQuietly(PDFViewCtrl pdfViewCtrl)
Calls closeDoc() quietly
static void closeQuietly(SecondaryFileFilter filter)
Closes the file filter proper quietly
static void closeQuietly(ParcelFileDescriptor pfd)
Closes the parcel descriptor quietly
static void closeQuietly(PDFDoc doc, SecondaryFileFilter filter)
Closes the PDFDoc and file filter proper quietly
static void closeQuietly(Closeable c)
Closes the closeable quietly
static void closeQuietly(PDFDoc doc)
Closes the PDF doc quietly
static void closeQuietly(FDFDoc doc)
Closes the FDF doc 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 Rect convertFromPageRectToScreenRect(PDFViewCtrl pdfViewCtrl, Rect rect, int pageNum)
Converts a rect in page space to screen space
static Rect convertFromPageRectToScrollViewerRect(PDFViewCtrl pdfViewCtrl, Rect rect, int pageNum)
Converts a rect in page space to scroll view space
static void copy(File src, File dst)
static File copyAssetsToTempFolder(Context context, String path, String folderName, boolean force)
Copies an assets file to cache path
static File copyAssetsToTempFolder(Context context, String path, boolean force)
Copies an assets file to cache path
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 String correctCommaBasedDecimal(EditText editText, String input)
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, int disableOpacity)
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)
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 createShareIntentForFile(Context context, String filePath, String mimeType)
Creates a generic share intent based on given file and mimetype
static Intent createShareIntents(Activity activity, ArrayList<FileInfo> files)
Returns a generic share intent for the specified files
static Intent createSystemPickerIntent(String[] fileMimeTypes)
static Intent createSystemPickerIntent(String[] fileMimeTypes, boolean multiSelect)
static Intent createSystemPickerIntent()
static Intent createSystemPickerIntentAllSource(String[] fileMimeTypes, boolean multiSelect)
static String createThumb(Context context, PDFDoc doc, int minSize)
static void deleteCacheFile(Context context, String cacheFileName)
Deletes the cache file.
static duplicateInDownload(Context context, ContentResolver cr, Uri uri, String title)
Returns an Single for a duplicating file in the "Downloads" folder.
static duplicateInFolder(ContentResolver cr, Uri uri, String title, File outputFolder)
Returns an Single for a duplicating file in the specified folder.
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 Context.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 getExternalDownloadDirectory(Context context)
static File getExternalFilesDir(Context context, String type)
A helper to get Context.getExternalFilesDir(String).
static File[] getExternalFilesDirs(Context context, String type)
A helper to get Context.getExternalFilesDirs(String).
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 int[] getImageFileDimensions(File file, int maxDimension)
getImageFileDimensions Helper method to extract width and height of an image File Optionally provide maxDimension to have it scale down to that lenght of it's longest dimension (either width or height), and then maintain it's aspect ratio e.g.
static int[] getImageFileDimensions(File file)
static String getLocaleDigits(String input)
Returns digits based on the Locale.
static String getLocaleLanguageCode()
static 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 int getPrimaryTextColor(Context context)
Returns the primary text 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 Context.getResources().
static int getScreenHeight(Context context)
Returns the screen height.
static Rect getScreenRectInPageSpace(PDFViewCtrl pdfViewCtrl, int pageNum)
static int getScreenWidth(Context context)
Returns the screen width.
static String getScreenshotFileName()
static int getSecondaryTextColor(Context context)
Returns the secondary text color defined in android attribute.
static String getTempFile(Context context, String ext)
static int getThemeAttrColor(Context context, int attr)
static String getUriDisplayName(Context context, Uri contentUri)
Returns the display name of the specified URI
static String getUriDisplayName(ContentResolver contentResolver, 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 PointF[] getVerticesFromPoly(PDFViewCtrl pdfViewCtrl, Polygon polygon, int pageNum)
static void handleEmptyPopup(PDFDoc pdfDoc, 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 hasInternetConnection(Context context)
static boolean hasRecordAudioPermission(Context context)
static boolean hasRightToLeftChar(String str)
Checks whether the specified string has any right-to-left characters.
static boolean hasStoragePermission(Context context)
This method is deprecated. please follow the latest Android permission guideline instead
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 isAndroidQ()
Checks if this device is running Android Q or higher.
static boolean isAndroidR()
Checks if this device is running Android R or higher.
static boolean isAndroidS()
Checks if this device is running Android S or higher.
static boolean isAndroidT()
Checks if this device is running Android T or higher.
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 isBackupFolderFile(Context context, File file)
Checks whether the specified file is stored in app sandbox.
static boolean isChromebook(Context context)
static boolean isColorDark(int color, float threshold)
Checks whether the given color is considered as dark.
static boolean isColorDark(int color)
Checks whether the given color is considered as dark.
static boolean isConvertibleFormat(String filePath, String[] fileTypes)
static boolean isConvertibleFormat(String filePath)
Checks whether the specified file is a convertible document.
static boolean isConvertibleFormatFromExt(String ext)
static boolean isConvertibleFormatFromExt(String ext, String[] fileTypes)
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 preview for a file.
static boolean isDoNotRequestThumbFile(String filePath)
Checks whether should request thumbnail preview for a file.
static boolean isDocModified(PDFDoc pdfDoc)
Checks whether the file is modified.
static boolean isEmulator()
static boolean isExtensionHandled(String extension)
Checks whether the specified extension is handled.
static boolean isHtmlDocument(String filePath)
Checks whether the specified file is an HTML document.
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 isImageFileFromExt(String ext)
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 isLargeTablet(Context context)
Checks if the device is a 10 inch plus tablet.
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 isNonPDFByMimeType(String mimeType)
Checks whether the specified mime type is an office mime type
static boolean isNotPdf(ContentResolver cr, Uri fileUri)
Checks whether the specified URI is non-PDF file.
static boolean isNotPdf(String filePath)
Checks whether the specified file is non-PDF file.
static boolean isNotPdfFromExt(String ext)
Checks whether the specified extension is non-PDF extension.
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 isOfficeDocumentFromExt(String ext)
static boolean isOreo()
Checks if this device is running Oreo or higher.
static boolean isPie()
Checks if this device is running Pie or higher.
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 isSamsungKeyboard(String keyboard)
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 boolean isUsingDocumentTree()
static void manageOOM(PDFViewCtrl pdfViewCtrl)
Frees up memory when out-of-memory happens.
static void manageOOM(Context context, 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 float parseFloat(String value)
static float parseFloat(String value, Locale locale)
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 Bitmap replace9PatchColor(Bitmap inputBmp, int toColor)
Replaces all non-white colors of a 9-patch bitmap.
static void requestPostNotificationsPermissions(Activity activity, int requestCode)
This permission check is new for Android API 33+
static void requestRecordAudioPermissions(Activity activity, View layout, int requestCode)
Requests the user for the record audio permission.
static void requestStoragePermissions(Activity activity, View layout, int requestCode)
This method is deprecated. please follow the latest Android permission guideline instead
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 simpleHTTPDownload(String link, File outputFile)
static void snapPointToRect(PointF point, RectF rect)
Snaps a point to the specified rectangle
static void throwIfNotOnMainThread()
static void throwIfOnMainThread()
static Bitmap tint(Bitmap bitmap, int color)
Tints a bitmap to a new color.
static Drawable tintDrawable(Context context, Drawable drawable)
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 void updateDashedLineColor(View view, int color)
static boolean uriHasReadPermission(Context context, Uri uri, CancellationSignal cancellationSignal)
Checks whether the specified URI has read permission.
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.
static boolean uriHasWritePermission(Context context, Uri uri)
Checks whether the specified URI has write permission.
static boolean validActivity(Activity activity)
Returns whether the activity is valid for displaying UI (such as dialogs).
static void validateContentResolver(ContentResolver cr, Uri uri)
[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

Fields

public static boolean CHECK_ALL_FILES_ACCESS_PERMISSION

public static boolean FORCE_PRE_ANDROID_Q

public static boolean sShowAlertDialog

public static boolean sTEST_MODE

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 double angleBetweenTwoPointsWithPivot (double point1X, double point1Y, double point2X, double point2Y, double pivotX, double pivotY)

public static boolean applyDayNight (Context context, AppCompatDelegate delegate)

Apply day night mode.

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

public static boolean applyDayNight (AppCompatActivity activity)

Apply day night mode.

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

public static void applyPrimaryTextTintToButton (ImageView imageView)

public static void applySecondaryTextTintToButton (ImageView imageView)

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 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 String capitalize (String s)

Capitalizes the first letter of the given string.

Parameters
s string to capitalize.
Returns
  • The String with first character capitalizes. If s is null then return an empty string.

public static void closeDocQuietly (PDFViewCtrl pdfViewCtrl)

Calls closeDoc() quietly

Parameters
pdfViewCtrl the PDFViewCtrl

public static void closeQuietly (SecondaryFileFilter filter)

Closes the file filter proper quietly

Parameters
filter the SecondaryFileFilter

public static void closeQuietly (ParcelFileDescriptor pfd)

Closes the parcel descriptor quietly

Parameters
pfd The parcel descriptor

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 (Closeable c)

Closes the closeable quietly

Parameters
c The closeable

public static void closeQuietly (PDFDoc doc)

Closes the PDF doc quietly

Parameters
doc The PDF doc

public static void closeQuietly (FDFDoc doc)

Closes the FDF doc quietly

Parameters
doc The FDF doc

public static ColorPt color2ColorPt (int color)

Converts an integer color to a color point

Parameters
color The color as integer
Returns

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 Rect convertFromPageRectToScreenRect (PDFViewCtrl pdfViewCtrl, 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
PDFNetException PDFNet exception

public static Rect convertFromPageRectToScrollViewerRect (PDFViewCtrl pdfViewCtrl, 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
PDFNetException PDFNet exception

public static void copy (File src, File dst)

Throws
IOException

public static File copyAssetsToTempFolder (Context context, String path, String folderName, boolean force)

Copies an assets file to cache path

Parameters
context the context
path the asset file path, i.e. /android_asset/test.pdf
folderName the folder to put the file
force whether to create a new copy if file exists or overwrite
Returns
  • the file path

public static File copyAssetsToTempFolder (Context context, String path, boolean force)

Copies an assets file to cache path

Parameters
context the context
path the asset file path, i.e. /android_asset/test.pdf
force whether to create a new copy if file exists or overwrite
Returns
  • the file path

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
PDFNetException PDFNet exception

public static String correctCommaBasedDecimal (EditText editText, String input)

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, 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 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 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 createShareIntentForFile (Context context, String filePath, String mimeType)

Creates a generic share intent based on given file and mimetype

Parameters
context The context
filePath File to share
mimeType Files mimetype (eg image/png)
Returns
  • created intent object

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 Intent createSystemPickerIntent (String[] fileMimeTypes)

Returns
  • Intent for launching the system file picker for specified files

public static Intent createSystemPickerIntent (String[] fileMimeTypes, boolean multiSelect)

public static Intent createSystemPickerIntent ()

Returns
  • Intent for launching the system file picker for supported files

public static Intent createSystemPickerIntentAllSource (String[] fileMimeTypes, boolean multiSelect)

public static String createThumb (Context context, PDFDoc doc, int minSize)

Throws
IOException
PDFNetException

public static void deleteCacheFile (Context context, String cacheFileName)

Deletes the cache file.

Parameters
context The context
cacheFileName The cache file name

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

Returns an Single for a duplicating file in the "Downloads" folder.

public static duplicateInFolder (ContentResolver cr, Uri uri, String title, File outputFolder)

Returns an Single for a duplicating file in the specified folder.

On subscribe: Duplicates a file in the specified folder /p>

If the folder 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
outputFolder The output folder to duplicate this file
Returns
  • Observable for duplicating files locally

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 Context.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 getExternalDownloadDirectory (Context context)

Returns
  • the File for the download

public static File getExternalFilesDir (Context context, String type)

A helper to get Context.getExternalFilesDir(String).

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

A helper to get Context.getExternalFilesDirs(String).

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 int[] getImageFileDimensions (File file, int maxDimension)

getImageFileDimensions Helper method to extract width and height of an image File Optionally provide maxDimension to have it scale down to that lenght of it's longest dimension (either width or height), and then maintain it's aspect ratio e.g. Width: 2000, Height: 1000 If you apply maxDimension 1000 it becomes [1000,500]

Parameters
file input file
maxDimension maximum dimension edge of image, it will retain aspect ratio, use 0 to disable
Returns
  • int array of [width, height] of the image dimensions from file

public static int[] getImageFileDimensions (File file)

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 String getLocaleLanguageCode ()

Returns
  • ISO-639 two letter Language Code

public static 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 int getPrimaryTextColor (Context context)

Returns the primary text color defined in android attribute.

Parameters
context The context
Returns
  • The primary text 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 Context.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 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 String getScreenshotFileName ()

Returns
  • the current filename for screenshots with date/time formatted as 'Screenshot_'yyyyMMdd-HHmmss

public static int getSecondaryTextColor (Context context)

Returns the secondary text color defined in android attribute.

Parameters
context The context
Returns
  • The secondary text color defined in android attribute

public static String getTempFile (Context context, String ext)

Throws
IOException

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 getUriDisplayName (ContentResolver contentResolver, Uri contentUri)

Returns the display name of the specified URI

Parameters
contentResolver The content resolver
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 or null if URI is invalid

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 PointF[] getVerticesFromPoly (PDFViewCtrl pdfViewCtrl, Polygon polygon, int pageNum)

public static void handleEmptyPopup (PDFDoc pdfDoc, Markup markup)

Handles an empty popup

Parameters
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 hasInternetConnection (Context context)

Returns
  • whether there is internet connection

public static boolean hasRecordAudioPermission (Context context)

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)

This method is deprecated.
please follow the latest Android permission guideline instead

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 isAndroidQ ()

Checks if this device is running Android Q or higher.

Returns
  • true if Android Q or higher, false otherwise.

public static boolean isAndroidR ()

Checks if this device is running Android R or higher.

Returns
  • true if Android R or higher, false otherwise.

public static boolean isAndroidS ()

Checks if this device is running Android S or higher.

Returns
  • true if Android S or higher, false otherwise.

public static boolean isAndroidT ()

Checks if this device is running Android T or higher.

Returns
  • true if Android T or higher, false otherwise.

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 isBackupFolderFile (Context context, File file)

Checks whether the specified file is stored in app sandbox.

public static boolean isChromebook (Context context)

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 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 isConvertibleFormat (String filePath, String[] fileTypes)

public static boolean isConvertibleFormat (String filePath)

Checks whether the specified file is a convertible document. For example .xod or .xps

Parameters
filePath The file path
Returns
  • True if the specified file is a convertible document

public static boolean isConvertibleFormatFromExt (String ext)

public static boolean isConvertibleFormatFromExt (String ext, String[] fileTypes)

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 preview for a file. Binary office files are skipped for better performance.

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

public static boolean isDoNotRequestThumbFile (String filePath)

Checks whether should request thumbnail preview for a file. Binary office files are skipped for better performance.

Parameters
filePath the file path
Returns
  • True if not request thumbnail preview for the file

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 isEmulator ()

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 isHtmlDocument (String filePath)

Checks whether the specified file is an HTML document.

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

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 isImageFileFromExt (String ext)

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 isLargeTablet (Context context)

Checks if the device is a 10 inch plus tablet.

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

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 isNonPDFByMimeType (String mimeType)

Checks whether the specified mime type is an office mime type

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 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 isNotPdfFromExt (String ext)

Checks whether the specified extension is non-PDF extension.

Parameters
ext The file extension
Returns
  • True if the specified file 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 isOfficeDocumentFromExt (String ext)

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 ()

Checks if this device is running Pie or higher.

Returns
  • true if Pie or higher, false otherwise.

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 isSamsungKeyboard (String keyboard)

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 boolean isUsingDocumentTree ()

public static void manageOOM (PDFViewCtrl pdfViewCtrl)

Frees up memory when out-of-memory happens.

Parameters
pdfViewCtrl The PDFViewCtrl

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 (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 float parseFloat (String value)

Throws
ParseException

public static float parseFloat (String value, Locale locale)

Throws
ParseException

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 Bitmap replace9PatchColor (Bitmap inputBmp, int toColor)

Replaces all non-white colors of a 9-patch bitmap.

Parameters
inputBmp The input 9-patch bitmap
toColor The color to replace all non-white pixels
Returns
  • The output bitmap after replacing the color

public static void requestPostNotificationsPermissions (Activity activity, int requestCode)

This permission check is new for Android API 33+

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

Requests the user for the record audio permission.

Parameters
activity The activity
requestCode The request code

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

This method is deprecated.
please follow the latest Android permission guideline instead

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 simpleHTTPDownload (String link, File outputFile)

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 void throwIfNotOnMainThread ()

Throws
IllegalStateException if not running on main thread

public static void throwIfOnMainThread ()

Throws
IllegalStateException if running on main thread

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 Drawable tintDrawable (Context context, Drawable drawable)

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 void updateDashedLineColor (View view, int color)

public static boolean uriHasReadPermission (Context context, Uri uri, CancellationSignal cancellationSignal)

Checks whether the specified URI has read permission.

Parameters
context The context
uri The URI
cancellationSignal Used to cancel any pending calls using openFileDescriptor
Returns
  • True if the specified URI has read permission

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

public static boolean uriHasWritePermission (Context context, Uri uri)

Checks whether the specified URI has write permission.

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

public static boolean validActivity (Activity activity)

Returns whether the activity is valid for displaying UI (such as dialogs).

Parameters
activity the activity to check
Returns
  • true if activity is not finishing, not destroyed, and is in a valid lifecycle state.

public static void validateContentResolver (ContentResolver cr, Uri uri)