pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

PebbleKit Android

  • Pebble C API
  • Pebble JavaScript API
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • com.getpebble.android.kit
    • Constants
    • PebbleKit
    • PebbleKit.FirmwareVersionInfo
    • PebbleKit.PebbleAckReceiver
    • PebbleKit.PebbleDataLogReceiver
    • PebbleKit.PebbleDataReceiver
    • PebbleKit.PebbleNackReceiver
    • Constants.PebbleAppType
    • Constants.PebbleDataType
  • com.getpebble.android.kit.util
    • PebbleDictionary
    • PebbleTuple
    • SportsState
    • PebbleDictionary.PebbleDictTypeException
    • PebbleDictionary.TupleOverflowException
    • PebbleTuple.ValueOverflowException

PebbleDictionary

  • java.lang.Object
    • com.getpebble.android.kit.util.PebbleDictionary
  • All Implemented Interfaces:
    java.lang.Iterable<PebbleTuple>


    public class PebbleDictionary
    extends java.lang.Object
    implements java.lang.Iterable<PebbleTuple>
    A collection of key-value pairs of heterogeneous types. PebbleDictionaries are the primary structure used to exchange data between the phone and watch. To accommodate the mixed-types contained within a PebbleDictionary, an internal JSON representation is used when exchanging the dictionary between Android processes.
    • Nested Class Summary

      Modifier and Type Class and Description
      static class  PebbleDictionary.PebbleDictTypeException 
      static class  PebbleDictionary.TupleOverflowException 
    • Field Summary

      Modifier and Type Field and Description
      protected java.util.Map<java.lang.Integer,PebbleTuple> tuples 
    • Constructor Summary

      Constructor and Description
      PebbleDictionary() 
    • Method Summary

      Modifier and Type Method and Description
      void addBytes(int key, byte[] bytes)
      Associate the specified byte array with the provided key in the dictionary.
      void addInt16(int key, short s)
      Associate the specified signed short with the provided key in the dictionary.
      void addInt32(int key, int i)
      Associate the specified signed int with the provided key in the dictionary.
      void addInt8(int key, byte b)
      Associate the specified signed byte with the provided key in the dictionary.
      void addString(int key, java.lang.String value)
      Associate the specified String with the provided key in the dictionary.
      protected void addTuple(PebbleTuple tuple) 
      void addUint16(int key, short s)
      Associate the specified unsigned short with the provided key in the dictionary.
      void addUint32(int key, int i)
      Associate the specified unsigned int with the provided key in the dictionary.
      void addUint8(int key, byte b)
      Associate the specified unsigned byte with the provided key in the dictionary.
      boolean contains(int key)
      Returns true if this dictionary contains a mapping for the specified key.
      static PebbleDictionary fromJson(java.lang.String jsonString)
      Deserializes a JSON representation of a PebbleDictionary.
      byte[] getBytes(int key)
      Returns the byte array to which the specified key is mapped, or null if the key does not exist in this dictionary.
      java.lang.Long getInteger(int key)
      Returns the signed integer to which the specified key is mapped, or null if the key does not exist in this dictionary.
      java.lang.String getString(int key)
      Returns the string to which the specified key is mapped, or null if the key does not exist in this dictionary.
      java.lang.Long getUnsignedIntegerAsLong(int key)
      Returns the unsigned integer as a long to which the specified key is mapped, or null if the key does not exist in this dictionary.
      java.util.Iterator<PebbleTuple> iterator()
      void remove(int key)
      Removes the mapping for a key from this map if it is present.
      int size()
      Returns the number of key-value pairs in this dictionary.
      java.lang.String toJsonString()
      Returns a JSON representation of this dictionary.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • tuples

        protected final java.util.Map<java.lang.Integer,PebbleTuple> tuples
    • Constructor Detail

      • PebbleDictionary

        public PebbleDictionary()
    • Method Detail

      • iterator

        public java.util.Iterator<PebbleTuple> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<PebbleTuple>
      • size

        public int size()
        Returns the number of key-value pairs in this dictionary.
        Returns:
        the number of key-value pairs in this dictionary
      • contains

        public boolean contains(int key)
        Returns true if this dictionary contains a mapping for the specified key.
        Parameters:
        key - key whose presence in this dictionary is to be tested
        Returns:
        true if this dictionary contains a mapping for the specified key
      • remove

        public void remove(int key)
        Removes the mapping for a key from this map if it is present.
        Parameters:
        key - key to be removed from the dictionary
      • addBytes

        public void addBytes(int key,
                             byte[] bytes)
        Associate the specified byte array with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.
        Parameters:
        key - key with which the specified value is associated
        bytes - value to be associated with the specified key
      • addString

        public void addString(int key,
                              java.lang.String value)
        Associate the specified String with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.
        Parameters:
        key - key with which the specified value is associated
        value - value to be associated with the specified key
      • addInt8

        public void addInt8(int key,
                            byte b)
        Associate the specified signed byte with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.
        Parameters:
        key - key with which the specified value is associated
        b - value to be associated with the specified key
      • addUint8

        public void addUint8(int key,
                             byte b)
        Associate the specified unsigned byte with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.
        Parameters:
        key - key with which the specified value is associated
        b - value to be associated with the specified key
      • addInt16

        public void addInt16(int key,
                             short s)
        Associate the specified signed short with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.
        Parameters:
        key - key with which the specified value is associated
        s - value to be associated with the specified key
      • addUint16

        public void addUint16(int key,
                              short s)
        Associate the specified unsigned short with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.
        Parameters:
        key - key with which the specified value is associated
        s - value to be associated with the specified key
      • addInt32

        public void addInt32(int key,
                             int i)
        Associate the specified signed int with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.
        Parameters:
        key - key with which the specified value is associated
        i - value to be associated with the specified key
      • addUint32

        public void addUint32(int key,
                              int i)
        Associate the specified unsigned int with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.
        Parameters:
        key - key with which the specified value is associated
        i - value to be associated with the specified key
      • getInteger

        public java.lang.Long getInteger(int key)
        Returns the signed integer to which the specified key is mapped, or null if the key does not exist in this dictionary.
        Parameters:
        key - key whose associated value is to be returned
        Returns:
        value to which the specified key is mapped
      • getUnsignedIntegerAsLong

        public java.lang.Long getUnsignedIntegerAsLong(int key)
        Returns the unsigned integer as a long to which the specified key is mapped, or null if the key does not exist in this dictionary. We are using the Long type here so that we can remove the guava dependency. This is done so that we dont have incompatibility issues with the UnsignedInteger class from the Holo application, which uses a newer version of Guava.
        Parameters:
        key - key whose associated value is to be returned
        Returns:
        value to which the specified key is mapped
      • getBytes

        public byte[] getBytes(int key)
        Returns the byte array to which the specified key is mapped, or null if the key does not exist in this dictionary.
        Parameters:
        key - key whose associated value is to be returned
        Returns:
        value to which the specified key is mapped
      • getString

        public java.lang.String getString(int key)
        Returns the string to which the specified key is mapped, or null if the key does not exist in this dictionary.
        Parameters:
        key - key whose associated value is to be returned
        Returns:
        value to which the specified key is mapped
      • addTuple

        protected void addTuple(PebbleTuple tuple)
      • toJsonString

        public java.lang.String toJsonString()
        Returns a JSON representation of this dictionary.
        Returns:
        a JSON representation of this dictionary
      • fromJson

        public static PebbleDictionary fromJson(java.lang.String jsonString)
                                         throws org.json.JSONException
        Deserializes a JSON representation of a PebbleDictionary.
        Parameters:
        jsonString - the JSON representation to be deserialized
        Throws:
        org.json.JSONException - thrown if the specified JSON representation cannot be parsed