@Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.vertical_viewpager);
   viewPager = (ViewPager) findViewById(R.id.viewpager);
   LayoutInflater inflater = LayoutInflater.from(this);
   View view = inflater.inflate(R.layout.ad_img_0, null);
   view.setRotation(-90.0f);
   views.add(view);
   titles.add("ImageView");
   view = inflater.inflate(R.layout.ad_img_0, null);
   view.setRotation(-90.0f);
   views.add(view);
   titles.add("ImageView");
   view = inflater.inflate(R.layout.ad_img_0, null);
   view.setRotation(-90.0f);
   views.add(view);
   titles.add("ImageView");
   view = inflater.inflate(R.layout.ad_img_0, null);
   view.setRotation(-90.0f);
   views.add(view);
   titles.add("ImageView");
   viewPager.setAdapter(new MyPagerAdapter(views, titles));
   viewPager.setRotation(90);
   viewPager.setHorizontalScrollBarEnabled(false);
   viewPager.setVerticalScrollBarEnabled(true);
 }
Exemple #2
0
 /** Move in response to touch. */
 public void move(final View photo, float x, float y, float a) {
   photo.animate().cancel();
   photo.setAlpha(1f);
   photo.setX((int) x);
   photo.setY((int) y);
   photo.setRotation((int) a);
 }
Exemple #3
0
 public void setRotation(float rotation) {
   if (NEEDS_PROXY) {
     wrap(this).setRotation(rotation);
   } else {
     super.setRotation(rotation);
   }
 }
 public void setOrientation(Orientation orientation) {
   if (orientation == null) throw new NullPointerException("Orientation may not be null");
   if (mOrientation != orientation) {
     this.mOrientation = orientation;
     if (orientation == Orientation.Disordered) {
       for (int i = 0; i < getChildCount(); i++) {
         View child = getChildAt(i);
         child.setRotation(getDisorderedRotation());
       }
     } else {
       for (int i = 0; i < getChildCount(); i++) {
         View child = getChildAt(i);
         child.setRotation(0);
       }
     }
     requestLayout();
   }
 }
