/** This function must be called from the UI thread. */
 public void abortAnimation() {
   checkMainThread();
   // this happens when gecko changes the viewport on us or if the device is rotated.
   // if that's the case, abort any animation in progress and re-zoom so that the page
   // snaps to edges. for other cases (where the user's finger(s) are down) don't do
   // anything special.
   switch (mState) {
     case FLING:
       mX.stopFling();
       mY.stopFling();
       // fall through
     case BOUNCE:
     case ANIMATED_ZOOM:
       // the zoom that's in progress likely makes no sense any more (such as if
       // the screen orientation changed) so abort it
       setState(PanZoomState.NOTHING);
       // fall through
     case NOTHING:
       // Don't do animations here; they're distracting and can cause flashes on page
       // transitions.
       synchronized (mTarget.getLock()) {
         mTarget.setViewportMetrics(getValidViewportMetrics());
       }
       break;
   }
 }
 /** This must be called on the UI thread. */
 public void pageRectUpdated() {
   if (mState == PanZoomState.NOTHING) {
     synchronized (mTarget.getLock()) {
       ImmutableViewportMetrics validated = getValidViewportMetrics();
       if (!getMetrics().fuzzyEquals(validated)) {
         // page size changed such that we are now in overscroll. snap to the
         // the nearest valid viewport
         mTarget.setViewportMetrics(validated);
       }
     }
   }
 }
 /**
  * Scales the viewport, keeping the given focus point in the same place before and after the scale
  * operation. You must hold the monitor while calling this.
  */
 private void scaleWithFocus(float zoomFactor, PointF focus) {
   ImmutableViewportMetrics viewportMetrics = getMetrics();
   viewportMetrics = viewportMetrics.scaleTo(zoomFactor, focus);
   mTarget.setViewportMetrics(viewportMetrics);
 }
 private void scrollBy(float dx, float dy) {
   ImmutableViewportMetrics scrolled = getMetrics().offsetViewportBy(dx, dy);
   mTarget.setViewportMetrics(scrolled);
 }