Exemplo n.º 1
1
  @Override
  public boolean getWorkspaceChildStaticTransformation(
      ViewGroup parent,
      View view,
      Transformation transformation,
      Camera camera,
      float ratio,
      int currentScreen,
      float indicatorOffset,
      boolean isPortrait) {
    // TODO Auto-generated method stub
    float width = 0.0f;
    float height = 0.0f;
    float angle = 0.0f;
    Matrix matrix = transformation.getMatrix();

    if (isPortrait) {
      width = view.getMeasuredWidth();
      height = view.getMeasuredHeight() - indicatorOffset;

      angle = -90.0f * ratio;
      matrix.setRotate(angle, width / 2.0f, height);
    } else {
      width = view.getMeasuredWidth() - indicatorOffset;
      height = view.getMeasuredHeight();

      angle = 90.0f * ratio;
      matrix.setRotate(angle, width, height / 2.0f);
    }

    transformation.setTransformationType(Transformation.TYPE_MATRIX);
    return true;
  }
  /**
   * 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();
  }
Exemplo n.º 3
0
 protected void applyTransformation(float interpolatedTime, Transformation t) {
   View view = mView.get();
   if (view != null) {
     t.setAlpha(mAlpha);
     transformMatrix(t.getMatrix(), view);
   }
 }
 // 控制gallery中每个图片的旋转(重写的gallery中方法)
 protected boolean getChildStaticTransformation(View child, Transformation t) {
   // 取得当前子view的半径值
   final int childCenter = getCenterOfView(child);
   System.out.println("childCenter:" + childCenter);
   final int childWidth = child.getWidth();
   // 旋转角度
   int rotationAngle = 0;
   // 重置转换状态
   t.clear();
   // 设置转换类型
   t.setTransformationType(Transformation.TYPE_MATRIX);
   // 如果图片位于中心位置不需要进行旋转
   if (childCenter == mCoveflowCenter) {
     transformImageBitmap((ImageView) child, t, 0);
   } else {
     // 根据图片在gallery中的位置来计算图片的旋转角度
     rotationAngle =
         (int) (((float) (mCoveflowCenter - childCenter) / childWidth) * mMaxRotationAngle);
     System.out.println("rotationAngle:" + rotationAngle);
     // 如果旋转角度绝对值大于最大旋转角度返回(-mMaxRotationAngle或mMaxRotationAngle;)
     if (Math.abs(rotationAngle) > mMaxRotationAngle) {
       rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle : mMaxRotationAngle;
     }
     transformImageBitmap((ImageView) child, t, rotationAngle);
   }
   return true;
 }
Exemplo n.º 5
0
  // 重写Garray方法 ,产生层叠和放大效果
  @Override
  protected boolean getChildStaticTransformation(View child, Transformation t) {
    final int childCenter = getCenterOfView(child);
    final int childWidth = child.getWidth();
    int rotationAngle = 0;
    t.clear();
    t.setTransformationType(Transformation.TYPE_MATRIX);
    if (childCenter == mCoveflowCenter) {
      transformImageBitmap(child, t, 0, 0);
    } else {
      rotationAngle =
          (int) (((float) (mCoveflowCenter - childCenter) / childWidth) * mMaxRotationAngle);
      // Log.d("test", "recanglenum:"+Math.floor ((mCoveflowCenter -
      // childCenter) / childWidth));

      /*
       * if (Math.abs(rotationAngle) > mMaxRotationAngle) { rotationAngle
       * = (rotationAngle < 0) ? -mMaxRotationAngle : mMaxRotationAngle; }
       */
      transformImageBitmap(
          child,
          t,
          rotationAngle,
          (int) Math.floor((mCoveflowCenter - childCenter) / (childWidth == 0 ? 1 : childWidth)));
    }
    return true;
  }
Exemplo n.º 6
0
  public void drawNinePatch(NinePatchTexture tex, int x, int y, int width, int height) {

    NinePatchChunk chunk = tex.getNinePatchChunk();

    // The code should be easily extended to handle the general cases by
    // allocating more space for buffers. But let's just handle the only
    // use case.
    if (chunk.mDivX.length != 2 || chunk.mDivY.length != 2) {
      throw new RuntimeException("unsupported nine patch");
    }
    if (!tex.bind(this, mGL)) {
      throw new RuntimeException("cannot bind" + tex.toString());
    }
    if (width <= 0 || height <= 0) return;

    int divX[] = mNinePatchX;
    int divY[] = mNinePatchY;
    float divU[] = mNinePatchU;
    float divV[] = mNinePatchV;

    int nx = stretch(divX, divU, chunk.mDivX, tex.getWidth(), width);
    int ny = stretch(divY, divV, chunk.mDivY, tex.getHeight(), height);

    setAlphaValue(mTransformation.getAlpha());
    Matrix matrix = mTransformation.getMatrix();
    matrix.getValues(mMatrixValues);
    GL11 gl = mGL;
    gl.glPushMatrix();
    gl.glMultMatrixf(toGLMatrix(mMatrixValues), 0);
    gl.glTranslatef(x, y, 0);
    drawMesh(divX, divY, divU, divV, nx, ny);
    gl.glPopMatrix();
  }
