Java Code Examples for org.chromium.base.ApiCompatibilityUtils#isLayoutRtl()

The following examples show how to use org.chromium.base.ApiCompatibilityUtils#isLayoutRtl() . 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: ViewAndroidDelegate.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Set the anchor view to specified position and size (all units in dp).
 * @param view The anchor view that needs to be positioned.
 * @param x X coordinate of the top left corner of the anchor view.
 * @param y Y coordinate of the top left corner of the anchor view.
 * @param width The width of the anchor view.
 * @param height The height of the anchor view.
 */
@CalledByNative
public void setViewPosition(View view, float x, float y,
        float width, float height, float scale, int leftMargin, int topMargin) {
    ViewGroup containerView = getContainerView();
    if (containerView == null) return;

    int scaledWidth = Math.round(width * scale);
    int scaledHeight = Math.round(height * scale);
    int startMargin;

    if (ApiCompatibilityUtils.isLayoutRtl(containerView)) {
        startMargin = containerView.getMeasuredWidth() - Math.round((width + x) * scale);
    } else {
        startMargin = leftMargin;
    }
    if (scaledWidth + startMargin > containerView.getWidth()) {
        scaledWidth = containerView.getWidth() - startMargin;
    }
    LayoutParams lp = new LayoutParams(scaledWidth, scaledHeight);
    ApiCompatibilityUtils.setMarginStart(lp, startMargin);
    lp.topMargin = topMargin;
    view.setLayoutParams(lp);
}
 
Example 2
Source File: InfoBarControlLayout.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int width = right - left;
    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);

    // Child positions were already determined during the measurement pass.
    for (int childIndex = 0; childIndex < getChildCount(); childIndex++) {
        View child = getChildAt(childIndex);
        int childLeft = getControlLayoutParams(child).start;
        if (isRtl) childLeft = width - childLeft - child.getMeasuredWidth();

        int childTop = getControlLayoutParams(child).top;
        int childRight = childLeft + child.getMeasuredWidth();
        int childBottom = childTop + child.getMeasuredHeight();
        child.layout(childLeft, childTop, childRight, childBottom);
    }
}
 
Example 3
Source File: ValidationMessageBubble.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private float getAnchorOffset() {
    final View root = mPopup.getContentView();
    final int width = root.getMeasuredWidth();
    final int arrowWidth = root.findViewById(R.id.arrow_image).getMeasuredWidth();
    return ApiCompatibilityUtils.isLayoutRtl(root)
            ? (width * 3 / 4 - arrowWidth / 2) : (width / 4 + arrowWidth / 2);
}
 
Example 4
Source File: ToolbarPhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @param visualState The current {@link VisualState} of the toolbar.
 * @return The left bounds of the location bar, accounting for any buttons on the left side
 *         of the toolbar.
 */
protected int getViewBoundsLeftOfLocationBar(VisualState visualState) {
    // Uses getMeasuredWidth()s instead of getLeft() because this is called in onMeasure
    // and the layout values have not yet been set.
    if (visualState == VisualState.NEW_TAB_NORMAL) {
        return 0;
    } else if (ApiCompatibilityUtils.isLayoutRtl(this)) {
        return getBoundsAfterAccountingForRightButtons();
    } else {
        return getBoundsAfterAccountingForLeftButton();
    }
}
 
Example 5
Source File: LocationBarPhone.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void getContentRect(Rect outRect) {
    super.getContentRect(outRect);
    if (mIncognitoBadge.getVisibility() == View.GONE) return;

    if (!ApiCompatibilityUtils.isLayoutRtl(this)) {
        outRect.left += mIncognitoBadge.getWidth();
    } else {
        outRect.right -= mIncognitoBadge.getWidth();
    }
}
 
