List of usage examples for android.graphics RectF centerY
public final float centerY()
From source file:com.example.g40_70m.framedemo.view.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override/*from w w w. j a va 2 s .c o m*/ public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } else { L.w("onTouch getParent() returned null"); } // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector) { boolean wasScaling = mScaleDragDetector.isScaling(); boolean wasDragging = mScaleDragDetector.isDragging(); handled = mScaleDragDetector.onTouchEvent(ev); boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling(); boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging(); mBlockParentIntercept = didntScale && didntDrag; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
From source file:com.org.lengend.photoview.library.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override/*from w w w . j av a 2s. c om*/ public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } else { Logger.i(LOG_TAG, "onTouch getParent() returned null"); } // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector) { boolean wasScaling = mScaleDragDetector.isScaling(); boolean wasDragging = mScaleDragDetector.isDragging(); handled = mScaleDragDetector.onTouchEvent(ev); boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling(); boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging(); mBlockParentIntercept = didntScale && didntDrag; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java
@SuppressLint("ClickableViewAccessibility") @Override//from ww w . j av a 2 s. co m public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) { parent.requestDisallowInterceptTouchEvent(true); } else { LogManager.getLogger().i(LOG_TAG, "onTouch getParent() returned null"); } // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector) { boolean wasScaling = mScaleDragDetector.isScaling(); boolean wasDragging = mScaleDragDetector.isDragging(); handled = mScaleDragDetector.onTouchEvent(ev); boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling(); boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging(); mBlockParentIntercept = didntScale && didntDrag; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
From source file:com.huyn.demogroup.freechild.FixedViewAttacher.java
private boolean checkMatrixBounds() { final RectF rect = getVisibleRect(); if (rect == null) { return false; }/* w w w . j a v a 2s.c o m*/ RectF src = new RectF(); src.set(rect); final float h = rect.height(), w = rect.width(); float deltaX = 0, deltaY = 0; View parent = (View) mImageView.getParent(); final int viewHeight = parent.getHeight();//getImageViewHeight(mImageView); final int viewWidth = parent.getWidth();//getImageViewWidth(mImageView); System.out.println("===============================================width:" + viewWidth + "/" + viewHeight); System.out .println("+++++++++rect.left:" + rect.left + "/" + rect.top + "/" + rect.right + "/" + rect.bottom); float scale = getScale(); float centerX = rect.centerX(); float centerY = rect.centerY(); float targetW = w * scale; float targetH = h * scale; RectF targetRect = new RectF(centerX - targetW / 2, centerY - targetH / 2, centerX + targetW / 2, centerY + targetH / 2); rect.set(targetRect); final float height = rect.height(), width = rect.width(); if (height <= viewHeight) { deltaY = (viewHeight - height) / 2 - rect.top; } else if (rect.top > 0) { deltaY = -rect.top; } else if (rect.bottom < viewHeight) { deltaY = viewHeight - rect.bottom; } if (width <= viewWidth) { deltaX = (viewWidth - width) / 2 - rect.left; mScrollEdge = EDGE_BOTH; } else if (rect.left > 0) { mScrollEdge = EDGE_LEFT; deltaX = -rect.left; } else if (rect.right < viewWidth) { deltaX = viewWidth - rect.right; mScrollEdge = EDGE_RIGHT; } else { mScrollEdge = EDGE_NONE; } // Finally actually translate the matrix if (!mStable) { System.out.println("+++++++++++deltaX:" + deltaX + "/deltaY:" + deltaY + "---" + getScale()); postTranslate(deltaX, deltaY); } return true; }
From source file:org.getlantern.firetweet.view.ShapedImageView.java
private void drawBorder(@NonNull final Canvas canvas, @NonNull final RectF dest) { if (mBorderColors == null) return;/*from ww w .j av a 2 s .co m*/ final RectF transitionSrc = mTransitionSource, transitionDst = mTransitionDestination; final float strokeWidth; if (transitionSrc != null && transitionDst != null) { final float progress = 1 - (dest.width() - transitionDst.width()) / (transitionSrc.width() - transitionDst.width()); strokeWidth = mStrokeWidth * progress; mBorderPaint.setAlpha(Math.round(mBorderAlpha * progress)); ViewCompat.setTranslationZ(this, -ViewCompat.getElevation(this) * (1 - progress)); } else { strokeWidth = mStrokeWidth; mBorderPaint.setAlpha(mBorderAlpha); ViewCompat.setTranslationZ(this, 0); } mBorderPaint.setStrokeWidth(strokeWidth); if (getStyle() == SHAPE_CIRCLE) { final float circleRadius = Math.min(dest.width(), dest.height()) / 2f - strokeWidth / 2; canvas.drawCircle(dest.centerX(), dest.centerY(), circleRadius, mBorderPaint); } else { final float radius = getCalculatedCornerRadius(); final float inset = mStrokeWidth / 2; dest.inset(inset, inset); canvas.drawRoundRect(dest, radius, radius, mBorderPaint); dest.inset(-inset, -inset); } }
From source file:de.vanita5.twittnuker.view.ColorPickerView.java
private void drawAlphaPanel(final Canvas canvas) { if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null) return;//from ww w . j a v a2 s . c om final RectF rect = mAlphaRect; if (BORDER_WIDTH_PX > 0) { mBorderPaint.setColor(mBorderColor); canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint); } mAlphaPattern.draw(canvas); final float[] hsv = new float[] { mHue, mSat, mVal }; final int color = Color.HSVToColor(hsv); final int acolor = Color.HSVToColor(0, hsv); mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, color, acolor, TileMode.CLAMP); mAlphaPaint.setShader(mAlphaShader); canvas.drawRect(rect, mAlphaPaint); if (mAlphaSliderText != null && mAlphaSliderText != "") { canvas.drawText(mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity, mAlphaTextPaint); } final float rectWidth = 4 * mDensity / 2; final Point p = alphaToPoint(mAlpha); final RectF r = new RectF(); r.left = p.x - rectWidth; r.right = p.x + rectWidth; r.top = rect.top - RECTANGLE_TRACKER_OFFSET; r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET; canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint); }
From source file:org.akop.crosswords.view.CrosswordView.java
private void renderCell(Canvas canvas, Cell cell, RectF cellRect, Paint fillPaint) { canvas.drawRect(cellRect, fillPaint); canvas.drawRect(cellRect, mCellStrokePaint); if (cell.mCircled) { canvas.drawCircle(cellRect.centerX(), cellRect.centerY(), mCircleRadius, mCircleStrokePaint); }/*from w w w. ja v a 2 s .c o m*/ if (cell.mNumber != null) { mNumberTextPaint.getTextBounds(cell.mNumber, 0, cell.mNumber.length(), mTempRect); float numberX = cellRect.left + mNumberTextPadding + (mTempRect.width() / 2); float numberY = cellRect.top + mNumberTextPadding + mTempRect.height(); if (cell.mCircled) { canvas.drawText(cell.mNumber, numberX, numberY, mNumberStrokePaint); } canvas.drawText(cell.mNumber, numberX, numberY, mNumberTextPaint); } if (cell.mCheated) { Path path = new Path(); path.moveTo(cellRect.right, cellRect.bottom); path.lineTo(cellRect.right - mMarkerSideLength, cellRect.bottom); path.lineTo(cellRect.right, cellRect.bottom - mMarkerSideLength); path.close(); canvas.drawPath(path, mCheatedCellFillPaint); canvas.drawPath(path, mCellStrokePaint); } if (cell.mError) { Path path = new Path(); path.moveTo(cellRect.left, cellRect.bottom); path.lineTo(cellRect.left + mMarkerSideLength, cellRect.bottom); path.lineTo(cellRect.left, cellRect.bottom - mMarkerSideLength); path.close(); canvas.drawPath(path, mMistakeCellFillPaint); canvas.drawPath(path, mCellStrokePaint); } if (!cell.isEmpty()) { mAnswerTextPaint.getTextBounds(cell.mCharStr, 0, cell.mCharStr.length(), mTempRect); canvas.drawText(cell.mCharStr, cellRect.left + mCellSize / 2, cellRect.top + mCellSize - mAnswerTextPadding, mAnswerTextPaint); } }
From source file:com.ape.camera2raw.Camera2RawFragment.java
/** * Configure the necessary {@link Matrix} transformation to `mTextureView`, * and start/restart the preview capture session if necessary. * <p/>// www .j a v a 2 s . c o m * This method should be called after the camera state has been initialized in * setUpCameraOutputs. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ private void configureTransform(int viewWidth, int viewHeight) { Activity activity = getActivity(); synchronized (mCameraStateLock) { if (null == mTextureView || null == activity) { return; } StreamConfigurationMap map = mCharacteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); // For still image captures, we always use the largest available size. Size largestJpeg = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); // Find the rotation of the device relative to the native device orientation. int deviceRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Point displaySize = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(displaySize); // Find the rotation of the device relative to the camera sensor's orientation. int totalRotation = sensorToDeviceRotation(mCharacteristics, deviceRotation); // Swap the view dimensions for calculation as needed if they are rotated relative to // the sensor. boolean swappedDimensions = totalRotation == 90 || totalRotation == 270; int rotatedViewWidth = viewWidth; int rotatedViewHeight = viewHeight; int maxPreviewWidth = displaySize.x; int maxPreviewHeight = displaySize.y; if (swappedDimensions) { rotatedViewWidth = viewHeight; rotatedViewHeight = viewWidth; maxPreviewWidth = displaySize.y; maxPreviewHeight = displaySize.x; } // Preview should not be larger than display size and 1080p. if (maxPreviewWidth > MAX_PREVIEW_WIDTH) { maxPreviewWidth = MAX_PREVIEW_WIDTH; } if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) { maxPreviewHeight = MAX_PREVIEW_HEIGHT; } // Find the best preview size for these view dimensions and configured JPEG size. Size previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedViewWidth, rotatedViewHeight, maxPreviewWidth, maxPreviewHeight, largestJpeg); if (swappedDimensions) { mTextureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth()); } else { mTextureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight()); } // Find rotation of device in degrees (reverse device orientation for front-facing // cameras). int rotation = (mCharacteristics .get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) ? (360 + ORIENTATIONS.get(deviceRotation)) % 360 : (360 - ORIENTATIONS.get(deviceRotation)) % 360; Matrix matrix = new Matrix(); RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth()); float centerX = viewRect.centerX(); float centerY = viewRect.centerY(); // Initially, output stream images from the Camera2 API will be rotated to the native // device orientation from the sensor's orientation, and the TextureView will default to // scaling these buffers to fill it's view bounds. If the aspect ratios and relative // orientations are correct, this is fine. // // However, if the device orientation has been rotated relative to its native // orientation so that the TextureView's dimensions are swapped relative to the // native device orientation, we must do the following to ensure the output stream // images are not incorrectly scaled by the TextureView: // - Undo the scale-to-fill from the output buffer's dimensions (i.e. its dimensions // in the native device orientation) to the TextureView's dimension. // - Apply a scale-to-fill from the output buffer's rotated dimensions // (i.e. its dimensions in the current device orientation) to the TextureView's // dimensions. // - Apply the rotation from the native device orientation to the current device // rotation. if (Surface.ROTATION_90 == deviceRotation || Surface.ROTATION_270 == deviceRotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); float scale = Math.max((float) viewHeight / previewSize.getHeight(), (float) viewWidth / previewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); } matrix.postRotate(rotation, centerX, centerY); mTextureView.setTransform(matrix); // Start or restart the active capture session if the preview was initialized or // if its aspect ratio changed significantly. if (mPreviewSize == null || !checkAspectsEqual(previewSize, mPreviewSize)) { mPreviewSize = previewSize; if (mState != STATE_CLOSED) { createCameraPreviewSessionLocked(); } } } }