Пример #1
1
  private Animator createHideItemAnimator(final View item) {
    final float dx = centerItem.getX() - item.getX();
    final float dy = centerItem.getY() - item.getY();

    Animator anim =
        ObjectAnimator.ofPropertyValuesHolder(
            item,
            AnimatorUtils.scaleX(1f, 0f),
            AnimatorUtils.scaleY(1f, 0f),
            AnimatorUtils.translationX(0f, dx),
            AnimatorUtils.translationY(0f, dy));

    anim.setInterpolator(new DecelerateInterpolator());
    anim.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            item.setTranslationX(0f);
            item.setTranslationY(0f);
          }
        });
    anim.setDuration(50);
    return anim;
  }
Пример #2
1
 public void move(final View photo, float dx, float dy, boolean drop) {
   if (photo != null) {
     final float x = photo.getX() + dx;
     final float y = photo.getY() + dy;
     photo.setX(x);
     photo.setY(y);
     Log.d(TAG, "[" + photo.getX() + ", " + photo.getY() + "] + (" + dx + "," + dy + ")");
     if (drop && photoOffTable(photo)) {
       fadeAway(photo, true);
     }
   }
 }
 /**
  * Method that returns the view under the rect
  *
  * @return The view
  */
 private View findViewFromRect(Rect r) {
   int count = getChildCount();
   for (int i = 0; i < count; i++) {
     View v = getChildAt(i);
     if (v.getX() < (r.left + (r.width() / 2))
         && (v.getX() + v.getWidth()) > (r.left + (r.width() / 2))
         && v.getY() < (r.top + (r.height() / 2))
         && (v.getY() + v.getHeight()) > (r.top + (r.height() / 2))) {
       return v;
     }
   }
   return null;
 }
 /**
  * Method that returns the target view for the current resize frame
  *
  * @return The target view
  */
 View findTargetFromResizeFrame() {
   int count = getChildCount();
   for (int i = 0; i < count; i++) {
     View v = getChildAt(i);
     if (v.getX() < (mResizeFrame.getX() + (mResizeFrame.getWidth() / 2))
         && (v.getX() + v.getWidth()) > (mResizeFrame.getX() + (mResizeFrame.getWidth() / 2))
         && v.getY() < (mResizeFrame.getY() + (mResizeFrame.getHeight() / 2))
         && (v.getY() + v.getHeight()) > (mResizeFrame.getY() + (mResizeFrame.getHeight() / 2))) {
       return v;
     }
   }
   return null;
 }
 @Override
 public boolean onTouch(View v, MotionEvent event) {
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       if (!mEditable) {
         return false;
       }
       touchX = event.getX();
       touchY = event.getY();
       return true;
     case MotionEvent.ACTION_MOVE:
       float moveX = event.getX() - touchX;
       float moveY = event.getY() - touchY;
       v.setX(v.getX() + moveX);
       v.setY(v.getY() + moveY);
       return true;
     case MotionEvent.ACTION_UP:
       if (v.getY() > getSize()) {
         videoTags.remove(tagViews.indexOf(v));
         removeView(v);
       }
       return true;
   }
   return false;
 }
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
      Log.d("Fling", "Fling with " + velocityX + ", " + velocityY);
      final View topCard = mTopCard;
      float dx = e2.getX() - e1.getX();
      if (Math.abs(dx) > mTouchSlop
          && Math.abs(velocityX) > Math.abs(velocityY)
          && Math.abs(velocityX) > mFlingSlop * 3) {
        float targetX = topCard.getX();
        float targetY = topCard.getY();
        long duration = 0;

        boundsRect.set(
            0 - topCard.getWidth() - 100,
            0 - topCard.getHeight() - 100,
            getWidth() + 100,
            getHeight() + 100);

        while (boundsRect.contains((int) targetX, (int) targetY)) {
          targetX += velocityX / 10;
          targetY += velocityY / 10;
          duration += 100;
        }

        duration = Math.min(500, duration);

        mTopCard = getChildAt(getChildCount() - 2);
        CardModel cardModel = (CardModel) getAdapter().getItem(getChildCount() - 1);

        if (mTopCard != null) mTopCard.setLayerType(LAYER_TYPE_HARDWARE, null);

        if (cardModel.getOnCardDismissedListener() != null) {
          if (targetX > 0) {
            cardModel.getOnCardDismissedListener().onLike();
          } else {
            cardModel.getOnCardDismissedListener().onDislike();
          }
        }

        topCard
            .animate()
            .setDuration(duration)
            .alpha(.75f)
            .setInterpolator(new LinearInterpolator())
            .x(targetX)
            .y(targetY)
            .rotation(Math.copySign(45, velocityX))
            .setListener(
                new AnimatorListenerAdapter() {
                  @Override
                  public void onAnimationEnd(Animator animation) {
                    removeViewInLayout(topCard);
                    ensureFull();
                  }

                  @Override
                  public void onAnimationCancel(Animator animation) {
                    onAnimationEnd(animation);
                  }
                });
        return true;
      } else return false;
    }
