List of usage examples for android.graphics PointF PointF
public PointF(float x, float y)
From source file:com.funzio.pure2D.atlas.JsonAtlas.java
protected AtlasFrame parseFrame(final int index, final JSONObject frameJson, final float scale) throws JSONException { final JSONObject frame = frameJson.getJSONObject("frame"); final boolean trimmed = frameJson.getBoolean("trimmed"); final boolean rotated = frameJson.getBoolean("rotated"); final int left = frame.getInt("x"); final int top = frame.getInt("y"); final int w = frame.getInt("w"); final int h = frame.getInt("h"); final int right = left + (rotated ? h : w); final int bottom = top + (rotated ? w : h); final AtlasFrame atlasFrame = new AtlasFrame(this, index, frameJson.getString("filename"), new RectF(left * scale, top * scale, right * scale, bottom * scale)); if (trimmed) { final JSONObject spriteSourceSize = frameJson.getJSONObject("spriteSourceSize"); final int offsetX = spriteSourceSize.getInt("x"); int offsetY = spriteSourceSize.getInt("y"); // check axis if (mAxisSystem == Scene.AXIS_BOTTOM_LEFT) { final JSONObject sourceSize = frameJson.getJSONObject("sourceSize"); // flip for axis offsetY = sourceSize.getInt("h") - (spriteSourceSize.getInt("y") + spriteSourceSize.getInt("h")); }/*from w w w . j a va2s . c o m*/ if (offsetX != 0 || offsetY != 0) { atlasFrame.mOffset = new PointF(offsetX * scale, offsetY * scale); } } if (rotated) { atlasFrame.rotateCCW(); } return atlasFrame; }
From source file:org.thoughtcrime.securesms.scribbles.widget.MotionView.java
private void updateOnLongPress(MotionEvent e) { // if layer is currently selected and point inside layer - move it to front if (selectedEntity != null) { PointF p = new PointF(e.getX(), e.getY()); if (selectedEntity.pointInLayerRect(p)) { bringLayerToFront(selectedEntity); }/* w w w . j a v a2s. c o m*/ } }
From source file:eu.veldsoft.adsbobball.ActivityStateEnum.java
@Override public boolean onTouch(View v, MotionEvent event) { if (gameView == null || gameManager == null) return true; PointF evPoint = gameView.transformPix2Coords(new PointF(event.getX(), event.getY())); if (event.getAction() == MotionEvent.ACTION_DOWN) { initialTouchPoint = evPoint;/* ww w .j ava2 s .co m*/ } else if (event.getAction() == MotionEvent.ACTION_UP) { initialTouchPoint = null; } else if (event.getAction() == MotionEvent.ACTION_MOVE) { if (initialTouchPoint != null && gameManager.getGrid().validPoint(initialTouchPoint.x, initialTouchPoint.y)) { TouchDirection dir = null; if (evPoint.x > (initialTouchPoint.x + TOUCH_DETECT_SQUARES) || evPoint.x < initialTouchPoint.x - TOUCH_DETECT_SQUARES) dir = TouchDirection.HORIZONTAL; else if (evPoint.y > (initialTouchPoint.y + TOUCH_DETECT_SQUARES) || evPoint.y < initialTouchPoint.y - TOUCH_DETECT_SQUARES) dir = TouchDirection.VERTICAL; if (dir != null) { gameManager.addEvent( new GameEventStartBar(gameManager.getGameTime(), initialTouchPoint, dir, playerId)); initialTouchPoint = null; } } } return true; }
From source file:com.devbrackets.android.recyclerext.decoration.ReorderDecoration.java
/** * Manually starts the reorder process for the specified view. This should not be used if the {@link #setDragHandleId(int)} is * set and should control the reordering. * * @param view The View to start reordering * @param startMotionEvent The MotionEvent that starts the reorder */// w w w . j av a2 s .c o m public void startReorder(View view, @Nullable MotionEvent startMotionEvent) { if (dragState == DragState.DRAGGING) { return; } if (startMotionEvent != null) { fingerOffset = new PointF(startMotionEvent.getRawX(), startMotionEvent.getRawY()); int[] rawViewLoc = new int[2]; view.getLocationOnScreen(rawViewLoc); fingerOffset.x = rawViewLoc[0] - fingerOffset.x; fingerOffset.y = rawViewLoc[1] - fingerOffset.y; } dragState = DragState.DRAGGING; dragItem = createDragBitmap(view); selectedDragItemPosition = recyclerView.getChildAdapterPosition(view); }
From source file:com.zenithed.core.widget.scaledimageview.ScaledImageView.java
@Override public void computeScroll() { super.computeScroll(); if (isEnabled() && mContentWidth > 0 && mContentHeight > 0) { // handles scroll changes. if (mScroller.computeScrollOffset()) { final int currX = mScroller.getCurrX(); final int currY = mScroller.getCurrY(); final int maxOffsetX = (int) (mContentWidth * mScale) - getWidth(); final int maxOffsetY = (int) (mContentHeight * mScale) - getHeight(); if (mScroller.getFinalX() > maxOffsetX) { mScroller.setFinalX(maxOffsetX); }//w w w .ja va 2s . c om if (mScroller.getFinalY() > maxOffsetY) { mScroller.setFinalY(maxOffsetY); } mTranslate.x = currX * -1; mTranslate.y = currY * -1; fitToBounds(); refreshRequiredTiles(false); ViewCompat.postInvalidateOnAnimation(ScaledImageView.this); } // handles zoom changes. if (mZoomer.computeZoom()) { mScale = Math.min(mMaxScale, mZoomer.getCurrZoom()); zoomAndFocusOnPoint(mZoomerInitialDestinationPoint, new PointF(getWidth() / 2, getHeight() / 2), mZoomerInitialScale); } } }
From source file:com.rstar.mobile.thermocouple.functions.Fn.java
public PointF[] getSeebeckCurveControlPoints() { double[] controlTemperature = getControlTemperaturesFor_dE(); if (controlTemperature == null || controlTemperature.length == 0) return null; try {/* w w w .j a v a 2s . co m*/ int count = controlTemperature.length; double[] dEdT = new double[count]; for (int index = 0; index < count; index++) { dEdT[index] = compute_dEdT(controlTemperature[index]); } PointF[] pointF = new PointF[count]; for (int index = 0; index < count; index++) { pointF[index] = new PointF((float) controlTemperature[index], (float) dEdT[index]); } return pointF; } catch (Exception e) { return null; } }
From source file:com.heneryh.aquanotes.ui.controllers.GraphsFragment.java
public boolean onTouch(View arg0, MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: // Start gesture firstFinger = new PointF(event.getX(), event.getY()); mode = ONE_FINGER_DRAG;/*from w ww.j a v a 2s. c o m*/ break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: //When the gesture ends, a thread is created to give inertia to the scrolling and zoom final Timer t = new Timer(); t.schedule(new TimerTask() { @Override public void run() { while (Math.abs(lastScrolling) > 1f || Math.abs(lastZooming - 1) < 1.01) { lastScrolling *= .8; //speed of scrolling damping scroll(lastScrolling); lastZooming += (1 - lastZooming) * .2; //speed of zooming damping zoom(lastZooming); checkBoundaries(); try { mySimpleXYPlot.postRedraw(); } catch (final InterruptedException e) { e.printStackTrace(); } // the thread lives until the scrolling and zooming are imperceptible } } }, 0); case MotionEvent.ACTION_POINTER_DOWN: // second finger distBetweenFingers = spacing(event); // the distance check is done to avoid false alarms if (distBetweenFingers > 5f) mode = TWO_FINGERS_DRAG; break; case MotionEvent.ACTION_MOVE: if (mode == ONE_FINGER_DRAG) { final PointF oldFirstFinger = firstFinger; firstFinger = new PointF(event.getX(), event.getY()); lastScrolling = oldFirstFinger.x - firstFinger.x; scroll(lastScrolling); lastZooming = (firstFinger.y - oldFirstFinger.y) / mySimpleXYPlot.getHeight(); if (lastZooming < 0) lastZooming = 1 / (1 - lastZooming); else lastZooming += 1; zoom(lastZooming); checkBoundaries(); mySimpleXYPlot.redraw(); } else if (mode == TWO_FINGERS_DRAG) { final float oldDist = distBetweenFingers; distBetweenFingers = spacing(event); lastZooming = oldDist / distBetweenFingers; zoom(lastZooming); checkBoundaries(); mySimpleXYPlot.redraw(); } break; } return true; }
From source file:eu.hydrologis.geopaparazzi.chart.ProfileChartActivity.java
private void updateView() { // Remove all current series from each plot for (XYSeries setElement : xyPlotSpeed.getSeriesSet()) { xyPlotSpeed.removeSeries(setElement); }/*from w ww. ja va 2 s . c om*/ for (XYSeries setElement : xyPlotElev.getSeriesSet()) { xyPlotElev.removeSeries(setElement); } // Add series to each plot as needed. xyPlotSpeed.addSeries(seriesSpeed, seriesSpeedFormat); xyPlotElev.addSeries(seriesElev, seriesElevFormat); // Finalise each Plot based on whether they have any series or not. if (!xyPlotElev.getSeriesSet().isEmpty()) { xyPlotElev.setVisibility(XYPlot.VISIBLE); xyPlotElev.redraw(); } else { xyPlotElev.setVisibility(XYPlot.INVISIBLE); } if (!xyPlotSpeed.getSeriesSet().isEmpty()) { xyPlotSpeed.setVisibility(XYPlot.VISIBLE); xyPlotSpeed.redraw(); } else { xyPlotSpeed.setVisibility(XYPlot.INVISIBLE); } xyPlotSpeed.calculateMinMaxVals(); minXYSpeed = new PointF(xyPlotSpeed.getCalculatedMinX().floatValue(), xyPlotSpeed.getCalculatedMinY().floatValue()); maxXYSpeed = new PointF(xyPlotSpeed.getCalculatedMaxX().floatValue(), xyPlotSpeed.getCalculatedMaxY().floatValue()); xyPlotElev.calculateMinMaxVals(); minXYElevation = new PointF(xyPlotElev.getCalculatedMinX().floatValue(), xyPlotElev.getCalculatedMinY().floatValue()); maxXYElevation = new PointF(xyPlotElev.getCalculatedMaxX().floatValue(), xyPlotElev.getCalculatedMaxY().floatValue()); infoTextView.setText("Active elevation diff: " + elevDifference + "m"); }
From source file:com.jrummyapps.android.widget.AnimatedSvgView.java
/** * Set the viewport width and height of the SVG. This can be found in the viewBox in the SVG. This is not the size * of the view./*from w ww.j a v a2s . c o m*/ * * @param viewportWidth * the width * @param viewportHeight * the height */ public void setViewportSize(float viewportWidth, float viewportHeight) { mViewportWidth = viewportWidth; mViewportHeight = viewportHeight; aspectRatioWidth = viewportWidth; aspectRatioHeight = viewportHeight; mViewport = new PointF(mViewportWidth, mViewportHeight); requestLayout(); }
From source file:android.support.v7.extensions.BaseLayoutManager.java
public PointF computeScrollVectorForPosition(int targetPosition) { if (getChildCount() == 0) { return null; }/*from www . j a v a 2 s. c o m*/ final int firstChildPos = getPosition(getChildAt(0)); final int direction = targetPosition < firstChildPos != mShouldReverseLayout ? -1 : 1; if (mOrientation == HORIZONTAL) { return new PointF(direction, 0); } else { return new PointF(0, direction); } }