Exemplo n.º 1
0
  /*
   * A touch point (x,y) occurs in LayerView, this point should be displayed
   * in the center of the zoomed view. The returned point is the position of
   * the Top-Left zoomed view point on the screen device
   */
  private PointF getZoomedViewTopLeftPositionFromTouchPosition(float x, float y) {
    ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
    final float parentWidth = metrics.getWidth();
    final float parentHeight = metrics.getHeight();

    // See comments in getUnzoomedPositionFromPointInZoomedView, but the
    // transformations here are largely the reverse of that function.

    float visibleContentPixels = viewWidth / zoomFactor;
    float maxContentOffset = parentWidth - visibleContentPixels;
    float maxZoomedViewOffset = parentWidth - viewContainerWidth;
    float contentPixelOffset = x - (visibleContentPixels / 2.0f);
    returnValue.x = (int) (contentPixelOffset * (maxZoomedViewOffset / maxContentOffset));

    visibleContentPixels = viewHeight / zoomFactor;
    maxContentOffset = parentHeight - visibleContentPixels;
    maxZoomedViewOffset = parentHeight - (viewContainerHeight - toolbarHeight);
    contentPixelOffset = y - (visibleContentPixels / 2.0f);
    float unscaledViewOffset = layerView.getSurfaceTranslation() - offsetDueToToolBarPosition;
    returnValue.y =
        (int)
            ((contentPixelOffset * (maxZoomedViewOffset / maxContentOffset)) + unscaledViewOffset);

    return returnValue;
  }
Exemplo n.º 2
0
 private void setCapturedSize(ImmutableViewportMetrics metrics) {
   float parentMinSize = Math.min(metrics.getWidth(), metrics.getHeight());
   viewWidth =
       (int) ((parentMinSize * W_CAPTURED_VIEW_IN_PERCENT / (zoomFactor * 100.0)) * zoomFactor);
   viewHeight =
       (int) ((parentMinSize * H_CAPTURED_VIEW_IN_PERCENT / (zoomFactor * 100.0)) * zoomFactor);
   viewContainerHeight = viewHeight + toolbarHeight + 2 * containterSize; // Top and bottom shadows
   viewContainerWidth = viewWidth + 2 * containterSize; // Right and left shadows
   // Display in zoomedview is corrupted when width is an odd number
   // More details about this issue here: bug 776906 comment 11
   viewWidth &= ~0x1;
 }
Exemplo n.º 3
0
  /*
   * Convert a click from ZoomedView. Return the position of the click in the
   * LayerView
   */
  private PointF getUnzoomedPositionFromPointInZoomedView(float x, float y) {
    ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
    final float parentWidth = metrics.getWidth();
    final float parentHeight = metrics.getHeight();
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();

    // The number of unzoomed content pixels that can be displayed in the
    // zoomed area.
    float visibleContentPixels = viewWidth / zoomFactor;
    // The offset in content pixels of the leftmost zoomed pixel from the
    // layerview's left edge when the zoomed view is moved to the right as
    // far as it can go.
    float maxContentOffset = parentWidth - visibleContentPixels;
    // The maximum offset in screen pixels that the zoomed view can have
    float maxZoomedViewOffset = parentWidth - viewContainerWidth;

    // The above values allow us to compute the term
    //   maxContentOffset / maxZoomedViewOffset
    // which is the number of content pixels that we should move over by
    // for every screen pixel that the zoomed view is moved over by.
    // This allows a smooth transition from when the zoomed view is at the
    // leftmost extent to when it is at the rightmost extent.

    // This is the offset in content pixels of the leftmost zoomed pixel
    // visible in the zoomed view. This value is relative to the layerview
    // edge.
    float zoomedContentOffset =
        ((float) params.leftMargin) * maxContentOffset / maxZoomedViewOffset;
    returnValue.x = (int) (zoomedContentOffset + (x / zoomFactor));

    // Same comments here vertically
    visibleContentPixels = viewHeight / zoomFactor;
    maxContentOffset = parentHeight - visibleContentPixels;
    maxZoomedViewOffset = parentHeight - (viewContainerHeight - toolbarHeight);
    float zoomedAreaOffset =
        (float) params.topMargin + offsetDueToToolBarPosition - layerView.getSurfaceTranslation();
    zoomedContentOffset = zoomedAreaOffset * maxContentOffset / maxZoomedViewOffset;
    returnValue.y = (int) (zoomedContentOffset + ((y - offsetDueToToolBarPosition) / zoomFactor));

    return returnValue;
  }