/**
   * 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 transformBitmap(View child, Transformation t, int rotationAngle) {

    final Matrix childMatrix = t.getMatrix();
    final int childHeight = child.getLayoutParams().height;
    final int childWidth = child.getLayoutParams().width;
    final int rotation = Math.abs(rotationAngle);

    mCamera.save();
    mCamera.translate(0.0f, 0.0f, 100.0f);
    // As the angle of the view gets less, zoom in
    if (rotation <= mMaxRotationAngle) {
      float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
      mCamera.translate(0.0f, 0.0f, zoomAmount);
      if (mCircleMode) {
        if (rotation < 40) mCamera.translate(0.0f, 155, 0.0f);
        else mCamera.translate(0.0f, (255 - rotation * 2.5f), 0.0f);
      }
      if (mAlphaMode) {
        ((ImageView) (child)).setAlpha((int) (255 - rotation * 2.5));
      }
    }
    mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(childMatrix);
    childMatrix.preTranslate(-(childWidth / 2), -(childHeight / 2));
    childMatrix.postTranslate((childWidth / 2), (childHeight / 2));
    mCamera.restore();
  }
 // ���Transformation
 @Override
 protected void applyTransformation(float interpolatedTime, Transformation t) {
   final float fromDegrees = mFromDegrees;
   // ����м�Ƕ�
   float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
   final float centerX = mCenterX;
   final float centerY = mCenterY;
   final Camera camera = mCamera;
   final Matrix matrix = t.getMatrix();
   camera.save();
   if (mReverse) {
     camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
   } else {
     camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
   }
   if (mRotate.equals("y")) {
     camera.rotateY(degrees);
   } else if (mRotate.equals("x")) {
     camera.rotateX(degrees);
   } else if (mRotate.equals("z")) {
     camera.rotateZ(degrees);
   }
   // ȡ�ñ任��ľ���
   camera.getMatrix(matrix);
   camera.restore();
   matrix.preTranslate(-centerX, -centerY);
   matrix.postTranslate(centerX, centerY);
 }
Beispiel #3
0
 /**
  * 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(View child, Transformation t, int rotationAngle, int d) {
   mCamera.save();
   final Matrix imageMatrix = t.getMatrix();
   final int imageHeight = child.getLayoutParams().height;
   final int imageWidth = child.getLayoutParams().width;
   final int rotation = Math.abs(rotationAngle);
   // mCamera.translate(0.0f, 0.0f, 100.0f);
   // As the angle of the view gets less, zoom in
   // if (rotation <= mMaxRotationAngle) {
   float zoomAmount = (float) (-140 + (rotation * 2));
   if (rotationAngle < 0) {
     mCamera.translate((float) (-rotation * 0.5), (float) (-rotation * 0.3) + 5, zoomAmount);
   } else {
     mCamera.translate((float) rotation, (float) (-rotation * 0.3) + 5, zoomAmount);
   }
   Log.i("info", "---------------------->" + rotationAngle);
   if (mCircleMode) {
     if (rotation < 40) {
       mCamera.translate(0.0f, 155, 0.0f);
     } else {
       mCamera.translate(0.0f, (255 - rotation * 2.5f), 0.0f);
     }
   }
   if (mAlphaMode) {
     // child.setBackgroundDrawable(getResources().getDrawable(R.drawable.app_bg));
     // child.setBackgroundColor(255);
   }
   // }
   // mCamera.rotateY(rotationAngle);
   mCamera.getMatrix(imageMatrix);
   imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
   imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
   mCamera.restore();
 }
Beispiel #4
0
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float FromDegree = mFromDegree;
    float degrees = FromDegree + (mToDegree - mFromDegree) * interpolatedTime;
    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Matrix matrix = t.getMatrix();

    if (degrees <= -76.0f) {
      degrees = -90.0f;
      mCamera.save();
      mCamera.rotateY(degrees);
      mCamera.getMatrix(matrix);
      mCamera.restore();
    } else if (degrees >= 76.0f) {
      degrees = 90.0f;
      mCamera.save();
      mCamera.rotateY(degrees);
      mCamera.getMatrix(matrix);
      mCamera.restore();
    } else {
      mCamera.save();
      // 这里很重要哦。
      mCamera.translate(0, 0, centerX);
      mCamera.rotateY(degrees);
      mCamera.translate(0, 0, -centerX);
      mCamera.getMatrix(matrix);
      mCamera.restore();
    }

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
  }
  private void transformImageBitmap(ImageView child, Transformation t, int rotationAngle) {
    // 对效果进行保存
    mCamera.save();
    final Matrix imageMatrix = t.getMatrix();
    // 图片高度
    final int imageHeight = child.getLayoutParams().height;
    // 图片宽度
    final int imageWidth = child.getLayoutParams().width;

    // 返回旋转角度的绝对值
    final int rotation = Math.abs(rotationAngle);

    // 在Z轴上正向移动camera的视角,实际效果为放大图片。
    // 如果在Y轴上移动,则图片上下移动;X轴上对应图片左右移动。
    mCamera.translate(0.0f, 0.0f, 100.0f);
    // As the angle of the view gets less, zoom in
    if (rotation < mMaxRotationAngle) {
      float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
      mCamera.translate(0.0f, 0.0f, zoomAmount);
    }
    // 在Y轴上旋转,对应图片竖向向里翻转。
    // 如果在X轴上旋转,则对应图片横向向里翻转。
    mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
    mCamera.restore();
  }
Beispiel #6
0
  private void transformImageBitmap(ImageView child, Transformation trans, int rotationAngle) {
    mCamera.save();

    final Matrix imageMatrix = trans.getMatrix();
    final int imageHeight = child.getLayoutParams().height;
    final int imageWidth = child.getLayoutParams().width;
    final int rotation = Math.abs(rotationAngle);

    // 在Z轴上正向移动camera的视角,实际效果为放大图片; 如果在Y轴上移动,则图片上下移动; X轴上对应图片左右移动。
    mCamera.translate(0.0f, 0.0f, -20.0f);

    // As the angle of the view gets less, zoom in
    if (rotation < mMaxRotationAngle) {
      float zoomAmount = (float) (mMaxZoom + (rotation * 1.0));
      mCamera.translate(0.0f, 0.0f, zoomAmount);
    }

    mCamera.rotateY(rotationAngle); // rotationAngle 为正,沿y轴向内旋转; 为负,沿y轴向外旋转

    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));

    mCamera.restore();
  }
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float FromDegree = mFromDegree;
    float degrees = FromDegree + (mToDegree - mFromDegree) * interpolatedTime;
    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Matrix matrix = t.getMatrix();

    float[] values = new float[9];
    matrix.getValues(values);
    Log.d(
        TAG,
        "MATRIX  scale:"
            + values[0]
            + ", degrees:"
            + degrees
            + ", centerX:"
            + centerX
            + ", centerY:"
            + centerY);

    if (degrees <= -76.0f) {
      degrees = -90.0f;
      mCamera.save();
      mCamera.rotateY(degrees);
      mCamera.getMatrix(matrix);
      mCamera.restore();
    } else if (degrees >= 76.0f) {
      degrees = 90.0f;
      mCamera.save();
      mCamera.rotateY(degrees);
      mCamera.getMatrix(matrix);
      mCamera.restore();
    } else {
      mCamera.save();

      //			mCamera.translate(0, 0, centerX);
      //			mCamera.rotateY(degrees);
      //			mCamera.translate(0, 0, -centerX);

      // 逐渐拉远
      float deltaZ = 120 * LinkLinkApplication.SCREEN_DENSITY * Math.abs(degrees) / 90;
      mCamera.translate(0, 0, deltaZ);
      mCamera.rotateY(degrees);
      mCamera.translate(0, 0, -deltaZ);

      mCamera.getMatrix(matrix);
      mCamera.restore();
    }

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
  }
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    // Angle around the y-axis of the rotation at the given time. It is
    // calculated both in radians and in the equivalent degrees.
    final double radians = Math.PI * interpolatedTime;
    float degrees = (float) (180.0 * radians / Math.PI);

    // Once we reach the midpoint in the animation, we need to hide the
    // source view and show the destination view. We also need to change
    // the angle by 180 degrees so that the destination does not come in
    // flipped around. This is the main problem with SDK sample, it does not
    // do this.
    if (interpolatedTime >= 0.5f) {
      degrees -= 180.f;

      if (!visibilitySwapped) {
        fromView.setVisibility(View.GONE);
        toView.setVisibility(View.VISIBLE);

        visibilitySwapped = true;
      }
    }

    if (forward) degrees = -degrees;

    final Matrix matrix = t.getMatrix();

    camera.save();

    if (translateDirection == DIRECTION_Z) {
      camera.translate(0.0f, 0.0f, (float) (150.0 * Math.sin(radians)));
    } else if (translateDirection == DIRECTION_Y) {
      camera.translate(0.0f, (float) (150.0 * Math.sin(radians)), 0.0f);
    } else {
      camera.translate((float) (150.0 * Math.sin(radians)), 0.0f, 0.0f);
    }

    if (rotationDirection == DIRECTION_Z) {
      camera.rotateZ(degrees);
    } else if (rotationDirection == DIRECTION_Y) {
      camera.rotateY(degrees);
    } else {
      camera.rotateX(degrees);
    }

    //        camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
  }
Beispiel #9
0
  /**
   * Transform the Image Bitmap by the Angle passed
   *
   * @param view 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(View view, Transformation t, int rotationAngle) {
    mCamera.save();
    final Matrix imageMatrix = t.getMatrix();
    final int imageHeight = view.getLayoutParams().height;
    final int imageWidth = view.getLayoutParams().width;
    final int rotation = Math.abs(rotationAngle);

    mCamera.translate(0.0f, 0.0f, 100.0f);

    // As the angle of the view gets less, zoom in
    if (rotation < mMaxRotationAngle) {
      float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
      mCamera.translate(0.0f, 0.0f, zoomAmount);
    }

    mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
    mCamera.restore();
  }
 @Override
 protected void applyTransformation(float interpolatedTime, Transformation t) {
   super.applyTransformation(interpolatedTime, t);
   camera.save();
   camera.translate(width - interpolatedTime * width, 0, 0);
   camera.rotateY(interpolatedTime * 60);
   camera.getMatrix(matrix);
   Logger.e(matrix.toString());
   camera.restore();
   //        matrix.preScale(1,1+interpolatedTime);
   //        matrix.preTranslate(540, 0);
   t.getMatrix().postConcat(matrix);
 }
Beispiel #11
0
  /**
   * 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(ImageView child, Transformation t, float angle, float deltaY) {
    mCamera.save();
    final Matrix imageMatrix = t.getMatrix();
    final int imageHeight = child.getLayoutParams().height;
    final int imageWidth = child.getLayoutParams().width;

    mCamera.translate(0.0f, -(float) deltaY, 0.0f);
    mCamera.rotateZ(angle);
    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
    mCamera.restore();
  }
Beispiel #12
0
  protected void applyTransformation(float var1, Transformation var2) {
    double var3;
    if (this.mReverse) {
      var3 = 0.0D;
    } else {
      double var10 = (double) var1;
      double var12 = 2.6179938779914944D * var10;
      var3 = 2.0943951023931953D + var12;
    }

    Camera var5 = this.mCamera;
    Matrix var6 = var2.getMatrix();
    var5.save();
    if (this.mReverse) {
      float var7 = this.mCenterX * var1;
      float var8 = this.mCenterY * var1;
      float var9 = this.mDepthZ * var1;
      var5.translate(var7, var8, var9);
    } else {
      float var14 = this.mCenterX;
      float var15 = this.mMoveX * var1;
      float var16 = (float) Math.cos(var3);
      float var17 = var15 * var16;
      float var18 = var14 + var17;
      float var19 = this.mCenterY;
      float var20 = this.mMoveY * var1;
      float var21 = (float) Math.sin(var3);
      float var22 = var20 * var21;
      float var23 = var19 - var22;
      float var24 = this.mDepthZ;
      var5.translate(var18, var23, var24);
    }

    var5.getMatrix(var6);
    var5.restore();
  }
Beispiel #13
0
 protected boolean getChildStaticTransformation(View child, Transformation t) {
   t.clear();
   t.setTransformationType(Transformation.TYPE_MATRIX);
   mCamera.save();
   final Matrix imageMatrix = t.getMatrix();
   if (flag) {
     firstChildWidth = getChildAt(0).getWidth();
     Log.i(TAG, "firstChildWidth = " + firstChildWidth);
     firstChildPaddingLeft = getChildAt(0).getPaddingLeft();
     flag = false;
   }
   offsetX = firstChildWidth / 2 + firstChildPaddingLeft + mPaddingLeft - mWidth / 2;
   mCamera.translate(offsetX, 0f, 0f);
   mCamera.getMatrix(imageMatrix);
   mCamera.restore();
   return true;
 }
Beispiel #14
0
  /**
   * Transform an item depending on it's coordinates.
   *
   * @param child the child
   * @param transformation the transformation
   * @return the child static transformation
   */
  @Override
  protected boolean getChildStaticTransformation(View child, Transformation transformation) {

    transformation.clear();
    transformation.setTransformationType(Transformation.TYPE_MATRIX);

    // Center of the view
    float centerX = (float) getWidth() / 2, centerY = (float) getHeight() / 2;

    // Save camera
    mCamera.save();

    // Translate the item to it's coordinates
    final Matrix matrix = transformation.getMatrix();

    mCamera.translate(
        ((CarouselItemView) child).getItemX(),
        ((CarouselItemView) child).getItemY(),
        ((CarouselItemView) child).getItemZ());

    // Align the item
    mCamera.getMatrix(matrix);

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);

    float[] values = new float[9];
    matrix.getValues(values);

    // Restore camera
    mCamera.restore();

    Matrix mm = new Matrix();
    mm.setValues(values);
    ((CarouselItemView) child).setCIMatrix(mm);

    // http://code.google.com/p/android/issues/detail?id=35178
    child.invalidate();
    return true;
  }
  private void prepareMatrix(final Matrix outMatrix, int distanceY, int r) {
    // clip the distance
    final int d = Math.min(r, Math.abs(distanceY));
    // use circle formula
    final float translateZ = (float) Math.sqrt((r * r) - (d * d));

    // solve for t: d = r*cos(t)
    double radians = Math.acos((float) d / r);
    double degree = 90 - (180 / Math.PI) * radians;

    mCamera.save();
    mCamera.translate(0, 0, r - translateZ);
    mCamera.rotateX((float) degree);
    if (distanceY < 0) {
      degree = 360 - degree;
    }
    mCamera.rotateY((float) degree);
    mCamera.getMatrix(outMatrix);
    mCamera.restore();

    // highlight elements in the middle
    mPaint.setColorFilter(calculateLight((float) degree));
  }
