Java Code Examples for android.graphics.Point#offset()

The following examples show how to use android.graphics.Point#offset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocView.java    From Mupdf with Apache License 2.0 6 votes vote down vote up
protected void positionHandle(DragHandle handle, DocPageView dpv, int pageX, int pageY)
{
	if (handle != null)
	{
		//  convert to DocPageView-based coords
		Point p = dpv.pageToView(pageX, pageY);

		//  offset to 0,0
		p.offset(dpv.getLeft(), dpv.getTop());

		//  offset to position in the scrolling view (this)
		p.offset(-getScrollX(), -getScrollY());

		//  offset based on handle size and padding
		p.offset(-selectionHandlePadPx - selectionHandleSizePx / 2, -selectionHandlePadPx - selectionHandleSizePx / 2);

		//  move it
		handle.moveTo(p.x, p.y);
	}
}
 
Example 2
Source File: DocView.java    From Mupdf with Apache License 2.0 6 votes vote down vote up
public Point getSelectedNoteLocation()
{
	int numPages = getPageCount();
	for (int i = 0; i < numPages; i++)
	{
		DocPageView cv = (DocPageView) getOrCreateChild(i);
		if (cv.hasNoteAnnotationSelected())
		{
			Point p = cv.getSelectedNoteLocation();
			if (p != null)
			{
				//  offset to 0,0
				p.offset(cv.getLeft(), cv.getTop());

				//  offset to position in the scrolling view (this)
				p.offset(-getScrollX(), -getScrollY());

				return p;
			}
		}
	}

	return null;
}
 
Example 3
Source File: LithoHierarchyPlugin.java    From screenshot-tests-for-android with Apache License 2.0 6 votes vote down vote up
@Override
public void putHierarchy(LayoutHierarchyDumper dumper, JSONObject root, Object obj, Point offset)
    throws JSONException {
  if (!accept(obj)) {
    return;
  }

  if (obj instanceof LithoView) {
    LithoView lithoView = (LithoView) obj;
    DebugComponent debugComponent = DebugComponent.getRootInstance(lithoView);
    if (debugComponent == null) {
      return;
    }
    final int offsetLeft = LayoutHierarchyDumper.getViewLeft(lithoView);
    final int offsetTop = LayoutHierarchyDumper.getViewTop(lithoView);
    offset.offset(offsetLeft, offsetTop);
    dumpHierarchy(dumper, root, debugComponent, offset);
    offset.offset(-offsetLeft, -offsetTop);
  } else {
    dumpHierarchy(dumper, root, (DebugComponent) obj, offset);
  }
}
 
Example 4
Source File: BaseViewHierarchyPlugin.java    From screenshot-tests-for-android with Apache License 2.0 6 votes vote down vote up
@Override
public void putHierarchy(LayoutHierarchyDumper dumper, JSONObject root, Object view, Point offset)
    throws JSONException {
  if (!(view instanceof ViewGroup)) {
    return;
  }

  ViewGroup group = (ViewGroup) view;
  final int offsetLeft = LayoutHierarchyDumper.getViewLeft(group);
  final int offsetTop = LayoutHierarchyDumper.getViewTop(group);
  offset.offset(offsetLeft, offsetTop);

  JSONArray children = new JSONArray();
  for (int i = 0, size = group.getChildCount(); i < size; ++i) {
    View child = group.getChildAt(i);
    children.put(dumper.dumpHierarchy(child, offset));
  }

  root.put(KEY_CHILDREN, children);
  offset.offset(-offsetLeft, -offsetTop);
}
 
Example 5
Source File: ZoomPanLayout.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * Scrolls and centers the ZoomPanLayout to the x and y values specified by {@param point} Point using scrolling animation
 * @param point (Point) Point instance containing the destination x and y values
 */
public void slideToAndCenter( Point point ) { // TODO:
	int x = (int) -( getWidth() * 0.5 );
	int y = (int) -( getHeight() * 0.5 );
	point.offset( x, y );
	slideToPoint( point );
}
 
Example 6
Source File: DocViewBase.java    From Mupdf with Apache License 2.0 5 votes vote down vote up
private Point viewToScreen(Point p)
{
	Point newPoint = new Point(p);

	Rect r = new Rect();
	this.getGlobalVisibleRect(r);

	newPoint.offset(r.left, r.top);

	return newPoint;
}
 
Example 7
Source File: DocView.java    From Mupdf with Apache License 2.0 5 votes vote down vote up
private Point viewToScreen(Point p)
{
	Point newPoint = new Point(p);

	Rect r = new Rect();
	this.getGlobalVisibleRect(r);

	newPoint.offset(r.left, r.top);

	return newPoint;
}
 
Example 8
Source File: Marker.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Populates this tooltip with all item info:
 * <ul>title and description in any case, </ul>
 * <ul>image and sub-description if any.</ul>
 * and centers the map view on the item if panIntoView is true. <br>
 */
