Class UtilsAndroidLib

    • Constructor Detail

      • UtilsAndroidLib

        UtilsAndroidLib()
    • 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,a
        tag - 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

      • 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 empty
        nFirstChars - can be higher than the size of the data.
      • 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)

      • 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 - inclusive
        maxValue - 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 1m
        rssi - 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 check
        bitPos - 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 check
        bitPos - 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 for
        str - 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.

      • 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.

      • 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

      • 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.