Java Code Examples for android.view.View#getPaddingTop()

The following examples show how to use android.view.View#getPaddingTop() . 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: ResponsiveUrl.java    From cloudinary_android with MIT License 6 votes vote down vote up
/**
 * Construct the final url with the dimensions included as the last transformation in the url.

 * @param view      The view to adapt the image size to.
 * @param baseUrl   The base cloudinary Url to chain the transformation to.
 * @return The url with the responsive transformation.
 */
private Url buildUrl(View view, Url baseUrl) {
    // add a new transformation on top of anything already there:
    Url url = baseUrl.clone();
    url.transformation().chain();

    if (autoHeight) {
        int contentHeight = view.getHeight() - view.getPaddingTop() - view.getPaddingBottom();
        url.transformation().height(trimAndRoundUp(contentHeight));
    }

    if (autoWidth) {
        int contentWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
        url.transformation().width(trimAndRoundUp(contentWidth));
    }

    url.transformation().crop(cropMode).gravity(gravity);

    return url;
}
 
Example 2
Source File: DialogsEmptyCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int totalHeight;
    if (getParent() instanceof View) {
        View view = (View) getParent();
        totalHeight = view.getMeasuredHeight();
        if (view.getPaddingTop() != 0 && Build.VERSION.SDK_INT >= 21) {
            totalHeight -= AndroidUtilities.statusBarHeight;
        }
    } else {
        totalHeight = MeasureSpec.getSize(heightMeasureSpec);
    }
    if (totalHeight == 0) {
        totalHeight = AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight() - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
    }
    if (currentType == 0 || currentType == 2 || currentType == 3) {
        ArrayList<TLRPC.RecentMeUrl> arrayList = MessagesController.getInstance(currentAccount).hintDialogs;
        if (!arrayList.isEmpty()) {
            totalHeight -= AndroidUtilities.dp(72) * arrayList.size() + arrayList.size() - 1 + AndroidUtilities.dp(12 + 38);
        }
        super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY));
    } else {
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(166), MeasureSpec.EXACTLY));
    }
}
 
Example 3
Source File: StickerSetGroupInfoCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), heightMeasureSpec);
    if (isLast) {
        View parent = (View) getParent();
        if (parent != null) {
            int height = parent.getMeasuredHeight() - parent.getPaddingBottom() - parent.getPaddingTop() - AndroidUtilities.dp(24);
            if (getMeasuredHeight() < height) {
                setMeasuredDimension(getMeasuredWidth(), height);
            }
        }
    }
}
 
Example 4
Source File: HingeAnimator.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(View target) {
    float x = target.getPaddingLeft();
    float y = target.getPaddingTop();
    getAnimatorAgent().playTogether(
            Glider.glide(Skill.SineEaseInOut, 1300, ObjectAnimator.ofFloat(target, "rotation", 0, 80, 60, 80, 60, 60)),
            ObjectAnimator.ofFloat(target, "translationY", 0, 0, 0, 0, 0, 700),
            ObjectAnimator.ofFloat(target, "alpha", 1, 1, 1, 1, 1, 0),
            ObjectAnimator.ofFloat(target, "pivotX", x, x, x, x, x, x),
            ObjectAnimator.ofFloat(target, "pivotY", y, y, y, y, y, y)
    );

    setDuration(1300);
}
 
Example 5
Source File: PaddingRightAttr.java    From AutoLayout with Apache License 2.0 5 votes vote down vote up
@Override
protected void execute(View view, int val)
{
    int l = view.getPaddingLeft();
    int t = view.getPaddingTop();
    int r = val;
    int b = view.getPaddingBottom();
    view.setPadding(l, t, r, b);

}
 
Example 6
Source File: UiUtil.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * CardView adds extra padding on pre-lollipop devices for shadows
 * This function removes that extra padding from its margins
 *
 * @param cardView The CardView that needs adjustments
 * @return float
 */
public static void adjustCardViewMargins(View cardView) {
    ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) cardView.getLayoutParams();
    params.topMargin -= cardView.getPaddingTop();
    params.leftMargin -= cardView.getPaddingLeft();
    params.rightMargin -= cardView.getPaddingRight();
    cardView.setLayoutParams(params);
}
 
Example 7
Source File: ViewUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取 View Padding
 * @param view {@link View}
 * @return new int[] {left, top, right, bottom}
 */
