org.chromium.ui.base.LocalizationUtils Java Examples

The following examples show how to use org.chromium.ui.base.LocalizationUtils. 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: FindResultBar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/** Dismisses this results bar by removing it from the view hierarchy. */
public void dismiss() {
    mDismissing = true;
    mFindInPageBridge = null;
    if (mVisibilityAnimation != null && mVisibilityAnimation.isRunning()) {
        mVisibilityAnimation.cancel();
    }

    mVisibilityAnimation = ObjectAnimator.ofFloat(this, TRANSLATION_X,
            MathUtils.flipSignIf(mBarTouchWidth, LocalizationUtils.isLayoutRtl()));
    mVisibilityAnimation.setDuration(VISIBILITY_ANIMATION_DURATION_MS);
    mVisibilityAnimation.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
    mTab.getWindowAndroid().startAnimationOverContent(mVisibilityAnimation);
    mVisibilityAnimation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);

            if (getParent() != null) ((ViewGroup) getParent()).removeView(FindResultBar.this);
        }
    });
}
 
Example #2
Source File: StripLayoutHelper.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * 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 delion with Apache License 2.0 6 votes vote down vote up
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 delion with Apache License 2.0 6 votes vote down vote up
/**
 * When the {@link ScrollingStripStacker} is being used, a fade is shown at the left and
 * right edges to indicate there is tab strip content off screen. As the scroll position
 * approaches the edge of the screen, the fade opacity is lowered.
 *
 * @param isLeft Whether the opacity for the left or right side should be returned.
 * @return The opacity to use for the fade.
 */
private float getFadeOpacity(boolean isLeft) {
    if (mShouldCascadeTabs) return 0.f;

    // In RTL, scroll position 0 is on the right side of the screen, whereas in LTR scroll
    // position 0 is on the left. Account for that in the offset calculation.
    boolean isRtl = LocalizationUtils.isLayoutRtl();
    boolean useUnadjustedScrollOffset = isRtl != isLeft;
    float offset = -(useUnadjustedScrollOffset ? mScrollOffset
            : (mMinScrollOffset - mScrollOffset));

    if (offset == 0.f) {
        return 0.f;
    } else if (offset >= FADE_FULL_OPACITY_THRESHOLD_DP) {
        return 1.f;
    } else {
        return offset / FADE_FULL_OPACITY_THRESHOLD_DP;
    }
}
 
Example #5
Source File: ContextualSearchPanel.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Simulates a tap on the panel's end button.
 */
@VisibleForTesting
public void simulateTapOnEndButton() {
    // Finish all currently running animations.
    onUpdateAnimation(System.currentTimeMillis(), true);

    // Determine the x-position for the simulated tap.
    float xPosition;
    if (LocalizationUtils.isLayoutRtl()) {
        xPosition = getContentX() + (mEndButtonWidthDp / 2);
    } else {
        xPosition = getContentX() + getWidth() - (mEndButtonWidthDp / 2);
    }

    // Determine the y-position for the simulated tap.
    float yPosition = getOffsetY() + (getHeight() / 2);

    // Simulate the tap.
    handleClick(System.currentTimeMillis(), xPosition, yPosition);
}
 
Example #6
Source File: Stack.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Called on drag event (from scroll events in the gesture detector).
 *
 * @param time    The current time of the app in ms.
 * @param x       The x coordinate of the end of the drag event.
 * @param y       The y coordinate of the end of the drag event.
 * @param amountX The number of pixels dragged in the x direction since the last event.
 * @param amountY The number of pixels dragged in the y direction since the last event.
 */
public void drag(long time, float x, float y, float amountX, float amountY) {
    float scrollDrag, discardDrag;
    if (mCurrentMode == Orientation.PORTRAIT) {
        discardDrag = amountX;
        scrollDrag = amountY;
    } else {
        discardDrag = amountY;
        scrollDrag = LocalizationUtils.isLayoutRtl() ? -amountX : amountX;
    }
    DragLock hintLock = computeDragLock(scrollDrag, discardDrag);
    if (hintLock == DragLock.DISCARD) {
        discard(x, y, amountX, amountY);
    } else {
        // Only cancel the current discard attempt if the scroll lock is committed:
        // by using mDragLock instead of hintLock.
        if (mDragLock == DragLock.SCROLL && mDiscardingTab != null) {
            commitDiscard(time, false);
        }
        scroll(x, y, LocalizationUtils.isLayoutRtl() ? -amountX : amountX, amountY, false);
    }
    requestUpdate();
}
 
