Class RangingAdapter

java.lang.Object
com.codename1.nearby.ranging.RangingAdapter
All Implemented Interfaces:
RangingListener

public class RangingAdapter extends Object implements RangingListener

A RangingListener whose methods all do nothing, so a caller interested in one event overrides one method.

session.addRangingListener(new RangingAdapter() {
    public void updated(RangingUpdate u) {
        if (u.hasDistance()) {
            label.setText(Math.round(u.getDistance(RangingUnit.CENTIMETERS)) + " cm");
        }
    }
});
  • Constructor Details

    • RangingAdapter

      public RangingAdapter()
  • Method Details

    • updated

      public void updated(RangingUpdate update)
      Description copied from interface: RangingListener

      A fresh measurement arrived. Expect these several times a second while the peer is in range, and expect individual fields to drop in and out -- see RangingUpdate.

      Parameters
      • update: the measurement
      Specified by:
      updated in interface RangingListener
    • peerRemoved

      public void peerRemoved(RangingRemovalReason reason)
      Description copied from interface: RangingListener

      The peer stopped being ranged. The session stays alive and will resume delivering updates if the peer comes back, so this is a cue to gray the UI out rather than to tear it down.

      Parameters
      • reason: why the peer went away
      Specified by:
      peerRemoved in interface RangingListener
    • suspended

      public void suspended()
      Description copied from interface: RangingListener
      The platform paused the session -- typically because the app went to the background without the entitlement that would let it keep ranging. No updates arrive until RangingListener.resumed() fires.
      Specified by:
      suspended in interface RangingListener
    • resumed

      public void resumed()
      Description copied from interface: RangingListener
      A suspended session started running again.
      Specified by:
      resumed in interface RangingListener
    • invalidated

      public void invalidated(NearbyException error)
      Description copied from interface: RangingListener

      The session died and cannot be restarted. Any further call on it fails; prepare a new session if the feature is still wanted.

      Parameters
      • error: why the session ended
      Specified by:
      invalidated in interface RangingListener