public static int[] getPadding(final View view) {
    int[] paddings = new int[]{0, 0, 0, 0};
    if (view != null) {
        paddings[0] = view.getPaddingLeft();
        paddings[1] = view.getPaddingTop();
        paddings[2] = view.getPaddingRight();
        paddings[3] = view.getPaddingBottom();
    }
    return paddings;
}
 
Example 8
Source File: DialogsEmptyCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void updateLayout() {
    if (getParent() instanceof View && (currentType == 2 || currentType == 3)) {
        View view = (View) getParent();
        int paddingTop = view.getPaddingTop();
        if (paddingTop != 0) {
            int offset = -(getTop() / 2);
            imageView.setTranslationY(offset);
            emptyTextView1.setTranslationY(offset);
            emptyTextView2.setTranslationY(offset);
        }
    }
}
 
Example 9
Source File: ChromeSwitchPreference.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void onBindView(View view) {
    super.onBindView(view);

    if (mDrawDivider) {
        int left = view.getPaddingLeft();
        int right = view.getPaddingRight();
        int top = view.getPaddingTop();
        int bottom = view.getPaddingBottom();
        view.setBackground(DividerDrawable.create(getContext()));
        view.setPadding(left, top, right, bottom);
    }

    SwitchCompat switchView = (SwitchCompat) view.findViewById(R.id.switch_widget);
    // On BLU Life Play devices SwitchPreference.setWidgetLayoutResource() does nothing. As a
    // result, the user will see a non-material Switch and switchView will be null, hence the
    // null check below. http://crbug.com/451447
    if (switchView != null) {
        switchView.setChecked(isChecked());
    }

    TextView title = (TextView) view.findViewById(android.R.id.title);
    title.setSingleLine(false);
    if (!mDontUseSummaryAsTitle && TextUtils.isEmpty(getTitle())) {
        TextView summary = (TextView) view.findViewById(android.R.id.summary);
        title.setText(summary.getText());
        title.setVisibility(View.VISIBLE);
        summary.setVisibility(View.GONE);
    }

    if (mManagedPrefDelegate != null) mManagedPrefDelegate.onBindViewToPreference(this, view);
}
 
Example 10
Source File: VerifyOTP.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouch(final View v, final MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN && drawable != null) {
        final int x = (int) event.getX();
        final int y = (int) event.getY();
        final Rect bounds = drawable.getBounds();
        if (x >= (v.getRight() - bounds.width() - fuzz) && x <= (v.getRight() - v.getPaddingRight() + fuzz)
                && y >= (v.getPaddingTop() - fuzz) && y <= (v.getHeight() - v.getPaddingBottom()) + fuzz) {
            return onDrawableTouch(event);
        }
    }
    return false;
}
 
Example 11
Source File: PaddingLeftAttr.java    From AutoLayout-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void execute(View view, int val) {
    int l = val;
    int t = view.getPaddingTop();
    int r = view.getPaddingRight();
    int b = view.getPaddingBottom();
    view.setPadding(l, t, r, b);

}
 
Example 12
Source File: DynamicViewUtils.java    From dynamic-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Apply window insets padding for the supplied view.
 *
 * @param view The view to set the insets padding.
 * @param left {@code true} to apply the left window inset padding.
 * @param top {@code true} to apply the top window inset padding.
 * @param right {@code true} to apply the right window inset padding.
 * @param bottom {@code true} to apply the bottom window inset padding.
 * @param consume {@code true} to consume the applied window insets.
 */
public static void applyWindowInsets(@Nullable View view, final boolean left,
        final boolean top, final boolean right, final boolean bottom, final boolean consume) {
    if (view == null) {
        return;
    }

    final int paddingLeft = view.getPaddingLeft();
    final int paddingTop = view.getPaddingTop();
    final int paddingRight = view.getPaddingRight();
    final int paddingBottom = view.getPaddingBottom();

    ViewCompat.setOnApplyWindowInsetsListener(view, new OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            v.setPadding(left ? paddingLeft + insets.getSystemWindowInsetLeft(): paddingLeft,
                    top ? paddingTop + insets.getSystemWindowInsetTop() : paddingTop,
                    right ? paddingRight + insets.getSystemWindowInsetRight() : paddingRight,
                    bottom ? paddingBottom + insets.getSystemWindowInsetBottom() : paddingBottom);

            return !consume ? insets :
                    new WindowInsetsCompat.Builder(insets).setSystemWindowInsets(
                            Insets.of(left ? 0 : insets.getSystemWindowInsetLeft(),
                                    top ? 0 : insets.getSystemWindowInsetTop(),
                                    right ? 0 : insets.getSystemWindowInsetRight(),
                                    bottom ? 0 : insets.getSystemWindowInsetBottom()))
                            .build();
        }
    });

    requestApplyWindowInsets(view);
}
 
