コード例 #1
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        break;
      case MotionEvent.ACTION_MOVE:
        if (parentView.getVisibility() == View.INVISIBLE) {
          break;
        }
        // 在移动时候leftview始终可见
        setLeftViewVisiable();
        int moveX = (int) event.getRawX();
        int deltaX = tempX - moveX;
        leftViewTotalMove += deltaX;
        long nowTime = System.currentTimeMillis();
        long deltaTime = nowTime - tempTime;
        tempTime = nowTime;
        tempX = moveX;
        if (Math.abs(moveX - downX) > mTouchSlop
            && Math.abs((int) event.getRawY() - downY) < mTouchSlop) {
          isSilding = true;
        }

        if (moveX - downX >= 0 && isSilding) {
          parentView.setX(parentView.getX() - deltaX);

          // 更新listview的文本
          changeListView();
          if (Math.abs(leftViewTotalMove * leftlist_move_rate) > 1) {
            float targetX = leftView.getX() - leftViewTotalMove * leftlist_move_rate;
            if (targetX >= -leftlist_img_width && leftView.getX() <= 0) {
              changeListView();
              leftView.setX(targetX);
            }
            leftViewTotalMove = 0;
          }
        }
        break;
      case MotionEvent.ACTION_UP:
        if (parentView.getVisibility() == View.INVISIBLE) {
          break;
        }
        leftViewTotalMove = 0;
        isSilding = false;
        if (parentView.getX() >= viewWidth / 3) { // 移动继续超过1/3就向右滑动
          scrollRight();
          extendLeftView();
        } else {
          scrollOrigin();
          leftViewSliding((int) leftView.getX(), -(int) leftlist_img_width, leftView, 500l);
        }

        break;
      case MotionEvent.ACTION_CANCEL:
        break;
    }

    return true;
  }
 /** Sets the touchable region of this popup to be the area occupied by its content. */
 private void setContentAreaAsTouchableSurface() {
   if (!mPopupWindow.isShowing()) {
     mContentContainer.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
   }
   int width = mContentContainer.getMeasuredWidth();
   int height = mContentContainer.getMeasuredHeight();
   mTouchableRegion.set(
       (int) mContentContainer.getX(),
       (int) mContentContainer.getY(),
       (int) mContentContainer.getX() + width,
       (int) mContentContainer.getY() + height);
 }
コード例 #3
0
 /** 滚动到起始位置 */
 public void scrollOrigin() {
   parentViewSliding(
       (int) parentView.getX(),
       0,
       parentView,
       500l,
       new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           super.onAnimationEnd(animation);
           parentViewScrollX = 0;
         }
       });
 }
    /**
     * Opens the floating toolbar overflow. This method should not be called if menu items have not
     * been laid out with {@link #layoutMenuItems(java.util.List, MenuItem.OnMenuItemClickListener,
     * int)}.
     *
     * @throws IllegalStateException if called when menu items have not been laid out.
     */
    private void openOverflow() {
      Preconditions.checkState(mMainPanel != null);
      Preconditions.checkState(mOverflowPanel != null);

      mMainPanel.fadeOut(true);
      Size overflowPanelSize = mOverflowPanel.measure();
      final int targetWidth = overflowPanelSize.getWidth();
      final int targetHeight = overflowPanelSize.getHeight();
      final boolean morphUpwards = (mOverflowDirection == OVERFLOW_DIRECTION_UP);
      final int startWidth = mContentContainer.getWidth();
      final int startHeight = mContentContainer.getHeight();
      final float startY = mContentContainer.getY();
      final float right = mContentContainer.getX() + mContentContainer.getWidth();
      Animation widthAnimation =
          new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
              ViewGroup.LayoutParams params = mContentContainer.getLayoutParams();
              int deltaWidth = (int) (interpolatedTime * (targetWidth - startWidth));
              params.width = startWidth + deltaWidth;
              mContentContainer.setLayoutParams(params);
              mContentContainer.setX(right - mContentContainer.getWidth());
            }
          };
      Animation heightAnimation =
          new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
              ViewGroup.LayoutParams params = mContentContainer.getLayoutParams();
              int deltaHeight = (int) (interpolatedTime * (targetHeight - startHeight));
              params.height = startHeight + deltaHeight;
              mContentContainer.setLayoutParams(params);
              if (morphUpwards) {
                float y = startY - (mContentContainer.getHeight() - startHeight);
                mContentContainer.setY(y);
              }
            }
          };
      widthAnimation.setDuration(240);
      heightAnimation.setDuration(180);
      heightAnimation.setStartOffset(60);
      mOpenOverflowAnimation.getAnimations().clear();
      mOpenOverflowAnimation.setAnimationListener(mOnOverflowOpened);
      mOpenOverflowAnimation.addAnimation(widthAnimation);
      mOpenOverflowAnimation.addAnimation(heightAnimation);
      mContentContainer.startAnimation(mOpenOverflowAnimation);
    }
コード例 #5
0
 /** 滚动出界面 */
 private void scrollRight() {
   parentViewSliding(
       (int) parentView.getX(),
       viewWidth,
       parentView,
       500l,
       new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           super.onAnimationEnd(animation);
           onLeftViewExtended();
           if (onSildingFinishListener != null) {
             onSildingFinishListener.onSildingFinish();
           }
         }
       });
 }
コード例 #6
0
  private void changeListView() {
    int visiblePosition = leftView.getFirstVisiblePosition();
    int lastVisiblePosition = leftView.getLastVisiblePosition();
    int selectedItemNum = selectItemPosition - visiblePosition;
    // Log.d("LogonActivity", String.format("SildingLayout:visiblePosition:%d ,lastVisiblePosition
    // %d",visiblePosition,lastVisiblePosition));
    for (int i = 0; i <= lastVisiblePosition - visiblePosition; i++) // 获取ListView的所有Item数目
    {
      //    LinearLayout linearlayout = (LinearLayout)mListView.getChildAt(i);
      View view = leftView.getChildAt(i);

      if (view != null && view.getTag() != null) {
        LeftViewAdapter.ViewHolder holder = (LeftViewAdapter.ViewHolder) view.getTag();
        // holder.textView.setText(String.valueOf(parentViewScrollX));
        holder.description.setAlpha(Math.abs(parentView.getX()) / viewWidth);
        if (i == selectedItemNum) {
          holder.textView.setText("我被选中了!");
        }
      }
    }
  }