Пример #7
0
 @Override
 public boolean onTouch(View v, MotionEvent event) {
   int action = event.getAction();
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       oldX = event.getRawX();
       newX = event.getRawX();
       break;
     case MotionEvent.ACTION_MOVE:
       newX = event.getRawX();
       if (v != layout) {
         v.setTranslationX((newX - oldX) * 1.075f);
         if (v.getX() > v.getWidth() - 150 || v.getX() < -v.getWidth() + 150) {
           contentFrameLayout.removeView(v);
         }
       } else {
         if (newX - oldX > 50) {
           int distance = (int) (newX - oldX);
           if (distance > v.getWidth() / 2) ;
           {
             finish();
             overridePendingTransition(R.anim.side_in_left, R.anim.slide_out_right);
           }
         }
       }
       break;
     case MotionEvent.ACTION_UP:
       if (v != layout) {
         v.setTranslationX(0);
       }
       break;
   }
   return true;
 }
Пример #8
0
 private void captureValues(TransitionValues transitionValues, float rotation) {
   final View view = transitionValues.view;
   transitionValues.values.put(getPropKey(PROP_ROTATION, view), rotation);
   transitionValues.values.put(getPropKey(PROP_X, view), view.getX());
   transitionValues.values.put(getPropKey(PROP_Y, view), view.getY());
   Log.i(LOG_TAG, "Captured values: " + dumpMap(transitionValues.values));
 }
Пример #9
0
 private void arrowlistener() {
   int width = arrowicon.getMeasuredWidth();
   int height = arrowicon.getMeasuredHeight();
   LogUtils.D("onClick" + width + " " + height);
   Matrix matrix = new Matrix();
   count++;
   matrix.postRotate(180 * count, width / 2, height / 2);
   arrowicon.setImageMatrix(matrix);
   if (count % 2 != 0) {
     list_title.setVisibility(View.VISIBLE);
     list_content.setVisibility(View.VISIBLE);
     View view = (View) mViewPager.getParent();
     Bitmap bitmap =
         BitmapUtils.shot(
             getView(),
             (int) view.getX(),
             (int) view.getY(),
             mViewPager.getMeasuredWidth(),
             mViewPager.getMeasuredHeight());
     if (bitmap != null)
       list_content.setBackground(
           new BitmapDrawable(BitmapUtils.blurBitmap(bitmap, getActivity())));
     //                    list_content.setBackground(new
     // BitmapDrawable(BitmapUtils.compressBmpFromBmp(bitmap)));
     mItemHScrollView.setVisibility(View.GONE);
     mViewPager.setVisibility(View.GONE);
   } else {
     list_title.setVisibility(View.GONE);
     list_content.setVisibility(View.GONE);
     list_content.setBackground(null);
     mItemHScrollView.setVisibility(View.VISIBLE);
     mViewPager.setVisibility(View.VISIBLE);
   }
 }
 /** {@inheritDoc} */
 public boolean onTouch(View view, MotionEvent motionEvent) {
   int action = motionEvent.getAction();
   if (action == MotionEvent.ACTION_MOVE) {
     view.setX(view.getX() + motionEvent.getX() - (view.getWidth() / 2));
     view.setY(view.getY() + motionEvent.getY() - (view.getHeight() / 2));
   }
   return true;
 }
Пример #11
0
  /**
   * Call this method in Activity's onTouchEvent method.
   *
   * @param ev
   * @return true if consumed the event, false if not.
   */
  public final boolean onTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getX() <= mScaledEdgeSlop) {
      mIsTrackingSwipeBackGesture = true;
      return true;
    }

    if (mIsTrackingSwipeBackGesture) {
      if (ev.getAction() == MotionEvent.ACTION_MOVE && Math.abs(ev.getX() - mLastX) > mTouchSlop) {
        mLastX = ev.getX();
        mDecorView.setX(ev.getX());
      } else if (ev.getAction() == MotionEvent.ACTION_UP) {
        mIsTrackingSwipeBackGesture = false;
        if (ev.getX() < 200.0f) {
          ObjectAnimator anim =
              ObjectAnimator.ofFloat(mDecorView, "translationX", mDecorView.getX(), 0);
          anim.start();
        } else {
          ObjectAnimator anim =
              ObjectAnimator.ofFloat(mDecorView, "translationX", mDecorView.getX(), mScreenWidth);
          anim.addListener(
              new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {}

                @Override
                public void onAnimationEnd(Animator animation) {
                  mActivity.finish();
                }

                @Override
                public void onAnimationCancel(Animator animation) {}

                @Override
                public void onAnimationRepeat(Animator animation) {}
              });
          anim.start();
        }
      }
      return true;
    }
    return false;
  }