Example 6
Source File: SuggestionView.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private int getUrlBarLeftOffset() {
    if (DeviceFormFactor.isTablet(getContext())) {
        mUrlBar.getLocationInWindow(mViewPositionHolder);
        return mViewPositionHolder[0];
    } else {
        return ApiCompatibilityUtils.isLayoutRtl(this) ? mPhoneUrlBarLeftOffsetRtlPx
                : mPhoneUrlBarLeftOffsetPx;
    }
}
 
Example 7
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private int getViewBoundsLeftOfLocationBar(VisualState visualState) {
    // Uses getMeasuredWidth()s instead of getLeft() because this is called in onMeasure
    // and the layout values have not yet been set.
    if (visualState == VisualState.NEW_TAB_NORMAL) {
        return 0;
    } else if (ApiCompatibilityUtils.isLayoutRtl(this)) {
        return Math.max(
                mToolbarSidePadding, mToolbarButtonsContainer.getMeasuredWidth());
    } else {
        return getBoundsAfterAccountingForLeftButton();
    }
}
 
Example 8
Source File: ViewAnchoredTextBubble.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void refreshAnchorBounds() {
    mAnchorView.getLocationOnScreen(mCachedScreenCoordinates);
    mAnchorRect.left = mCachedScreenCoordinates[0];
    mAnchorRect.top = mCachedScreenCoordinates[1];
    mAnchorRect.right = mAnchorRect.left + mAnchorView.getWidth();
    mAnchorRect.bottom = mAnchorRect.top + mAnchorView.getHeight();

    mAnchorRect.left += mInsetRect.left;
    mAnchorRect.top += mInsetRect.top;
    mAnchorRect.right -= mInsetRect.right;
    mAnchorRect.bottom -= mInsetRect.bottom;

    // Account for the padding.
    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(mAnchorView);
    mAnchorRect.left += isRtl ? ApiCompatibilityUtils.getPaddingEnd(mAnchorView)
                              : ApiCompatibilityUtils.getPaddingStart(mAnchorView);
    mAnchorRect.right -= isRtl ? ApiCompatibilityUtils.getPaddingStart(mAnchorView)
                               : ApiCompatibilityUtils.getPaddingEnd(mAnchorView);
    mAnchorRect.top += mAnchorView.getPaddingTop();
    mAnchorRect.bottom -= mAnchorView.getPaddingBottom();

    // Make sure we still have a valid Rect after applying the inset.
    mAnchorRect.right = Math.max(mAnchorRect.left, mAnchorRect.right);
    mAnchorRect.bottom = Math.max(mAnchorRect.top, mAnchorRect.bottom);

    setAnchorRect(mAnchorRect);
}
 
Example 9
Source File: NewTabButton.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
    int paddingStart = ApiCompatibilityUtils.getPaddingStart(this);
    int widthWithoutPadding = getWidth() - paddingStart;

    canvas.save();
    if (!isRtl) canvas.translate(paddingStart, 0);

    canvas.save();
    canvas.translate(0, (getHeight() - mNormalDrawable.getIntrinsicHeight()) / 2.f);
    if (isRtl) {
        canvas.translate(widthWithoutPadding - mNormalDrawable.getIntrinsicWidth(), 0);
    }
    mNormalDrawable.draw(canvas);
    canvas.restore();

    if (mIsIncognito || (mTransitionAnimation != null && mTransitionAnimation.isRunning())) {
        canvas.save();
        canvas.translate(0, (getHeight() - mIncognitoDrawable.getIntrinsicHeight()) / 2.f);
        if (isRtl) {
            canvas.translate(widthWithoutPadding - mIncognitoDrawable.getIntrinsicWidth(), 0);
        }
        mIncognitoDrawable.draw(canvas);
        canvas.restore();
    }

    canvas.restore();
}
 
Example 10
Source File: ToolbarPhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @param visualState The current {@link VisualState} of the toolbar.
 * @return The right bounds of the location bar, accounting for any buttons on the right side
 *         of the toolbar.
 */