Example #7
Source File: StripLayoutHelperManager.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onSizeChanged(
        float width, float height, float visibleViewportOffsetY, int orientation) {
    mWidth = width;
    mOrientation = orientation;
    if (!LocalizationUtils.isLayoutRtl()) {
        mModelSelectorButton.setX(
                mWidth - MODEL_SELECTOR_BUTTON_WIDTH_DP - MODEL_SELECTOR_BUTTON_END_PADDING_DP);
    } else {
        mModelSelectorButton.setX(MODEL_SELECTOR_BUTTON_END_PADDING_DP);
    }

    mNormalHelper.onSizeChanged(mWidth, mHeight);
    mIncognitoHelper.onSizeChanged(mWidth, mHeight);

    mStripFilterArea.set(0, 0, mWidth, Math.min(getHeight(), visibleViewportOffsetY));
    mEventFilter.setEventArea(mStripFilterArea);
}
 
Example #8
Source File: LayoutManagerChrome.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType launchType) {
    int tabId = tab.getId();
    if (launchType == TabLaunchType.FROM_RESTORE) {
        getActiveLayout().onTabRestored(time(), tabId);
    } else {
        boolean incognito = tab.isIncognito();
        boolean willBeSelected = launchType != TabLaunchType.FROM_LONGPRESS_BACKGROUND
                || (!getTabModelSelector().isIncognitoSelected() && incognito);
        float lastTapX = LocalizationUtils.isLayoutRtl() ? mLastContentWidthDp : 0.f;
        float lastTapY = 0.f;
        if (launchType != TabLaunchType.FROM_CHROME_UI) {
            float heightDelta =
                    mLastFullscreenViewportDp.height() - mLastVisibleViewportDp.height();
            lastTapX = mPxToDp * mLastTapX;
            lastTapY = mPxToDp * mLastTapY - heightDelta;
        }

        tabCreated(tabId, getTabModelSelector().getCurrentTabId(), launchType, incognito,
                willBeSelected, lastTapX, lastTapY);
    }
}
 
Example #9
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void updateNewTabButtonState() {
    // 1. Don't display the new tab button if we're in reorder mode.
    if (mInReorderMode || mStripTabs.length == 0) {
        mNewTabButton.setVisible(false);
        return;
    }

    // 1. Get offset from strip stacker.
    float offset = mStripStacker.computeNewTabButtonOffset(mStripTabs,
            mTabOverlapWidth, mLeftMargin, mRightMargin, mWidth, mNewTabButtonWidth);

    // 2. Hide the new tab button if it's not visible on the screen.
    boolean isRtl = LocalizationUtils.isLayoutRtl();
    if ((isRtl && offset + mNewTabButtonWidth < 0) || (!isRtl && offset > mWidth)) {
        mNewTabButton.setVisible(false);
        return;
    }
    mNewTabButton.setVisible(true);

    // 3. Position the new tab button.
    mNewTabButton.setX(offset);
}
 
Example #10
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #11
Source File: Stack.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Called on drag event (from scroll events in the gesture detector).
 *
 * @param time    The current time of the app in ms.
 * @param x       The x coordinate of the end of the drag event.
 * @param y       The y coordinate of the end of the drag event.
 * @param amountX The number of pixels dragged in the x direction since the last event.
 * @param amountY The number of pixels dragged in the y direction since the last event.
 */
public void drag(long time, float x, float y, float amountX, float amountY) {
    float scrollDrag, discardDrag;
    if (mCurrentMode == Orientation.PORTRAIT) {
        discardDrag = amountX;
        scrollDrag = amountY;
    } else {
        discardDrag = amountY;
        scrollDrag = LocalizationUtils.isLayoutRtl() ? -amountX : amountX;
    }
    DragLock hintLock = computeDragLock(scrollDrag, discardDrag);
    if (hintLock == DragLock.DISCARD) {
        discard(x, y, amountX, amountY);
    } else {
        // Only cancel the current discard attempt if the scroll lock is committed:
        // by using mDragLock instead of hintLock.
        if (mDragLock == DragLock.SCROLL && mDiscardingTab != null) {
            commitDiscard(time, false);
        }
        scroll(x, y, LocalizationUtils.isLayoutRtl() ? -amountX : amountX, amountY, false);
    }
    requestUpdate();
}
 