Пример #12
0
  private Animator createShowItemAnimator(View item) {
    float dx = centerItem.getX() - item.getX();
    float dy = centerItem.getY() - item.getY();

    item.setScaleX(0f);
    item.setScaleY(0f);
    item.setTranslationX(dx);
    item.setTranslationY(dy);

    Animator anim =
        ObjectAnimator.ofPropertyValuesHolder(
            item,
            AnimatorUtils.scaleX(0f, 1f),
            AnimatorUtils.scaleY(0f, 1f),
            AnimatorUtils.translationX(dx, 0f),
            AnimatorUtils.translationY(dy, 0f));

    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration(50);
    return anim;
  }
Пример #13
0
  // Remove File Path Views unitll chosen View
  public void removeViewPaths(View v) {
    String pathToRemove = "";
    float vX = v.getX();
    LinearLayout parentView = (LinearLayout) v.getParent();
    int numberOfChildern = parentView.getChildCount();

    for (int i = numberOfChildern - 1; i > 0; i--) {
      View currentView = parentView.getChildAt(i);
      if (currentView.getX() > vX) {
        pathToRemove = (pathToRemove + ((TextView) currentView).getText().toString());
        parentView.removeView(currentView);
      }
    }

    Log.d(TAG, "current File Path   -   " + currentFilePath);
    Log.d(TAG, "pathToRemove    -   " + pathToRemove);
    currentFilePath =
        currentFilePath.substring(0, currentFilePath.length() - pathToRemove.length());
    Log.d(TAG, "current File Path   -   " + currentFilePath);

    onPathChanged("", false);
  }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    View gridLayout = findViewById(R.id.book_folder_gridLayout);

    downloadingView.setX(gridLayout.getX() + gridLayout.getWidth() / 3);
    downloadingView.setY(gridLayout.getY() + gridLayout.getHeight() - 20);

    textView.setText(childViews.size() + "");
    textView.setX(gridLayout.getWidth() - textView.getWidth());
    textView.setY(gridLayout.getHeight() - 33);
  }
Пример #15
0
  /** Animate to a random place and orientation, down on the table (visually small). */
  public void dropOnTable(final View photo, final Interpolator interpolator) {
    float angle = randfrange(-mImageRotationLimit, mImageRotationLimit);
    PointF p =
        randMultiDrop(
            sRNG.nextInt(),
            (float) sRNG.nextGaussian(),
            (float) sRNG.nextGaussian(),
            mWidth,
            mHeight);
    float x = p.x;
    float y = p.y;

    log("drop it at %f, %f", x, y);

    float x0 = photo.getX();
    float y0 = photo.getY();

    x -= mLongSide / 2f;
    y -= mShortSide / 2f;
    log("fixed offset is %f, %f ", x, y);

    float dx = x - x0;
    float dy = y - y0;

    float dist = (float) Math.hypot(dx, dy);
    int duration = (int) (1000f * dist / mThrowSpeed);
    duration = Math.max(duration, 1000);

    log("animate it");
    // toss onto table
    resolveBackgroundQueue();
    photo
        .animate()
        .withLayer()
        .scaleX(mTableRatio / mImageRatio)
        .scaleY(mTableRatio / mImageRatio)
        .rotation(angle)
        .x(x)
        .y(y)
        .setDuration(duration)
        .setInterpolator(interpolator)
        .withEndAction(
            new Runnable() {
              @Override
              public void run() {
                mWaitingToJoinBackground.add(photo);
              }
            });
  }
Пример #16
0
 private void focusMove(final View v) {
   focusView
       .animate()
       .setListener(
           new AnimatorListenerAdapter() {
             @Override
             public void onAnimationEnd(Animator animation) {
               super.onAnimationEnd(animation);
               if (null != linearIndicatorListener) {
                 linearIndicatorListener.focusChanged(tags.indexOf(v) + 1);
               }
             }
           })
       .translationX(v.getX());
 }
Пример #17
0
  /** Fling with no touch hints, then land off screen. */
  public void fling(final View photo) {
    final float[] o = {mWidth + mLongSide / 2f, mHeight + mLongSide / 2f};
    final float[] a = {photo.getX(), photo.getY()};
    final float[] b = {o[0], a[1] + o[0] - a[0]};
    final float[] c = {a[0] + o[1] - a[1], o[1]};
    float[] delta = {0f, 0f};
    if (Math.hypot(b[0] - a[0], b[1] - a[1]) < Math.hypot(c[0] - a[0], c[1] - a[1])) {
      delta[0] = b[0] - a[0];
      delta[1] = b[1] - a[1];
    } else {
      delta[0] = c[0] - a[0];
      delta[1] = c[1] - a[1];
    }

    final float dist = (float) Math.hypot(delta[0], delta[1]);
    final int duration = (int) (1000f * dist / mThrowSpeed);
    fling(photo, delta[0], delta[1], duration, true);
  }