protected int getViewBoundsRightOfLocationBar(VisualState visualState) {
    // Uses getMeasuredWidth()s instead of getRight() because this is called in onMeasure
    // and the layout values have not yet been set.
    if (visualState == VisualState.NEW_TAB_NORMAL) {
        return getMeasuredWidth();
    } else if (ApiCompatibilityUtils.isLayoutRtl(this)) {
        return getMeasuredWidth() - getBoundsAfterAccountingForLeftButton();
    } else {
        return getMeasuredWidth() - getBoundsAfterAccountingForRightButtons();
    }
}
 
Example 11
Source File: ToolbarPhone.java    From delion with Apache License 2.0 5 votes vote down vote up
private void updateUnfocusedLocationBarLayoutParams() {
    boolean hasVisibleViewPriorToUrlBar = false;
    for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) {
        View child = mPhoneLocationBar.getChildAt(i);
        if (child == mUrlBar) break;
        if (child.getVisibility() != GONE) {
            hasVisibleViewPriorToUrlBar = true;
            break;
        }
    }

    int leftViewBounds = getViewBoundsLeftOfLocationBar(mVisualState);
    if (!hasVisibleViewPriorToUrlBar) leftViewBounds += mToolbarSidePadding;
    int rightViewBounds = getViewBoundsRightOfLocationBar(mVisualState);

    if (!mPhoneLocationBar.hasVisibleViewsAfterUrlBarWhenUnfocused()) {
        // Add spacing between the end of the URL and the edge of the omnibox drawable.
        // This only applies if there is no end aligned view that should be visible
        // while the omnibox is unfocused.
        if (ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar)) {
            leftViewBounds += mToolbarSidePadding;
        } else {
            rightViewBounds -= mToolbarSidePadding;
        }
    }

    mUnfocusedLocationBarLayoutWidth = rightViewBounds - leftViewBounds;
    mUnfocusedLocationBarLayoutLeft = leftViewBounds;
}
 
Example 12
Source File: LocationBarPhone.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void getContentRect(Rect outRect) {
    super.getContentRect(outRect);
    if (mIncognitoBadge.getVisibility() == View.GONE) return;

    if (!ApiCompatibilityUtils.isLayoutRtl(this)) {
        outRect.left += mIncognitoBadge.getWidth();
    } else {
        outRect.right -= mIncognitoBadge.getWidth();
    }
}
 
Example 13
Source File: BottomToolbarPhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private int getLocationBarBackgroundRightOffset() {
    if (!ApiCompatibilityUtils.isLayoutRtl(this)) {
        return mToolbarButtonsContainer.getMeasuredWidth() - mToolbarSidePadding;
    } else {
        return !mUseToolbarHandle ? mExpandButton.getMeasuredWidth() - mToolbarSidePadding : 0;
    }
}
 
Example 14
Source File: SuggestionView.java    From delion with Apache License 2.0 5 votes vote down vote up
private int getUrlBarLeftOffset() {
    if (DeviceFormFactor.isTablet(getContext())) {
        mUrlBar.getLocationInWindow(mViewPositionHolder);
        return mViewPositionHolder[0];
    } else {
        return ApiCompatibilityUtils.isLayoutRtl(this) ? mPhoneUrlBarLeftOffsetRtlPx
                : mPhoneUrlBarLeftOffsetPx;
    }
}
 