public void showBubble(InfoWindow tooltip, MapView aMapView, boolean panIntoView) {
    //offset the tooltip to be top-centered on the marker:
    Point markerH = getAnchor();
    Point tooltipH = getAnchor(HotspotPlace.TOP_CENTER);
    markerH.offset(-tooltipH.x, tooltipH.y);
    tooltip.open(this, this.getPoint(), markerH.x, markerH.y);
    if (panIntoView) {
        aMapView.getController().animateTo(getPoint());
    }

    bubbleShowing = true;
    tooltip.setBoundMarker(this);
}
 
Example 9
Source File: Projection.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Converts from map pixels to a Point value. Optionally reuses an existing Point.
 */
public Point fromMapPixels(final int x, final int y, final Point reuse) {
    final Point out = GeometryMath.reusable(reuse);
    out.set(x - viewWidth2, y - viewHeight2);
    out.offset(centerX, centerY);
    return out;
}
 
Example 10
Source File: ZoomPanLayout.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void performDrag() {
	Point delta = new Point();
	if ( secondFingerIsDown && !firstFingerIsDown ) {
		delta.set( lastSecondFinger.x, lastSecondFinger.y );
		delta.offset( -secondFinger.x, -secondFinger.y );
	} else {
		delta.set( lastFirstFinger.x, lastFirstFinger.y );
		delta.offset( -firstFinger.x, -firstFinger.y );
	}
	scrollPosition.offset( delta.x, delta.y );
	scrollToPoint( scrollPosition );
}
 
Example 11
Source File: ZoomPanLayout.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * Scrolls and centers the ZoomPanLayout to the x and y values specified by {@param point} Point
 * @param point (Point) Point instance containing the destination x and y values
 */
public void scrollToAndCenter( Point point ) { // TODO:
	int x = (int) -( getWidth() * 0.5 );
	int y = (int) -( getHeight() * 0.5 );
	point.offset( x, y );
	scrollToPoint( point );
}
 
Example 12
Source File: CustomMarkerActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * marker点击时跳动一下
 */
public void jumpPoint(final Marker marker) {
	final Handler handler = new Handler();
	final long start = SystemClock.uptimeMillis();
	Projection proj = aMap.getProjection();
	Point startPoint = proj.toScreenLocation(Constants.XIAN);
	startPoint.offset(0, -100);
	final LatLng startLatLng = proj.fromScreenLocation(startPoint);
	final long duration = 1500;

	final Interpolator interpolator = new BounceInterpolator();
	handler.post(new Runnable() {
		@Override
		public void run() {
			long elapsed = SystemClock.uptimeMillis() - start;
			float t = interpolator.getInterpolation((float) elapsed
					/ duration);
			double lng = t * Constants.XIAN.longitude + (1 - t)
					* startLatLng.longitude;
			double lat = t * Constants.XIAN.latitude + (1 - t)
					* startLatLng.latitude;
			marker.setPosition(new LatLng(lat, lng));
			if (t < 1.0) {
				handler.postDelayed(this, 16);
			}
		}
	});
}
 
Example 13
Source File: MarkerClickActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * marker点击时跳动一下
 */
public void jumpPoint(final Marker marker) {
	final Handler handler = new Handler();
       final long start = SystemClock.uptimeMillis();
       Projection proj = aMap.getProjection();
       final LatLng markerLatlng = marker.getPosition();
       Point markerPoint = proj.toScreenLocation(markerLatlng);
       markerPoint.offset(0, -100);
       final LatLng startLatLng = proj.fromScreenLocation(markerPoint);
       final long duration = 1500;

       final Interpolator interpolator = new BounceInterpolator();
       handler.post(new Runnable() {
           @Override
           public void run() {
               long elapsed = SystemClock.uptimeMillis() - start;
               float t = interpolator.getInterpolation((float) elapsed
                       / duration);
               double lng = t * markerLatlng.longitude + (1 - t)
                       * startLatLng.longitude;
               double lat = t * markerLatlng.latitude + (1 - t)
                       * startLatLng.latitude;
               marker.setPosition(new LatLng(lat, lng));
               if (t < 1.0) {
                   handler.postDelayed(this, 16);
               }
           }
       });
}
 
Example 14
Source File: WindowContainer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void getRelativePosition(Point outPos) {
    final Rect bounds = getBounds();
    outPos.set(bounds.left, bounds.top);
    final WindowContainer parent = getParent();
    if (parent != null) {
        final Rect parentBounds = parent.getBounds();
        outPos.offset(-parentBounds.left, -parentBounds.top);
    }
}
 
Example 15
Source File: PointerGesture.java    From za-Farmer with MIT License 4 votes vote down vote up
@Override
public Point interpolate(float fraction) {
    Point ret = new Point(start);
    ret.offset((int)(fraction * (end.x - start.x)), (int)(fraction * (end.y - start.y)));
    return ret;
}
 
Example 16
Source File: PointerGesture.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Point interpolate(float fraction) {
    Point ret = new Point(start);
    ret.offset((int)(fraction * (end.x - start.x)), (int)(fraction * (end.y - start.y)));
    return ret;
}
 