Пример #18
0
 /**
  * 判断是否在当前触摸位置存在View
  *
  * @param x
  * @param y
  * @return
  */
 private boolean hasView(int x, int y) {
   // 循环获取子view,判断xy是否在子view上,即判断是否按住了子view
   for (int index = 0; index < this.getChildCount(); index++) {
     View view = this.getChildAt(index);
     int left = (int) view.getX();
     int top = (int) view.getY();
     int right = view.getRight();
     int bottom = view.getBottom();
     Rect rect = new Rect(left, top, right, bottom);
     boolean contains = rect.contains(x, y);
     // 如果是与子view重叠则返回真,表示已经有了view不需要添加新view了
     if (contains) {
       touchView = view;
       touchView.bringToFront();
       return true;
     }
   }
   touchView = null;
   return false;
 }
Пример #19
0
 @Override
 public boolean onTouchEvent(@NonNull MotionEvent event) {
   final int action = event.getAction();
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       if (event.getX() < handle.getX()) return false;
       if (currentAnimator != null) currentAnimator.cancel();
       if (bubble.getVisibility() == INVISIBLE) showBubble();
       handle.setSelected(true);
     case MotionEvent.ACTION_MOVE:
       final float y = event.getY();
       setBubbleAndHandlePosition(y);
       setRecyclerViewPosition(y);
       return true;
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_CANCEL:
       handle.setSelected(false);
       hideBubble();
       return true;
   }
   return super.onTouchEvent(event);
 }
Пример #20
0
  // 处理点击下拉事件:弹出输入框的下拉框
  @SuppressLint("NewApi")
  private void showSearchTypeSpinnerDialog(View marginLeftView, View marginTopView) {
    View contentView =
        LayoutInflater.from(getActivity()).inflate(R.layout.popwin_select_spinner_scmake, null);
    // 获取组件
    ListView spinnerListView =
        (ListView) contentView.findViewById(R.id.lv_spinner_searchtype_scmake);
    // 数据
    spinnerNameList = DataSourceManager.getDataSourceManager().getPrepareSpinnerItemList();
    // Adapter
    ArrayAdapter adapter =
        new ArrayAdapter<String>(getActivity(), R.layout.item_spinner_searchtype, spinnerNameList);
    spinnerListView.setAdapter(adapter);

    // 配置Dialog样式
    // 注意:getY方法是获取视图和父视图之间的距离,由于布局中,输入框和父布局有8个像素的margin,所以Dialog的y是marginTop
    int x = (int) marginLeftView.getX();
    LinearLayout.LayoutParams tp = (LinearLayout.LayoutParams) marginTopView.getLayoutParams();
    LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) marginLeftView.getLayoutParams();
    int y = tp.topMargin + marginTopView.getHeight();
    int w = (int) (marginLeftView.getWidth() + getResources().getDimension(R.dimen.space_left_8));
    int h = marginTopView.getHeight();
    Log.e("SCMAKE", "w" + w);
    Log.e("SCMAKE", "h" + h);

    // 配置监听
    spinnerListView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            disposeOnsearchTypeSpinnerItemClick(position, id);
            dismissSpinnerDialog();
          }
        });

    showSpinnerDialog(contentView, x, y, w, h);
  }
Пример #21
0
  /**
   * Method that select a view as the target of to resize
   *
   * @param v The target view
   */
  boolean selectTarget(View v) {
    // Do not do long click if we do not have a target
    if (mTarget != null && v.equals(mTarget)) return false;
    if (mResizeFrame == null) return false;

    // Show the resize frame view just in place of the current clicked view

    mResizeFrame.hide();
    FrameLayout.LayoutParams frameParams =
        (FrameLayout.LayoutParams) mResizeFrame.getLayoutParams();
    int padding = mInternalPadding + mResizeFrame.getNeededPadding();
    frameParams.width = v.getWidth() + (padding * 2);
    frameParams.height = v.getHeight() + (padding * 2);
    mResizeFrame.setX(v.getX() - padding);
    mResizeFrame.setY(v.getY() - padding);
    mResizeFrame.show();

    // Save the new view
    mTarget = v;
    if (mOnFrameSelectedListener != null) {
      mOnFrameSelectedListener.onFrameSelectedListener(v);
    }
    return true;
  }
