Class UtilsAndroidLib
-
- All Implemented Interfaces:
public class UtilsAndroidLib
-
-
Constructor Summary
Constructors Constructor Description UtilsAndroidLib()
-
Method Summary
Modifier and Type Method Description static void
log(char logLevel, String tag, String text)
Logging helper: put new logs into the UI console static int
minMax(int min, int max, int input)
return min value if min >input return max value if max <input otherwise return input static String
generateRandomString(int length)
static Array<byte>
intToBytes(int i)
Convert integer into 4 bytes array static boolean
hasNegativeValue(List<Integer> integers)
Indicate if list contains at least one negative value in the array. static boolean
hasCharacter(@Nullable() String data, @Nullable() CharSequence c, @IntRange(from = 1) int nFirstChars)
Indicates if a char sequence is inside the first N chars. static Array<byte>
convertAsPrimitiveByteArray(List<Byte> list)
Converting Byte List to Primitive byte Array static boolean
stringsAreNullOrEmpty(Array<String> parameters)
Check if one of the given parameter is null or empty. static boolean
objectsAreNull(Array<Object> parameters)
return true if one of given objects is null. static List<Integer>
rangeClosed(int startInclusive, int endInclusive)
Return a list of integer with a suite of integer which begin from startInclusive to endInclusive value example rangeClosed(1, 3) return [1, 2 , 3] static IntRange
getFirstUndiscontinuedIntSuite(List<Integer> suite)
Return range of the first undiscontinued suite of integers. static int
convertBytesToMilliseconds(int bytes, int datarateBitsSecond)
static int
convertMillisecondsToBytes(int milliseconds, int datarateBitsSecond)
Convert a duration milliseconds to bytes according to the datarate. static Array<byte>
removeLeadingTrailingZeros(Array<byte> frame)
static Array<byte>
removeLeadingTrailingFFs(Array<byte> frame)
Remove all leading trailing 0xFF hosted in given bytes frame. static Array<byte>
removeLeadingTrailingFFsAndZeros(Array<byte> frame)
Remove all leading trailing 00 and FF. static Array<byte>
removeLeadingTrailingBytes(Array<byte> frame, List<Byte> bytesToRemove)
static int
isInRange(long value, long minValue, long maxValue)
Return 0 if value is in [minValue, maxValue] Return 1 if value is >maxValue Return -1 if value is <minValue static double
calculateDistance(int txPower, double rssi)
Estimates the distance between the mobile device and a BLE beacon based on the measured RSSI and a txPower calibration value that represents the expected RSSI for an iPhone 5 receiving the signal when it is 1 meter away. static int
convertRssiDBmToPercent(int rssidBm)
Convert a RSSI from dBm to percent. static Boolean
isBitSet(int data, int bitPos)
Checks if a bit is set in an integer static Boolean
isBitSet(Array<byte> data, int bitPos)
Checks if a bit is set in a byte array static String
getDeviceUniqueId(Context ctx)
Get Android ID, a 64-bit number (as a hex string) that is randomly generated on the device's first boot and should remain constant for the lifetime of the device. static int
countSubstring(String subStr, String str)
Count the number of non-overlapping occurrences of a substring inside a string. static boolean
validateMacAddress(String macAddress)
Checks for MAC address correctness. static long
getThreadId()
Returns a reference to the currently executing thread object. static String
getThreadSignature()
Returns a unique String identifying the current thread. static boolean
isRoguePro(Context context, String deviceModelName)
Indicates if the given model name represents a Rogue Pro static boolean
isRogueGov(Context context, String deviceModelName)
Indicates if the given model name represents a Rogue Gov static boolean
isRogue(Context context, String deviceModelName)
Indicates if the given model name represents a Rogue static boolean
isMarauderBasic(Context context, String deviceModelName)
Indicates if the given model name represents a Marauder Basic static boolean
isMarauderStandard(Context context, String deviceModelName)
Indicates if the given model name represents a Marauder Standard static boolean
isMarauderUltimate(Context context, String deviceModelName)
Indicates if the given model name represents a Marauder Ultimate static boolean
isMarauder(Context context, String deviceModelName)
Indicates if the given model name represents a Marauder static Array<byte>
arrayAddBytes(Array<byte> arr, Array<byte> elements)
This method will add elements to an array and return the resulting array static Array<byte>
arrayTruncateBytes(Array<byte> array, int newLength)
Truncates the given array to the request length. static void
arrayReverseBytes(Array<byte> array)
Reverse an array is by using a for loop static boolean
isDeviationNeeded(int modulation)
Indicates if the modulation requires setting the deviation parameter. static String
getPlatformSupportedAbis()
static boolean
isNullOrEmpty(String str)
Check if String is Empty or Null static boolean
isPositive(int i1)
static boolean
isSameSign(int i1, int i2)
static int
signInt(int i1, int i2)
Apply sign of i1 to i2 static boolean
isNonNullAndNonEmpty(String str)
Indicates if the string is non null &¬ empty. static int
searchSpaceChar(CharSequence data, int fromIndex, int toIndexExclusive)
Search next space char from a char sequence. static void
registerReceiverCompat(Context context, BroadcastReceiver receiver, IntentFilter filter, int flags)
Register to a broadcast receiver with compatibility support On android O or older SDKs the registerReceiver doesn't handle the flags EXPORTED/NOT_EXPORTED -
-
Method Detail
-
log
static void log(char logLevel, String tag, String text)
Logging helper: put new logs into the UI console
- Parameters:
logLevel
- Priority of the log message: v,d,e,i,w,e,atag
- Used to identify the source of a log message.text
- The message you would like logged.
-
minMax
static int minMax(int min, int max, int input)
return min value if min >input return max value if max <input otherwise return input
-
generateRandomString
static String generateRandomString(int length)
-
intToBytes
static Array<byte> intToBytes(int i)
Convert integer into 4 bytes array
- Parameters:
i
- integer to convert- Returns:
Byte array of size 4 bytes
-
hasNegativeValue
static boolean hasNegativeValue(List<Integer> integers)
Indicate if list contains at least one negative value in the array.
-
hasCharacter
static boolean hasCharacter(@Nullable() String data, @Nullable() CharSequence c, @IntRange(from = 1) int nFirstChars)
Indicates if a char sequence is inside the first N chars.
- Parameters:
data
- could be null or emptynFirstChars
- can be higher than the size of the data.
-
convertAsPrimitiveByteArray
static Array<byte> convertAsPrimitiveByteArray(List<Byte> list)
Converting Byte List to Primitive byte Array
-
stringsAreNullOrEmpty
static boolean stringsAreNullOrEmpty(Array<String> parameters)
Check if one of the given parameter is null or empty.
-
objectsAreNull
static boolean objectsAreNull(Array<Object> parameters)
return true if one of given objects is null. return false if all objects are not null.
-
rangeClosed
static List<Integer> rangeClosed(int startInclusive, int endInclusive)
Return a list of integer with a suite of integer which begin from startInclusive to endInclusive value example rangeClosed(1, 3) return [1, 2 , 3]
- Parameters:
startInclusive
- must be strictly lower or equals than endInclusive
-
getFirstUndiscontinuedIntSuite
@Nullable() static IntRange getFirstUndiscontinuedIntSuite(List<Integer> suite)
Return range of the first undiscontinued suite of integers. example: [1, 2, 3, 4, 6] return IntRange(1, 4) [1, 3, 4, 5, 6] * return IntRange(1, 1) [1, 2, 2, 2, 3, 4, 5, 6] * return IntRange(1, 6)
- Returns:
IntRange when begin is inclusive, end is inclusive.
-
convertBytesToMilliseconds
static int convertBytesToMilliseconds(int bytes, int datarateBitsSecond)
- Parameters:
datarateBitsSecond
- datarate in bits/s
-
convertMillisecondsToBytes
static int convertMillisecondsToBytes(int milliseconds, int datarateBitsSecond)
Convert a duration milliseconds to bytes according to the datarate. N milliseconds of capture with M datarate -> size of captured bytes is -> bytes = M(Byte/s) * N(seconds)
-
removeLeadingTrailingZeros
static Array<byte> removeLeadingTrailingZeros(Array<byte> frame)
-
removeLeadingTrailingFFs
static Array<byte> removeLeadingTrailingFFs(Array<byte> frame)
Remove all leading trailing 0xFF hosted in given bytes frame.
-
removeLeadingTrailingFFsAndZeros
static Array<byte> removeLeadingTrailingFFsAndZeros(Array<byte> frame)
Remove all leading trailing 00 and FF. Example: 00000AFF0CFFFF becomes 0AFF0C.
-
removeLeadingTrailingBytes
static Array<byte> removeLeadingTrailingBytes(Array<byte> frame, List<Byte> bytesToRemove)
-
isInRange
static int isInRange(long value, long minValue, long maxValue)
Return 0 if value is in [minValue, maxValue] Return 1 if value is >maxValue Return -1 if value is <minValue
- Parameters:
minValue
- inclusivemaxValue
- inclusive
-
calculateDistance
static double calculateDistance(int txPower, double rssi)
Estimates the distance between the mobile device and a BLE beacon based on the measured RSSI and a txPower calibration value that represents the expected RSSI for an iPhone 5 receiving the signal when it is 1 meter away. Cf. https://github.com/AltBeacon/android-beacon-library/blob/master/src/main/java/org/altbeacon/beacon/distance/CurveFittedDistanceCalculator.java
- Parameters:
txPower
- Reference rssi at 1mrssi
- Actual rssi at the current location- Returns:
Estimated distance in meters to the beacon based on a reference rssi at 1m and the known actual rssi at the current location
-
convertRssiDBmToPercent
static int convertRssiDBmToPercent(int rssidBm)
Convert a RSSI from dBm to percent.
- Parameters:
rssidBm
- RSSI level to be converted.- Returns:
RSSI in percent.
-
isBitSet
static Boolean isBitSet(int data, int bitPos)
Checks if a bit is set in an integer
- Parameters:
data
- Data to checkbitPos
- Index of bit to check- Returns:
True if bit is set, false else.
-
isBitSet
static Boolean isBitSet(Array<byte> data, int bitPos)
Checks if a bit is set in a byte array
- Parameters:
data
- Data to checkbitPos
- Index of bit to check- Returns:
True if bit is set, false else.
-
getDeviceUniqueId
static String getDeviceUniqueId(Context ctx)
Get Android ID, a 64-bit number (as a hex string) that is randomly generated on the device's first boot and should remain constant for the lifetime of the device. (The value may change if a factory reset is performed on the device.)
- Parameters:
ctx
- Current context- Returns:
Android ID
-
countSubstring
static int countSubstring(String subStr, String str)
Count the number of non-overlapping occurrences of a substring inside a string. https://rosettacode.org/wiki/Count_occurrences_of_a_substring#Java
- Parameters:
subStr
- substring to be searched forstr
- the string to search- Returns:
number of non-overlapping occurrences of subStr inside str
-
validateMacAddress
static boolean validateMacAddress(String macAddress)
Checks for MAC address correctness.
- Parameters:
macAddress
- A MAC address to check.- Returns:
true if the MAC address is valid
-
getThreadId
static long getThreadId()
Returns a reference to the currently executing thread object.
- Returns:
the currently executing thread.
-
getThreadSignature
static String getThreadSignature()
Returns a unique String identifying the current thread.
- Returns:
A string containing thread name + thread ID + thread priority + thread group
-
isRoguePro
static boolean isRoguePro(Context context, String deviceModelName)
Indicates if the given model name represents a Rogue Pro
-
isRogueGov
static boolean isRogueGov(Context context, String deviceModelName)
Indicates if the given model name represents a Rogue Gov
-
isRogue
static boolean isRogue(Context context, String deviceModelName)
Indicates if the given model name represents a Rogue
-
isMarauderBasic
static boolean isMarauderBasic(Context context, String deviceModelName)
Indicates if the given model name represents a Marauder Basic
-
isMarauderStandard
static boolean isMarauderStandard(Context context, String deviceModelName)
Indicates if the given model name represents a Marauder Standard
-
isMarauderUltimate
static boolean isMarauderUltimate(Context context, String deviceModelName)
Indicates if the given model name represents a Marauder Ultimate
-
isMarauder
static boolean isMarauder(Context context, String deviceModelName)
Indicates if the given model name represents a Marauder
-
arrayAddBytes
static Array<byte> arrayAddBytes(Array<byte> arr, Array<byte> elements)
This method will add elements to an array and return the resulting array
- Parameters:
arr
- Array of bytes where bytes elements need to be appended.elements
- Bytes to be appended.- Returns:
A new array of bytes where bytes elements have been appended.
-
arrayTruncateBytes
static Array<byte> arrayTruncateBytes(Array<byte> array, int newLength)
Truncates the given array to the request length.
-
arrayReverseBytes
static void arrayReverseBytes(Array<byte> array)
Reverse an array is by using a for loop
-
isDeviationNeeded
static boolean isDeviationNeeded(int modulation)
Indicates if the modulation requires setting the deviation parameter. Possible modulation values are <String, Integer>: "ASK/OOK": {@value com.comthings.gollum.api.gollumandroidlib.GollumDongle#MODULATION_ASK_OOK}, "2-FSK": {@value com.comthings.gollum.api.gollumandroidlib.GollumDongle#MODULATION_2FSK}, "4-FSK: {@value com.comthings.gollum.api.gollumandroidlib.GollumDongle#MODULATION_4FSK}, "GFSK": {@value com.comthings.gollum.api.gollumandroidlib.GollumDongle#MODULATION_GFSK}, "MSK": {@value com.comthings.gollum.api.gollumandroidlib.GollumDongle#MODULATION_MSK}
- Parameters:
modulation
- Modulation as an integer.- Returns:
true if the modulation requires setting the deviation parameter
-
getPlatformSupportedAbis
static String getPlatformSupportedAbis()
- Returns:
An ordered list of ABIs supported by this device. The most preferred ABI is the first element in the list.
-
isNullOrEmpty
static boolean isNullOrEmpty(String str)
Check if String is Empty or Null
-
isPositive
static boolean isPositive(int i1)
-
isSameSign
static boolean isSameSign(int i1, int i2)
-
signInt
static int signInt(int i1, int i2)
Apply sign of i1 to i2
- Returns:
i2 with the same sign as i1
-
isNonNullAndNonEmpty
static boolean isNonNullAndNonEmpty(String str)
Indicates if the string is non null &¬ empty.
-
searchSpaceChar
static int searchSpaceChar(CharSequence data, int fromIndex, int toIndexExclusive)
Search next space char from a char sequence. return -1 of no one space char is found.
-
registerReceiverCompat
static void registerReceiverCompat(Context context, BroadcastReceiver receiver, IntentFilter filter, int flags)
Register to a broadcast receiver with compatibility support On android O or older SDKs the registerReceiver doesn't handle the flags EXPORTED/NOT_EXPORTED
- Parameters:
flags
- Must ContextCompat.RECEIVER_NOT_EXPORTED or ContextCompat.
-
-
-
-