Example 17
Source File: ImageInfo.java    From mil-sym-android with Apache License 2.0 4 votes vote down vote up
public ImageInfo getSquareImageInfo()
{
	ImageInfo ii = null;
       int iwidth, iheight, x, y;
       int width = this._imageBounds.width();
       int height = this._imageBounds.height();
       
       if(this._imageBounds.width() > this._imageBounds.height())
       {
           iwidth = this._imageBounds.width();
           iheight = this._imageBounds.width();
           x=0;
           y=(iheight - height)/2;
       }
       else if(this._imageBounds.width() < this._imageBounds.height())
       {
           iwidth = this._imageBounds.height();
           iheight = this._imageBounds.height();
           x = (iwidth - width)/2;
           y = 0;
       }
       else
       {
           iwidth = this._imageBounds.width();
           iheight = this._imageBounds.height();
           x=0;
           y=0;
       }

     //Draw glyphs to bitmap
	Bitmap bmp = Bitmap.createBitmap(iwidth, iheight, Config.ARGB_8888);
	Canvas ctx = new Canvas(bmp);

       
       ctx.drawBitmap(_image,x,y,null);
       
       //create new ImageInfo
       Point center = new Point(_centerPoint);
       center.offset(x,y);
       Rect symbolBounds = new Rect(_symbolBounds);
       symbolBounds.offset(x,y);

       ii = new ImageInfo(bmp,center, symbolBounds);
       
       
       return ii;
}
 
Example 18
Source File: ShareLocationActivity.java    From imsdk-android with MIT License 4 votes vote down vote up
private synchronized void addOverLay(final String id, final LatLng point, float rotate) {
        if (overlayMap.get(id) != null) {
            overlayMap.get(id).remove();
        }
        if (headMap.get(id) != null) {
            headMap.get(id).remove();
        }

        //添加头像Overlay
        LatLng latLng = new LatLng(point.latitude,point.longitude);
        if (projection != null) {
            Point screenPoint = projection.toScreenLocation(point);
            screenPoint.offset(0, -30);
            latLng = projection.fromScreenLocation(screenPoint);
        }
        Bitmap bmp = getBitmapWithId(id);
        if (bmp != null) {
            OverlayOptions head = new MarkerOptions().draggable(false)
                    .position(latLng)
                    .icon(BitmapDescriptorFactory.fromBitmap(bmp));
            Overlay headOverlay = baiduMap.addOverlay(head);
            Bundle extra = new Bundle();
            extra.putDouble(EXTRA_LATITUDE, point.latitude);
            extra.putDouble(EXTRA_LONGITUDE, point.longitude);
            extra.putParcelable(EXTRA_BITMAP, bmp);
            headOverlay.setExtraInfo(extra);
            headMap.put(id, headOverlay);
        }
        //添加图标Overlay
        OverlayOptions options = new MarkerOptions().draggable(false)
                .position(point)
                .rotate(rotate)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.atom_ui_loc));
        Overlay overlay = baiduMap.addOverlay(options);
        overlayMap.put(id, overlay);
//
//        ProfileUtils.loadNickName(id, false, new ProfileUtils.LoadNickNameCallback() {
//            @Override
//            public void finish(String name) {
//                OverlayOptions head = new TextOptions()
//                        .position(point)
//                        .text(name)
//                        .fontSize(50);
//                Overlay headOverlay = baiduMap.addOverlay(head);
//                headMap.put(id, headOverlay);
//            }
//        });
    }
 
Example 19
Source File: DocView.java    From Mupdf with Apache License 2.0 4 votes vote down vote up
@Override
public void onDrag(DragHandle handle)
{
	if (handle == mSelectionHandleTopLeft)
	{
		Point p1 = mSelectionHandleTopLeft.getPosition();
		p1.offset(selectionHandlePadPx + selectionHandleSizePx / 2, selectionHandlePadPx + selectionHandleSizePx / 2);
		p1 = viewToScreen(p1);
		DocPageView pageView1 = findPageViewContainingPoint(p1.x, p1.y, false);
		if (pageView1 != null)
		{
			selectionStartPage = pageView1;
			p1 = pageView1.screenToPage(p1);
			selectionStartLoc.set(p1.x, p1.y);
			onChangeSelection();
		}
	}

	if (handle == mSelectionHandleBottomRight)
	{
		Point p2 = mSelectionHandleBottomRight.getPosition();
		p2.offset(selectionHandlePadPx + selectionHandleSizePx / 2, selectionHandlePadPx + selectionHandleSizePx / 2);
		p2 = viewToScreen(p2);
		DocPageView pageView2 = findPageViewContainingPoint(p2.x, p2.y, false);
		if (pageView2 != null)
		{
			selectionEndPage = pageView2;
			p2 = pageView2.screenToPage(p2);
			selectionEndLoc.set(p2.x, p2.y);
			onChangeSelection();
		}
	}

	//  TODO: for now, we're dealing with one page at a time
	int numPages = getPageCount();
	for (int i = 0; i < numPages; i++)
	{
		DocPageView cv = (DocPageView) getOrCreateChild(i);
		if (cv.isReallyVisible() && cv == selectionStartPage && cv == selectionEndPage)
		{
			cv.setSelection(selectionStartLoc, selectionEndLoc);
		}
		else
		{
			cv.removeSelection();
		}
		cv.invalidate();
	}
}