Пример #22
0
  // Show(or hide) one view with some effects
  private void showView(int viewId, int delay, int b) {
    View myView = findViewById(viewId);
    final int behavior = b;

    if (android.os.Build.VERSION.SDK_INT >= 21) {

      float x = myView.getX();
      float y = myView.getY();

      Path path1 = new Path();
      Path path2 = new Path();

      // Show with bounce effect
      if (behavior == 0) {
        path1.moveTo(x, y + 100);
        path1.rLineTo(0, -100);
        path2.moveTo(0, 0);
        path2.lineTo(1, 1);
      }
      // Show with bounce effect(and drop from top)
      else if (behavior == 1) {
        path1.moveTo(x, y - 300);
        path1.rLineTo(0, 300);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
      }
      // Show with inflate effect
      else if (behavior == 2) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(10, 10);
      }
      // Hide with deflate effect(from large shape)
      else if (behavior == 3) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(10, 10);
        path2.lineTo(1, 1);
      }
      // Fade in and float
      else if (behavior == 4) {
        path1.moveTo(x, y + 50);
        path1.rLineTo(0, -50);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
      }
      // Fade out
      else if (behavior == 5) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
      }
      // Hide with deflate effect
      else if (behavior == 6) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(0, 0);
      }
      // Show with inflate effect
      else if (behavior == 7) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(20, 20);
      }
      // Hide with deflate effect(from large shape)
      else if (behavior == 8) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(20, 20);
        path2.lineTo(1, 1);
      }
      // This effect only used for the flipTimes label
      else if (behavior == 9) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
        path2.lineTo(2, 2);
      }

      ObjectAnimator mAnimator1, mAnimator2, mAnimator3;
      mAnimator1 = ObjectAnimator.ofFloat(myView, View.X, View.Y, path1);
      mAnimator2 = ObjectAnimator.ofFloat(myView, View.SCALE_X, View.SCALE_Y, path2);
      mAnimator1.setDuration(300);
      mAnimator2.setDuration(300);
      mAnimator1.setStartDelay(delay);
      mAnimator2.setStartDelay(delay);

      if (behavior == 0 || behavior == 1) {
        mAnimator1.setInterpolator(new BounceInterpolator());
        mAnimator2.setInterpolator(new BounceInterpolator());
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 1);
        mAnimator3.setDuration(10);
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 2 || behavior == 7) {
        myView.bringToFront();
        FrameLayout menuLayout = (FrameLayout) findViewById(R.id.menu);
        menuLayout.requestLayout();
        menuLayout.invalidate();

        mAnimator3 =
            ObjectAnimator.ofArgb(
                myView, "textColor", ((Button) myView).getCurrentTextColor(), Color.TRANSPARENT);
        mAnimator3.setDuration(100);
        mAnimator1.setInterpolator(new AccelerateInterpolator());
        mAnimator2.setInterpolator(new AccelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
        mSound.play(mSoundID[SOUND_OPEN], 1, 1, 1, 0, 1);
      } else if (behavior == 3 || behavior == 8) {
        mAnimator3 =
            ObjectAnimator.ofArgb(
                myView, "textColor", ((Button) myView).getCurrentTextColor(), Color.WHITE);
        mAnimator3.setDuration(100);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay + 200);
        mAnimator3.start();
        mSound.play(mSoundID[SOUND_CLOSE], 1, 1, 1, 0, 1);
      } else if (behavior == 4) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 1);
        mAnimator3.setDuration(300);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 5) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 0);
        mAnimator3.setDuration(300);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 6) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 0);
        mAnimator3.setDuration(300);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 9) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", 1, 0);
        mAnimator2.setDuration(1000);
        mAnimator3.setDuration(1000);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setRepeatCount(Animation.INFINITE);
        mAnimator3.setRepeatCount(Animation.INFINITE);
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      }
      if (behavior == 0 || behavior == 1 || behavior == 4) {
        mAnimator1.start();
      }
      mAnimator2.start();

      mAnimator1.addListener(
          new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
              if (behavior == 0) {
                mSound.play(mSoundID[SOUND_BLOP], 1, 1, 1, 0, 1);
              }
            }

            @Override
            public void onAnimationEnd(Animator animation) {}

            @Override
            public void onAnimationCancel(Animator animation) {}

            @Override
            public void onAnimationRepeat(Animator animation) {}
          });
    }
    // If the device OS is below Lollipop, the animation feature will be lost
    else {
      if (behavior == 5 || behavior == 6) {
        myView.setAlpha(0);
      } else {
        myView.setAlpha(1);
      }

      if (behavior == 2) {
        myView.setScaleX(10);
        myView.setScaleY(10);
        ((Button) myView).setTextColor(Color.TRANSPARENT);
      } else if (behavior == 3) {
        myView.setScaleX(1);
        myView.setScaleY(1);
        ((Button) myView).setTextColor(Color.WHITE);
      }

      if (behavior == 0) {
        mSound.play(mSoundID[SOUND_BLOP], 1, 1, 1, 0, 1);
      } else if (behavior == 2 || behavior == 7) {
        mSound.play(mSoundID[SOUND_OPEN], 1, 1, 1, 0, 1);
      } else if (behavior == 3 || behavior == 8) {
        mSound.play(mSoundID[SOUND_CLOSE], 1, 1, 1, 0, 1);
      } else if (behavior == 6) {
        mSound.play(mSoundID[SOUND_CLICK], 1, 1, 1, 0, 1);
      }
    }
  }
