private Animation buildFlipHorizonalAnimation(final boolean forward) { final float centerY = container.getHeight() / 2.0f; final float centerX = 0; long duration = getFlipDurationFromPreference(); Animation rotation = AnimationFactory.buildHorizontalFlipAnimation(forward, duration, centerX, centerY); rotation.setAnimationListener(flipAnimationListener); return rotation; }
@SuppressLint("ResourceAsColor") @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override public boolean onTouch(final View view, MotionEvent event) { if (mViewWidth < 2) { mViewWidth = mListView.getWidth(); smallWidth = mViewWidth / 7; textwidth2 = mViewWidth / 3; textwidth = textwidth2; // 原版 // largewidth = textwidth+textwidth2; // 自己修改 largewidth = textwidth; } int tempwidth = 0; if (SwipeType == 1) tempwidth = smallWidth; else tempwidth = textwidth2 / 2; switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: { if (mPaused) { return false; } Rect rect = new Rect(); int childCount = mListView.getChildCount(); int[] listViewCoords = new int[2]; mListView.getLocationOnScreen(listViewCoords); int x = (int) event.getRawX() - listViewCoords[0]; int y = (int) event.getRawY() - listViewCoords[1]; ViewGroup child; for (int i = 0; i < childCount; i++) { child = (ViewGroup) mListView.getChildAt(i); child.getHitRect(rect); if (rect.contains(x, y)) { mDownView_parent = child; mDownView = (ViewGroup) child.findViewById(R.id.list_display_view_container); if (mDownView_parent.getChildCount() == 1) { textheight = mDownView_parent.getHeight(); if (SwipeType == Dismiss) { HalfColor = singleColor; // HalfDrawable = // activity.getResources().getDrawable(R.drawable.content_discard); } SetBackGroundforList(); } if (old_mDownView != null && mDownView != old_mDownView) { ResetListItem(old_mDownView); old_mDownView = null; return false; } break; } } if (mDownView != null) { mDownX = event.getRawX(); mDownY = event.getRawY(); mDownPosition = mListView.getPositionForView(mDownView); mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(event); } else { mDownView = null; } // mSwipeDetected = false; temp_position = mListView.pointToPosition((int) event.getX(), (int) event.getY()); view.onTouchEvent(event); return true; } case MotionEvent.ACTION_UP: { if (mVelocityTracker == null) { break; } float deltaX = event.getRawX() - mDownX; // 在OnItemClick事件中判断如果Deltax!=0则表示不是点击事件 DeltaX = deltaX; mVelocityTracker.addMovement(event); mVelocityTracker.computeCurrentVelocity(1000); // 1000 by defaut but float velocityX = mVelocityTracker.getXVelocity(); // it was too much float absVelocityX = Math.abs(velocityX); float absVelocityY = Math.abs(mVelocityTracker.getYVelocity()); boolean swipe = false; boolean swipeRight = false; if (Math.abs(deltaX) > tempwidth) { swipe = true; swipeRight = deltaX > 0; } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity && absVelocityY < absVelocityX) { // dismiss only if flinging in the same direction as dragging swipe = (velocityX < 0) == (deltaX < 0); swipeRight = mVelocityTracker.getXVelocity() > 0; } if (deltaX < 0 && swipe) { mListView.setDrawSelectorOnTop(false); // && Math.abs(DeltaY)<30 if (swipe && !swipeRight && deltaX <= -tempwidth && Math.abs(DeltaY) < 100) { FullSwipeTrigger(); } else if (deltaX >= -textwidth && SwipeType == Double) { ResetListItem(mDownView); } else { ResetListItem(mDownView); } } else if (deltaX != 0) { ResetListItem(mDownView); } mVelocityTracker.recycle(); mVelocityTracker = null; mDownX = 0; mDownView = null; mDownPosition = ListView.INVALID_POSITION; mSwiping = false; break; } // 根据手势滑动方向滑出滑入 case MotionEvent.ACTION_MOVE: { float deltaX = event.getRawX() - mDownX; float deltaY = event.getRawY() - mDownY; DeltaY = deltaY; if (mVelocityTracker == null || mPaused || deltaX > 0) { break; } mVelocityTracker.addMovement(event); // && Math.abs(deltaY)<30 if (Math.abs(deltaX) > (mSlop * 5) && Math.abs(deltaY) < 50) { mSwiping = true; mListView.requestDisallowInterceptTouchEvent(true); // Cancel ListView's touch (un-highlighting the item) MotionEvent cancelEvent = MotionEvent.obtain(event); cancelEvent.setAction( MotionEvent.ACTION_CANCEL | (event.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); mListView.onTouchEvent(cancelEvent); cancelEvent.recycle(); } else if (Math.abs(deltaY) > 50) { mSwiping = false; // ResetListItem(mDownView); } System.out.println( "<<<<<<<<<" + deltaY + "<<<<<<" + deltaX + "<<<<" + mSwiping + "<<<<<" + mSlop * 10); if (mSwiping && deltaX < 0) { int width; // if(SwipeType==1){ width = textwidth2; // } // else{ // width = largewidth; // } if (-deltaX < width) { mDownView.setTranslationX(deltaX); return false; } return false; } else if (mSwiping) { ResetListItem(mDownView); } break; } } return false; }