Class KeypadData

  • All Implemented Interfaces:
    java.lang.Comparable<java.lang.Object>

    public class KeypadData
    extends FunctionData
    Represents a keypad event data that is collected when a change with some key from the keypad has occurred.

    The key pressed event is using TYPE_PRESSED type, while the key released event is using TYPE_RELEASED type.

    See Also:
    Keypad, FunctionData
    • Constructor Summary

      Constructors 
      Constructor Description
      KeypadData​(long timestamp, java.util.Map<java.lang.String,​java.lang.Object> metadata, int type, int subType, int keyCode, java.lang.String keyName)
      Constructs new KeypadData instance with the specified arguments.
      KeypadData​(java.util.Map<java.lang.String,​?> fields)
      Constructs new KeypadData instance with the specified field values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(java.lang.Object o)
      Compares this KeypadData instance with the given argument.
      boolean equals​(java.lang.Object o)
      Two KeypadData instances are equal if they contain equal metadata, timestamp, event type, key code and key name.
      int getKeyCode()
      The code of the key.
      java.lang.String getKeyName()
      Represents a human readable name of the corresponding key code.
      int getSubType()
      Returns the event sub-type.
      int getType()
      Returns the event type.
      int hashCode()
      Returns the hash code for this KeypadData object.
      java.lang.String toString()
      Returns the string representation of this keypad data.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • FIELD_TYPE

        public static final java.lang.String FIELD_TYPE
        Represents the event type field name. The field value is available with getType(). The field type is int. The constant can be used as a key to KeypadData(Map).
        See Also:
        Constant Field Values
      • FIELD_SUB_TYPE

        public static final java.lang.String FIELD_SUB_TYPE
        Represents the event sub-type field name. The field value is available with getSubType(). The field type is int. The constant can be used as a key to KeypadData(Map).
        See Also:
        Constant Field Values
      • FIELD_KEY_CODE

        public static final java.lang.String FIELD_KEY_CODE
        Represents the key code field name. The field value is available with getKeyCode(). The field type is int . The constant can be used as a key to KeypadData(Map).
        See Also:
        Constant Field Values
      • FIELD_KEY_NAME

        public static final java.lang.String FIELD_KEY_NAME
        Represents the key name field name. The field value is available with getKeyName(). The field type is String. The constant can be used as a key to KeypadData(Map).
        See Also:
        Constant Field Values
      • TYPE_PRESSED

        public static final int TYPE_PRESSED
        Represents a keypad event type for a key pressed event.
        See Also:
        Constant Field Values
      • TYPE_RELEASED

        public static final int TYPE_RELEASED
        Represents a keypad event type for a key released event.
        See Also:
        Constant Field Values
      • SUB_TYPE_PRESSED_NORMAL

        public static final int SUB_TYPE_PRESSED_NORMAL
        Represents a keypad event sub-type for a normal key pressed event. Usually, there is a single press and the key is not held down. This sub-type is used with TYPE_PRESSED type.
        See Also:
        Constant Field Values
      • SUB_TYPE_PRESSED_LONG

        public static final int SUB_TYPE_PRESSED_LONG
        Represents a keypad event sub-type for a long key pressed event. Usually, there is a single press and the key is held down. This sub-type is used with TYPE_PRESSED type.
        See Also:
        Constant Field Values
      • SUB_TYPE_PRESSED_DOUBLE

        public static final int SUB_TYPE_PRESSED_DOUBLE
        Represents a keypad event sub-type for a double key pressed event. Usually, there are two press actions and the key is not held down after the second press. This sub-type is used with TYPE_PRESSED type.
        See Also:
        Constant Field Values
      • SUB_TYPE_PRESSED_DOUBLE_LONG

        public static final int SUB_TYPE_PRESSED_DOUBLE_LONG
        Represents a keypad event sub-type for a double long key pressed event. Usually, there are two press actions and the key is held down after the second press. This sub-type is used with TYPE_PRESSED type.
        See Also:
        Constant Field Values
    • Constructor Detail

      • KeypadData

        public KeypadData​(java.util.Map<java.lang.String,​?> fields)
        Constructs new KeypadData instance with the specified field values. The map keys must match to the field names. The map values will be assigned to the appropriate class fields. For example, the maps can be: {"type"=Integer(1)...}. That map will initialize the FIELD_TYPE field with 1.
        Parameters:
        fields - Contains the new KeypadData instance field values.
        Throws:
        java.lang.ClassCastException - If the field value types are not expected.
        java.lang.IllegalArgumentException - If the event type or key code is missing or invalid arguments are specified.
        java.lang.NullPointerException - If the fields map is null.
      • KeypadData

        public KeypadData​(long timestamp,
                          java.util.Map<java.lang.String,​java.lang.Object> metadata,
                          int type,
                          int subType,
                          int keyCode,
                          java.lang.String keyName)
        Constructs new KeypadData instance with the specified arguments.
        Parameters:
        timestamp - The data timestamp optional field.
        metadata - The data metadata optional field.
        type - The data event type mandatory field.
        subType - The data event sub-type optional field or 0 if there is no sub-type.
        keyCode - The data key code mandatory field.
        keyName - The data key name optional field or null if there is no key name.
    • Method Detail

      • getType

        public int getType()
        Returns the event type. The type represents the main reason for this event. It can be one of:
        Returns:
        The event type.
      • getSubType

        public int getSubType()
        Returns the event sub-type. The sub-type provides additional details about the event. The sub-type can be one of: Zero and positive values are reserved for this definition and further extensions of the sub-types. Custom sub-types can be used only as negative values to prevent potential collisions.
        Returns:
        The event sub-type.
      • getKeyCode

        public int getKeyCode()
        The code of the key. This field is mandatory and it holds the semantics(meaning) of the key.
        Returns:
        The key code.
      • getKeyName

        public java.lang.String getKeyName()
        Represents a human readable name of the corresponding key code. This field is optional and sometimes it could be missed(might be null ).
        Returns:
        A string with the name of the key or null if not specified.
      • equals

        public boolean equals​(java.lang.Object o)
        Two KeypadData instances are equal if they contain equal metadata, timestamp, event type, key code and key name.
        Overrides:
        equals in class FunctionData
        Parameters:
        o - The object to compare this data.
        Returns:
        true if this object is equivalent to the specified one.
        See Also:
        FunctionData.equals(java.lang.Object)
      • hashCode

        public int hashCode()
        Returns the hash code for this KeypadData object. The hash code is a sum of FunctionData.hashCode(), String.hashCode(), event type, event sub-type and key code, where String.hashCode() represents the key name hash code if available.
        Overrides:
        hashCode in class FunctionData
        Returns:
        The hash code of this LevelData object.
        See Also:
        FunctionData.hashCode()
      • compareTo

        public int compareTo​(java.lang.Object o)
        Compares this KeypadData instance with the given argument. If the argument is not KeypadData, it throws ClassCastException. Otherwise, this method returns:
        • -1 if this instance field is less than a field of the specified argument.
        • 0 if all fields are equivalent.
        • 1 if this instance field is greater than a field of the specified argument.
        The fields are compared in this order: timestamp, metadata, type, sub-type, key code, key name.
        Specified by:
        compareTo in interface java.lang.Comparable<java.lang.Object>
        Overrides:
        compareTo in class FunctionData
        Parameters:
        o - KeypadData to be compared.
        Returns:
        -1, 0 or 1 depending on the comparison rules.
        Throws:
        java.lang.ClassCastException - If the method argument is not of type KeypadData.
        See Also:
        Comparable.compareTo(java.lang.Object)
      • toString

        public java.lang.String toString()
        Returns the string representation of this keypad data.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string representation of this keypad data.