Пример #23
0
    @Override
    public void draw(Canvas canvas) {

      Paint paint = new Paint();
      paint.setStrokeWidth(5);
      paint.setColor(getResources().getColor(R.color.main));
      final int lineGap = 20; // 换行时的横向延长线

      final int count = stationGroup.getChildCount();
      int row = 0; // which row lay you view relative to parent
      for (int i = 0; i < count - 1; i++) {
        final View child = stationGroup.getChildAt(i);
        final View childNext = stationGroup.getChildAt(i + 1);

        int width = child.getMeasuredWidth();
        int height = child.getMeasuredHeight();
        float startX = child.getX() + width;
        float startY = child.getY() + height / 2;
        float stopX = childNext.getX();
        float stopY = childNext.getY() + height / 2;

        if (startY != stopY) {
          /** 出现换行 */
          if (stationGroup.getRightTurnedNodes().contains(child)) {
            /** 右转换行 */
            int nextWidth = childNext.getMeasuredWidth();
            stopX = childNext.getX() + nextWidth;
            float firstLineStartX = 0;
            float firstLineStopX = 0;
            float firstLineStartY = 0;
            float firstLineStopY = 0;
            if (startX > stopX) {
              firstLineStartX = startX;
              firstLineStopX = startX + lineGap;
              firstLineStartY = startY;
              firstLineStopY = firstLineStartY;
            } else {
              firstLineStartX = startX;
              firstLineStopX = lineGap + stopX;
              firstLineStartY = startY;
              firstLineStopY = firstLineStartY;
            }
            /** 第一段横向延长线 */
            canvas.drawLine(
                firstLineStartX, firstLineStartY, firstLineStopX, firstLineStopY, paint);
            /** 纵向行间连接线 */
            canvas.drawLine(
                firstLineStopX,
                startY - paint.getStrokeWidth() / 2,
                firstLineStopX,
                stopY + paint.getStrokeWidth() / 2,
                paint);
            /** 下一行的横向延长线 */
            canvas.drawLine(stopX, stopY, firstLineStopX, stopY, paint);
          } else {
            /** 左转换行 */
            int nextWidth = childNext.getMeasuredWidth();
            startX = child.getX();
            startY = child.getY() + height / 2;
            stopX = childNext.getX();
            stopY = childNext.getY() + height / 2;
            float firstLineStartX = 0;
            float firstLineStopX = 0;
            float firstLineStartY = 0;
            float firstLineStopY = 0;
            if (startX > stopX) {
              firstLineStartX = stopX - lineGap;
              firstLineStopX = startX;
              firstLineStartY = startY;
              firstLineStopY = firstLineStartY;
            } else {
              firstLineStartX = startX - lineGap;
              firstLineStopX = startX;
              firstLineStartY = startY;
              firstLineStopY = firstLineStartY;
            }
            /** 第一段横向延长线 */
            canvas.drawLine(
                firstLineStartX, firstLineStartY, firstLineStopX, firstLineStopY, paint);
            /** 纵向行间连接线 */
            canvas.drawLine(
                firstLineStartX,
                startY - paint.getStrokeWidth() / 2,
                firstLineStartX,
                stopY + paint.getStrokeWidth() / 2,
                paint);
            /** 下一行的横向延长线 */
            canvas.drawLine(firstLineStartX, stopY, stopX, stopY, paint);
          }
        } else {
          canvas.drawLine(startX, startY, stopX, stopY, paint);
        }
      }
    }
Пример #24
0
 private double[] getCenter(View photo) {
   float width = (float) ((Integer) photo.getTag(R.id.photo_width)).intValue();
   float height = (float) ((Integer) photo.getTag(R.id.photo_height)).intValue();
   double[] center = {photo.getX() + width / 2f, -(photo.getY() + height / 2f)};
   return center;
 }