Example 15
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@SuppressLint("RtlHardcoded")
private boolean layoutLocationBar(int containerWidth) {
    // Note that Toolbar's direction depends on system layout direction while
    // LocationBar's direction depends on its text inside.
    FrameLayout.LayoutParams locationBarLayoutParams =
            getFrameLayoutParams(getLocationBar().getContainerView());

    // Chrome prevents layout_gravity="left" from being defined in XML, but it simplifies
    // the logic, so it is manually specified here.
    locationBarLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;

    int width = 0;
    int leftMargin = 0;

    // Always update the unfocused layout params regardless of whether we are using
    // those in this current layout pass as they are needed for animations.
    updateUnfocusedLocationBarLayoutParams();

    if (mLayoutLocationBarInFocusedMode || mVisualState == VisualState.NEW_TAB_NORMAL) {
        int priorVisibleWidth = 0;
        for (int i = 0; i < mLocationBar.getChildCount(); i++) {
            View child = mLocationBar.getChildAt(i);
            if (child == mLocationBar.getFirstViewVisibleWhenFocused()) break;
            if (child.getVisibility() == GONE) continue;
            priorVisibleWidth += child.getMeasuredWidth();
        }

        width = containerWidth - (2 * mToolbarSidePadding) + priorVisibleWidth;
        if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) {
            leftMargin = mToolbarSidePadding;
        } else {
            leftMargin = -priorVisibleWidth + mToolbarSidePadding;
        }
    } else {
        width = mUnfocusedLocationBarLayoutWidth;
        leftMargin = mUnfocusedLocationBarLayoutLeft;
    }

    boolean changed = false;
    changed |= (width != locationBarLayoutParams.width);
    locationBarLayoutParams.width = width;

    changed |= (leftMargin != locationBarLayoutParams.leftMargin);
    locationBarLayoutParams.leftMargin = leftMargin;

    return changed;
}
 
Example 16
Source File: ToolbarPhone.java    From delion with Apache License 2.0 4 votes vote down vote up
private void populateUrlClearFocusingAnimatorSet(List<Animator> animators) {
    Animator animator = ObjectAnimator.ofFloat(this, mUrlFocusChangePercentProperty, 0f);
    animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, TRANSLATION_X, 0);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 1);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    if (mToggleTabStackButton != null) {
        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, TRANSLATION_X, 0);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setStartDelay(URL_CLEAR_FOCUS_TABSTACK_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);

        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, ALPHA, 1);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setStartDelay(URL_CLEAR_FOCUS_TABSTACK_DELAY_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, 1);
        animator.setStartDelay(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setDuration(URL_CLEAR_FOCUS_MENU_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);
    }

    if (isLocationBarShownInNTP() && mNtpSearchBoxScrollPercent == 0f) return;

    // The call to getLayout() can return null briefly during text changes, but as it
    // is only needed for RTL calculations, we proceed if the location bar is showing
    // LTR content.
    boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar);
    if (!isLocationBarRtl || mUrlBar.getLayout() != null) {
        int urlBarStartScrollX = 0;
        if (isLocationBarRtl) {
            urlBarStartScrollX = (int) mUrlBar.getLayout().getPrimaryHorizontal(0);
            urlBarStartScrollX -= mUrlBar.getWidth();
        }

        // If the scroll position matches the current scroll position, do not trigger
        // this animation as it will cause visible jumps when going from cleared text
        // back to page URLs (despite it continually calling setScrollX with the same
        // number).
        if (mUrlBar.getScrollX() != urlBarStartScrollX) {
            animator = ObjectAnimator.ofInt(
                    mUrlBar,
                    buildUrlScrollProperty(mPhoneLocationBar, isLocationBarRtl),
                    urlBarStartScrollX);
            animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
            animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
            animators.add(animator);
        }
    }
}
 
