List of usage examples for android.graphics PointF PointF
public PointF(float x, float y)
From source file:xyz.zpayh.hdimage.HDImageView.java
@Override protected void onRestoreInstanceState(Parcelable state) { if (!(state instanceof SavedState)) { super.onRestoreInstanceState(state); return;/*from w ww .ja va2 s . com*/ } SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState()); if (ss.mUri == null) { return; } ImageViewOptions imageViewOptions = new ImageViewOptions(ss.mScale, new PointF(ss.mCenterX, ss.mCenterY)); setImageSource(ImageSourceBuilder.newBuilder().setUri(ss.mUri).setOrientation(ss.mOrientation) .setImageViewOptions(imageViewOptions).build()); Log.d(TAG, "onRestoreInstanceState"); }
From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java
private Paint createShadowPaint(int left, int top, int width, int height, int shadowStrokeWidth) { List<PointF> points = getPoints(width, height); PointF fromPoint = new PointF(left + points.get(0).x, top + points.get(0).y); PointF toPoint = new PointF(left + points.get(1).x, top + points.get(1).y); PointF midpoint = new PointF((fromPoint.x + toPoint.x) * 0.5f, (fromPoint.y + toPoint.y) * 0.5f); PointF vector = new PointF(fromPoint.x - midpoint.x, fromPoint.y - midpoint.y); PointF rotatedVector = new PointF(vector.y, -vector.x); float vectorLength = (float) Math.sqrt((vector.x * vector.x) + (vector.y * vector.y)); PointF shadowVector = new PointF(rotatedVector.x * (shadowStrokeWidth * 0.5f) / vectorLength, rotatedVector.y * (shadowStrokeWidth * 0.5f) / vectorLength); LinearGradient gradient = new LinearGradient(midpoint.x, midpoint.y, midpoint.x + shadowVector.x, midpoint.y + shadowVector.y, Color.argb(100, 0, 0, 0), Color.argb(0, 0, 0, 0), TileMode.MIRROR); Paint paint = new Paint(); paint.setStyle(Style.STROKE); paint.setShader(gradient);//from ww w.j a va2 s .c om paint.setStrokeWidth(shadowStrokeWidth); paint.setStrokeCap(Cap.SQUARE); return paint; }
From source file:org.bobstuff.bobball.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;/*from w w w .j a v a 2 s. com*/ } 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)) { Direction dir = null; if (evPoint.x > (initialTouchPoint.x + TOUCH_DETECT_SQUARES)) dir = Direction.RIGHT; else if (evPoint.x < initialTouchPoint.x - TOUCH_DETECT_SQUARES) dir = Direction.LEFT; else if (evPoint.y > (initialTouchPoint.y + TOUCH_DETECT_SQUARES)) dir = Direction.DOWN; else if (evPoint.y < initialTouchPoint.y - TOUCH_DETECT_SQUARES) dir = Direction.UP; if (dir != null && !gameManager.hasWonLevel()) { gameManager.addEvent( new GameEventStartBar(gameManager.getGameTime(), initialTouchPoint, dir, playerId)); initialTouchPoint = null; } } } return true; }
From source file:android.support.v7.widget.LinearLayoutManagerEx.java
@Override public void smoothScrollToPosition(RecyclerViewEx recyclerView, RecyclerViewEx.State state, int position) { final LinearSmoothScrollerEx scroller = new LinearSmoothScrollerEx(recyclerView.getContext()) { @Override// www.jav a2 s .com public PointF computeScrollVectorForPosition(int targetPosition) { if (getChildCount() == 0) { return null; } final int direction = targetPosition < getFirstVisiblePosition() ? -1 : 1; if (DEBUG) { LogEx.d(TAG, "direction:" + direction); } if (mOrientation != HORIZONTAL) { return new PointF(0, direction); } else { return new PointF(direction, 0); } } @Override protected int getVerticalSnapPreference() { return LinearSmoothScroller.SNAP_TO_START; } @Override protected int getHorizontalSnapPreference() { return LinearSmoothScroller.SNAP_TO_START; } @Override protected int calculateTimeForScrolling(int dx) { int originVal = super.calculateTimeForScrolling(dx); return Math.max(originVal, 100); } @Override protected int calculateTimeForDeceleration(int dx) { // we want to cover same area with the linear interpolator for the first 10% of the // interpolation. After that, deceleration will take control. // area under curve (1-(1-x)^2) can be calculated as (1 - x/3) * x * x // which gives 0.100028 when x = .3356 // this is why we divide linear scrolling time with .3356 return (int) Math.ceil(calculateTimeForScrolling(dx) / .3356); } }; scroller.setTargetPosition(position); startSmoothScroll(scroller); }
From source file:com.jest.phone.PhoneActivity.java
@Override 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;/*w w w . j ava 2 s .c o m*/ stopThread = true; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; 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) { PointF oldFirstFinger = firstFinger; firstFinger = new PointF(event.getX(), event.getY()); scroll(oldFirstFinger.x - firstFinger.x); sensorHistoryPlot.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED); sensorHistoryPlot.redraw(); } else if (mode == TWO_FINGERS_DRAG) { float oldDist = distBetweenFingers; distBetweenFingers = spacing(event); zoom(oldDist / distBetweenFingers); sensorHistoryPlot.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED); sensorHistoryPlot.redraw(); } break; } return true; }
From source file:project.pamela.slambench.fragments.RankPlot.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Replace LinearLayout by the type of the root element of the layout you're trying to load LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.rank_plot, container, false); TextView oclLegend = (TextView) llLayout.findViewById(R.id.oclLegend); TextView cppLegend = (TextView) llLayout.findViewById(R.id.cppLegend); TextView otherLegend = (TextView) llLayout.findViewById(R.id.otherLegend); TextView yoursLegend = (TextView) llLayout.findViewById(R.id.yoursLegend); oclLegend.setBackgroundColor(getResources().getColor(R.color.oclLegendColor)); cppLegend.setBackgroundColor(getResources().getColor(R.color.cppLegendColor)); otherLegend.setBackgroundColor(getResources().getColor(R.color.othersLegendColor)); yoursLegend.setBackgroundColor(getResources().getColor(R.color.yoursLegendColor)); /*//from w w w . jav a2s . c om if (SLAMBenchApplication.getBenchmark() == null) { // Need to run the configuration download .... try { InputStream inputStream = this.getActivity().getAssets().open("demo.xml"); SLAMBenchXmlParser parser = new SLAMBenchXmlParser(); SLAMConfiguration entries = parser.parse(inputStream); inputStream.close(); SLAMBenchApplication.setBenchmark(new SLAMBench(entries)); if (entries == null ) { Log.e(SLAMBenchApplication.LOG_TAG, getString(R.string.log_configuration_error)); } } catch (IOException e) { Log.e(SLAMBenchApplication.LOG_TAG, getString(R.string.log_configuration_error), e); } catch (XmlPullParserException e) { Log.e(SLAMBenchApplication.LOG_TAG, getString(R.string.log_configuration_error), e); } } */ if (SLAMBenchApplication.getBenchmark() == null) { return llLayout; } List<SLAMRank> ranks = SLAMBenchApplication.getBenchmark().getDevicesRank(); values = new Double[ranks.size() + 1]; devices = new String[ranks.size() + 1]; versions = new String[ranks.size() + 1]; for (int i = 0; i < ranks.size(); i++) { SLAMRank r = ranks.get(i); values[i] = r.get_result(); devices[i] = r.get_device(); versions[i] = (r.get_test() == null) ? "" : r.get_test().name; } double best = SLAMBenchApplication.getBenchmark().getBestSpeed(); values[values.length - 1] = (best <= 0) ? 0 : 1.0 / best; devices[values.length - 1] = YOUR_DEVICE; if (SLAMBenchApplication.getBenchmark() != null && SLAMBenchApplication.getBenchmark().getBestResult() != null && SLAMBenchApplication.getBenchmark().getBestResult().test != null) { versions[values.length - 1] = SLAMBenchApplication.getBenchmark().getBestResult().test.name; } else { versions[values.length - 1] = ""; } for (int n = 0; n < values.length; n++) { for (int m = 0; m < values.length - 1 - n; m++) { if ((values[m].compareTo(values[m + 1])) <= 0) { String swapString = devices[m]; devices[m] = devices[m + 1]; devices[m + 1] = swapString; swapString = versions[m]; versions[m] = versions[m + 1]; versions[m + 1] = swapString; Double swapInt = values[m]; values[m] = values[m + 1]; values[m + 1] = swapInt; } } } int start = Math.max(0, values.length - RANK_SIZE - 1); int end = values.length - 1; Log.d(SLAMBenchApplication.LOG_TAG, "Default ArrayOfRange(" + Integer.valueOf(start) + "," + Integer.valueOf(end) + ")"); for (int i = 0; i < values.length; i++) { if (devices[i].equals(YOUR_DEVICE)) { start = Math.max(0, i - (RANK_SIZE / 2)); end = Math.min(values.length - 1, start + RANK_SIZE); if (end - start < RANK_SIZE) { start = Math.max(0, end - RANK_SIZE); } break; } } Log.d(SLAMBenchApplication.LOG_TAG, "ArrayOfRange(" + Integer.valueOf(start) + "," + Integer.valueOf(end) + ")"); if (best > 0) { values = Arrays.copyOfRange(values, start, end); devices = Arrays.copyOfRange(devices, start, end); versions = Arrays.copyOfRange(versions, start, end); } else { values = Arrays.copyOf(values, values.length - 1); devices = Arrays.copyOf(devices, devices.length - 1); versions = Arrays.copyOf(versions, versions.length - 1); } // initialize our XYPlot reference: plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot); // colors plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE); plot.getBorderPaint().setColor(Color.WHITE); plot.getBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeLabelPaint().setTextSize(20); plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainGridLinePaint().setColor(Color.TRANSPARENT); //plot.getGraphWidget().getRangeGridLinePaint().setColor(Color.TRANSPARENT); formatter1 = new MyBarFormatter(getResources().getColor(R.color.othersLegendColor), Color.WHITE); openclFormatter = new MyBarFormatter(getResources().getColor(R.color.oclLegendColor), Color.WHITE); cppFormatter = new MyBarFormatter(getResources().getColor(R.color.cppLegendColor), Color.WHITE); currentFormatter = new MyBarFormatter(getResources().getColor(R.color.yoursLegendColor), Color.WHITE); plot.setTicksPerRangeLabel(1); //plot.getLayoutManager().remove(plot.getLegendWidget()); plot.getLayoutManager().remove(plot.getTitleWidget()); plot.getLayoutManager().remove(plot.getDomainLabelWidget()); plot.getLayoutManager().remove(plot.getRangeLabelWidget()); plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 0.5); plot.getGraphWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_LEFT, 0, YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM); plot.getGraphWidget().setSize(new SizeMetrics(0, SizeLayoutType.FILL, 0, SizeLayoutType.FILL)); plot.setDomainValueFormat(new NumberFormat() { @Override public StringBuffer format(double value, StringBuffer buffer, FieldPosition field) { int index = (int) (value); //if ((index) == (value)) { // return new StringBuffer(devices[index]); //} return new StringBuffer(""); } @Override public StringBuffer format(long value, StringBuffer buffer, FieldPosition field) { throw new UnsupportedOperationException("Not yet implemented."); } @Override public Number parse(String string, ParsePosition position) { throw new UnsupportedOperationException("Not yet implemented."); } }); // Setup our Series with the selected number of elements series1 = new SimpleXYSeries(Arrays.asList(values), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "devices"); // add a new series' to the xyplot: plot.addSeries(series1, formatter1); // Setup the BarRenderer with our selected options MyBarRenderer renderer = ((MyBarRenderer) plot.getRenderer(MyBarRenderer.class)); renderer.setBarRenderStyle(BarRenderer.BarRenderStyle.OVERLAID); renderer.setBarWidthStyle(BarRenderer.BarWidthStyle.VARIABLE_WIDTH); renderer.setBarWidth(BAR_GAP); renderer.setBarGap(BAR_GAP); plot.getGraphWidget().setDomainLabelOrientation(-90); plot.getGraphWidget().setGridPaddingRight(0); plot.getGraphWidget().setGridPaddingTop(0); plot.getGraphWidget().setGridPaddingLeft(0); plot.getGraphWidget().setGridPaddingBottom(0); plot.calculateMinMaxVals(); PointF minXY = new PointF(plot.getCalculatedMinX().floatValue(), plot.getCalculatedMinY().floatValue()); PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue()); plot.setDomainBoundaries(minXY.x - 0.5, maxXY.x + 0.5, BoundaryMode.FIXED); plot.setRangeBoundaries(0, (int) (maxXY.y / 10) * 10f + 10f, BoundaryMode.FIXED); plot.redraw(); return llLayout; }
From source file:ac.robinson.paperchains.PaperChainsActivity.java
private void addAudioRects() { for (AudioAreaHolder holder : mAudioAreas) { // convert grid-based coordinates to image-based coordinates, accounting for image rotation/inversion by // making sure to use the min/max values of each coordinate Rect rect = holder.serverRect;/*from ww w . ja va 2 s . co m*/ PointF leftTop = QRImageParser.getImagePosition(mImageParameters, new PointF(rect.left, rect.top)); PointF rightBottom = QRImageParser.getImagePosition(mImageParameters, new PointF(rect.right, rect.bottom)); RectF displayRect = new RectF(Math.min(leftTop.x, rightBottom.x), Math.min(leftTop.y, rightBottom.y), Math.max(rightBottom.x, leftTop.x), Math.max(leftTop.y, rightBottom.y)); Rect imageRect = new Rect(); displayRect.roundOut(imageRect); holder.setImageRect(imageRect); mImageView.addAudioAreaRect(imageRect); } }
From source file:com.chauthai.overscroll.BouncyAdapter.java
/** * Get the deceleration vector for {@link DecelerateSmoothScroller} *///from w w w. ja v a2 s.c om private PointF getDecelVector(int headerVisible) { if (headerVisible > 0) { if (directionVertical()) return new PointF(0, (!mLayoutManager.getReverseLayout() ? -1 : 1)); else return new PointF((!mLayoutManager.getReverseLayout() ? -1 : 1), 0); } if (directionVertical()) return new PointF(0, (!mLayoutManager.getReverseLayout() ? 1 : -1)); return new PointF((!mLayoutManager.getReverseLayout() ? 1 : -1), 0); }
From source file:xiaofan.llongimageview.view.SubsamplingScaleImageView.java
private void setGestureDetector(final Context context) { this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override/*from w ww .j a v a 2 s . c o m*/ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50) && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) { PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f), vTranslate.y + (velocityY * 0.25f)); float sCenterXEnd = ((getWidth() / 2) - vTranslateEnd.x) / scale; float sCenterYEnd = ((getHeight() / 2) - vTranslateEnd.y) / scale; new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD) .withPanLimited(false).start(); return true; } return super.onFling(e1, e2, velocityX, velocityY); } @Override public boolean onSingleTapConfirmed(MotionEvent e) { performClick(); return true; } @Override public boolean onDoubleTap(MotionEvent e) { if (zoomEnabled && readySent && vTranslate != null) { float doubleTapZoomScale = Math.min(maxScale, SubsamplingScaleImageView.this.doubleTapZoomScale); boolean zoomIn = scale <= doubleTapZoomScale * 0.9; float targetScale = zoomIn ? doubleTapZoomScale : Math.min(getWidth() / (float) sWidth(), getHeight() / (float) sHeight()); PointF targetSCenter = viewToSourceCoord(new PointF(e.getX(), e.getY())); if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER_IMMEDIATE) { setScaleAndCenter(targetScale, targetSCenter); } else if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER || !zoomIn) { new AnimationBuilder(targetScale, targetSCenter).withInterruptible(false).start(); } else if (doubleTapZoomStyle == ZOOM_FOCUS_FIXED) { new AnimationBuilder(targetScale, targetSCenter, new PointF(e.getX(), e.getY())) .withInterruptible(false).start(); } // Hacky solution for #15 - after a double tap the GestureDetector gets in a state where the next // fling is ignored, so here we replace it with a new one. setGestureDetector(context); invalidate(); return true; } return super.onDoubleTapEvent(e); } }); }
From source file:eu.hydrologis.geopaparazzi.chart.ProfileChartActivity.java
@Override 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;// w ww . j a v a 2 s .com stopThread = true; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; 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) { PointF oldFirstFinger = firstFinger; firstFinger = new PointF(event.getX(), event.getY()); scrollElev(oldFirstFinger.x - firstFinger.x); scrollSpeed(oldFirstFinger.x - firstFinger.x); xyPlotSpeed.setDomainBoundaries(minXYSpeed.x, maxXYSpeed.x, BoundaryMode.FIXED); xyPlotElev.setDomainBoundaries(minXYElevation.x, maxXYElevation.x, BoundaryMode.FIXED); xyPlotSpeed.redraw(); xyPlotElev.redraw(); } else if (mode == TWO_FINGERS_DRAG) { float oldDist = distBetweenFingers; distBetweenFingers = spacing(event); zoomElev(oldDist / distBetweenFingers); zoomSpeed(oldDist / distBetweenFingers); xyPlotSpeed.setDomainBoundaries(minXYSpeed.x, maxXYSpeed.x, BoundaryMode.FIXED); xyPlotElev.setDomainBoundaries(minXYElevation.x, maxXYElevation.x, BoundaryMode.FIXED); xyPlotSpeed.redraw(); xyPlotElev.redraw(); } break; } return true; }