Example 13
Source File: AutoUtils.java    From Autolayout with Apache License 2.0 5 votes vote down vote up
public static void autoPadding(View view){
    int l = view.getPaddingLeft();
    int t = view.getPaddingTop();
    int r = view.getPaddingRight();
    int b = view.getPaddingBottom();

    l = getDisplayWidthValue(l);
    t = getDisplayHeightValue(t);
    r = getDisplayWidthValue(r);
    b = getDisplayHeightValue(b);

    view.setPadding(l, t, r, b);
}
 
Example 14
Source File: ScrollBoundaryHorizontal.java    From SmartRefreshHorizontal with Apache License 2.0 5 votes vote down vote up
public static boolean canScrollLeft(@NonNull View targetView) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (targetView instanceof AbsListView) {
            final ViewGroup viewGroup = (ViewGroup) targetView;
            final AbsListView absListView = (AbsListView) targetView;
            return viewGroup.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0
                    || viewGroup.getChildAt(0).getTop() < targetView.getPaddingTop());
        } else {
            return targetView.getScrollY() > 0;
        }
    } else {
        return targetView.canScrollHorizontally(-1);
    }
}
 
Example 15
Source File: PaddingBottomAttr.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
@Override
protected void execute(View view, int val)
{
    int l = view.getPaddingLeft();
    int t = view.getPaddingTop();
    int r = view.getPaddingRight();
    int b = val;
    view.setPadding(l, t, r, b);

}
 
Example 16
Source File: MoreKeysKeyboardView.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void showMoreKeysPanel(final View parentView, final Controller controller,
        final int pointX, final int pointY, final KeyboardActionListener listener) {
    mController = controller;
    mListener = listener;
    final View container = getContainerView();
    // The coordinates of panel's left-top corner in parentView's coordinate system.
    // We need to consider background drawable paddings.
    final int x = pointX - getDefaultCoordX() - container.getPaddingLeft() - getPaddingLeft();
    final int y = pointY - container.getMeasuredHeight() + container.getPaddingBottom()
            + getPaddingBottom();

    parentView.getLocationInWindow(mCoordinates);
    // Ensure the horizontal position of the panel does not extend past the parentView edges.
    final int maxX = parentView.getMeasuredWidth() - container.getMeasuredWidth();
    final int panelX = Math.max(0, Math.min(maxX, x)) + CoordinateUtils.x(mCoordinates);
    final int panelY = y + CoordinateUtils.y(mCoordinates);
    container.setX(panelX);
    container.setY(panelY);

    mOriginX = x + container.getPaddingLeft();
    mOriginY = y + container.getPaddingTop();
    controller.onShowMoreKeysPanel(this);
    final MoreKeysKeyboardAccessibilityDelegate accessibilityDelegate = mAccessibilityDelegate;
    if (accessibilityDelegate != null
            && AccessibilityUtils.Companion.getInstance().isAccessibilityEnabled()) {
        accessibilityDelegate.onShowMoreKeysKeyboard();
    }
}
 