Exemple #5
0
  /** Wind up off screen, so we can animate in. */
  private void throwOnTable(final View photo) {
    mOnTable.offer(photo);
    log("start offscreen");
    photo.setRotation(mThrowRotation);
    photo.setX(-mLongSide);
    photo.setY(-mLongSide);

    dropOnTable(photo, mThrowInterpolator);
  }
  @Override
  protected void onTransform(View view, float position) {
    final float width = view.getWidth();
    final float rotation = ROT_MOD * position;

    view.setPivotX(width * 0.5f);
    view.setPivotY(0f);
    view.setTranslationX(0f);
    view.setRotation(rotation);
  }
 /**
  * reset the view to default status
  *
  * @param target the target
  */
 public void reset(View target) {
   target.setAlpha(1);
   target.setScaleX(1);
   target.setScaleY(1);
   target.setTranslationX(0);
   target.setTranslationY(0);
   target.setRotation(0);
   target.setRotationY(0);
   target.setRotationX(0);
   target.setPivotX(target.getMeasuredWidth() / 2.0f);
   target.setPivotY(target.getMeasuredHeight() / 2.0f);
 }
  public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();
    int pageHeight = view.getHeight();
    view.setPivotX((float) pageWidth / 2);
    view.setPivotY((float) (pageHeight + pageWidth * distanceToCentreFactor));

    if (position < -1) { // [-infinity,1)
      // off to the left by a lot
      view.setRotation(0);
      view.setAlpha(0);
      view.setTranslationX(0);
    } else if (position <= 1) { // [-1,1]
      view.setTranslationX((-position) * pageWidth);
      view.setRotation(position * (180 - degrees));

      // Fade the page relative to its distance from the center
      view.setAlpha(Math.max(minAlpha, 1 - Math.abs(position) / 3));
    } else { // (1, +infinity]
      // off to the right by a lot
      view.setRotation(0);
      view.setAlpha(0);
      view.setTranslationX(0);
    }
  }
 public void animateGesture(
     float offsetStartX, float offsetStartY, float offsetEndX, float offsetEndY) {
   mHandy =
       ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
           .inflate(R.layout.handy, null);
   addView(mHandy);
   mHandy.setRotation(mOrientation);
   moveHand(
       offsetStartX,
       offsetStartY,
       offsetEndX,
       offsetEndY,
       new AnimationEndListener() {
         @Override
         public void onAnimationEnd() {
           removeView(mHandy);
         }
       });
 }
 private GuillotineAnimation(GuillotineBuilder builder) {
   this.mActionBarView = builder.actionBarView;
   this.mListener = builder.guillotineListener;
   this.mGuillotineView = builder.guillotineView;
   this.mDuration = builder.duration > 0 ? builder.duration : DEFAULT_DURATION;
   this.mDelay = builder.startDelay;
   this.mIsRightToLeftLayout = builder.isRightToLeftLayout;
   this.mInterpolator =
       builder.interpolator == null ? new GuillotineInterpolator() : builder.interpolator;
   setUpOpeningView(builder.openingView);
   setUpClosingView(builder.closingView);
   this.mOpeningAnimation = buildOpeningAnimation();
   this.mClosingAnimation = buildClosingAnimation();
   if (builder.isClosedOnStart) {
     mGuillotineView.setRotation(GUILLOTINE_CLOSED_ANGLE);
     mGuillotineView.setVisibility(View.GONE);
   }
   // TODO handle right-to-left layouts
   // TODO handle landscape orientation
 }
  private void ensureFull() {
    while (mNextAdapterPosition < mListAdapter.getCount() && getChildCount() < mMaxVisible) {
      View view = mListAdapter.getView(mNextAdapterPosition, null, this);
      view.setLayerType(LAYER_TYPE_SOFTWARE, null);
      if (mOrientation == Orientation.Disordered) {
        view.setRotation(getDisorderedRotation());
      }
      addViewInLayout(
          view,
          0,
          new LayoutParams(
              LayoutParams.WRAP_CONTENT,
              LayoutParams.WRAP_CONTENT,
              mListAdapter.getItemViewType(mNextAdapterPosition)),
          false);

      requestLayout();

      mNextAdapterPosition += 1;
    }
  }
  /**
   * Translate a view to the specified translation values, while rotating to the specified rotation
   * value.
   */
  public static void addTranslationRotationAnimators(
      List<Animator> animators,
      final View view,
      int xTranslation,
      int yTranslation,
      float rotation,
      int animationDelay) {
    addXYTranslationAnimators(animators, view, xTranslation, yTranslation, animationDelay);

    view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    view.setRotation(rotation);

    final ObjectAnimator rotateAnimatorY =
        ObjectAnimator.ofFloat(view, View.ROTATION, view.getRotation(), 0.0f);
    rotateAnimatorY.setInterpolator(sDecelerateQuintInterpolator);
    rotateAnimatorY.setDuration(sAnimationDuration);
    rotateAnimatorY.setStartDelay(animationDelay);
    rotateAnimatorY.addListener(
        new AnimatorListenerAdapter() {
          private boolean mIsCanceled = false;

          @Override
          public void onAnimationCancel(Animator animation) {
            mIsCanceled = true;
          }

          @Override
          public void onAnimationEnd(Animator animation) {
            if (!mIsCanceled) {
              view.setRotation(0);
            }

            view.setLayerType(View.LAYER_TYPE_NONE, null);
          }
        });

    animators.add(rotateAnimatorY);
  }
Exemple #13
0
  /** Animate the selected photo to the foreground: zooming in to bring it forward. */
  private void pickUp(final View photo) {
    float photoWidth = photo.getWidth();
    float photoHeight = photo.getHeight();

    float scale = Math.min(getHeight() / photoHeight, getWidth() / photoWidth);

    log("scale is %f", scale);
    log("target it");
    float x = (getWidth() - photoWidth) / 2f;
    float y = (getHeight() - photoHeight) / 2f;

    photo.setRotation(wrapAngle(photo.getRotation()));

    log("animate it");
    // lift up to the glass for a good look
    mWaitingToJoinBackground.remove(photo);
    moveToForeground(photo);
    photo
        .animate()
        .withLayer()
        .rotation(0f)
        .rotationY(0f)
        .alpha(1f)
        .scaleX(scale)
        .scaleY(scale)
        .x(x)
        .y(y)
        .setDuration(mPickUpDuration)
        .setInterpolator(new DecelerateInterpolator(2f))
        .withEndAction(
            new Runnable() {
              @Override
              public void run() {
                log("endtimes: %f", photo.getX());
              }
            });
  }
 @Override
 public void setRotation(View view, float rotation) {
   view.setRotation(rotation);
 }