Example 17
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void populateUrlClearFocusingAnimatorSet(List<Animator> animators) {
    Animator animator = ObjectAnimator.ofFloat(this, mUrlFocusChangePercentProperty, 0f);
    animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, TRANSLATION_X, 0);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 1);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    if (mToggleTabStackButton != null) {
        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, TRANSLATION_X, 0);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setStartDelay(URL_CLEAR_FOCUS_TABSTACK_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);

        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, ALPHA, 1);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setStartDelay(URL_CLEAR_FOCUS_TABSTACK_DELAY_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, 1);
        animator.setStartDelay(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setDuration(URL_CLEAR_FOCUS_MENU_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);
    }

    if (isLocationBarShownInNTP() && mNtpSearchBoxScrollPercent == 0f) return;

    // The call to getLayout() can return null briefly during text changes, but as it
    // is only needed for RTL calculations, we proceed if the location bar is showing
    // LTR content.
    boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar);
    if (!isLocationBarRtl || mUrlBar.getLayout() != null) {
        int urlBarStartScrollX = 0;
        if (isLocationBarRtl) {
            urlBarStartScrollX = (int) mUrlBar.getLayout().getPrimaryHorizontal(0);
            urlBarStartScrollX -= mUrlBar.getWidth();
        }

        // If the scroll position matches the current scroll position, do not trigger
        // this animation as it will cause visible jumps when going from cleared text
        // back to page URLs (despite it continually calling setScrollX with the same
        // number).
        if (mUrlBar.getScrollX() != urlBarStartScrollX) {
            animator = ObjectAnimator.ofInt(mUrlBar,
                    buildUrlScrollProperty(mLocationBar, isLocationBarRtl), urlBarStartScrollX);
            animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
            animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
            animators.add(animator);
        }
    }
}
 
Example 18
Source File: ToolbarPhone.java    From delion with Apache License 2.0 4 votes vote down vote up
@SuppressLint("RtlHardcoded")
private boolean layoutLocationBar(int containerWidth) {
    // Note that Toolbar's direction depends on system layout direction while
    // LocationBar's direction depends on its text inside.
    FrameLayout.LayoutParams locationBarLayoutParams =
            getFrameLayoutParams(getLocationBar().getContainerView());

    // Chrome prevents layout_gravity="left" from being defined in XML, but it simplifies
    // the logic, so it is manually specified here.
    locationBarLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;

    int width = 0;
    int leftMargin = 0;

    // Always update the unfocused layout params regardless of whether we are using
    // those in this current layout pass as they are needed for animations.
    updateUnfocusedLocationBarLayoutParams();

    if (mLayoutLocationBarInFocusedMode || mVisualState == VisualState.NEW_TAB_NORMAL) {
        int priorVisibleWidth = 0;
        for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) {
            View child = mPhoneLocationBar.getChildAt(i);
            if (child == mPhoneLocationBar.getFirstViewVisibleWhenFocused()) break;
            if (child.getVisibility() == GONE) continue;
            priorVisibleWidth += child.getMeasuredWidth();
        }

        width = containerWidth - (2 * mToolbarSidePadding) + priorVisibleWidth;
        if (ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar)) {
            leftMargin = mToolbarSidePadding;
        } else {
            leftMargin = -priorVisibleWidth + mToolbarSidePadding;
        }
    } else {
        width = mUnfocusedLocationBarLayoutWidth;
        leftMargin = mUnfocusedLocationBarLayoutLeft;
    }

    boolean changed = false;
    changed |= (width != locationBarLayoutParams.width);
    locationBarLayoutParams.width = width;

    changed |= (leftMargin != locationBarLayoutParams.leftMargin);
    locationBarLayoutParams.leftMargin = leftMargin;

    return changed;
}
 
Example 19
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the parameters relating to expanding the location bar, as the result of either a
 * focus change or scrolling the New Tab Page.
 */