Example 17
Source File: FitCenterFrameLayout.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int childCount = getChildCount();

    final int parentLeft = getPaddingLeft();
    final int parentTop = getPaddingTop();
    final int parentRight = r - l - getPaddingRight();
    final int parentBottom = b - t - getPaddingBottom();

    final int parentWidth = parentRight - parentLeft;
    final int parentHeight = parentBottom - parentTop;

    int unpaddedWidth, unpaddedHeight, parentUnpaddedWidth, parentUnpaddedHeight;
    int childPaddingLeft, childPaddingTop, childPaddingRight, childPaddingBottom;

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE) {
            continue;
        }

        // Fit and center the child within the parent. Make sure not to consider padding
        // as part of the child's aspect ratio.

        childPaddingLeft = child.getPaddingLeft();
        childPaddingTop = child.getPaddingTop();
        childPaddingRight = child.getPaddingRight();
        childPaddingBottom = child.getPaddingBottom();

        unpaddedWidth = child.getMeasuredWidth() - childPaddingLeft - childPaddingRight;
        unpaddedHeight = child.getMeasuredHeight() - childPaddingTop - childPaddingBottom;

        parentUnpaddedWidth = parentWidth - childPaddingLeft - childPaddingRight;
        parentUnpaddedHeight = parentHeight - childPaddingTop - childPaddingBottom;

        if (parentUnpaddedWidth * unpaddedHeight > parentUnpaddedHeight * unpaddedWidth) {
            // The child view should be left/right letterboxed.
            final int scaledChildWidth = unpaddedWidth * parentUnpaddedHeight
                    / unpaddedHeight + childPaddingLeft + childPaddingRight;
            child.layout(
                    parentLeft + (parentWidth - scaledChildWidth) / 2,
                    parentTop,
                    parentRight - (parentWidth - scaledChildWidth) / 2,
                    parentBottom);
        } else {
            // The child view should be top/bottom letterboxed.
            final int scaledChildHeight = unpaddedHeight * parentUnpaddedWidth
                    / unpaddedWidth + childPaddingTop + childPaddingBottom;
            child.layout(
                    parentLeft,
                    parentTop + (parentHeight - scaledChildHeight) / 2,
                    parentRight,
                    parentTop + (parentHeight + scaledChildHeight) / 2);
        }
    }
}
 
Example 18
Source File: ViewCheckInfoDokitView.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
private String getViewExtraInfo(View v) {
    StringBuilder info = new StringBuilder();
    // 背景色
    Drawable drawable = v.getBackground();
    if (drawable != null) {
        if (drawable instanceof ColorDrawable) {
            int colorInt = ((ColorDrawable) drawable).getColor();
            String backgroundColor = ColorUtil.parseColorInt(colorInt);
            info.append(getResources().getString(R.string.dk_view_check_info_desc, backgroundColor));
            info.append("\n");
        }
    }
    // padding
    if (v.getPaddingLeft() != 0 && v.getPaddingTop() != 0 && v.getPaddingRight() != 0 && v.getPaddingBottom() != 0) {
        info.append(getResources().getString(R.string.dk_view_check_info_padding, v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(), v.getPaddingBottom()));
        info.append("\n");
    }
    // margin
    final ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
    if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
        final ViewGroup.MarginLayoutParams mp = ((ViewGroup.MarginLayoutParams) layoutParams);
        if (mp.leftMargin != 0 && mp.topMargin != 0 && mp.rightMargin != 0 && mp.bottomMargin != 0) {
            info.append(getResources().getString(R.string.dk_view_check_info_margin, mp.leftMargin, mp.topMargin, mp.rightMargin, mp.bottomMargin));
            info.append("\n");
        }
    }
    // TextView信息
    if (v instanceof TextView) {
        TextView tv = ((TextView) v);
        String textColor = ColorUtil.parseColorInt(tv.getCurrentTextColor());
        info.append(getResources().getString(R.string.dk_view_check_info_text_color, textColor));
        info.append("\n");
        info.append(getResources().getString(R.string.dk_view_check_info_text_size, (int) tv.getTextSize()));
        info.append("\n");

    }
    // 删除最后一个换行
    if (!TextUtils.isEmpty(info)) {
        info.deleteCharAt(info.length() - 1);
    }
    return info.toString();
}
 
Example 19
Source File: InfoBarLayout.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Update the backgrounds for the buttons to account for their current positioning.
 * The primary and secondary buttons are special-cased in that their backgrounds change to
 * create the illusion of a single-stroke boundary between them.
 */