Exemple #15
0
  private void dealScroll() {
    // 最小缩放值
    float progress = 1 - getScrollX() * 1.0f / (mScreenWidth - mMenuOffset);
    // 移动动画处理
    switch (mTransInt) {
      case 1:
        mMenuView.setTranslationX(getScrollX());
        break;
      case 2:
        break;
      case 3:
        mMenuView.setTranslationX(getScrollX() * progress);
        break;
    }
    // 状态栏跟随内容区域滑动
    if (isTranslate) {
      statusView.setTranslationX(progress * (mScreenWidth - mMenuOffset));
    }
    // 缩放动画处理
    if (mScaleInt == 2) {
      mMenuView.setScaleX(progress * (1 - mStartScale) + mStartScale);
      mMenuView.setScaleY(progress * (1 - mStartScale) + mStartScale);
    }
    // 透明动画处理
    if (mAlphaInt == 2) {
      mMenuView.setAlpha(mStartAlpha + (1 - mStartAlpha) * progress);
    }
    // 旋转动画处理
    switch (mRotateInt) {
      case 2: // 中心
        mMenuView.setPivotX(mMenuView.getWidth() / 2);
        mMenuView.setPivotY(mMenuView.getHeight() / 2);
        mMenuView.setRotation(progress * 360);

        break;
      case 3: // 3D左侧翻转
        mMenuView.setPivotX(0);
        mMenuView.setPivotY(mMenuView.getHeight() / 2);
        mMenuView.setRotationY(progress * -(90 - mStart3DAngle) + (90 - mStart3DAngle));
        break;
      case 4: // x翻转
        mMenuView.setPivotX(0);
        mMenuView.setPivotY(0);
        mMenuView.setRotation(progress * -90 + 90);
        break;
      case 5: // 左上角
        mMenuView.setPivotX(mMenuView.getWidth() / 2);
        mMenuView.setPivotY(mMenuView.getHeight() / 2);
        mMenuView.setRotationX(progress * -(45) + 45);
        break;
      case 6: // 左下角
        mMenuView.setPivotX(0);
        mMenuView.setPivotY(mMenuView.getHeight());
        mMenuView.setRotation(progress * +90 + -90);
        break;
    }
    // 渐变状态栏
    if (mListener != null) { // 进度监听
      mListener.onProgressChange(progress);
    }
    // 设置动态模糊
    if (mBackImageView != null) {
      mBackImageView.setAlpha(progress);
    }
  }
