Esempio n. 1
0
    /** アニメーションの処理を行います。 */
    @Override
    public void handleMessage(Message msg) {
      final FloatingView floatingView = mFloatingView.get();
      if (floatingView == null) {
        removeMessages(ANIMATION_IN_TOUCH);
        return;
      }

      final int animationCode = msg.what;
      final int animationType = msg.arg1;
      final WindowManager.LayoutParams params = floatingView.mParams;
      final WindowManager windowManager = floatingView.mWindowManager;

      // 状態変更またはアニメーションを開始した場合の初期化
      if (mIsChangeState || animationType == TYPE_FIRST) {
        // 状態変更時のみアニメーション時間を使う
        mStartTime = mIsChangeState ? SystemClock.uptimeMillis() : 0;
        mStartX = params.x;
        mStartY = params.y;
        mStartedCode = animationCode;
        mIsChangeState = false;
      }
      // 経過時間
      final float elapsedTime = SystemClock.uptimeMillis() - mStartTime;
      final float trackingTargetTimeRate = Math.min(elapsedTime / CAPTURE_DURATION_MILLIS, 1.0f);

      // 重なっていない場合のアニメーション
      if (mState == FloatingView.STATE_NORMAL) {
        final float basePosition = calcAnimationPosition(trackingTargetTimeRate);
        // 画面外へのオーバーを認める
        final Rect moveLimitRect = floatingView.mMoveLimitRect;
        // 最終的な到達点
        final float targetPositionX =
            Math.min(Math.max(moveLimitRect.left, (int) mTouchPositionX), moveLimitRect.right);
        final float targetPositionY =
            Math.min(Math.max(moveLimitRect.top, (int) mTouchPositionY), moveLimitRect.bottom);
        params.x = (int) (mStartX + (targetPositionX - mStartX) * basePosition);
        params.y = (int) (mStartY + (targetPositionY - mStartY) * basePosition);
        windowManager.updateViewLayout(floatingView, params);
        sendMessageAtTime(
            newMessage(animationCode, TYPE_UPDATE),
            SystemClock.uptimeMillis() + ANIMATION_REFRESH_TIME_MILLIS);
      }
      // 重なった場合のアニメーション
      else if (mState == FloatingView.STATE_INTERSECTING) {
        final float basePosition = calcAnimationPosition(trackingTargetTimeRate);
        // 最終的な到達点
        final float targetPositionX = mTargetPositionX - floatingView.getWidth() / 2;
        final float targetPositionY = mTargetPositionY - floatingView.getHeight() / 2;
        // 現在地からの移動
        params.x = (int) (mStartX + (targetPositionX - mStartX) * basePosition);
        params.y = (int) (mStartY + (targetPositionY - mStartY) * basePosition);
        windowManager.updateViewLayout(floatingView, params);
        sendMessageAtTime(
            newMessage(animationCode, TYPE_UPDATE),
            SystemClock.uptimeMillis() + ANIMATION_REFRESH_TIME_MILLIS);
      }
    }
Esempio n. 2
0
    @Override
    public void handleMessage(Message msg) {
      FloatingView view = mFloatingView.get();
      if (view == null) {
        removeMessages(LONG_PRESSED);
        return;
      }

      view.onLongClick();
    }