private void updateUrlExpansionAnimation() {
    if (mTabSwitcherState != STATIC_TAB) {
        mToolbarButtonsContainer.setVisibility(VISIBLE);
        return;
    }

    FrameLayout.LayoutParams locationBarLayoutParams = getFrameLayoutParams(mLocationBar);
    int currentLeftMargin = locationBarLayoutParams.leftMargin;
    int currentWidth = locationBarLayoutParams.width;

    float locationBarBaseTranslationX = mUnfocusedLocationBarLayoutLeft - currentLeftMargin;
    boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar);
    if (isLocationBarRtl) {
        locationBarBaseTranslationX += mUnfocusedLocationBarLayoutWidth - currentWidth;
    }
    locationBarBaseTranslationX *= 1f - mUrlExpansionPercent;

    mLocationBarBackgroundNtpOffset.setEmpty();
    mLocationBarNtpOffsetLeft = 0;
    mLocationBarNtpOffsetRight = 0;

    Tab currentTab = getToolbarDataProvider().getTab();
    if (currentTab != null) {
        NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
        if (ntp != null) {
            ntp.setUrlFocusChangeAnimationPercent(mUrlFocusChangePercent);
        }

        if (isLocationBarShownInNTP()) {
            updateNtpTransitionAnimation();
        } else {
            // Reset these values in case we transitioned to a different page during the
            // transition.
            resetNtpAnimationValues();
        }
    }

    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);

    float locationBarTranslationX;
    // Get the padding straight from the location bar instead of
    // |mLocationBarBackgroundPadding|, because it might be different in incognito mode.
    if (isRtl) {
        locationBarTranslationX = locationBarBaseTranslationX
                + mLocationBarNtpOffsetRight - mLocationBar.getPaddingRight();
    } else {
        locationBarTranslationX = locationBarBaseTranslationX
                + mLocationBarNtpOffsetLeft + mLocationBar.getPaddingLeft();
    }
    mLocationBar.setTranslationX(locationBarTranslationX);

    // Negate the location bar translation to keep the URL action container in the same
    // place during the focus expansion.
    float urlActionsTranslationX = 0;
    if (!isLocationBarRtl || isRtl) {
        urlActionsTranslationX = -locationBarBaseTranslationX;
    }

    if (isRtl) {
        urlActionsTranslationX += mLocationBarNtpOffsetLeft - mLocationBarNtpOffsetRight;
    } else {
        urlActionsTranslationX += mLocationBarNtpOffsetRight - mLocationBarNtpOffsetLeft;
    }
    mUrlActionContainer.setTranslationX(urlActionsTranslationX);

    mLocationBar.setUrlFocusChangePercent(mUrlExpansionPercent);

    // Ensure the buttons are invisible after focusing the omnibox to prevent them from
    // accepting click events.
    int toolbarButtonVisibility = mUrlExpansionPercent == 1f ? INVISIBLE : VISIBLE;
    mToolbarButtonsContainer.setVisibility(toolbarButtonVisibility);
    if (mHomeButton.getVisibility() != GONE) {
        mHomeButton.setVisibility(toolbarButtonVisibility);
    }

    // Force an invalidation of the location bar to properly handle the clipping of the URL
    // bar text as a result of the url action container translations.
    mLocationBar.invalidate();
    invalidate();
}
 
Example 20
Source File: PaymentRequestBottomBar.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    MarginLayoutParams layoutParams = (MarginLayoutParams) getLayoutParams();
    int leftSpace = getPaddingLeft() + layoutParams.leftMargin;
    int rightSpace = getPaddingRight() + layoutParams.rightMargin;
    int topSpace = getPaddingTop() + layoutParams.topMargin;
    int bottomSpace = getPaddingBottom() + layoutParams.bottomMargin;
    int viewHeight = bottom - top;
    int viewWidth = right - left;
    int childVerticalSpace = viewHeight - topSpace - bottomSpace;

    int childLeft;
    int childRight;
    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
    if (isRtl) {
        childRight = viewWidth - rightSpace;
        childLeft = childRight;
    } else {
        childLeft = leftSpace;
        childRight = childLeft;
    }

    for (int childIndex = 0; childIndex < getChildCount(); childIndex++) {
        View child = getChildAt(childIndex);
        if (child.getVisibility() == View.GONE) continue;

        int childWidth = child.getMeasuredWidth();
        int childHeight = child.getMeasuredHeight();
        if (isRtl) {
            childRight = childLeft;
            childLeft = childRight - childWidth;
        } else {
            childLeft = childRight;
            childRight = childLeft + childWidth;
        }

        // Center child vertically.
        int childTop = topSpace + (childVerticalSpace - childHeight) / 2;
        child.layout(childLeft, childTop, childRight, childTop + childHeight);
    }
}