title: Detecting complete end of motion in MapBox Android
body: <p>I'm looking to detect complete end of motion of the map in the Android SDK of MapBox. By complete end I mean no more user interaction (touch) and camera movement (touch move or fling inertia).</p>
  
  <p>As there is no such callback in the SDK, I combined two listeners on the <code>MapView</code>, <code>OnTouchListener</code> and <code>OnMapChangedListener</code> like so (in Kotlin but pretty clear):</p>
  
  <pre><code>mapView.setOnTouchListener { _, event -&gt;
      when (event.actionMasked) {
          MotionEvent.ACTION_DOWN -&gt; {
              listener?.onMapDragBegin()
          }
          MotionEvent.ACTION_UP -&gt; {
              listener?.onMapDragEnd()
          }
      }
      false
  }
  
  mapView.addOnMapChangedListener { c -&gt;
      when (c) {
          MapView.REGION_WILL_CHANGE, MapView.REGION_WILL_CHANGE_ANIMATED -&gt; {
              listener?.onMapMovementBegin()
          }
          MapView.REGION_DID_CHANGE, MapView.REGION_DID_CHANGE_ANIMATED -&gt; {
              listener?.onMapMovementEnd()
          }
      }
  }
  </code></pre>
  
  <p>The listener waits for both events to have ended. This works pretty well, except for one tiny detail: when flinging, both end events are sent when the user stops touching the screen, and only after is the <code>REGION_WILL_CHANGE_ANIMATED</code> map change invoked. So there's a moment at which I can't know whether the map is still moving or not. Looks like this in the logs:</p>
  
  <pre><code>19:23:42.431: Map touch started
  19:23:42.537: Map region change started
  19:23:42.538: Map region change ended
  ...
  19:23:42.570: Map region change started
  19:23:42.570: Map region change ended
  19:23:42.577: Map touch ended
  19:23:42.577: Map movement ended at -122,420511, 37,748315
  // Both touch and movement now have ended according to the MapView
  // Fling inertia begins
  19:23:42.582: Map region change started
  19:23:43.154: Map region change ended
  19:23:43.154: Map movement ended at -122,424123, 37,741793
  </code></pre>
  
  <p>I need to do an API call after the movement ended. If the map starts moving again I will cancel any active call so it's not a huge issue, but I'd like to know if the SDK provides a way to avoid having this call/cancel/call every time the user flings the map. For example I've thought of checking any scroll speed at the end of the movement but coulnd't find any way to access it.</p>