public class

Utility

extends Object
java.lang.Object
   ↳ com.sap.cloud.mobile.fiori.common.Utility

Class Overview

Common utility functions

Summary

Fields
public static int TABLET_SMALLEST_WIDTH_DP The smallest width in dp that a tablet could have.
Public Constructors
Utility()
Public Methods
static BitmapDrawable convertViewToDrawable(View view)
static int dpToPx(int dp)
Convert Dp to Px
static Activity findActivity(Context context)
static Bitmap getBitmapFromView(View view)
static int getColorResourceFromTheme(Context context, int attr, int defaultColor)
static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs)
Get the value of the data column for this Uri.
static float getDimenResourceFromTheme(Context context, int attr, int dimen)
static Typeface getFioriTypeface(int styleIndex)
static float getFloat(Resources resources, int id)
Returns a float resource.
static String getLocalPath(Context context, Uri uri)
Get the local path of the given Uri from the Context
static int getResourceFromTheme(Context context, int attr, int defaultRes)
static Bitmap getScreenViewBitmap(View view)
static float getSpacingAdd(TextPaint paint, float lineHeight)
Returns spacingAdd by comparing lineHeight and font metrics.
static float getSpacingMultiplier(TextPaint paint, float lineHeight)
Returns spacingMultiplier by comparing lineHeight and font metrics.
static int getTrueSurfaceColor(Context context, float elevation)
A tool for Dark Theme that returns the custom View's surface color based on its elevation.
static void hideKeyboard(Activity activity)
static boolean isDownloadsDocument(Uri uri)
static boolean isExternalStorageDocument(Uri uri)
static boolean isLandscapeOrientation(Context context)
Check if the device is in landscape mode or not
static boolean isMediaDocument(Uri uri)
static boolean isNightMode(Context context)
static boolean isRTL()
static boolean isTablet(Context context)
Tests whether the current application runs on a tablet.
static Date parseTime(String time)
static int pxToDp(int px)
Convert pixels to density independent pixels (dp).
static float smootherStep(float edge1, float edge2, float val)
By Ken Perlin.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static int TABLET_SMALLEST_WIDTH_DP

The smallest width in dp that a tablet could have.

Public Constructors

public Utility ()

Public Methods

public static BitmapDrawable convertViewToDrawable (View view)

public static int dpToPx (int dp)

Convert Dp to Px

Parameters
dp int
Returns
  • int

public static Activity findActivity (Context context)

public static Bitmap getBitmapFromView (View view)

public static int getColorResourceFromTheme (Context context, int attr, int defaultColor)

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

Get 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 the file path.

public static float getDimenResourceFromTheme (Context context, int attr, int dimen)

public static Typeface getFioriTypeface (int styleIndex)

Parameters
styleIndex The style (normal, bold, italic) of the typeface. e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC

public static float getFloat (Resources resources, int id)

Returns a float resource. Resources.getFloat is hidden in API v28.

Parameters
resources resources object
id float resource id defined as

public static String getLocalPath (Context context, Uri uri)

Get the local path of the given Uri from the Context

Parameters
context Context
uri Uri
Returns
  • String

public static int getResourceFromTheme (Context context, int attr, int defaultRes)

public static Bitmap getScreenViewBitmap (View view)

public static float getSpacingAdd (TextPaint paint, float lineHeight)

Returns spacingAdd by comparing lineHeight and font metrics.

public static float getSpacingMultiplier (TextPaint paint, float lineHeight)

Returns spacingMultiplier by comparing lineHeight and font metrics.

public static int getTrueSurfaceColor (Context context, float elevation)

A tool for Dark Theme that returns the custom View's surface color based on its elevation.

public static void hideKeyboard (Activity activity)

public static boolean isDownloadsDocument (Uri uri)

Parameters
uri The Uri to check.
Returns
  • Whether the Uri authority is DownloadsProvider.

public static boolean isExternalStorageDocument (Uri uri)

Parameters
uri Uri
Returns
  • boolean, Whether the Uri authority is ExternalStorageProvider.

public static boolean isLandscapeOrientation (Context context)

Check if the device is in landscape mode or not

Returns
  • boolean

public static boolean isMediaDocument (Uri uri)

Parameters
uri The Uri to check.
Returns
  • Whether the Uri authority is MediaProvider.

public static boolean isNightMode (Context context)

public static boolean isRTL ()

public static boolean isTablet (Context context)

Tests whether the current application runs on a tablet.

Parameters
context context of the application

public static Date parseTime (String time)

public static int pxToDp (int px)

Convert pixels to density independent pixels (dp).

Parameters
px The number of pixels.
Returns
  • The corresponding number of dp.

public static float smootherStep (float edge1, float edge2, float val)

By Ken Perlin. See Smoothstep - Wikipedia.