Code example for Transformation

Methods: clear, getMatrix, setTransformationType

0
    final int childCenter = getCenterOfView(child);
    if (childCenter == mCovertflowCenter) { return false;  }
 
    final int childWidth = child.getWidth();
 
    t.clear();
    t.setTransformationType(Transformation.TYPE_MATRIX);
 
    int rotationAngle = (int)(((float)(mCovertflowCenter - childCenter) / childWidth) *  mMaxRotationAngle);
    if (Math.abs(rotationAngle) > mMaxRotationAngle) {
      rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle : mMaxRotationAngle;
    } 
    transformImageBitmap(child, t, rotationAngle);
 
    return true; 
  } 
 
  @Override 
  protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (zoomChanged) {
      final boolean[] scrap = new boolean[1];
      final View view = obtainView(getSelectedItemPosition(), scrap);
      if (view != null) {
        // Return to scrap 
        mRecycler.addScrapView(view);
        final int myWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
        zoomFactor = (float)myWidth / view.getMeasuredWidth() / 2;
      } 
    } 
  } 
 
  @Override 
  protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) {
    mCovertflowCenter = getCenterOfGallery();
    zoomChanged = true;
    super.onSizeChanged(w, h, oldw, oldh);
  } 
 
  /** 
   * Transform the image bitmap by the angle passed. 
   * @param imageView ImageView the ImageView whose bitmap we want to rotate 
   * @param t transformation 
   * @param rotationAngle the Angle by which to rotate the Bitmap 
   */ 
  private void transformImageBitmap(final View child, final Transformation t, final int rotationAngle) {
    mCamera.save();
    final Matrix imageMatrix = t.getMatrix();
    final int imageHeight = child.getWidth();
    final int imageWidth = child.getHeight();
    final int rotation = Math.min(Math.abs(rotationAngle), mMaxRotationAngle);
 
    //As the angle of the view gets less, zoom in