Example #12
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * When the {@link ScrollingStripStacker} is being used, a fade is shown at the left and
 * right edges to indicate there is tab strip content off screen. As the scroll position
 * approaches the edge of the screen, the fade opacity is lowered.
 *
 * @param isLeft Whether the opacity for the left or right side should be returned.
 * @return The opacity to use for the fade.
 */
private float getFadeOpacity(boolean isLeft) {
    if (mShouldCascadeTabs) return 0.f;

    // In RTL, scroll position 0 is on the right side of the screen, whereas in LTR scroll
    // position 0 is on the left. Account for that in the offset calculation.
    boolean isRtl = LocalizationUtils.isLayoutRtl();
    boolean useUnadjustedScrollOffset = isRtl != isLeft;
    float offset = -(useUnadjustedScrollOffset ? mScrollOffset
            : (mMinScrollOffset - mScrollOffset));

    if (offset == 0.f) {
        return 0.f;
    } else if (offset >= FADE_FULL_OPACITY_THRESHOLD_DP) {
        return 1.f;
    } else {
        return offset / FADE_FULL_OPACITY_THRESHOLD_DP;
    }
}
 
Example #13
Source File: FindResultBar.java    From delion with Apache License 2.0 6 votes vote down vote up
/** Dismisses this results bar by removing it from the view hierarchy. */
public void dismiss() {
    mDismissing = true;
    mFindInPageBridge = null;
    if (mVisibilityAnimation != null && mVisibilityAnimation.isRunning()) {
        mVisibilityAnimation.cancel();
    }

    mVisibilityAnimation = ObjectAnimator.ofFloat(this, TRANSLATION_X,
            MathUtils.flipSignIf(mBarTouchWidth, LocalizationUtils.isLayoutRtl()));
    mVisibilityAnimation.setDuration(VISIBILITY_ANIMATION_DURATION_MS);
    mVisibilityAnimation.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
    mTab.getWindowAndroid().startAnimationOverContent(mVisibilityAnimation);
    mVisibilityAnimation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);

            if (getParent() != null) ((ViewGroup) getParent()).removeView(FindResultBar.this);
        }
    });
}
 
Example #14
Source File: LocationBarTablet.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Updates completion percentage for the location bar width change animation.
 * @param percent How complete the animation is, where 0 represents the normal width (toolbar
 *                buttons fully visible) and 1.f represents the expanded width (toolbar buttons
 *                fully hidden).
 */
private void setWidthChangeAnimationPercent(float percent) {
    mWidthChangePercent = percent;
    float offset = (mToolbarButtonsWidth + mToolbarStartPaddingDifference) * percent;

    if (LocalizationUtils.isLayoutRtl()) {
        // The location bar's right edge is its regular layout position when toolbar buttons are
        // completely visible and its layout position + mToolbarButtonsWidth when toolbar
        // buttons are completely hidden.
        setRight((int) (mLayoutRight + offset));
    } else {
        // The location bar's left edge is it's regular layout position when toolbar buttons are
        // completely visible and its layout position - mToolbarButtonsWidth when they are
        // completely hidden.
        setLeft((int) (mLayoutLeft - offset));
    }

    // As the location bar's right edge moves right (increases) or left edge moves left
    // (decreases), the child views' translation X increases, keeping them visually in the same
    // location for the duration of the animation.
    int deleteOffset = (int) (mMicButtonWidth * percent);
    setChildTranslationsForWidthChangeAnimation((int) offset, deleteOffset);
}
 
Example #15
Source File: LayoutManagerChrome.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType launchType) {
    int tabId = tab.getId();
    if (launchType != TabLaunchType.FROM_RESTORE) {
        boolean incognito = tab.isIncognito();
        boolean willBeSelected = launchType != TabLaunchType.FROM_LONGPRESS_BACKGROUND
                || (!getTabModelSelector().isIncognitoSelected() && incognito);
        float lastTapX = LocalizationUtils.isLayoutRtl() ? mLastContentWidthDp : 0.f;
        float lastTapY = 0.f;
        if (launchType != TabLaunchType.FROM_CHROME_UI) {
            float heightDelta =
                    mLastFullscreenViewportDp.height() - mLastVisibleViewportDp.height();
            lastTapX = mPxToDp * mLastTapX;
            lastTapY = mPxToDp * mLastTapY - heightDelta;
        }

        tabCreated(tabId, getTabModelSelector().getCurrentTabId(), launchType, incognito,
                willBeSelected, lastTapX, lastTapY);
    }
}
 
