Skip to content

Commit

Permalink
updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
sephiroth74 committed Jun 14, 2012
1 parent e390db7 commit b212d73
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

/**
* Base View to manage image zoom/scrool/pinch operations
*
* @author alessandro
*
*
*/
public class ImageViewTouchBase extends ImageView implements IDisposable {

Expand Down Expand Up @@ -99,14 +100,49 @@ public void setImageBitmap( Bitmap bm ) {
setImageBitmap( bm, true );
}

/**
* Set the new image to display and reset the internal matrix.
*
* @param bitmap
* - the {@link Bitmap} to display
* @param reset
* - if true the image bounds will be recreated, otherwise the old {@link Matrix} is used to display the new bitmap
* @see #setImageBitmap(Bitmap)
*/
public void setImageBitmap( final Bitmap bitmap, final boolean reset ) {
setImageBitmap( bitmap, reset, null );
}

/**
* Similar to {@link #setImageBitmap(Bitmap, boolean)} but an optional view {@link Matrix} can be passed to determine the new
* bitmap view matrix.<br />
* This method is useful if you need to restore a Bitmap with the same zoom/pan values from a previous state
*
* @param bitmap
* - the {@link Bitmap} to display
* @param reset
* @param matrix
* - the {@link Matrix} to be used to display the new bitmap
*
* @see #setImageBitmap(Bitmap, boolean)
* @see #setImageBitmap(Bitmap)
* @see #getImageViewMatrix()
* @see #getDisplayMatrix()
*/
public void setImageBitmap( final Bitmap bitmap, final boolean reset, Matrix matrix ) {
setImageBitmap( bitmap, reset, matrix, -1 );
}

/**
*
* @param bitmap
* @param reset
* @param matrix
* @param maxZoom
* - maximum zoom allowd during zoom gestures
*
* @see #setImageBitmap(Bitmap, boolean, Matrix)
*/
public void setImageBitmap( final Bitmap bitmap, final boolean reset, Matrix matrix, float maxZoom ) {

Log.i( LOG_TAG, "setImageBitmap: " + bitmap );
Expand Down Expand Up @@ -199,6 +235,12 @@ public Matrix getImageViewMatrix() {
return mDisplayMatrix;
}

/**
* Returns the current image display matrix. This matrix can be used in the next call to the
* {@link #setImageBitmap(Bitmap, boolean, Matrix)} to restore the same view state of the previous {@link Bitmap}
*
* @return
*/
public Matrix getDisplayMatrix() {
return new Matrix( mSuppMatrix );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void selectRandomImage() {
Bitmap bitmap = DecodeUtils.decode( this, imageUri, 1024, 1024 );
if( null != bitmap )
{
mImage.setImageBitmap( bitmap, true );
mImage.setImageBitmap( bitmap );
} else {
Toast.makeText( this, "Failed to load the image", Toast.LENGTH_LONG ).show();
}
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
ImageViewZoom
=============

Android ImageView widget with zoom and pan capabilities
Android ImageView widget with zoom and pan capabilities.
This is an implementation of the ImageView widget used in the Gallery app of the Android opensource project.

Checkout the repository and run the **ImageViewTouchTest** project to see how it works.
Beside the superclass **setImageBitmap** method it offers the following methods:

* setImageDrawable( Drawable drawable )
* setImageBitmap( final Bitmap bitmap, final boolean reset )
* setImageBitmap( final Bitmap bitmap, final boolean reset, Matrix matrix )
* setImageBitmap( final Bitmap bitmap, final boolean reset, Matrix matrix, float maxZoom )


If you want to load a new Bitmap with a particular zoom/pan state (let's say the same from another imageview ), you can call:
> Matrix matrix = mImageView1.getDisplayMatrix();
> mImageView2.setImageBitmap( bitmap, true, matrix );

0 comments on commit b212d73

Please sign in to comment.