Exemple #16
0
 static void setRotation(View view, float rotation) {
   view.setRotation(rotation);
 }
 public static void setRotation(View view, float f) {
   view.setRotation(f);
 }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (mTopCard == null) {
      return false;
    }
    if (mGestureDetector.onTouchEvent(event)) {
      return true;
    }
    // Log.d("Touch Event", MotionEvent.actionToString(event.getActionMasked()) + " ");
    final int pointerIndex;
    final float x, y;
    final float dx, dy;
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        mTopCard.getHitRect(childRect);

        pointerIndex = event.getActionIndex();
        x = event.getX(pointerIndex);
        y = event.getY(pointerIndex);

        if (!childRect.contains((int) x, (int) y)) {
          return false;
        }
        mLastTouchX = x;
        mLastTouchY = y;
        mActivePointerId = event.getPointerId(pointerIndex);

        float[] points = new float[] {x - mTopCard.getLeft(), y - mTopCard.getTop()};
        mTopCard.getMatrix().invert(mMatrix);
        mMatrix.mapPoints(points);
        mTopCard.setPivotX(points[0]);
        mTopCard.setPivotY(points[1]);

        break;
      case MotionEvent.ACTION_MOVE:
        pointerIndex = event.findPointerIndex(mActivePointerId);
        x = event.getX(pointerIndex);
        y = event.getY(pointerIndex);

        dx = x - mLastTouchX;
        dy = y - mLastTouchY;

        if (Math.abs(dx) > mTouchSlop || Math.abs(dy) > mTouchSlop) {
          mDragging = true;
        }

        if (!mDragging) {
          return true;
        }

        mTopCard.setTranslationX(mTopCard.getTranslationX() + dx);
        mTopCard.setTranslationY(mTopCard.getTranslationY() + dy);

        mTopCard.setRotation(40 * mTopCard.getTranslationX() / (getWidth() / 2.f));

        mLastTouchX = x;
        mLastTouchY = y;
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (!mDragging) {
          return true;
        }
        mDragging = false;
        mActivePointerId = INVALID_POINTER_ID;
        ValueAnimator animator =
            ObjectAnimator.ofPropertyValuesHolder(
                    mTopCard,
                    PropertyValuesHolder.ofFloat("translationX", 0),
                    PropertyValuesHolder.ofFloat("translationY", 0),
                    PropertyValuesHolder.ofFloat(
                        "rotation",
                        (float)
                            Math.toDegrees(
                                mRandom.nextGaussian() * DISORDERED_MAX_ROTATION_RADIANS)),
                    PropertyValuesHolder.ofFloat("pivotX", mTopCard.getWidth() / 2.f),
                    PropertyValuesHolder.ofFloat("pivotY", mTopCard.getHeight() / 2.f))
                .setDuration(250);
        animator.setInterpolator(new AccelerateInterpolator());
        animator.start();
        break;
      case MotionEvent.ACTION_POINTER_UP:
        pointerIndex = event.getActionIndex();
        final int pointerId = event.getPointerId(pointerIndex);

        if (pointerId == mActivePointerId) {
          final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
          mLastTouchX = event.getX(newPointerIndex);
          mLastTouchY = event.getY(newPointerIndex);

          mActivePointerId = event.getPointerId(newPointerIndex);
        }
        break;
    }

    return true;
  }
  public synchronized void place(View v, Point pt, boolean animate) {
    final int i = pt.x;
    final int j = pt.y;
    final float rnd = frand();
    if (v.getTag(TAG_POS) != null) {
      for (final Point oc : getOccupied(v)) {
        mFreeList.add(oc);
        mCells[oc.y * mColumns + oc.x] = null;
      }
    }
    int scale = 1;
    if (rnd < PROB_4X) {
      if (!(i >= mColumns - 3 || j >= mRows - 3)) {
        scale = 4;
      }
    } else if (rnd < PROB_3X) {
      if (!(i >= mColumns - 2 || j >= mRows - 2)) {
        scale = 3;
      }
    } else if (rnd < PROB_2X) {
      if (!(i == mColumns - 1 || j == mRows - 1)) {
        scale = 2;
      }
    }

    v.setTag(TAG_POS, pt);
    v.setTag(TAG_SPAN, scale);

    tmpSet.clear();

    final Point[] occupied = getOccupied(v);
    for (final Point oc : occupied) {
      final View squatter = mCells[oc.y * mColumns + oc.x];
      if (squatter != null) {
        tmpSet.add(squatter);
      }
    }

    for (final View squatter : tmpSet) {
      for (final Point sq : getOccupied(squatter)) {
        mFreeList.add(sq);
        mCells[sq.y * mColumns + sq.x] = null;
      }
      if (squatter != v) {
        squatter.setTag(TAG_POS, null);
        if (animate) {
          squatter
              .animate()
              .withLayer()
              .scaleX(0.5f)
              .scaleY(0.5f)
              .alpha(0)
              .setDuration(DURATION)
              .setInterpolator(new AccelerateInterpolator())
              .setListener(
                  new Animator.AnimatorListener() {
                    public void onAnimationStart(Animator animator) {}

                    public void onAnimationEnd(Animator animator) {
                      removeView(squatter);
                    }

                    public void onAnimationCancel(Animator animator) {}

                    public void onAnimationRepeat(Animator animator) {}
                  })
              .start();
        } else {
          removeView(squatter);
        }
      }
    }

    for (final Point oc : occupied) {
      mCells[oc.y * mColumns + oc.x] = v;
      mFreeList.remove(oc);
    }

    final float rot = (float) irand(0, 4) * 90f;

    if (animate) {
      v.bringToFront();

      AnimatorSet set1 = new AnimatorSet();
      set1.playTogether(
          ObjectAnimator.ofFloat(v, View.SCALE_X, (float) scale),
          ObjectAnimator.ofFloat(v, View.SCALE_Y, (float) scale));
      set1.setInterpolator(new AnticipateOvershootInterpolator());
      set1.setDuration(DURATION);

      AnimatorSet set2 = new AnimatorSet();
      set2.playTogether(
          ObjectAnimator.ofFloat(v, View.ROTATION, rot),
          ObjectAnimator.ofFloat(v, View.X, i * mCellSize + (scale - 1) * mCellSize / 2),
          ObjectAnimator.ofFloat(v, View.Y, j * mCellSize + (scale - 1) * mCellSize / 2));
      set2.setInterpolator(new DecelerateInterpolator());
      set2.setDuration(DURATION);

      set1.addListener(makeHardwareLayerListener(v));

      set1.start();
      set2.start();
    } else {
      v.setX(i * mCellSize + (scale - 1) * mCellSize / 2);
      v.setY(j * mCellSize + (scale - 1) * mCellSize / 2);
      v.setScaleX((float) scale);
      v.setScaleY((float) scale);
      v.setRotation(rot);
    }
  }