Java Code Examples for org.chromium.chrome.browser.util.MathUtils#flipSignIf()
The following examples show how to use
org.chromium.chrome.browser.util.MathUtils#flipSignIf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StripLayoutHelper.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Called on touch fling event. This is called before the onUpOrCancel event. * @param time The current time of the app in ms. * @param x The y coordinate of the start of the fling event. * @param y The y coordinate of the start of the fling event. * @param velocityX The amount of velocity in the x direction. * @param velocityY The amount of velocity in the y direction. */ public void fling(long time, float x, float y, float velocityX, float velocityY) { resetResizeTimeout(false); velocityX = MathUtils.flipSignIf(velocityX, LocalizationUtils.isLayoutRtl()); // 1. If we're currently in reorder mode, don't allow the user to fling. if (mInReorderMode) return; // 2. If we're fast expanding or scrolling, figure out the destination of the scroll so we // can apply it to the end of this fling. int scrollDeltaRemaining = 0; if (!mScroller.isFinished()) { scrollDeltaRemaining = mScroller.getFinalX() - mScrollOffset; mInteractingTab = null; mScroller.forceFinished(true); } // 3. Kick off the fling. mScroller.fling( mScrollOffset, 0, (int) velocityX, 0, (int) mMinScrollOffset, 0, 0, 0, 0, 0, time); mScroller.setFinalX(mScroller.getFinalX() + scrollDeltaRemaining); mUpdateHost.requestUpdate(); }
Example 2
Source File: StripLayoutHelper.java From 365browser with Apache License 2.0 | 6 votes |
/** * Called on touch fling event. This is called before the onUpOrCancel event. * @param time The current time of the app in ms. * @param x The y coordinate of the start of the fling event. * @param y The y coordinate of the start of the fling event. * @param velocityX The amount of velocity in the x direction. * @param velocityY The amount of velocity in the y direction. */ public void fling(long time, float x, float y, float velocityX, float velocityY) { resetResizeTimeout(false); velocityX = MathUtils.flipSignIf(velocityX, LocalizationUtils.isLayoutRtl()); // 1. If we're currently in reorder mode, don't allow the user to fling. if (mInReorderMode) return; // 2. If we're fast expanding or scrolling, figure out the destination of the scroll so we // can apply it to the end of this fling. int scrollDeltaRemaining = 0; if (!mScroller.isFinished()) { scrollDeltaRemaining = mScroller.getFinalX() - mScrollOffset; mInteractingTab = null; mScroller.forceFinished(true); } // 3. Kick off the fling. mScroller.fling( mScrollOffset, 0, (int) velocityX, 0, (int) mMinScrollOffset, 0, 0, 0, 0, 0, time); mScroller.setFinalX(mScroller.getFinalX() + scrollDeltaRemaining); mUpdateHost.requestUpdate(); }
Example 3
Source File: StripLayoutHelper.java From AndroidChromium with Apache License 2.0 | 6 votes |
private void computeTabInitialPositions() { // Shift all of the tabs over by the the left margin because we're // no longer base lined at 0 float tabPosition; if (!LocalizationUtils.isLayoutRtl()) { tabPosition = mScrollOffset + mLeftMargin; } else { tabPosition = mWidth - mCachedTabWidth - mScrollOffset - mRightMargin; } for (int i = 0; i < mStripTabs.length; i++) { StripLayoutTab tab = mStripTabs[i]; tab.setIdealX(tabPosition); float delta = (tab.getWidth() - mTabOverlapWidth) * tab.getWidthWeight(); delta = MathUtils.flipSignIf(delta, LocalizationUtils.isLayoutRtl()); tabPosition += delta; } }
Example 4
Source File: StripLayoutHelper.java From 365browser with Apache License 2.0 | 6 votes |
private void computeTabInitialPositions() { // Shift all of the tabs over by the the left margin because we're // no longer base lined at 0 float tabPosition; if (!LocalizationUtils.isLayoutRtl()) { tabPosition = mScrollOffset + mLeftMargin; } else { tabPosition = mWidth - mCachedTabWidth - mScrollOffset - mRightMargin; } for (int i = 0; i < mStripTabs.length; i++) { StripLayoutTab tab = mStripTabs[i]; tab.setIdealX(tabPosition); float delta = (tab.getWidth() - mTabOverlapWidth) * tab.getWidthWeight(); delta = MathUtils.flipSignIf(delta, LocalizationUtils.isLayoutRtl()); tabPosition += delta; } }
Example 5
Source File: StripLayoutHelper.java From delion with Apache License 2.0 | 6 votes |
/** * Called on touch fling event. This is called before the onUpOrCancel event. * @param time The current time of the app in ms. * @param x The y coordinate of the start of the fling event. * @param y The y coordinate of the start of the fling event. * @param velocityX The amount of velocity in the x direction. * @param velocityY The amount of velocity in the y direction. */ public void fling(long time, float x, float y, float velocityX, float velocityY) { resetResizeTimeout(false); velocityX = MathUtils.flipSignIf(velocityX, LocalizationUtils.isLayoutRtl()); // 1. If we're currently in reorder mode, don't allow the user to fling. if (mInReorderMode) return; // 2. If we're fast expanding or scrolling, figure out the destination of the scroll so we // can apply it to the end of this fling. int scrollDeltaRemaining = 0; if (!mScroller.isFinished()) { scrollDeltaRemaining = mScroller.getFinalX() - mScrollOffset; mInteractingTab = null; mScroller.forceFinished(true); } // 3. Kick off the fling. mScroller.fling( mScrollOffset, 0, (int) velocityX, 0, (int) mMinScrollOffset, 0, 0, 0, 0, 0, time); mScroller.setFinalX(mScroller.getFinalX() + scrollDeltaRemaining); mUpdateHost.requestUpdate(); }
Example 6
Source File: StripLayoutHelper.java From delion with Apache License 2.0 | 5 votes |
private void reorderTab(int id, int oldIndex, int newIndex, boolean animate) { StripLayoutTab tab = findTabById(id); if (tab == null || oldIndex == newIndex) return; // 1. If the tab is already at the right spot, don't do anything. int index = findIndexForTab(id); if (index == newIndex) return; // 2. Check if it's the tab we are dragging, but we have an old source index. Ignore in // this case because we probably just already moved it. if (mInReorderMode && index != oldIndex && tab == mInteractingTab) return; // 3. Swap the tabs. moveElement(mStripTabs, index, newIndex); // 4. Update newIndex to point to the proper element. if (index < newIndex) newIndex--; // 5. Animate if necessary. if (animate) { final float flipWidth = mCachedTabWidth - mTabOverlapWidth; final int direction = oldIndex <= newIndex ? 1 : -1; final float animationLength = MathUtils.flipSignIf(direction * flipWidth, LocalizationUtils.isLayoutRtl()); StripLayoutTab slideTab = mStripTabs[newIndex - direction]; startAnimation(buildTabMoveAnimation(slideTab, animationLength), true); } }
Example 7
Source File: StripLayoutHelper.java From 365browser with Apache License 2.0 | 5 votes |
private void updateScrollOffsetPosition(int pos) { int oldScrollOffset = mScrollOffset; mScrollOffset = MathUtils.clamp(pos, (int) mMinScrollOffset, 0); if (mInReorderMode && mScroller.isFinished()) { int delta = MathUtils.flipSignIf( oldScrollOffset - mScrollOffset, LocalizationUtils.isLayoutRtl()); updateReorderPosition(delta); } }
Example 8
Source File: StripLayoutHelper.java From AndroidChromium with Apache License 2.0 | 5 votes |
private void updateScrollOffsetPosition(int pos) { int oldScrollOffset = mScrollOffset; mScrollOffset = MathUtils.clamp(pos, (int) mMinScrollOffset, 0); if (mInReorderMode && mScroller.isFinished()) { int delta = MathUtils.flipSignIf( oldScrollOffset - mScrollOffset, LocalizationUtils.isLayoutRtl()); updateReorderPosition(delta); } }
Example 9
Source File: StripLayoutHelper.java From delion with Apache License 2.0 | 5 votes |
private void updateScrollOffsetPosition(int pos) { int oldScrollOffset = mScrollOffset; mScrollOffset = MathUtils.clamp(pos, (int) mMinScrollOffset, 0); if (mInReorderMode && mScroller.isFinished()) { int delta = MathUtils.flipSignIf( oldScrollOffset - mScrollOffset, LocalizationUtils.isLayoutRtl()); updateReorderPosition(delta); } }
Example 10
Source File: StripLayoutHelper.java From AndroidChromium with Apache License 2.0 | 5 votes |
private void reorderTab(int id, int oldIndex, int newIndex, boolean animate) { StripLayoutTab tab = findTabById(id); if (tab == null || oldIndex == newIndex) return; // 1. If the tab is already at the right spot, don't do anything. int index = findIndexForTab(id); if (index == newIndex) return; // 2. Check if it's the tab we are dragging, but we have an old source index. Ignore in // this case because we probably just already moved it. if (mInReorderMode && index != oldIndex && tab == mInteractingTab) return; // 3. Swap the tabs. moveElement(mStripTabs, index, newIndex); // 4. Update newIndex to point to the proper element. if (index < newIndex) newIndex--; // 5. Animate if necessary. if (animate && !mAnimationsDisabledForTesting) { final float flipWidth = mCachedTabWidth - mTabOverlapWidth; final int direction = oldIndex <= newIndex ? 1 : -1; final float animationLength = MathUtils.flipSignIf(direction * flipWidth, LocalizationUtils.isLayoutRtl()); StripLayoutTab slideTab = mStripTabs[newIndex - direction]; startAnimation(buildTabMoveAnimation(slideTab, animationLength), true); } }
Example 11
Source File: StackLayout.java From AndroidChromium with Apache License 2.0 | 5 votes |
private void scrollStacks(float delta) { cancelAnimation(this, Property.STACK_SNAP); float fullDistance = getFullScrollDistance(); mScrollIndexOffset += MathUtils.flipSignIf(delta / fullDistance, getOrientation() == Orientation.PORTRAIT && LocalizationUtils.isLayoutRtl()); if (canScrollLinearly(getTabStackIndex())) { mRenderedScrollOffset = mScrollIndexOffset; } else { mRenderedScrollOffset = (int) MathUtils.clamp( mScrollIndexOffset, 0, mStacks[1].isDisplayable() ? -1 : 0); } requestStackUpdate(); }
Example 12
Source File: StripLayoutHelper.java From delion with Apache License 2.0 | 4 votes |
private void updateReorderPosition(float deltaX) { if (!mInReorderMode || mInteractingTab == null) return; float offset = mInteractingTab.getOffsetX() + deltaX; int curIndex = findIndexForTab(mInteractingTab.getId()); // 1. Compute the reorder threshold values. final float flipWidth = mCachedTabWidth - mTabOverlapWidth; final float flipThreshold = REORDER_OVERLAP_SWITCH_PERCENTAGE * flipWidth; // 2. Check if we should swap tabs and track the new destination index. int destIndex = TabModel.INVALID_TAB_INDEX; boolean pastLeftThreshold = offset < -flipThreshold; boolean pastRightThreshold = offset > flipThreshold; boolean isNotRightMost = curIndex < mStripTabs.length - 1; boolean isNotLeftMost = curIndex > 0; if (LocalizationUtils.isLayoutRtl()) { boolean oldLeft = pastLeftThreshold; pastLeftThreshold = pastRightThreshold; pastRightThreshold = oldLeft; } if (pastRightThreshold && isNotRightMost) { destIndex = curIndex + 2; } else if (pastLeftThreshold && isNotLeftMost) { destIndex = curIndex - 1; } // 3. If we should swap tabs, make the swap. if (destIndex != TabModel.INVALID_TAB_INDEX) { // 3.a. Since we're about to move the tab we're dragging, adjust it's offset so it // stays in the same apparent position. boolean shouldFlip = LocalizationUtils.isLayoutRtl() ? destIndex < curIndex : destIndex > curIndex; offset += MathUtils.flipSignIf(flipWidth, shouldFlip); // 3.b. Swap the tabs. reorderTab(mInteractingTab.getId(), curIndex, destIndex, true); mModel.moveTab(mInteractingTab.getId(), destIndex); // 3.c. Update our curIndex as we have just moved the tab. curIndex += destIndex > curIndex ? 1 : -1; // 3.d. Update visual tab ordering. updateVisualTabOrdering(); } // 4. Limit offset based on tab position. First tab can't drag left, last tab can't drag // right. if (curIndex == 0) { offset = LocalizationUtils.isLayoutRtl() ? Math.min(0.f, offset) : Math.max(0.f, offset); } if (curIndex == mStripTabs.length - 1) { offset = LocalizationUtils.isLayoutRtl() ? Math.max(0.f, offset) : Math.min(0.f, offset); } // 5. Set the new offset. mInteractingTab.setOffsetX(offset); }
Example 13
Source File: StripLayoutHelper.java From 365browser with Apache License 2.0 | 4 votes |
private void handleReorderAutoScrolling(long time) { if (!mInReorderMode) return; // 1. Track the delta time since the last auto scroll. final float deltaSec = mLastReorderScrollTime == 0 ? 0.f : (time - mLastReorderScrollTime) / 1000.f; mLastReorderScrollTime = time; final float x = mInteractingTab.getDrawX(); // 2. Calculate the gutters for accelerating the scroll speed. // Speed: MAX MIN MIN MAX // |-------|======|--------------------|======|-------| final float dragRange = REORDER_EDGE_SCROLL_START_MAX_DP - REORDER_EDGE_SCROLL_START_MIN_DP; final float leftMinX = REORDER_EDGE_SCROLL_START_MIN_DP + mLeftMargin; final float leftMaxX = REORDER_EDGE_SCROLL_START_MAX_DP + mLeftMargin; final float rightMinX = mWidth - mLeftMargin - mRightMargin - REORDER_EDGE_SCROLL_START_MIN_DP; final float rightMaxX = mWidth - mLeftMargin - mRightMargin - REORDER_EDGE_SCROLL_START_MAX_DP; // 3. See if the current draw position is in one of the gutters and figure out how far in. // Note that we only allow scrolling in each direction if the user has already manually // moved that way. float dragSpeedRatio = 0.f; if ((mReorderState & REORDER_SCROLL_LEFT) != 0 && x < leftMinX) { dragSpeedRatio = -(leftMinX - Math.max(x, leftMaxX)) / dragRange; } else if ((mReorderState & REORDER_SCROLL_RIGHT) != 0 && x + mCachedTabWidth > rightMinX) { dragSpeedRatio = (Math.min(x + mCachedTabWidth, rightMaxX) - rightMinX) / dragRange; } dragSpeedRatio = MathUtils.flipSignIf(dragSpeedRatio, LocalizationUtils.isLayoutRtl()); if (dragSpeedRatio != 0.f) { // 4.a. We're in a gutter. Update the scroll offset. float dragSpeed = REORDER_EDGE_SCROLL_MAX_SPEED_DP * dragSpeedRatio; updateScrollOffsetPosition((int) (mScrollOffset + dragSpeed * deltaSec)); mUpdateHost.requestUpdate(); } else { // 4.b. We're not in a gutter. Reset the scroll delta time tracker. mLastReorderScrollTime = 0; } }
Example 14
Source File: ToolbarPhone.java From delion with Apache License 2.0 | 4 votes |
private void populateUrlFocusingAnimatorSet(List<Animator> animators) { Animator animator = ObjectAnimator.ofFloat(this, mUrlFocusChangePercentProperty, 1f); animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animators.add(animator); for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) { View childView = mPhoneLocationBar.getChildAt(i); if (childView == mPhoneLocationBar.getFirstViewVisibleWhenFocused()) break; animator = ObjectAnimator.ofFloat(childView, ALPHA, 0); animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animators.add(animator); } float density = getContext().getResources().getDisplayMetrics().density; boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this); float toolbarButtonTranslationX = MathUtils.flipSignIf( URL_FOCUS_TOOLBAR_BUTTONS_TRANSLATION_X_DP, isRtl) * density; animator = ObjectAnimator.ofFloat( mMenuButtonWrapper, TRANSLATION_X, toolbarButtonTranslationX); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 0); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); if (mToggleTabStackButton != null) { animator = ObjectAnimator.ofFloat( mToggleTabStackButton, TRANSLATION_X, toolbarButtonTranslationX); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); animator = ObjectAnimator.ofFloat(mToggleTabStackButton, ALPHA, 0); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); } }
Example 15
Source File: StripLayoutHelper.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Called on touch drag event. * @param time The current time of the app in ms. * @param x The y coordinate of the end of the drag event. * @param y The y coordinate of the end of the drag event. * @param deltaX The number of pixels dragged in the x direction. * @param deltaY The number of pixels dragged in the y direction. * @param totalX The total delta x since the drag started. * @param totalY The total delta y since the drag started. */ public void drag( long time, float x, float y, float deltaX, float deltaY, float totalX, float totalY) { resetResizeTimeout(false); deltaX = MathUtils.flipSignIf(deltaX, LocalizationUtils.isLayoutRtl()); // 1. Reset the button state. mNewTabButton.drag(x, y); if (mLastPressedCloseButton != null) { if (!mLastPressedCloseButton.drag(x, y)) mLastPressedCloseButton = null; } if (mInReorderMode) { // 2.a. Handle reordering tabs. // This isn't the accumulated delta since the beginning of the drag. It accumulates // the delta X until a threshold is crossed and then the event gets processed. float accumulatedDeltaX = x - mLastReorderX; if (Math.abs(accumulatedDeltaX) >= 1.f) { if (!LocalizationUtils.isLayoutRtl()) { if (deltaX >= 1.f) { mReorderState |= REORDER_SCROLL_RIGHT; } else if (deltaX <= -1.f) { mReorderState |= REORDER_SCROLL_LEFT; } } else { if (deltaX >= 1.f) { mReorderState |= REORDER_SCROLL_LEFT; } else if (deltaX <= -1.f) { mReorderState |= REORDER_SCROLL_RIGHT; } } mLastReorderX = x; updateReorderPosition(accumulatedDeltaX); } } else if (!mScroller.isFinished()) { // 2.b. Still scrolling, update the scroll destination here. mScroller.setFinalX((int) (mScroller.getFinalX() + deltaX)); } else { // 2.c. Not scrolling. Check if we need to fast expand. float fastExpandDelta; if (mShouldCascadeTabs) { fastExpandDelta = calculateOffsetToMakeTabVisible(mInteractingTab, true, true, true); } else { // Non-cascaded tabs are never hidden behind each other, so there's no need to fast // expand. fastExpandDelta = 0.f; } if (mInteractingTab != null && fastExpandDelta != 0.f) { if ((fastExpandDelta > 0 && deltaX > 0) || (fastExpandDelta < 0 && deltaX < 0)) { mScroller.startScroll( mScrollOffset, 0, (int) fastExpandDelta, 0, time, EXPAND_DURATION_MS); } } else { updateScrollOffsetPosition((int) (mScrollOffset + deltaX)); } } // 3. Check if we should start the reorder mode if (!mInReorderMode) { final float absTotalX = Math.abs(totalX); final float absTotalY = Math.abs(totalY); if (totalY > mReorderMoveStartThreshold && absTotalX < mReorderMoveStartThreshold * 2.f && (absTotalX > EPSILON && (absTotalY / absTotalX) > TAN_OF_REORDER_ANGLE_START_THRESHOLD)) { startReorderMode(time, x, x - totalX); } } // If we're scrolling at all we aren't interacting with any particular tab. // We already kicked off a fast expansion earlier if we needed one. Reorder mode will // repopulate this if necessary. if (!mInReorderMode) mInteractingTab = null; mUpdateHost.requestUpdate(); }
Example 16
Source File: ToolbarPhone.java From 365browser with Apache License 2.0 | 4 votes |
private void populateUrlFocusingAnimatorSet(List<Animator> animators) { Animator animator = ObjectAnimator.ofFloat(this, mUrlFocusChangePercentProperty, 1f); animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animators.add(animator); for (int i = 0; i < mLocationBar.getChildCount(); i++) { View childView = mLocationBar.getChildAt(i); if (childView == mLocationBar.getFirstViewVisibleWhenFocused()) break; animator = ObjectAnimator.ofFloat(childView, ALPHA, 0); animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animators.add(animator); } float density = getContext().getResources().getDisplayMetrics().density; boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this); float toolbarButtonTranslationX = MathUtils.flipSignIf( URL_FOCUS_TOOLBAR_BUTTONS_TRANSLATION_X_DP, isRtl) * density; animator = ObjectAnimator.ofFloat( mMenuButtonWrapper, TRANSLATION_X, toolbarButtonTranslationX); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 0); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); if (mToggleTabStackButton != null) { animator = ObjectAnimator.ofFloat( mToggleTabStackButton, TRANSLATION_X, toolbarButtonTranslationX); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); animator = ObjectAnimator.ofFloat(mToggleTabStackButton, ALPHA, 0); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); } }
Example 17
Source File: StripLayoutHelper.java From AndroidChromium with Apache License 2.0 | 4 votes |
private void updateReorderPosition(float deltaX) { if (!mInReorderMode || mInteractingTab == null) return; float offset = mInteractingTab.getOffsetX() + deltaX; int curIndex = findIndexForTab(mInteractingTab.getId()); // 1. Compute the reorder threshold values. final float flipWidth = mCachedTabWidth - mTabOverlapWidth; final float flipThreshold = REORDER_OVERLAP_SWITCH_PERCENTAGE * flipWidth; // 2. Check if we should swap tabs and track the new destination index. int destIndex = TabModel.INVALID_TAB_INDEX; boolean pastLeftThreshold = offset < -flipThreshold; boolean pastRightThreshold = offset > flipThreshold; boolean isNotRightMost = curIndex < mStripTabs.length - 1; boolean isNotLeftMost = curIndex > 0; if (LocalizationUtils.isLayoutRtl()) { boolean oldLeft = pastLeftThreshold; pastLeftThreshold = pastRightThreshold; pastRightThreshold = oldLeft; } if (pastRightThreshold && isNotRightMost) { destIndex = curIndex + 2; } else if (pastLeftThreshold && isNotLeftMost) { destIndex = curIndex - 1; } // 3. If we should swap tabs, make the swap. if (destIndex != TabModel.INVALID_TAB_INDEX) { // 3.a. Since we're about to move the tab we're dragging, adjust it's offset so it // stays in the same apparent position. boolean shouldFlip = LocalizationUtils.isLayoutRtl() ? destIndex < curIndex : destIndex > curIndex; offset += MathUtils.flipSignIf(flipWidth, shouldFlip); // 3.b. Swap the tabs. reorderTab(mInteractingTab.getId(), curIndex, destIndex, true); mModel.moveTab(mInteractingTab.getId(), destIndex); // 3.c. Update our curIndex as we have just moved the tab. curIndex += destIndex > curIndex ? 1 : -1; // 3.d. Update visual tab ordering. updateVisualTabOrdering(); } // 4. Limit offset based on tab position. First tab can't drag left, last tab can't drag // right. if (curIndex == 0) { offset = LocalizationUtils.isLayoutRtl() ? Math.min(0.f, offset) : Math.max(0.f, offset); } if (curIndex == mStripTabs.length - 1) { offset = LocalizationUtils.isLayoutRtl() ? Math.max(0.f, offset) : Math.min(0.f, offset); } // 5. Set the new offset. mInteractingTab.setOffsetX(offset); }
Example 18
Source File: StripLayoutHelper.java From AndroidChromium with Apache License 2.0 | 4 votes |
private void handleReorderAutoScrolling(long time) { if (!mInReorderMode) return; // 1. Track the delta time since the last auto scroll. final float deltaSec = mLastReorderScrollTime == 0 ? 0.f : (time - mLastReorderScrollTime) / 1000.f; mLastReorderScrollTime = time; final float x = mInteractingTab.getDrawX(); // 2. Calculate the gutters for accelerating the scroll speed. // Speed: MAX MIN MIN MAX // |-------|======|--------------------|======|-------| final float dragRange = REORDER_EDGE_SCROLL_START_MAX_DP - REORDER_EDGE_SCROLL_START_MIN_DP; final float leftMinX = REORDER_EDGE_SCROLL_START_MIN_DP + mLeftMargin; final float leftMaxX = REORDER_EDGE_SCROLL_START_MAX_DP + mLeftMargin; final float rightMinX = mWidth - mLeftMargin - mRightMargin - REORDER_EDGE_SCROLL_START_MIN_DP; final float rightMaxX = mWidth - mLeftMargin - mRightMargin - REORDER_EDGE_SCROLL_START_MAX_DP; // 3. See if the current draw position is in one of the gutters and figure out how far in. // Note that we only allow scrolling in each direction if the user has already manually // moved that way. float dragSpeedRatio = 0.f; if ((mReorderState & REORDER_SCROLL_LEFT) != 0 && x < leftMinX) { dragSpeedRatio = -(leftMinX - Math.max(x, leftMaxX)) / dragRange; } else if ((mReorderState & REORDER_SCROLL_RIGHT) != 0 && x + mCachedTabWidth > rightMinX) { dragSpeedRatio = (Math.min(x + mCachedTabWidth, rightMaxX) - rightMinX) / dragRange; } dragSpeedRatio = MathUtils.flipSignIf(dragSpeedRatio, LocalizationUtils.isLayoutRtl()); if (dragSpeedRatio != 0.f) { // 4.a. We're in a gutter. Update the scroll offset. float dragSpeed = REORDER_EDGE_SCROLL_MAX_SPEED_DP * dragSpeedRatio; updateScrollOffsetPosition((int) (mScrollOffset + dragSpeed * deltaSec)); mUpdateHost.requestUpdate(); } else { // 4.b. We're not in a gutter. Reset the scroll delta time tracker. mLastReorderScrollTime = 0; } }
Example 19
Source File: ToolbarPhone.java From AndroidChromium with Apache License 2.0 | 4 votes |
private void populateUrlFocusingAnimatorSet(List<Animator> animators) { Animator animator = ObjectAnimator.ofFloat(this, mUrlFocusChangePercentProperty, 1f); animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animators.add(animator); for (int i = 0; i < mLocationBar.getChildCount(); i++) { View childView = mLocationBar.getChildAt(i); if (childView == mLocationBar.getFirstViewVisibleWhenFocused()) break; animator = ObjectAnimator.ofFloat(childView, ALPHA, 0); animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animators.add(animator); } float density = getContext().getResources().getDisplayMetrics().density; boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this); float toolbarButtonTranslationX = MathUtils.flipSignIf( URL_FOCUS_TOOLBAR_BUTTONS_TRANSLATION_X_DP, isRtl) * density; animator = ObjectAnimator.ofFloat( mMenuButtonWrapper, TRANSLATION_X, toolbarButtonTranslationX); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 0); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); if (mToggleTabStackButton != null) { animator = ObjectAnimator.ofFloat( mToggleTabStackButton, TRANSLATION_X, toolbarButtonTranslationX); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); animator = ObjectAnimator.ofFloat(mToggleTabStackButton, ALPHA, 0); animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); animators.add(animator); } }
Example 20
Source File: StripLayoutHelper.java From 365browser with Apache License 2.0 | 4 votes |
/** * Called on touch drag event. * @param time The current time of the app in ms. * @param x The y coordinate of the end of the drag event. * @param y The y coordinate of the end of the drag event. * @param deltaX The number of pixels dragged in the x direction. * @param deltaY The number of pixels dragged in the y direction. * @param totalX The total delta x since the drag started. * @param totalY The total delta y since the drag started. */ public void drag( long time, float x, float y, float deltaX, float deltaY, float totalX, float totalY) { resetResizeTimeout(false); deltaX = MathUtils.flipSignIf(deltaX, LocalizationUtils.isLayoutRtl()); // 1. Reset the button state. mNewTabButton.drag(x, y); if (mLastPressedCloseButton != null) { if (!mLastPressedCloseButton.drag(x, y)) mLastPressedCloseButton = null; } if (mInReorderMode) { // 2.a. Handle reordering tabs. // This isn't the accumulated delta since the beginning of the drag. It accumulates // the delta X until a threshold is crossed and then the event gets processed. float accumulatedDeltaX = x - mLastReorderX; if (Math.abs(accumulatedDeltaX) >= 1.f) { if (!LocalizationUtils.isLayoutRtl()) { if (deltaX >= 1.f) { mReorderState |= REORDER_SCROLL_RIGHT; } else if (deltaX <= -1.f) { mReorderState |= REORDER_SCROLL_LEFT; } } else { if (deltaX >= 1.f) { mReorderState |= REORDER_SCROLL_LEFT; } else if (deltaX <= -1.f) { mReorderState |= REORDER_SCROLL_RIGHT; } } mLastReorderX = x; updateReorderPosition(accumulatedDeltaX); } } else if (!mScroller.isFinished()) { // 2.b. Still scrolling, update the scroll destination here. mScroller.setFinalX((int) (mScroller.getFinalX() + deltaX)); } else { // 2.c. Not scrolling. Check if we need to fast expand. float fastExpandDelta; if (mShouldCascadeTabs) { fastExpandDelta = calculateOffsetToMakeTabVisible(mInteractingTab, true, true, true); } else { // Non-cascaded tabs are never hidden behind each other, so there's no need to fast // expand. fastExpandDelta = 0.f; } if (mInteractingTab != null && fastExpandDelta != 0.f) { if ((fastExpandDelta > 0 && deltaX > 0) || (fastExpandDelta < 0 && deltaX < 0)) { mScroller.startScroll( mScrollOffset, 0, (int) fastExpandDelta, 0, time, EXPAND_DURATION_MS); } } else { updateScrollOffsetPosition((int) (mScrollOffset + deltaX)); } } // 3. Check if we should start the reorder mode if (!mInReorderMode) { final float absTotalX = Math.abs(totalX); final float absTotalY = Math.abs(totalY); if (totalY > mReorderMoveStartThreshold && absTotalX < mReorderMoveStartThreshold * 2.f && (absTotalX > EPSILON && (absTotalY / absTotalX) > TAN_OF_REORDER_ANGLE_START_THRESHOLD)) { startReorderMode(time, x, x - totalX); } } // If we're scrolling at all we aren't interacting with any particular tab. // We already kicked off a fast expansion earlier if we needed one. Reorder mode will // repopulate this if necessary. if (!mInReorderMode) mInteractingTab = null; mUpdateHost.requestUpdate(); }