private void updateBackgroundsForButtons() {
    boolean bothButtonsExist = findViewById(R.id.button_primary) != null
            && findViewById(R.id.button_secondary) != null;

    for (int row = 0; row < mIndicesOfRows.size() - 1; row++) {
        final int rowStart = mIndicesOfRows.get(row);
        final int rowEnd = mIndicesOfRows.get(row + 1);
        final int rowSize = rowEnd - rowStart;

        for (int i = rowStart; i < rowEnd; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() == View.GONE || !isButton(child)) continue;

            // Determine which background we need to show.
            int background;
            if (row == 0) {
                // Button will be floating.
                background = mBackgroundFloating;
            } else if (rowSize == 1 || !bothButtonsExist) {
                // Button takes up the full width of the screen.
                background = mBackgroundFullRight;
            } else if (mLayoutRTL) {
                // Primary button will be to the left of the secondary.
                background = child.getId() == R.id.button_primary
                        ? mBackgroundFullLeft : mBackgroundFullRight;
            } else {
                // Primary button will be to the right of the secondary.
                background = child.getId() == R.id.button_primary
                        ? mBackgroundFullRight : mBackgroundFullLeft;
            }

            // Update the background.
            LayoutParams params = (LayoutParams) child.getLayoutParams();
            if (params.background != background) {
                params.background = background;

                // Save the padding; Android decides to overwrite it on some builds.
                int paddingLeft = child.getPaddingLeft();
                int paddingTop = child.getPaddingTop();
                int paddingRight = child.getPaddingRight();
                int paddingBottom = child.getPaddingBottom();
                int buttonWidth = child.getMeasuredWidth();
                int buttonHeight = child.getMeasuredHeight();

                // Set the background, then restore the padding.
                child.setBackgroundResource(background);
                child.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);

                // Re-measuring is necessary to correct the text gravity.
                int specWidth = MeasureSpec.makeMeasureSpec(buttonWidth, MeasureSpec.EXACTLY);
                int specHeight = MeasureSpec.makeMeasureSpec(buttonHeight, MeasureSpec.EXACTLY);
                measureChild(child, specWidth, specHeight);
            }
        }
    }
}
 
Example 20
Source File: TimePickerClockDelegate.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void setAmPmStart(boolean isAmPmAtStart) {
    final RelativeLayout.LayoutParams params =
            (RelativeLayout.LayoutParams) mAmPmLayout.getLayoutParams();
    if (params.getRule(RelativeLayout.RIGHT_OF) != 0
            || params.getRule(RelativeLayout.LEFT_OF) != 0) {
        // Horizontal mode, with AM/PM appearing to left/right of hours and minutes.
        final boolean isAmPmAtLeft;
        if (TextUtils.getLayoutDirectionFromLocale(mLocale) == View.LAYOUT_DIRECTION_LTR) {
            isAmPmAtLeft = isAmPmAtStart;
        } else {
            isAmPmAtLeft = !isAmPmAtStart;
        }
        if (mIsAmPmAtLeft == isAmPmAtLeft) {
            // AM/PM is already at the correct location. No change needed.
            return;
        }

        if (isAmPmAtLeft) {
            params.removeRule(RelativeLayout.RIGHT_OF);
            params.addRule(RelativeLayout.LEFT_OF, mHourView.getId());
        } else {
            params.removeRule(RelativeLayout.LEFT_OF);
            params.addRule(RelativeLayout.RIGHT_OF, mMinuteView.getId());
        }
        mIsAmPmAtLeft = isAmPmAtLeft;
    } else if (params.getRule(RelativeLayout.BELOW) != 0
            || params.getRule(RelativeLayout.ABOVE) != 0) {
        // Vertical mode, with AM/PM appearing to top/bottom of hours and minutes.
        if (mIsAmPmAtTop == isAmPmAtStart) {
            // AM/PM is already at the correct location. No change needed.
            return;
        }

        final int otherViewId;
        if (isAmPmAtStart) {
            otherViewId = params.getRule(RelativeLayout.BELOW);
            params.removeRule(RelativeLayout.BELOW);
            params.addRule(RelativeLayout.ABOVE, otherViewId);
        } else {
            otherViewId = params.getRule(RelativeLayout.ABOVE);
            params.removeRule(RelativeLayout.ABOVE);
            params.addRule(RelativeLayout.BELOW, otherViewId);
        }

        // Switch the top and bottom paddings on the other view.
        final View otherView = mRadialTimePickerHeader.findViewById(otherViewId);
        final int top = otherView.getPaddingTop();
        final int bottom = otherView.getPaddingBottom();
        final int left = otherView.getPaddingLeft();
        final int right = otherView.getPaddingRight();
        otherView.setPadding(left, bottom, right, top);

        mIsAmPmAtTop = isAmPmAtStart;
    }

    mAmPmLayout.setLayoutParams(params);
}