Пример #25
0
 public static float getX(View view) {
   return view.getX();
 }
  /*
   * method: onTouch
   * purpose: handles drag and drop of ships
   * @param: arg0 - ship being dragged
   * @param: arg1 - where ship is being dragged
   */
  @Override
  public boolean onTouch(View arg0, MotionEvent arg1) {

    for (index = 0; index < ships.length; index++)
      if (arg0 == findViewById(ships[index].viewID)) break;

    Log.i("SHIP: " + ships[index].shipID + "", arg0.getX() + " " + arg0.getY());
    p1.deleteShip(ships[index]);
    switch (arg1.getAction()) {
      case MotionEvent.ACTION_DOWN:
        diffX = arg0.getX() - arg1.getRawX();
        diffY = arg0.getY() - arg1.getRawY();
        moving = true;
        break;
      case MotionEvent.ACTION_MOVE:
        if (moving) {
          x = arg1.getRawX() + diffX;
          y = arg1.getRawY() + diffY;
          arg0.setX(x);
          arg0.setY(y);
          Log.i("X Position : Y Position", x + "  " + y);

          if (x < 250) arg0.setX(149.47f);
          else if (x < 350 && x > 250) arg0.setX(254.21f);
          else if (x < 460 && x > 350) arg0.setX(355.61f);
          else if (x < 560 && x > 460) arg0.setX(461.45f);
          else if (x < 669 && x > 560) arg0.setX(564.4f);
          else if (x < 772 && x > 669) arg0.setX(669.24f);
          else if (x < 877 && x > 772) arg0.setX(772.31f);
          else if (x < 980 && x > 877) arg0.setX(877.16f);
          else if (x < 1080 && x > 980) arg0.setX(981.11f);
          else if (x < 1165 && x > 1080) arg0.setX(1085.07f);

          if (x < 1165) {
            if (y < 250) arg0.setY(152.266f);
            else if (y < 359.699 && y > 250) arg0.setY(253.233f);
            else if (y < 463.165 && y > 359.7) arg0.setY(359.699f);
            else if (y < 569.13 && y > 463.165) arg0.setY(463.165f);
            else if (y < 667.6 && y > 569.13) arg0.setY(569.13f);
            else if (y < 773.565 && y > 667.6) arg0.setY(667.6f);
            else if (y < 878.12 && y > 773.565) arg0.setY(773.565f);
            else if (y < 980.09 && y > 878.12) arg0.setY(878.12f);
            else if (y < 1081.06 && y > 980.09) arg0.setY(980.09f);
            else if (y < 1190 && y > 1081.1) arg0.setY(1081.06f);
          }

          column = setColumn(x);
          row = setRow(y);
          if (column + ships[index].length > 10 || row + ships[index].height > 10)
            findViewById(ships[index].viewID).setBackgroundColor(Color.RED);
          else if (p1.testShip(row, column, ships[index]) == false)
            findViewById(ships[index].viewID).setBackgroundColor(Color.RED);
          else findViewById(ships[index].viewID).setBackgroundResource(ships[index].imageID);
        }
        break;
      case MotionEvent.ACTION_UP:
        Log.i("X : Y", column + " " + row);
        Boolean worked = p1.addShipToGrid(row, column, ships[index]);
        if (worked) {
          ships[index].togglePlaced();
        } else if (!worked) {
          reset(ships[index]);
        }
        moving = false;
        break;
    }
    return true;
  }
Пример #27
0
  /** Method that request the deletion of the current selected frame */
  @SuppressWarnings("boxing")
  public void deleteCurrentFrame() {
    if (mTarget == null) return;
    if (mResizeFrame == null) return;

    final Disposition targetDisposition = resizerToDisposition();

    // Get valid dispositions to move
    final List<Disposition> adjacents = findAdjacentsDispositions(targetDisposition);
    if (adjacents == null) {
      // Nothing to do
      Toast.makeText(
              getContext(), R.string.pref_disposition_unable_delete_advise, Toast.LENGTH_SHORT)
          .show();
      return;
    }

    // Hide resizer
    mResizeFrame.setVisibility(View.GONE);

    // Animate adjacents views
    List<Animator> animators = new ArrayList<Animator>();
    animators.add(ObjectAnimator.ofFloat(mTarget, "scaleX", 1.0f, 0.0f));
    animators.add(ObjectAnimator.ofFloat(mTarget, "scaleY", 1.0f, 0.0f));

    Disposition first = null;
    for (Disposition adjacent : adjacents) {
      // Extract the view and remove from dispositions
      View v = findViewFromRect(getLocationFromDisposition(adjacent));
      mDispositions.remove(adjacent);

      // Clone first disposition
      if (first == null) {
        first = new Disposition();
        first.x = adjacent.x;
        first.y = adjacent.y;
        first.w = adjacent.w;
        first.h = adjacent.h;
      }

      // Add animators and fix the adjacent
      if (v != null) {
        if (first.x < targetDisposition.x) {
          // From Left to Right
          int width = mTarget.getWidth() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.WidthEvaluator(v), v.getWidth(), v.getWidth() + width));

          // Update the adjacent
          adjacent.w += targetDisposition.w;
          mDispositions.add(adjacent);

        } else if (first.x > targetDisposition.x) {
          // From Right to Left
          int width = mTarget.getWidth() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.WidthEvaluator(v), v.getWidth(), v.getWidth() + width));
          animators.add(ObjectAnimator.ofFloat(v, "x", v.getX(), mTarget.getX()));

          // Update the adjacent
          adjacent.x = targetDisposition.x;
          adjacent.w += targetDisposition.w;
          mDispositions.add(adjacent);

        } else if (first.y < targetDisposition.y) {
          // From Top to Bottom
          int height = mTarget.getHeight() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.HeightEvaluator(v), v.getHeight(), v.getHeight() + height));

          // Update the adjacent
          adjacent.h += targetDisposition.h;
          mDispositions.add(adjacent);

        } else if (first.y > targetDisposition.y) {
          // From Bottom to Top
          int height = mTarget.getHeight() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.HeightEvaluator(v), v.getHeight(), v.getHeight() + height));
          animators.add(ObjectAnimator.ofFloat(v, "y", v.getY(), mTarget.getY()));

          // Update the adjacent
          adjacent.y = targetDisposition.y;
          adjacent.h += targetDisposition.h;
          mDispositions.add(adjacent);
        }
      }
    }
    if (animators.size() > 0) {
      AnimatorSet animSet = new AnimatorSet();
      animSet.playTogether(animators);
      animSet.setDuration(getResources().getInteger(R.integer.disposition_hide_anim));
      animSet.setInterpolator(new AccelerateInterpolator());
      animSet.addListener(
          new AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
              // Ignore
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
              // Ignore
            }

            @Override
            public void onAnimationEnd(Animator animation) {
              finishDeleteAnimation(targetDisposition);
            }

            @Override
            public void onAnimationCancel(Animator animation) {
              finishDeleteAnimation(targetDisposition);
            }
          });
      animSet.start();
    }
  }
 private int getOffsetLeftPos(View view) {
   return (int) (view.getX() - view.getLeft());
 }