Exemplo n.º 7
0
  /**
   * {@inheritDoc}
   *
   * @see #setStaticTransformationsEnabled(boolean)
   */
  protected boolean getChildStaticTransformation(View child, Transformation t) {
    final int childCenter = getCenterOfView(child);
    float RADIUS = DensityUtil.dip2px(mContext, CAROUSEL_RADIUS);
    float rotationAngle;
    float deltaY;

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

    if (childCenter == mCoveflowCenter) {
      transformImageBitmap((ImageView) child, t, 0, 0);
    } else {
      float deltaX = (float) (mCoveflowCenter - childCenter);

      rotationAngle = (float) Math.toDegrees(Math.asin(deltaX / RADIUS));
      deltaY = RADIUS - (float) Math.sqrt(RADIUS * RADIUS - deltaX * deltaX);

      Log.v("ANGLE", "delta x is " + deltaX);
      Log.v("ANGLE", "rotate agle is:" + rotationAngle);

      transformImageBitmap((ImageView) child, t, rotationAngle, deltaY);
    }

    return true;
  }
Exemplo n.º 8
0
  // CHECKSTYLE:OFF unchanged method
  @Override
  protected boolean getChildStaticTransformation(final View child, final Transformation t) {

    t.clear();
    t.setAlpha(child == mSelectedChild ? 1.0f : mUnselectedAlpha);

    return true;
  }
Exemplo n.º 9
0
 public Transformation obtainTransformation() {
   if (!mFreeTransform.isEmpty()) {
     Transformation t = mFreeTransform.pop();
     t.clear();
     return t;
   }
   return new Transformation();
 }
Exemplo n.º 10
0
 @Override
 protected boolean getChildStaticTransformation(View child, Transformation t) {
   Matrix m = getViewMatrix(child);
   if (m != null) {
     t.getMatrix().set(m);
     t.setTransformationType(Transformation.TYPE_MATRIX);
     return true;
   } else {
     return false;
   }
 }
Exemplo n.º 11
0
  /*
   * interpolatedTime 动画从0开始到1结束 t 动画的属性
   */
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {

    Matrix m = t.getMatrix();
    m.setTranslate((float) (Math.sin(interpolatedTime * 10) * 15), 0);
    if (state == 0) {
      t.setAlpha(interpolatedTime);
    } else {
      t.setAlpha(1 - interpolatedTime);
    }

    super.applyTransformation(interpolatedTime, t);
  }
Exemplo n.º 12
0
  @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 (mDirection == ROTATION_X) camera.rotateX(degrees);
    else camera.rotateY(degrees);

    camera.getMatrix(matrix);
    camera.restore();

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

    matrix.preScale(
        scaleType.getScale(scale, interpolatedTime),
        scaleType.getScale(scale, interpolatedTime),
        centerX,
        centerY);
  }
Exemplo n.º 13
0
  @Override
  protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Drawable d = mCurrentDrawable;
    if (d != null) {
      // Translate canvas so a indeterminate circular progress bar with padding
      // rotates properly in its animation
      canvas.save();
      canvas.translate(mPaddingLeft, mPaddingTop);
      long time = getDrawingTime();
      if (mAnimation != null) {
        mAnimation.getTransformation(time, mTransformation);
        float scale = mTransformation.getAlpha();
        try {
          mInDrawing = true;
          d.setLevel((int) (scale * MAX_LEVEL));
        } finally {
          mInDrawing = false;
        }
        if (SystemClock.uptimeMillis() - mLastDrawTime >= ANIMATION_RESOLUTION) {
          mLastDrawTime = SystemClock.uptimeMillis();
          postInvalidateDelayed(ANIMATION_RESOLUTION);
        }
      }
      d.draw(canvas);
      canvas.restore();
      if (mShouldStartAnimationDrawable && d instanceof Animatable) {
        ((Animatable) d).start();
        mShouldStartAnimationDrawable = false;
      }
    }
  }
Exemplo n.º 14
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();
  }
Exemplo n.º 15
0
  @Override
  protected void onDraw(Canvas canvas) {
    if (mImage != null) {
      // Switch the current animation if needed.
      if (mCurrentAnim == null || mCurrentAnim.hasEnded()) switchAnimation(canvas);

      // Animate and draw
      mCurrentAnim.getTransformation(AnimationUtils.currentAnimationTimeMillis(), mTrans);
      mStartPos[0] = 0;
      mStartPos[1] = 0;
      mTrans.getMatrix().mapPoints(mStartPos);

      mSrc.set(0, 0, mImage.getWidth(), mImage.getHeight());
      mDst.set(
          (int) mStartPos[0],
          (int) mStartPos[1],
          (int) mStartPos[0] + mScaledImageWidth,
          (int) mStartPos[1] + mScaledImageHeight);
      mPaint.setFilterBitmap(true);
      canvas.drawBitmap(mImage, mSrc, mDst, mPaint);
      super.onDraw(canvas);

      // Request another draw operation until time is up.
      invalidate();
    }
  }