Example #16
Source File: StackViewAnimation.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private Animator createNewTabOpenedAnimator(
        StackTab[] tabs, ViewGroup container, TabModel model, int focusIndex) {
    Tab tab = model.getTabAt(focusIndex);
    if (tab == null || !tab.isNativePage()) return null;

    View view = tab.getView();
    if (view == null) return null;

    // Set up the view hierarchy
    if (view.getParent() != null) ((ViewGroup) view.getParent()).removeView(view);
    ViewGroup bgView = new FrameLayout(view.getContext());
    bgView.setBackgroundColor(tab.getBackgroundColor());
    bgView.addView(view);
    container.addView(
            bgView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    // Update any compositor state that needs to change
    if (tabs != null && focusIndex >= 0 && focusIndex < tabs.length) {
        tabs[focusIndex].setAlpha(0.f);
    }

    // Build the view animations
    PropertyValuesHolder xScale = PropertyValuesHolder.ofFloat(View.SCALE_X, 0.f, 1.f);
    PropertyValuesHolder yScale = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0.f, 1.f);
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat(View.ALPHA, 0.f, 1.f);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
            bgView, xScale, yScale, alpha);

    animator.setDuration(TAB_OPENED_ANIMATION_DURATION);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_FOLLOW_THROUGH_CURVE);

    float insetPx = TAB_OPENED_PIVOT_INSET_DP * mDpToPx;

    bgView.setPivotY(TAB_OPENED_PIVOT_INSET_DP);
    bgView.setPivotX(LocalizationUtils.isLayoutRtl() ? mWidthDp * mDpToPx - insetPx : insetPx);
    return animator;
}
 
Example #17
Source File: Stack.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called on touch click event.
 *
 * @param time The current time of the app in ms.
 * @param x    The x coordinate in pixel inside the stack view.
 * @param y    The y coordinate in pixel inside the stack view.
 */
public void click(long time, float x, float y) {
    if (mOverviewAnimationType != OverviewAnimationType.NONE
            && mOverviewAnimationType != OverviewAnimationType.DISCARD
            && mOverviewAnimationType != OverviewAnimationType.UNDISCARD
            && mOverviewAnimationType != OverviewAnimationType.DISCARD_ALL) {
        return;
    }
    int clicked = getTabIndexAtPositon(x, y, LayoutTab.getTouchSlop());
    if (clicked >= 0) {
        // Check if the click was within the boundaries of the close button defined by its
        // visible coordinates.
        boolean isRtl =
                !((mCurrentMode == Orientation.PORTRAIT) ^ LocalizationUtils.isLayoutRtl());
        if (mStackTabs[clicked].getLayoutTab().checkCloseHitTest(x, y, isRtl)) {
            // Tell the model to close the tab because the close button was pressed.  The model
            // will then trigger a notification which will start the actual close process here
            // if necessary.
            StackTab tab = mStackTabs[clicked];
            final float halfCloseBtnWidth = LayoutTab.CLOSE_BUTTON_WIDTH_DP / 2.f;
            final float halfCloseBtnHeight = mBorderTopPadding / 2.f;
            final float contentWidth = tab.getLayoutTab().getOriginalContentWidth();

            tab.setDiscardOriginY(halfCloseBtnHeight);
            tab.setDiscardOriginX(isRtl ? halfCloseBtnWidth : contentWidth - halfCloseBtnWidth);
            tab.setDiscardFromClick(true);
            mLayout.uiRequestingCloseTab(time, tab.getId());
            RecordUserAction.record("MobileStackViewCloseTab");
            RecordUserAction.record("MobileTabClosed");
        } else {
            // Let the model know that a new {@link LayoutTab} was selected. The model will
            // notify us if we need to do anything visual. setIndex() will possibly switch the
            // models and broadcast the event.
            mLayout.uiSelectingTab(time, mStackTabs[clicked].getId());
        }
    }
}
 