Пример #29
0
    @Override
    public void run() {
      long delay = MOVE_DELAY;
      if (mContentView == null || mSaverView == null) {
        mHandler.removeCallbacks(this);
        mHandler.postDelayed(this, delay);
        return;
      }

      final float xrange = mContentView.getWidth() - mSaverView.getWidth();
      final float yrange = mContentView.getHeight() - mSaverView.getHeight();
      Log.v("xrange: " + xrange + " yrange: " + yrange);

      if (xrange == 0 && yrange == 0) {
        delay = 500; // back in a split second
      } else {
        final int nextx = (int) (Math.random() * xrange);
        final int nexty = (int) (Math.random() * yrange);

        if (mSaverView.getAlpha() == 0f) {
          // jump right there
          mSaverView.setX(nextx);
          mSaverView.setY(nexty);
          ObjectAnimator.ofFloat(mSaverView, "alpha", 0f, 1f).setDuration(FADE_TIME).start();
        } else {
          AnimatorSet s = new AnimatorSet();
          Animator xMove = ObjectAnimator.ofFloat(mSaverView, "x", mSaverView.getX(), nextx);
          Animator yMove = ObjectAnimator.ofFloat(mSaverView, "y", mSaverView.getY(), nexty);

          Animator xShrink = ObjectAnimator.ofFloat(mSaverView, "scaleX", 1f, 0.85f);
          Animator xGrow = ObjectAnimator.ofFloat(mSaverView, "scaleX", 0.85f, 1f);

          Animator yShrink = ObjectAnimator.ofFloat(mSaverView, "scaleY", 1f, 0.85f);
          Animator yGrow = ObjectAnimator.ofFloat(mSaverView, "scaleY", 0.85f, 1f);
          AnimatorSet shrink = new AnimatorSet();
          shrink.play(xShrink).with(yShrink);
          AnimatorSet grow = new AnimatorSet();
          grow.play(xGrow).with(yGrow);

          Animator fadeout = ObjectAnimator.ofFloat(mSaverView, "alpha", 1f, 0f);
          Animator fadein = ObjectAnimator.ofFloat(mSaverView, "alpha", 0f, 1f);

          if (SLIDE) {
            s.play(xMove).with(yMove);
            s.setDuration(SLIDE_TIME);

            s.play(shrink.setDuration(SLIDE_TIME / 2));
            s.play(grow.setDuration(SLIDE_TIME / 2)).after(shrink);
            s.setInterpolator(mSlowStartWithBrakes);
          } else {
            AccelerateInterpolator accel = new AccelerateInterpolator();
            DecelerateInterpolator decel = new DecelerateInterpolator();

            shrink.setDuration(FADE_TIME).setInterpolator(accel);
            fadeout.setDuration(FADE_TIME).setInterpolator(accel);
            grow.setDuration(FADE_TIME).setInterpolator(decel);
            fadein.setDuration(FADE_TIME).setInterpolator(decel);
            s.play(shrink);
            s.play(fadeout);
            s.play(xMove.setDuration(0)).after(FADE_TIME);
            s.play(yMove.setDuration(0)).after(FADE_TIME);
            s.play(fadein).after(FADE_TIME);
            s.play(grow).after(FADE_TIME);
          }
          s.start();
        }

        long now = System.currentTimeMillis();
        long adjust = (now % 60000);
        delay =
            delay
                + (MOVE_DELAY - adjust) // minute aligned
                - (SLIDE ? 0 : FADE_TIME) // start moving before the fade
        ;
      }

      mHandler.removeCallbacks(this);
      mHandler.postDelayed(this, delay);
    }
Пример #30
0
 protected void adjustPosition(View tabToAddTo) {
   setX((float) (tabToAddTo.getX() + (tabToAddTo.getWidth() / 1.75)));
 }