Exemplo n.º 16
0
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

    final Matrix matrix = t.getMatrix();

    mCamera.save();
    switch (mRollType) {
      case ROLL_BY_X:
        mCamera.rotateX(degrees);
        break;
      case ROLL_BY_Y:
        mCamera.rotateY(degrees);
        break;
      case ROLL_BY_Z:
        mCamera.rotateZ(degrees);
        break;
    }
    mCamera.getMatrix(matrix);
    mCamera.restore();

    matrix.preTranslate(-mPivotX, -mPivotY);
    matrix.postTranslate(mPivotX, mPivotY);
  }
Exemplo n.º 17
0
  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();
  }
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    // Angle around the y-axis of the rotation at the given time
    // calculated both in radians and 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
    if (interpolatedTime >= 0.5f) {
      degrees -= 180.f;
      fromView.setVisibility(View.GONE);
      toView.setVisibility(View.VISIBLE);
    }

    if (forward) degrees = -degrees; // determines direction of rotation when flip begins

    final Matrix matrix = t.getMatrix();
    camera.save();
    camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();
    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
  }
Exemplo n.º 19
0
  /**
   * Starts the animation and sets view visible
   *
   * @see android.widget.ProgressBar#startAnimation() for rotation logic
   */
  public void startAnimating() {
    if (!isAnimating) {
      isAnimating = true;
      setVisibility(VISIBLE);

      if (mInterpolator == null) {
        mInterpolator = new LinearInterpolator();
      }

      if (mTransformation == null) {
        mTransformation = new Transformation();
      } else {
        mTransformation.clear();
      }

      if (mAnimation == null) {
        mAnimation = new AlphaAnimation(0.0f, 1.0f);
      } else {
        mAnimation.reset();
      }

      mAnimation.setRepeatMode(AlphaAnimation.RESTART);
      mAnimation.setRepeatCount(Animation.INFINITE);
      mAnimation.setDuration(ANIMATION_DURATION);
      mAnimation.setInterpolator(mInterpolator);
      mAnimation.setStartTime(Animation.START_ON_FIRST_FRAME);
    }
  }
 // ���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);
 }
Exemplo n.º 21
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();
 }
Exemplo n.º 22
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);
  }
Exemplo n.º 23
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;
 }
 protected boolean getChildStaticTransformation(View child, Transformation t) {
   final int childCenter = getCenterOfView(child);
   final int childWidth = child.getWidth();
   int rotationAngle = 0;
   t.clear();
   t.setTransformationType(Transformation.TYPE_MATRIX);
   if (childCenter == mCoveflowCenter) {
     transformBitmap(child, t, 0);
   } else {
     rotationAngle =
         (int) (((float) (mCoveflowCenter - childCenter) / childWidth) * mMaxRotationAngle);
     if (Math.abs(rotationAngle) > mMaxRotationAngle) {
       rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle : mMaxRotationAngle;
     }
     transformBitmap(child, t, rotationAngle);
   }
   return true;
 }
Exemplo n.º 25
0
  void updateSurfacesInTransaction() {
    if (!mStarted) {
      return;
    }

    if (mSurface != null) {
      if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
        if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
        mSurface.hide();
      }
    }

    if (mCustomBlackFrame != null) {
      if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
        if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
        mCustomBlackFrame.hide();
      } else {
        mCustomBlackFrame.setMatrix(mFrameTransformation.getMatrix());
      }
    }

    if (mExitingBlackFrame != null) {
      if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
        if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding exiting frame");
        mExitingBlackFrame.hide();
      } else {
        mExitFrameFinalMatrix.setConcat(mExitTransformation.getMatrix(), mFrameInitialMatrix);
        mExitingBlackFrame.setMatrix(mExitFrameFinalMatrix);
      }
    }

    if (mEnteringBlackFrame != null) {
      if (!mMoreStartEnter && !mMoreFinishEnter && !mMoreRotateEnter) {
        if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding entering frame");
        mEnteringBlackFrame.hide();
      } else {
        mEnteringBlackFrame.setMatrix(mEnterTransformation.getMatrix());
      }
    }

    setSnapshotTransformInTransaction(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
  }
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float degrees = mFromDegrees + ((mToDegrees - mFromDegrees) * interpolatedTime);
    if (mPivotX == 0.0f && mPivotY == 0.0f) {
      t.getMatrix().setRotate(degrees);
    } else {
      t.getMatrix().setRotate(degrees, mPivotX, mPivotY);
    }

    float dx = mFromXDelta;
    float dy = mFromYDelta;
    if (mFromXDelta != mToXDelta) {
      dx = mFromXDelta + ((mToXDelta - mFromXDelta) * interpolatedTime);
    }
    if (mFromYDelta != mToYDelta) {
      dy = mFromYDelta + ((mToYDelta - mFromYDelta) * interpolatedTime);
    }

    t.getMatrix().postTranslate(dx, dy);
  }
Exemplo n.º 27
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();

    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);
  }
Exemplo n.º 28
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;
  }
  @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);
  }
Exemplo n.º 30
0
 @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);
 }