List of usage examples for android.graphics Matrix postTranslate
public boolean postTranslate(float dx, float dy)
From source file:bmcx.aiton.com.passenger.view.activity.SmsLoginActivity.java
private void initAnim() { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int screenW = dm.widthPixels;// ? offset = screenW / 2;// ??? Matrix matrix = new Matrix(); matrix.postTranslate(offset, 0); mImageView_tiao01.setImageMatrix(matrix);// ?? }
From source file:org.deviceconnect.android.deviceplugin.host.activity.CanvasProfileActivity.java
/** * ????./*from ww w . ja va 2 s . c om*/ * @param drawObj ?? */ private void showDrawObject(final CanvasDrawImageObject drawObj) { switch (drawObj.getMode()) { default: case NON_SCALE_MODE: Matrix matrix = new Matrix(); matrix.postTranslate((float) drawObj.getX(), (float) drawObj.getY()); mCanvasView.setImageBitmap(mBitmap); mCanvasView.setScaleType(ScaleType.MATRIX); mCanvasView.setImageMatrix(matrix); break; case SCALE_MODE: mCanvasView.setImageBitmap(mBitmap); mCanvasView.setScaleType(ScaleType.FIT_CENTER); mCanvasView.setTranslationX((int) drawObj.getX()); mCanvasView.setTranslationY((int) drawObj.getY()); break; case FILL_MODE: BitmapDrawable bd = new BitmapDrawable(getResources(), mBitmap); bd.setTileModeX(Shader.TileMode.REPEAT); bd.setTileModeY(Shader.TileMode.REPEAT); mCanvasView.setImageDrawable(bd); mCanvasView.setScaleType(ScaleType.FIT_XY); mCanvasView.setTranslationX((int) drawObj.getX()); mCanvasView.setTranslationY((int) drawObj.getY()); break; } }
From source file:com.actionbarsherlock.internal.nineoldandroids.view.animation.AnimatorProxy.java
private void transformMatrix(Matrix m, View view) { final float w = view.getWidth(); final float h = view.getHeight(); final float sX = mScaleX; final float sY = mScaleY; if ((sX != 1.0f) || (sY != 1.0f)) { final float deltaSX = ((sX * w) - w) / 2f; final float deltaSY = ((sY * h) - h) / 2f; m.postScale(sX, sY);/*from w w w . j a v a 2 s .c o m*/ m.postTranslate(-deltaSX, -deltaSY); } m.postTranslate(mTranslationX, mTranslationY); }
From source file:org.mdc.chess.ChessBoard.java
private void drawMoveHints(Canvas canvas) { if ((moveHints == null) || blindMode) { return;//ww w. ja v a 2 s . c o m } float h = (float) (sqSize / 2.0); float d = (float) (sqSize / 8.0); double v = 35 * Math.PI / 180; double cosv = Math.cos(v); double sinv = Math.sin(v); double tanv = Math.tan(v); int n = Math.min(moveMarkPaint.size(), moveHints.size()); for (int i = 0; i < n; i++) { Move m = moveHints.get(i); if ((m == null) || (m.from == m.to)) { continue; } float x0 = getXCrd(Position.getX(m.from)) + h; float y0 = getYCrd(Position.getY(m.from)) + h; float x1 = getXCrd(Position.getX(m.to)) + h; float y1 = getYCrd(Position.getY(m.to)) + h; float x2 = (float) (Math.hypot(x1 - x0, y1 - y0) + d); float y2 = 0; float x3 = (float) (x2 - h * cosv); float y3 = (float) (y2 - h * sinv); float x4 = (float) (x3 - d * sinv); float y4 = (float) (y3 + d * cosv); float x5 = (float) (x4 + (-d / 2 - y4) / tanv); float y5 = -d / 2; float x6 = 0; float y6 = y5 / 2; Path path = new Path(); path.moveTo(x2, y2); path.lineTo(x3, y3); // path.lineTo(x4, y4); path.lineTo(x5, y5); path.lineTo(x6, y6); path.lineTo(x6, -y6); path.lineTo(x5, -y5); // path.lineTo(x4, -y4); path.lineTo(x3, -y3); path.close(); Matrix mtx = new Matrix(); mtx.postRotate((float) (Math.atan2(y1 - y0, x1 - x0) * 180 / Math.PI)); mtx.postTranslate(x0, y0); path.transform(mtx); Paint p = moveMarkPaint.get(i); canvas.drawPath(path, p); } }
From source file:org.y20k.transistor.helpers.ImageHelper.java
public Bitmap createCircularFramedImage(int size) { // create empty bitmap and canvas Bitmap outputImage = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas imageCanvas = new Canvas(outputImage); // construct circular background mBackgroundColor.setStyle(Paint.Style.FILL); float cx = size / 2; float cy = size / 2; float radius = size / 2; // draw circular background imageCanvas.drawCircle(cx, cy, radius, mBackgroundColor); // get size of original image float inputImageHeight = (float) mInputImage.getHeight(); float inputImageWidth = (float) mInputImage.getWidth(); // calculate padding float padding = (float) size / 4; // define variables needed for transformation matrix Matrix transformationMatrix = new Matrix(); float aspectRatio = 0.0f; float xTranslation = 0.0f; float yTranslation = 0.0f; // landscape format and square if (inputImageWidth >= inputImageHeight) { aspectRatio = (size - padding * 2) / inputImageWidth; xTranslation = 0.0f + padding;/* w ww .ja v a 2 s . co m*/ yTranslation = (size - inputImageHeight * aspectRatio) / 2.0f; } // portrait format else if (inputImageHeight > inputImageWidth) { aspectRatio = (size - padding * 2) / inputImageHeight; yTranslation = 0.0f + padding; xTranslation = (size - inputImageWidth * aspectRatio) / 2.0f; } // construct transformation matrix transformationMatrix.postTranslate(xTranslation, yTranslation); transformationMatrix.preScale(aspectRatio, aspectRatio); // draw input image onto canvas using transformation matrix Paint paint = new Paint(); paint.setFilterBitmap(true); imageCanvas.drawBitmap(mInputImage, transformationMatrix, paint); return outputImage; }
From source file:com.zhenlaidian.ui.InputCarNumberActivity.java
/** * 2 * ?????//from ww w. j a v a 2 s . com */ private void InitImageView() { imageView = (ImageView) findViewById(R.id.cursor_dialog); bmpW = BitmapFactory.decodeResource(context.getResources(), R.drawable.viewpage).getWidth();// ? DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int screenW = dm.widthPixels;// ? offset = (screenW / 3 - bmpW) / 2;// ??? Matrix matrix = new Matrix(); matrix.postTranslate(offset, 0); imageView.setImageMatrix(matrix);// ?? }
From source file:org.videolan.vlc.gui.MyFragment.java
/** * ?/*from w ww . j a v a 2 s .com*/ */ private void initIndView() { cursor = (ImageView) findViewById(R.id.cursor); int bmpW = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.indicator_blue_small) .getWidth();// ? DisplayMetrics dm = new DisplayMetrics(); ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(dm); int screenW = dm.widthPixels;// ? offset = (screenW / 2 - bmpW) / 2;// ??? one = offset + screenW / 2; two = offset + (screenW / 2) * 2; Matrix matrix = new Matrix(); matrix.postTranslate(offset, 0); cursor.setImageMatrix(matrix);// ?? }
From source file:com.ddoskify.CameraOverlayActivity.java
/** * Initializes the UI and initiates the creation of a face detector. *//*from w w w .j a v a2 s .co m*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay); mFaces = new ArrayList<FaceTracker>(); final ImageButton button = (ImageButton) findViewById(R.id.flipButton); button.setOnClickListener(mFlipButtonListener); if (savedInstanceState != null) { mIsFrontFacing = savedInstanceState.getBoolean("IsFrontFacing"); } mTakePictureButton = (Button) findViewById(R.id.takePictureButton); mTakePictureButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Log.e("CameraOverlay", "Button has been pressed"); mCameraSource.takePicture(new CameraSource.ShutterCallback() { @Override public void onShutter() { // mCameraSource.stop(); Snackbar.make(findViewById(android.R.id.content), "Picture Taken!", Snackbar.LENGTH_SHORT) .setActionTextColor(Color.BLACK).show(); } }, new CameraSource.PictureCallback() { public void onPictureTaken(byte[] data) { int re = ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE); if (!isStorageAllowed()) { requestStoragePermission(); } File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } try { Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length); Bitmap resizedBitmap = Bitmap.createBitmap(mGraphicOverlay.getWidth(), mGraphicOverlay.getHeight(), picture.getConfig()); Canvas canvas = new Canvas(resizedBitmap); Matrix matrix = new Matrix(); matrix.setScale((float) resizedBitmap.getWidth() / (float) picture.getWidth(), (float) resizedBitmap.getHeight() / (float) picture.getHeight()); if (mIsFrontFacing) { // mirror by inverting scale and translating matrix.preScale(-1, 1); matrix.postTranslate(canvas.getWidth(), 0); } Paint paint = new Paint(); canvas.drawBitmap(picture, matrix, paint); mGraphicOverlay.draw(canvas); // make those accessible FileOutputStream fos = new FileOutputStream(pictureFile); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos); fos.close(); Intent intent = new Intent(getApplicationContext(), PhotoReviewActivity.class); intent.putExtra(BITMAP_MESSAGE, pictureFile.toString()); startActivity(intent); Log.d("CameraOverlay", "Starting PhotoReviewActivity " + pictureFile.toString()); } catch (FileNotFoundException e) { Log.e("CameraOverlay", e.toString()); } catch (IOException e) { Log.e("CameraOverlay", e.toString()); } } }); } }); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(); } else { requestCameraPermission(); } }
From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.MarkerDrawable.java
private void computePath(Rect bounds) { final float currentScale = mCurrentScale; final Path path = mPath; final RectF rect = mRect; final Matrix matrix = mMatrix; path.reset();//from w w w . ja va 2s . c o m int totalSize = Math.min(bounds.width(), bounds.height()); float initial = mClosedStateSize; float destination = totalSize; float currentSize = initial + (destination - initial) * currentScale; float halfSize = currentSize / 2f; float inverseScale = 1f - currentScale; float cornerSize = halfSize * inverseScale; float[] corners = new float[] { halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize, cornerSize }; rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize); path.addRoundRect(rect, corners, Path.Direction.CCW); matrix.reset(); matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize); matrix.postTranslate((bounds.width() - currentSize) / 2, 0); float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale; matrix.postTranslate(0, hDiff); path.transform(matrix); }
From source file:com.inmobi.nativead.sample.photopages.CustomViewPager.java
@Override protected boolean getChildStaticTransformation(View child, Transformation t) { // We can cast here because CustomPagerAdapter only creates wrappers. CustomViewPagerItemWrapper item = (CustomViewPagerItemWrapper) child; // Since Jelly Bean children won't get invalidated automatically, // needs to be added for the smooth coverflow animation if (android.os.Build.VERSION.SDK_INT >= 16) { item.invalidate();// w w w. j ava 2 s . c o m } final int coverFlowWidth = this.getWidth(); final int coverFlowCenter = coverFlowWidth / 2; final int childWidth = item.getWidth(); final int childHeight = item.getHeight(); final int childCenter = item.getLeft() + childWidth / 2; // Use coverflow width when its defined as automatic. final int actionDistance = (this.actionDistance == ACTION_DISTANCE_AUTO) ? (int) ((coverFlowWidth + childWidth) / 2.0f) : this.actionDistance; // Calculate the abstract amount for all effects. final float effectsAmount = Math.min(1.0f, Math.max(-1.0f, (1.0f / actionDistance) * (childCenter - coverFlowCenter))); // Clear previous transformations and set transformation type (matrix + alpha). t.clear(); t.setTransformationType(Transformation.TYPE_BOTH); // Alpha if (this.unselectedAlpha != 1) { final float alphaAmount = (this.unselectedAlpha - 1) * Math.abs(effectsAmount) + 1; t.setAlpha(alphaAmount); } // Saturation if (this.unselectedSaturation != 1) { // Pass over saturation to the wrapper. final float saturationAmount = (this.unselectedSaturation - 1) * Math.abs(effectsAmount) + 1; item.setSaturation(saturationAmount); } final Matrix imageMatrix = t.getMatrix(); // Apply rotation. if (this.maxRotation != 0) { final int rotationAngle = (int) (-effectsAmount * this.maxRotation); this.transformationCamera.save(); this.transformationCamera.rotateY(rotationAngle); this.transformationCamera.getMatrix(imageMatrix); this.transformationCamera.restore(); } // Zoom. if (this.unselectedScale != 1) { final float zoomAmount = (this.unselectedScale - 1) * Math.abs(effectsAmount) + 1; // Calculate the scale anchor (y anchor can be altered) final float translateX = childWidth / 2.0f; final float translateY = childHeight * this.scaleDownGravity; imageMatrix.preTranslate(-translateX, -translateY); imageMatrix.postScale(zoomAmount, zoomAmount); imageMatrix.postTranslate(translateX, translateY); } return true; }