/** * Scroll to child. * * @param i the i */ void scrollToChild(int i) { CarouselItemView view = (CarouselItemView) getAdapter().getView(i, null, null); float angle = view.getCurrentAngle(); if (angle == 0) return; if (angle > 180.0f) angle = 360.0f - angle; else angle = -angle; mFlingRunnable.startUsingDistance(angle); }
/** * 描述:TODO * * @see android.view.GestureDetector.OnGestureListener#onFling(android.view.MotionEvent, * android.view.MotionEvent, float, float) * @author: zhaoqp * @date:2013-11-28 上午11:14:35 * @version v1.0 */ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (!mShouldCallbackDuringFling) { // We want to suppress selection changes // Remove any future code to set mSuppressSelectionChanged = false removeCallbacks(mDisableSuppressSelectionChangedRunnable); // This will get reset once we scroll into slots if (!mSuppressSelectionChanged) mSuppressSelectionChanged = true; } // Fling the gallery! // mFlingRunnable.startUsingVelocity((int) -velocityX); mFlingRunnable.startUsingVelocity((int) velocityX); return true; }
/** * 描述:TODO * * @see android.view.GestureDetector.OnGestureListener#onDown(android.view.MotionEvent) * @author: zhaoqp * @date:2013-11-28 上午11:14:35 * @version v1.0 */ public boolean onDown(MotionEvent e) { // Kill any existing fling/scroll mFlingRunnable.stop(false); ///// Don't know yet what for it is // Get the item's view that was touched mDownTouchPosition = pointToPositionView((int) e.getX(), (int) e.getY()); if (mDownTouchPosition >= 0) { mDownTouchView = getChildAt(mDownTouchPosition - mFirstPosition); mDownTouchView.setPressed(true); } // Reset the multiple-scroll tracking state mIsFirstScroll = true; // Must return true to get matching events for this down event. return true; }
/** Brings an item with nearest to 0 degrees angle to this angle and sets it selected. */ private void scrollIntoSlots() { // Nothing to do if (getChildCount() == 0 || mSelectedChild == null) return; // get nearest item to the 0 degrees angle // Sort itmes and get nearest angle float angle; int position; ArrayList<CarouselItemView> arr = new ArrayList<CarouselItemView>(); for (int i = 0; i < getAdapter().getCount(); i++) arr.add(((CarouselItemView) getAdapter().getView(i, null, null))); Collections.sort( arr, new Comparator<CarouselItemView>() { public int compare(CarouselItemView c1, CarouselItemView c2) { int a1 = (int) c1.getCurrentAngle(); if (a1 > 180) a1 = 360 - a1; int a2 = (int) c2.getCurrentAngle(); if (a2 > 180) a2 = 360 - a2; return (a1 - a2); } }); angle = arr.get(0).getCurrentAngle(); // Make it minimum to rotate if (angle > 180.0f) angle = -(360.0f - angle); // Start rotation if needed if (angle != 0.0f) { mFlingRunnable.startUsingDistance(-angle); } else { // Set selected position position = arr.get(0).getIndex(); setSelectedPositionInt(position); onFinishedMovement(); } }