Example #18
Source File: ScrollingStripStacker.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public float computeNewTabButtonOffset(StripLayoutTab[] indexOrderedTabs,
        float tabOverlapWidth, float stripLeftMargin, float stripRightMargin, float stripWidth,
        float newTabButtonWidth) {
    return LocalizationUtils.isLayoutRtl()
            ? computeNewTabButtonOffsetRtl(indexOrderedTabs, tabOverlapWidth, stripRightMargin,
                    stripWidth, newTabButtonWidth)
                            : computeNewTabButtonOffsetLtr(indexOrderedTabs, tabOverlapWidth,
                                    stripLeftMargin, stripWidth);
}
 
Example #19
Source File: StackLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
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 #20
Source File: Stack.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Animates all the tabs closing at once.
 *
 * @param time The current time of the app in ms.
 */
public void tabsAllClosingEffect(long time) {
    boolean needAnimation = false;

    if (mStackTabs != null) {
        for (int i = 0; i < mStackTabs.length; ++i) {
            needAnimation |= !mStackTabs[i].isDying();
            mStackTabs[i].setDying(true);
        }
    } else {
        // This needs to be set to true to handle the case where both the normal and incognito
        // tabs are being closed.
        needAnimation = true;
    }

    if (needAnimation) {
        mScrollOffsetForDyingTabs = mScrollOffset;
        mSpacing = computeSpacing(0);

        if (mStackTabs != null) {
            boolean isRtl =
                    !((mCurrentMode == Orientation.PORTRAIT) ^ LocalizationUtils.isLayoutRtl());
            for (int i = 0; i < mStackTabs.length; i++) {
                StackTab tab = mStackTabs[i];
                tab.setDiscardOriginY(0.f);
                tab.setDiscardOriginX(
                        isRtl ? 0.f : tab.getLayoutTab().getOriginalContentWidth());
                tab.setDiscardFromClick(true);
            }
        }
        startAnimation(time, OverviewAnimationType.DISCARD_ALL);
    }

    mIsDying = true;
}
 
Example #21
Source File: FindResultBar.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
RectF toRectF() {
    int leftMargin = getLeftMargin();
    RectF rect = new RectF(leftMargin, mTop, leftMargin + mBarDrawWidth, mBottom);
    rect.inset(2.0f, 0.5f);
    rect.offset(LocalizationUtils.isLayoutRtl() ? -0.5f : 0.5f, 0);
    return rect;
}
 
Example #22
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
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 #23
Source File: ContextualSearchPromoControl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the Promo Android View. By making the Android View visible, we are allowing the
 * Promo to be interactive. Since snapshots are not interactive (they are just a bitmap),
 * we need to temporarily show the Android View on top of the snapshot, so the user will
 * be able to click in the Promo buttons and/or link.
 */
private void showPromoView() {
    float y = getYPx();
    View view = getView();
    if (view == null
            || !mIsVisible
            || (mIsShowingView && mPromoViewY == y)
            || mHeightPx == 0.f) return;

    float offsetX = mOverlayPanel.getOffsetX() * mDpToPx;
    if (LocalizationUtils.isLayoutRtl()) {
        offsetX = -offsetX;
    }

    view.setTranslationX(offsetX);
    view.setTranslationY(y);
    view.setVisibility(View.VISIBLE);

    // NOTE(pedrosimonetti): We need to call requestLayout, otherwise
    // the Promo View will not become visible.
    view.requestLayout();

    mIsShowingView = true;
    mPromoViewY = y;

    // The Promo can only be interacted when the View is being displayed.
    mWasInteractive = true;
}
 
Example #24
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @param margin The distance between the last tab and the edge of the screen.
 */
public void setEndMargin(float margin) {
    if (LocalizationUtils.isLayoutRtl()) {
        mLeftMargin = margin + mNewTabButtonWidth;
    } else {
        mRightMargin = margin + mNewTabButtonWidth;
    }
}
 
Example #25
Source File: ContextualSearchPanel.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private boolean isCoordinateInsideActionTarget(float x) {
    if (LocalizationUtils.isLayoutRtl()) {
        return x >= getContentX() + mEndButtonWidthDp;
    } else {
        return x <= getContentX() + getWidth() - mEndButtonWidthDp;
    }
}
 
