List of usage examples for android.widget ImageView setImageMatrix
public void setImageMatrix(Matrix matrix)
From source file:android.support.v17.leanback.widget.DetailsOverviewSharedElementHelper.java
private void restoreImageViewScale() { if (mSavedScaleType != null) { if (DEBUG) { Log.d(TAG, "restoreImageViewScale to " + mSavedScaleType); }//from w ww.j av a2s . c o m ImageView imageView = mViewHolder.mImageView; imageView.setScaleType(mSavedScaleType); if (mSavedScaleType == ScaleType.MATRIX) { imageView.setImageMatrix(mSavedMatrix); } // only restore once unless another save happens mSavedScaleType = null; updateImageViewAfterScaleTypeChange(imageView); } }
From source file:android.support.v17.leanback.widget.DetailsOverviewSharedElementHelper.java
private void changeImageViewScale(View snapshotView) { ImageView snapshotImageView = (ImageView) snapshotView; ImageView imageView = mViewHolder.mImageView; if (DEBUG) {/*from w w w . ja v a 2 s . com*/ Log.d(TAG, "changeImageViewScale to " + snapshotImageView.getScaleType()); } imageView.setScaleType(snapshotImageView.getScaleType()); if (snapshotImageView.getScaleType() == ScaleType.MATRIX) { imageView.setImageMatrix(snapshotImageView.getImageMatrix()); } updateImageViewAfterScaleTypeChange(imageView); }
From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java
private Bitmap fillUpperLeft(final Drawable drawable, ImageView imageView, Bitmap prevBm) { // Compute matrix to fill viewer with drawable starting with upper left // Stretching till 2nd edge is crossed (filling screen) with correct aspect ratio. Matrix m = new Matrix(); m.reset();// www .j a v a 2 s.c om int imgWidth = drawable.getIntrinsicWidth(); int imgHeight = drawable.getIntrinsicHeight(); int viewWidth = imageView.getWidth(); int viewHeight = imageView.getHeight(); float xScale = (float) viewWidth / imgWidth; float yScale = (float) viewHeight / imgHeight; float maxScale = Math.max(xScale, yScale); m.postScale(maxScale, maxScale); imageView.setScaleType(ImageView.ScaleType.MATRIX); imageView.setImageMatrix(m); imageView.setImageDrawable(drawable); return prevBm; }
From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java
private Bitmap fillLowerLeft(final Drawable drawable, ImageView imageView, Bitmap prevBm) { // Compute matrix to fill viewer with drawable starting with upper left // Stretching till 2nd edge is crossed (filling screen) with correct aspect ratio. Matrix m = new Matrix(); m.reset();//from www .j a va2 s. c o m int imgWidth = drawable.getIntrinsicWidth(); int imgHeight = drawable.getIntrinsicHeight(); int viewWidth = imageView.getWidth(); int viewHeight = imageView.getHeight(); float xScale = (float) viewWidth / imgWidth; float yScale = (float) viewHeight / imgHeight; float maxScale = Math.max(xScale, yScale); float dy = (imgHeight * maxScale - viewHeight) / maxScale; // dy = imgHeight / 2; m.preTranslate(0, -dy); m.postScale(maxScale, maxScale); imageView.setScaleType(ImageView.ScaleType.MATRIX); imageView.setImageMatrix(m); imageView.setImageDrawable(drawable); return prevBm; }
From source file:com.widgets.photoview.PhotoViewAttacher.java
private void setImageViewMatrix(Matrix matrix) { ImageView imageView = getImageView(); if (null != imageView) { checkImageViewScaleType();//from w ww .j a v a2 s . c o m imageView.setImageMatrix(matrix); // Call MatrixChangedListener if needed if (null != mMatrixChangeListener) { RectF displayRect = getDisplayRect(matrix); if (null != displayRect) { mMatrixChangeListener.onMatrixChanged(displayRect); } } } }
From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java
private void setImageViewMatrix(Matrix matrix) { ImageView imageView = getImageView(); if (null != imageView) { checkImageViewScaleType();// w ww. j ava 2 s. co m imageView.setImageMatrix(matrix); // Call MatrixChangedListener if needed if (null != mMatrixChangeListener) { RectF displayRect = getDisplayRect(matrix); if (null != displayRect) { mMatrixChangeListener.onMatrixChanged(displayRect); } } } }
From source file:org.openbmap.activities.MapViewActivity.java
/** * Draws compass//from w ww .ja va 2s .co m * @param iv image view used for compass * @param ressourceId resource id compass needle * @param bearing bearing (azimuth) */ private void drawCompass(final ImageView iv, final Integer ressourceId, final float bearing) { // refresh only if needed if (ressourceId != R.drawable.arrow) { iv.setImageResource(R.drawable.arrow); } // rotate arrow final Matrix matrix = new Matrix(); iv.setScaleType(ScaleType.MATRIX); //required matrix.postRotate(bearing, iv.getWidth() / 2f, iv.getHeight() / 2f); iv.setImageMatrix(matrix); }
From source file:com.windnow.StationPicActivity.java
@SuppressLint("NewApi") @Override// www . j a v a 2 s . c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_station_pic); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { getActionBar().setDisplayHomeAsUpEnabled(true); } TextView tv = (TextView) findViewById(R.id.textViewPicName); tv.setText(getIntent().getExtras().getString("name")); imageDetail = (ImageView) findViewById(R.id.imageView1); String filename = "pic" + getIntent().getExtras().getString("txt").hashCode(); Bitmap pic = null; try { FileInputStream is = this.openFileInput(filename); pic = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { LoadSaveOps.printErrorToLog(e); } imageDetail.setImageBitmap(pic); imageDetail.setOnTouchListener(new View.OnTouchListener() { @SuppressLint("ClickableViewAccessibility") @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: savedMatrix.set(matrix); startPoint.set(event.getX(), event.getY()); mode = DRAG; break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); if (oldDist > 10f) { savedMatrix.set(matrix); midPoint(midPoint, event); mode = ZOOM; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; case MotionEvent.ACTION_MOVE: if (mode == DRAG) { matrix.set(savedMatrix); matrix.postTranslate(event.getX() - startPoint.x, event.getY() - startPoint.y); } else if (mode == ZOOM) { float newDist = spacing(event); if (newDist > 10f) { matrix.set(savedMatrix); float scale = newDist / oldDist; matrix.postScale(scale, scale, midPoint.x, midPoint.y); matrix.postTranslate(event.getX() - startPoint.x, event.getY() - startPoint.y); //new } } break; } view.setImageMatrix(matrix); return true; } @SuppressLint("FloatMath") private float spacing(MotionEvent event) { float x = event.getX(0) - event.getX(1); float y = event.getY(0) - event.getY(1); return FloatMath.sqrt(x * x + y * y); } private void midPoint(PointF point, MotionEvent event) { float x = event.getX(0) + event.getX(1); float y = event.getY(0) + event.getY(1); point.set(x / 2, y / 2); } }); }
From source file:org.que.activities.fragments.MapImageFragment.java
/** * The onTouch method which will be called if an onTouch event appears. * //from w w w . j a v a2 s. co m * @param view the view which was touched * @param event the touch event * @return true if the touch event was handled, false otherwise */ public boolean onTouch(View view, MotionEvent event) { Boolean consumed; ImageView image = (ImageView) view; switch (event.getAction() & MotionEvent.ACTION_MASK) //bitwise and with mask { case MotionEvent.ACTION_DOWN: saved.set(m); p.set(event.getX(), event.getY()); mode = TOUCH_MODE.DRAG; consumed = true; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: mode = TOUCH_MODE.NONE; consumed = true; break; case MotionEvent.ACTION_POINTER_DOWN: saved.set(m); mode = TOUCH_MODE.ZOOM; oldDis = euclideanDistance(event); p = calcMidPoint(p, event); consumed = true; break; case MotionEvent.ACTION_MOVE: if (mode == TOUCH_MODE.ZOOM) { m.set(saved); newDis = euclideanDistance(event); scale = newDis / oldDis; m.postScale(scale, scale, p.x, p.y); float[] values = new float[9]; m.getValues(values); float mscale = values[Matrix.MSCALE_X]; if (mscale < MIN_ZOOM) { m.setScale(MIN_ZOOM, MIN_ZOOM, p.x, p.y); } else if (mscale > MAX_ZOOM) { m.setScale(MAX_ZOOM, MAX_ZOOM, p.x, p.y); } } else if (mode == TOUCH_MODE.DRAG) { m.set(saved); m.postTranslate(event.getX() - p.x, event.getY() - p.y); } consumed = true; break; default: consumed = false; } image.setImageMatrix(m); return consumed; }
From source file:com.bofsoft.laio.laiovehiclegps.Fragment.BaiduMapFragment.java
private void addOverlay(GPSInfoData gpsInfoData) {//marker ?? ? LatLng llA = new LatLng(gpsInfoData.Latitude, gpsInfoData.Longitude); // GPSGPS?????? CoordinateConverter converter = new CoordinateConverter(); converter.from(CoordinateConverter.CoordType.GPS); // sourceLatLng??? converter.coord(llA);//from w w w. j a va 2 s. co m // desLatLng = converter.convert(); LatLng tmpLL = converter.convert(); View v_temp = LayoutInflater.from(getActivity()).inflate(R.layout.map_marker, null);// TextView tv_temp = (TextView) v_temp.findViewById(R.id.tv_marker);//?textview ImageView img_temp = (ImageView) v_temp.findViewById(R.id.iv_marker);//?imageview tv_temp.setText(gpsInfoData.License);//? if (gpsInfoData.Status == 0) { img_temp.setImageResource(imgIds[0]);//marker bitmap = BitmapFactory.decodeResource(getResources(), imgIds[0]); } else { img_temp.setImageResource(imgIds[2]);//marker bitmap = BitmapFactory.decodeResource(getResources(), imgIds[2]); } Matrix matrix = new Matrix(); img_temp.setScaleType(ImageView.ScaleType.MATRIX); //required matrix.postScale(1, 1); //ImageViewImage int dw = bitmap.getWidth(); int dh = bitmap.getHeight(); matrix.postRotate((float) gpsInfoData.Direction, (float) dw / 2, (float) dh / 2);// img_temp.setImageMatrix(matrix); bd_temp = BitmapDescriptorFactory.fromView(v_temp);//?marker MarkerOptions oo = new MarkerOptions().position(tmpLL).icon(bd_temp).anchor(0.5f, 1.0f).zIndex(15); Marker mMarkerA = (Marker) (mBaiduMap.addOverlay(oo)); Bundle bundle = new Bundle(); bundle.putString("License", gpsInfoData.getLicense()); mMarkerA.setExtraInfo(bundle); }