Beispiel #16
0
  void rotate(int degreeX, Bitmap turnBmpBack) {

    deltaX += degreeX;

    if (isLR) {

      if (deltaX > 180) {
        deltaX = 180;
      } else if (deltaX < 0) {
        deltaX = 0;
      } else if (deltaX > 90) {
        tmpLbmp = turnBmpBack;
      } else if (deltaX < 90) {
        tmpLbmp = Lbmp;
      }

      mCamera.save();
      mCamera.rotateY(deltaX);
      mCamera.translate(-centerX, 0, 0);
      mCamera.getMatrix(mMatrix);
      mCamera.restore();

      mMatrix.preTranslate(0, -centerY);
      mMatrix.postTranslate(centerX, centerY);

      Log.d(LOGTAG, "rotate you click [LEFT] deltaX " + deltaX);
    } else {

      if (deltaX < -180) {
        deltaX = -180;
      } else if (deltaX > 0) {
        deltaX = 0;
      } else if (deltaX < -90) {

        tmpRbmp = turnBmpBack;
      } else if (deltaX > -90) {
        tmpRbmp = Rbmp;
      }

      mCamera.save();
      mCamera.translate(0, 0, -1);
      mCamera.rotateY(deltaX);
      mCamera.getMatrix(mMatrix);
      mCamera.restore();

      mMatrix.preTranslate(0, -centerY);
      mMatrix.postTranslate(0, centerY);

      Log.d(LOGTAG, "rotate you click [RIGHT] deltaX " + deltaX);
    }

    mCamera.save();

    shadowX = (float) (centerX * Math.cos(Math.abs(deltaX * 1d)));

    Log.d(
        LOGTAG,
        "rotate shadowX >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "
            + shadowX
            + " Math.abs(deltaX*1d)) = "
            + Math.abs(deltaX * 1d)
            + "Math.cos(Math.abs(deltaX*1d) = "
            + Math.cos(Math.abs(deltaX * 1d)));
    Log.d(
        LOGTAG,
        "rotate shadowX >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Math.cos(75) = "
            + Math.cos(75.0 * 180 / Math.PI));
    postInvalidate();
  }