List of usage examples for android.support.v4.view MarginLayoutParamsCompat getMarginEnd
public static int getMarginEnd(MarginLayoutParams marginLayoutParams)
From source file:Main.java
static int getMarginHorizontally(View v) { if (v == null) { return 0; }//from w w w.j a va2s. c o m ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams(); return MarginLayoutParamsCompat.getMarginStart(lp) + MarginLayoutParamsCompat.getMarginEnd(lp); }
From source file:Main.java
static int getMarginEnd(View v) { if (v == null) { return 0; }/* ww w . j av a 2 s . c o m*/ ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams(); return MarginLayoutParamsCompat.getMarginEnd(lp); }
From source file:com.google.android.apps.flexbox.FlexItem.java
public static FlexItem fromFlexView(View view, int index) { FlexboxLayout.LayoutParams lp = (FlexboxLayout.LayoutParams) view.getLayoutParams(); FlexItem flexItem = new FlexItem(); flexItem.index = index;/*w w w .j a v a2 s. c o m*/ flexItem.order = lp.order; flexItem.flexGrow = lp.flexGrow; flexItem.flexShrink = lp.flexShrink; flexItem.alignSelf = lp.alignSelf; flexItem.flexBasisPercent = lp.flexBasisPercent; flexItem.width = Util.pixelToDp(view.getContext(), lp.width); flexItem.height = Util.pixelToDp(view.getContext(), lp.height); flexItem.topMargin = lp.topMargin; flexItem.startMargin = MarginLayoutParamsCompat.getMarginStart(lp); flexItem.endMargin = MarginLayoutParamsCompat.getMarginEnd(lp); flexItem.bottomMargin = lp.bottomMargin; flexItem.paddingTop = view.getPaddingTop(); flexItem.paddingStart = ViewCompat.getPaddingStart(view); flexItem.paddingEnd = ViewCompat.getPaddingEnd(view); flexItem.paddingBottom = view.getPaddingBottom(); flexItem.minWidth = Util.pixelToDp(view.getContext(), lp.minWidth); flexItem.minHeight = Util.pixelToDp(view.getContext(), lp.minHeight); flexItem.maxWidth = Util.pixelToDp(view.getContext(), lp.maxWidth); flexItem.maxHeight = Util.pixelToDp(view.getContext(), lp.maxHeight); flexItem.wrapBefore = lp.wrapBefore; return flexItem; }
From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java
private void applyXmlAttributes(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatingSearchView, defStyleAttr, defStyleRes);/*from w ww. ja va 2 s . c o m*/ // Search bar width View suggestionsContainer = findViewById(R.id.fsv_suggestions_container); int searchBarWidth = a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_searchBarWidth, searchContainer.getLayoutParams().width); searchContainer.getLayoutParams().width = searchBarWidth; suggestionsContainer.getLayoutParams().width = searchBarWidth; // Divider ViewUtils.setBackground(divider, a.getDrawable(R.styleable.FloatingSearchView_android_divider)); int dividerHeight = a.getDimensionPixelSize(R.styleable.FloatingSearchView_android_dividerHeight, -1); MarginLayoutParams dividerLP = (MarginLayoutParams) divider.getLayoutParams(); if (divider.getBackground() != null && dividerHeight != -1) dividerLP.height = dividerHeight; float maxShadowSize = searchBackground.getMaxShadowSize(); float cornerRadius = searchBackground.getCornerRadius(); int horizontalPadding = (int) (RoundRectDrawableWithShadow.calculateHorizontalPadding(maxShadowSize, cornerRadius, false) + .5f); dividerLP.setMargins(horizontalPadding, dividerLP.topMargin, horizontalPadding, dividerLP.bottomMargin); divider.setLayoutParams(dividerLP); // Content inset MarginLayoutParams searchParams = (MarginLayoutParams) searchInput.getLayoutParams(); int contentInsetStart = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetStart, MarginLayoutParamsCompat.getMarginStart(searchParams)); int contentInsetEnd = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetEnd, MarginLayoutParamsCompat.getMarginEnd(searchParams)); MarginLayoutParamsCompat.setMarginStart(searchParams, contentInsetStart); MarginLayoutParamsCompat.setMarginEnd(searchParams, contentInsetEnd); // anything else setLogo(a.getDrawable(R.styleable.FloatingSearchView_logo)); setContentBackgroundColor( a.getColor(R.styleable.FloatingSearchView_fsv_contentBackgroundColor, DEFAULT_CONTENT_COLOR)); setRadius(a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_cornerRadius, ViewUtils.dpToPx(DEFAULT_RADIUS))); inflateMenu(a.getResourceId(R.styleable.FloatingSearchView_fsv_menu, 0)); setPopupTheme(a.getResourceId(R.styleable.FloatingSearchView_popupTheme, 0)); setHint(a.getString(R.styleable.FloatingSearchView_android_hint)); setIcon(a.getDrawable(R.styleable.FloatingSearchView_fsv_icon)); a.recycle(); }
From source file:org.chromium.chrome.browser.autofill.CardUnmaskPrompt.java
private void onTooltipIconClicked() { // Don't show the popup if there's already one showing (or one has been dismissed // recently). This prevents a tap on the (?) from hiding and then immediately re-showing // the popup. if (mStoreLocallyTooltipPopup != null) return;//from w w w . j a v a 2 s . c om mStoreLocallyTooltipPopup = new PopupWindow(mDialog.getContext()); TextView text = new TextView(mDialog.getContext()); text.setText(R.string.autofill_card_unmask_prompt_storage_tooltip); // Width is the dialog's width less the margins and padding around the checkbox and // icon. text.setWidth(mMainView.getWidth() - ViewCompat.getPaddingStart(mStoreLocallyCheckbox) - ViewCompat.getPaddingEnd(mStoreLocallyTooltipIcon) - MarginLayoutParamsCompat .getMarginStart((RelativeLayout.LayoutParams) mStoreLocallyCheckbox.getLayoutParams()) - MarginLayoutParamsCompat .getMarginEnd((RelativeLayout.LayoutParams) mStoreLocallyTooltipIcon.getLayoutParams())); text.setTextColor(Color.WHITE); Resources resources = mDialog.getContext().getResources(); int hPadding = resources.getDimensionPixelSize(R.dimen.autofill_card_unmask_tooltip_horizontal_padding); int vPadding = resources.getDimensionPixelSize(R.dimen.autofill_card_unmask_tooltip_vertical_padding); text.setPadding(hPadding, vPadding, hPadding, vPadding); mStoreLocallyTooltipPopup.setContentView(text); mStoreLocallyTooltipPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); mStoreLocallyTooltipPopup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); mStoreLocallyTooltipPopup.setOutsideTouchable(true); mStoreLocallyTooltipPopup.setBackgroundDrawable( ApiCompatibilityUtils.getDrawable(resources, R.drawable.store_locally_tooltip_background)); mStoreLocallyTooltipPopup.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { Handler h = new Handler(); h.postDelayed(new Runnable() { @Override public void run() { mStoreLocallyTooltipPopup = null; } }, 200); } }); mStoreLocallyTooltipPopup.showAsDropDown(mStoreLocallyCheckbox, ViewCompat.getPaddingStart(mStoreLocallyCheckbox), 0); text.announceForAccessibility(text.getText()); }
From source file:android.support.v7.widget.Toolbar.java
private int getHorizontalMargins(View v) { final MarginLayoutParams mlp = (MarginLayoutParams) v.getLayoutParams(); return MarginLayoutParamsCompat.getMarginStart(mlp) + MarginLayoutParamsCompat.getMarginEnd(mlp); }
From source file:com.google.android.flexbox.FlexboxHelper.java
/** * Place a single View when the layout direction is vertical * ({@link FlexContainer#getFlexDirection()} is either {@link FlexDirection#COLUMN} or * {@link FlexDirection#COLUMN_REVERSE}). * * @param view the View to be placed * @param flexLine the {@link FlexLine} where the View belongs to * @param isRtl {@code true} if the layout direction is right to left, {@code false} * otherwise/*from w w w .j a v a 2 s. com*/ * @param left the left position of the flex line where the View belongs to. The actual * View's left position is shifted depending on the isLayoutRtl and alignItems * attributes * @param top the top position of the View, which the View's margin is already taken * into account * @param right the right position of the flex line where the View belongs to. The actual * View's right position is shifted depending on the isLayoutRtl and alignItems * attributes * @param bottom the bottom position of the View, which the View's margin is already taken * into account * @see FlexContainer#getAlignItems() * @see FlexContainer#setAlignItems(int) * @see FlexItem#getAlignSelf() */ void layoutSingleChildVertical(View view, FlexLine flexLine, boolean isRtl, int left, int top, int right, int bottom) { FlexItem flexItem = (FlexItem) view.getLayoutParams(); int alignItems = mFlexContainer.getAlignItems(); if (flexItem.getAlignSelf() != AlignSelf.AUTO) { // Expecting the values for alignItems and mAlignSelf match except for ALIGN_SELF_AUTO. // Assigning the mAlignSelf value as alignItems should work. alignItems = flexItem.getAlignSelf(); } int crossSize = flexLine.mCrossSize; switch (alignItems) { case AlignItems.FLEX_START: // Intentional fall through case AlignItems.STRETCH: // Intentional fall through case AlignItems.BASELINE: if (!isRtl) { view.layout(left + flexItem.getMarginLeft(), top, right + flexItem.getMarginLeft(), bottom); } else { view.layout(left - flexItem.getMarginRight(), top, right - flexItem.getMarginRight(), bottom); } break; case AlignItems.FLEX_END: if (!isRtl) { view.layout(left + crossSize - view.getMeasuredWidth() - flexItem.getMarginRight(), top, right + crossSize - view.getMeasuredWidth() - flexItem.getMarginRight(), bottom); } else { // If the flexWrap == WRAP_REVERSE, the direction of the // flexEnd is flipped (from left to right). view.layout(left - crossSize + view.getMeasuredWidth() + flexItem.getMarginLeft(), top, right - crossSize + view.getMeasuredWidth() + flexItem.getMarginLeft(), bottom); } break; case AlignItems.CENTER: ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); int leftFromCrossAxis = (crossSize - view.getMeasuredWidth() + MarginLayoutParamsCompat.getMarginStart(lp) - MarginLayoutParamsCompat.getMarginEnd(lp)) / 2; if (!isRtl) { view.layout(left + leftFromCrossAxis, top, right + leftFromCrossAxis, bottom); } else { view.layout(left - leftFromCrossAxis, top, right - leftFromCrossAxis, bottom); } break; } }
From source file:com.cxsplay.wallyskim.widget.flexbox.FlexboxLayout.java
/** * Place a single View when the layout direction is vertical ({@link #mFlexDirection} is * either {@link #FLEX_DIRECTION_COLUMN} or {@link #FLEX_DIRECTION_COLUMN_REVERSE}). * * @param view the View to be placed * @param flexLine the {@link FlexLine} where the View belongs to * @param isRtl {@code true} if the layout direction is right to left, {@code false} * otherwise// w ww .j a v a 2s . c o m * @param alignItems the align items attribute of this FlexboxLayout * @param left the left position of the flex line where the View belongs to. The actual * View's left position is shifted depending on the isRtl and alignItems * attributes * @param top the top position of the View, which the View's margin is already taken * into account * @param right the right position of the flex line where the View belongs to. The actual * View's right position is shifted depending on the isRtl and alignItems * attributes * @param bottom the bottom position of the View, which the View's margin is already taken * into account * @see #getAlignItems() * @see #setAlignItems(int) * @see LayoutParams#alignSelf */ private void layoutSingleChildVertical(View view, FlexLine flexLine, boolean isRtl, int alignItems, int left, int top, int right, int bottom) { LayoutParams lp = (LayoutParams) view.getLayoutParams(); if (lp.alignSelf != LayoutParams.ALIGN_SELF_AUTO) { // Expecting the values for alignItems and alignSelf match except for ALIGN_SELF_AUTO. // Assigning the alignSelf value as alignItems should work. alignItems = lp.alignSelf; } int crossSize = flexLine.mCrossSize; switch (alignItems) { case ALIGN_ITEMS_FLEX_START: // Intentional fall through case ALIGN_ITEMS_STRETCH: // Intentional fall through case ALIGN_ITEMS_BASELINE: if (!isRtl) { view.layout(left + lp.leftMargin, top, right + lp.leftMargin, bottom); } else { view.layout(left - lp.rightMargin, top, right - lp.rightMargin, bottom); } break; case ALIGN_ITEMS_FLEX_END: if (!isRtl) { view.layout(left + crossSize - view.getMeasuredWidth() - lp.rightMargin, top, right + crossSize - view.getMeasuredWidth() - lp.rightMargin, bottom); } else { // If the flexWrap == FLEX_WRAP_WRAP_REVERSE, the direction of the // flexEnd is flipped (from left to right). view.layout(left - crossSize + view.getMeasuredWidth() + lp.leftMargin, top, right - crossSize + view.getMeasuredWidth() + lp.leftMargin, bottom); } break; case ALIGN_ITEMS_CENTER: int leftFromCrossAxis = (crossSize - view.getMeasuredWidth() + MarginLayoutParamsCompat.getMarginStart(lp) - MarginLayoutParamsCompat.getMarginEnd(lp)) / 2; if (!isRtl) { view.layout(left + leftFromCrossAxis, top, right + leftFromCrossAxis, bottom); } else { view.layout(left - leftFromCrossAxis, top, right - leftFromCrossAxis, bottom); } break; } }