Example #26
Source File: ScrollingStripStacker.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public float computeNewTabButtonOffset(StripLayoutTab[] indexOrderedTabs,
        float tabOverlapWidth, float stripLeftMargin, float stripRightMargin, float stripWidth,
        float newTabButtonWidth) {
    return LocalizationUtils.isLayoutRtl()
            ? computeNewTabButtonOffsetRtl(indexOrderedTabs, tabOverlapWidth, stripRightMargin,
                    stripWidth, newTabButtonWidth)
                            : computeNewTabButtonOffsetLtr(indexOrderedTabs, tabOverlapWidth,
                                    stripLeftMargin, stripWidth);
}
 
Example #27
Source File: FindResultBar.java    From delion with Apache License 2.0 5 votes vote down vote up
RectF toRectF() {
    int leftMargin = getLeftMargin();
    RectF rect = new RectF(leftMargin, mTop, leftMargin + mBarDrawWidth, mBottom);
    rect.inset(2.0f, 0.5f);
    rect.offset(LocalizationUtils.isLayoutRtl() ? -0.5f : 0.5f, 0);
    return rect;
}
 
Example #28
Source File: ContextualSearchBarControl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @param x The x-position of the touch in px.
 * @return Whether the touch occurred on the search Bar's end button.
 */
private boolean isTouchOnEndButton(float x) {
    if (getDividerLineVisibilityPercentage() == 0.f) return false;

    float xPx = x * mDpToPx;
    if (LocalizationUtils.isLayoutRtl()) return xPx <= getDividerLineXOffset();
    return xPx > getDividerLineXOffset();
}
 
Example #29
Source File: StackLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Computes the input mode for drag and fling based on the first event position.
 * @param time The current time of the app in ms.
 * @param x    The x layout position of the mouse (without the displacement).
 * @param y    The y layout position of the mouse (without the displacement).
 * @param dx   The x displacement happening this frame.
 * @param dy   The y displacement happening this frame.
 * @return     The input mode to select.
 */
private SwipeMode computeInputMode(long time, float x, float y, float dx, float dy) {
    if (!mStacks[1].isDisplayable()) return SwipeMode.SEND_TO_STACK;
    int currentIndex = getTabStackIndex();
    if (currentIndex != getViewportParameters().getStackIndexAt(x, y)) {
        return SwipeMode.SWITCH_STACK;
    }
    float relativeX = mLastOnDownX - (x + dx);
    float relativeY = mLastOnDownY - (y + dy);
    float distanceToDownSqr = dx * dx + dy * dy;
    float switchDelta = getOrientation() == Orientation.PORTRAIT ? relativeX : relativeY;
    float otherDelta = getOrientation() == Orientation.PORTRAIT ? relativeY : relativeX;

    // Dragging in the opposite direction of the stack switch
    if (distanceToDownSqr > mMinDirectionThreshold * mMinDirectionThreshold
            && Math.abs(otherDelta) > Math.abs(switchDelta)) {
        return SwipeMode.SEND_TO_STACK;
    }
    // Dragging in a direction the stack cannot switch
    if (Math.abs(switchDelta) > mMinDirectionThreshold) {
        if ((currentIndex == 0) ^ (switchDelta > 0)
                ^ (getOrientation() == Orientation.PORTRAIT
                          && LocalizationUtils.isLayoutRtl())) {
            return SwipeMode.SEND_TO_STACK;
        }
    }
    if (isDraggingStackInWrongDirection(
                mLastOnDownX, mLastOnDownY, x, y, dx, dy, getOrientation(), currentIndex)) {
        return SwipeMode.SWITCH_STACK;
    }
    // Not moving the finger
    if (time - mLastOnDownTimeStamp > THRESHOLD_TIME_TO_SWITCH_STACK_INPUT_MODE) {
        return SwipeMode.SEND_TO_STACK;
    }
    // Dragging fast
    if (distanceToDownSqr > mMinShortPressThresholdSqr) {
        return SwipeMode.SWITCH_STACK;
    }
    return SwipeMode.NONE;
}
 
Example #30
Source File: ContextualSearchBarControl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return The x-offset for the divider line relative to the x-position of the Bar in px.
 */
public float getDividerLineXOffset() {
    if (LocalizationUtils.isLayoutRtl()) {
        return mEndButtonWidth;
    } else {
        return mOverlayPanel.getContentViewWidthPx() - mEndButtonWidth - getDividerLineWidth();
    }
}