Java Code Examples for org.chromium.base.ApiCompatibilityUtils#setMarginStart()
The following examples show how to use
org.chromium.base.ApiCompatibilityUtils#setMarginStart() .
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: SnackbarView.java From AndroidChromium with Apache License 2.0 | 6 votes |
void adjustViewPosition() { mParent.getWindowVisibleDisplayFrame(mCurrentVisibleRect); // Only update if the visible frame has changed, otherwise there will be a layout loop. if (!mCurrentVisibleRect.equals(mPreviousVisibleRect)) { mPreviousVisibleRect.set(mCurrentVisibleRect); int keyboardHeight = mParent.getHeight() - mCurrentVisibleRect.bottom + mCurrentVisibleRect.top; MarginLayoutParams lp = getLayoutParams(); lp.bottomMargin = keyboardHeight; if (mIsTablet) { int margin = mParent.getResources() .getDimensionPixelSize(R.dimen.snackbar_margin_tablet); ApiCompatibilityUtils.setMarginStart(lp, margin); lp.bottomMargin += margin; int width = mParent.getResources() .getDimensionPixelSize(R.dimen.snackbar_width_tablet); lp.width = Math.min(width, mParent.getWidth() - 2 * margin); } mView.setLayoutParams(lp); } }
Example 2
Source File: PaymentRequestSection.java From delion with Apache License 2.0 | 6 votes |
private View createIcon(GridLayout parent, int rowIndex) { // The icon has a pre-defined width. ImageView icon = new ImageView(parent.getContext()); icon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); icon.setBackgroundResource(R.drawable.payments_ui_logo_bg); icon.setImageResource(mOption.getDrawableIconId()); icon.setMaxWidth(mIconMaxWidth); // The icon floats to the right of everything. GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams( GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(2, 1)); iconParams.topMargin = mVerticalMargin; ApiCompatibilityUtils.setMarginStart(iconParams, mLargeSpacing); parent.addView(icon, iconParams); icon.setOnClickListener(OptionSection.this); return icon; }
Example 3
Source File: ViewAndroidDelegate.java From 365browser with Apache License 2.0 | 6 votes |
/** * 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 4
Source File: PaymentRequestSection.java From delion with Apache License 2.0 | 5 votes |
private static ImageView createAndAddLogoView( ViewGroup parent, int resourceId, int startMargin) { ImageView view = new ImageView(parent.getContext()); view.setBackgroundResource(R.drawable.payments_ui_logo_bg); if (resourceId != 0) view.setImageResource(resourceId); // The logo has a pre-defined height and width. LayoutParams params = new LayoutParams( parent.getResources().getDimensionPixelSize(R.dimen.payments_section_logo_width), parent.getResources().getDimensionPixelSize(R.dimen.payments_section_logo_height)); ApiCompatibilityUtils.setMarginStart(params, startMargin); parent.addView(view, params); return view; }
Example 5
Source File: PaymentRequestSection.java From 365browser with Apache License 2.0 | 5 votes |
private Button createAndAddEditButton(ViewGroup parent) { Resources resources = parent.getResources(); Button view = DualControlLayout.createButtonForLayout( parent.getContext(), true, resources.getString(R.string.choose), this); view.setId(R.id.payments_section); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing); parent.addView(view, params); return view; }
Example 6
Source File: PaymentRequestSection.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** Creates the View and adds it to the parent at the given index. */ public SectionSeparator(ViewGroup parent, int index) { super(parent.getContext()); Resources resources = parent.getContext().getResources(); setBackgroundColor(ApiCompatibilityUtils.getColor( resources, R.color.payments_section_separator)); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, resources.getDimensionPixelSize(R.dimen.payments_section_separator_height)); int margin = resources.getDimensionPixelSize(R.dimen.payments_section_large_spacing); ApiCompatibilityUtils.setMarginStart(params, margin); ApiCompatibilityUtils.setMarginEnd(params, margin); parent.addView(this, index, params); }
Example 7
Source File: PaymentRequestSection.java From AndroidChromium with Apache License 2.0 | 5 votes |
private ImageView createAndAddChevron(ViewGroup parent) { Resources resources = parent.getResources(); TintedDrawable chevron = TintedDrawable.constructTintedDrawable( resources, R.drawable.ic_expanded, R.color.payments_section_chevron); ImageView view = new ImageView(parent.getContext()); view.setImageDrawable(chevron); // Wrap whatever image is passed in. LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing); parent.addView(view, params); return view; }
Example 8
Source File: PaymentRequestSection.java From AndroidChromium with Apache License 2.0 | 5 votes |
private Button createAndAddEditButton(ViewGroup parent) { Resources resources = parent.getResources(); Button view = DualControlLayout.createButtonForLayout( parent.getContext(), true, resources.getString(R.string.select), this); view.setId(R.id.payments_section); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing); parent.addView(view, params); return view; }
Example 9
Source File: PaymentRequestSection.java From AndroidChromium with Apache License 2.0 | 5 votes |
private static ImageView createAndAddLogoView( ViewGroup parent, int resourceId, int startMargin) { ImageView view = new ImageView(parent.getContext()); view.setBackgroundResource(R.drawable.payments_ui_logo_bg); if (resourceId != 0) view.setImageResource(resourceId); // The logo has a pre-defined height and width. LayoutParams params = new LayoutParams( parent.getResources().getDimensionPixelSize(R.dimen.payments_section_logo_width), parent.getResources().getDimensionPixelSize(R.dimen.payments_section_logo_height)); ApiCompatibilityUtils.setMarginStart(params, startMargin); parent.addView(view, params); return view; }
Example 10
Source File: PaymentRequestSection.java From 365browser with Apache License 2.0 | 5 votes |
/** Creates the View and adds it to the parent at the given index. */ public SectionSeparator(ViewGroup parent, int index) { super(parent.getContext()); Resources resources = parent.getContext().getResources(); setBackgroundColor(ApiCompatibilityUtils.getColor( resources, R.color.payments_section_separator)); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, resources.getDimensionPixelSize(R.dimen.separator_height)); int margin = resources.getDimensionPixelSize(R.dimen.payments_section_large_spacing); ApiCompatibilityUtils.setMarginStart(params, margin); ApiCompatibilityUtils.setMarginEnd(params, margin); parent.addView(this, index, params); }
Example 11
Source File: PaymentRequestSection.java From delion with Apache License 2.0 | 5 votes |
/** Creates the View and adds it to the parent at the given index. */ public SectionSeparator(ViewGroup parent, int index) { super(parent.getContext()); Resources resources = parent.getContext().getResources(); setBackgroundColor(ApiCompatibilityUtils.getColor( resources, R.color.payments_section_separator)); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, resources.getDimensionPixelSize(R.dimen.payments_section_separator_height)); int margin = resources.getDimensionPixelSize(R.dimen.payments_section_large_spacing); ApiCompatibilityUtils.setMarginStart(params, margin); ApiCompatibilityUtils.setMarginEnd(params, margin); parent.addView(this, index, params); }
Example 12
Source File: PaymentRequestSection.java From delion with Apache License 2.0 | 5 votes |
private ImageView createAndAddChevron(ViewGroup parent) { Resources resources = parent.getResources(); TintedDrawable chevron = TintedDrawable.constructTintedDrawable( resources, R.drawable.ic_expanded, R.color.payments_section_chevron); ImageView view = new ImageView(parent.getContext()); view.setImageDrawable(chevron); // Wrap whatever image is passed in. LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing); parent.addView(view, params); return view; }
Example 13
Source File: PaymentRequestSection.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Creates the main section. Subclasses must call super#createMainSection() immediately to * guarantee that Views are added in the correct order. * * @param sectionName Title to display for the section. */ private LinearLayout prepareMainSection(String sectionName) { // The main section is a vertical linear layout that subclasses can append to. LinearLayout mainSectionLayout = new LinearLayout(getContext()); mainSectionLayout.setOrientation(VERTICAL); LinearLayout.LayoutParams mainParams = new LayoutParams(0, LayoutParams.WRAP_CONTENT); mainParams.weight = 1; addView(mainSectionLayout, mainParams); // The title is always displayed for the row at the top of the main section. mTitleView = new TextView(getContext()); mTitleView.setText(sectionName); ApiCompatibilityUtils.setTextAppearance( mTitleView, R.style.PaymentsUiSectionHeader); mainSectionLayout.addView( mTitleView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); // Create the two TextViews for showing the summary text. mSummaryLeftTextView = new TextView(getContext()); mSummaryLeftTextView.setId(R.id.payments_left_summary_label); ApiCompatibilityUtils.setTextAppearance( mSummaryLeftTextView, R.style.PaymentsUiSectionDefaultText); mSummaryRightTextView = new TextView(getContext()); ApiCompatibilityUtils.setTextAppearance( mSummaryRightTextView, R.style.PaymentsUiSectionDefaultText); ApiCompatibilityUtils.setTextAlignment(mSummaryRightTextView, TEXT_ALIGNMENT_TEXT_END); // The main TextView sucks up all the available space. LinearLayout.LayoutParams leftLayoutParams = new LinearLayout.LayoutParams( 0, LayoutParams.WRAP_CONTENT); leftLayoutParams.weight = 1; LinearLayout.LayoutParams rightLayoutParams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ApiCompatibilityUtils.setMarginStart( rightLayoutParams, getContext().getResources().getDimensionPixelSize( R.dimen.payments_section_small_spacing)); // The summary section displays up to two TextViews side by side. mSummaryLayout = new LinearLayout(getContext()); mSummaryLayout.addView(mSummaryLeftTextView, leftLayoutParams); mSummaryLayout.addView(mSummaryRightTextView, rightLayoutParams); mainSectionLayout.addView(mSummaryLayout, new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); setSummaryText(null, null); createMainSectionContent(mainSectionLayout); return mainSectionLayout; }
Example 14
Source File: PaymentRequestSection.java From delion with Apache License 2.0 | 4 votes |
/** Expand the separator to be the full width of the dialog. */ public void expand() { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLayoutParams(); ApiCompatibilityUtils.setMarginStart(params, 0); ApiCompatibilityUtils.setMarginEnd(params, 0); }
Example 15
Source File: PaymentRequestSection.java From delion with Apache License 2.0 | 4 votes |
/** * Updates the total and how it's broken down. * * @param cart The shopping cart contents and the total. */ public void update(ShoppingCart cart) { Context context = mBreakdownLayout.getContext(); // Update the summary to display information about the total. setSummaryText(cart.getTotal().getLabel(), createValueString( cart.getTotal().getCurrency(), cart.getTotal().getPrice(), true)); mBreakdownLayout.removeAllViews(); if (cart.getContents() == null) return; // Update the breakdown, using one row per {@link LineItem}. int numItems = cart.getContents().size(); mBreakdownLayout.setRowCount(numItems); for (int i = 0; i < numItems; i++) { LineItem item = cart.getContents().get(i); TextView description = new TextView(context); ApiCompatibilityUtils.setTextAppearance( description, R.style.PaymentsUiSectionDescriptiveTextEndAligned); description.setText(item.getLabel()); TextView amount = new TextView(context); ApiCompatibilityUtils.setTextAppearance( amount, R.style.PaymentsUiSectionDescriptiveTextEndAligned); amount.setText(createValueString(item.getCurrency(), item.getPrice(), false)); // Each item is represented by a row in the GridLayout. GridLayout.LayoutParams descriptionParams = new GridLayout.LayoutParams( GridLayout.spec(i, 1, GridLayout.END), GridLayout.spec(0, 1, GridLayout.END)); GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams( GridLayout.spec(i, 1, GridLayout.END), GridLayout.spec(1, 1, GridLayout.END)); ApiCompatibilityUtils.setMarginStart(amountParams, context.getResources().getDimensionPixelSize( R.dimen.payments_section_descriptive_item_spacing)); mBreakdownLayout.addView(description, descriptionParams); mBreakdownLayout.addView(amount, amountParams); } }
Example 16
Source File: PaymentRequestSection.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** Expand the separator to be the full width of the dialog. */ public void expand() { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLayoutParams(); ApiCompatibilityUtils.setMarginStart(params, 0); ApiCompatibilityUtils.setMarginEnd(params, 0); }
Example 17
Source File: PaymentRequestSection.java From 365browser with Apache License 2.0 | 4 votes |
/** * Creates the main section. Subclasses must call super#createMainSection() immediately to * guarantee that Views are added in the correct order. * * @param sectionName Title to display for the section. */ private LinearLayout prepareMainSection(String sectionName) { // The main section is a vertical linear layout that subclasses can append to. LinearLayout mainSectionLayout = new LinearLayout(getContext()); mainSectionLayout.setOrientation(VERTICAL); LinearLayout.LayoutParams mainParams = new LayoutParams(0, LayoutParams.WRAP_CONTENT); mainParams.weight = 1; addView(mainSectionLayout, mainParams); // The title is always displayed for the row at the top of the main section. mTitleView = new TextView(getContext()); mTitleView.setText(sectionName); ApiCompatibilityUtils.setTextAppearance( mTitleView, R.style.PaymentsUiSectionHeader); mainSectionLayout.addView( mTitleView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); // Create the two TextViews for showing the summary text. mSummaryLeftTextView = new TextView(getContext()); mSummaryLeftTextView.setId(R.id.payments_left_summary_label); ApiCompatibilityUtils.setTextAppearance( mSummaryLeftTextView, R.style.PaymentsUiSectionDefaultText); mSummaryRightTextView = new TextView(getContext()); ApiCompatibilityUtils.setTextAppearance( mSummaryRightTextView, R.style.PaymentsUiSectionDefaultText); ApiCompatibilityUtils.setTextAlignment(mSummaryRightTextView, TEXT_ALIGNMENT_TEXT_END); // The main TextView sucks up all the available space. LinearLayout.LayoutParams leftLayoutParams = new LinearLayout.LayoutParams( 0, LayoutParams.WRAP_CONTENT); leftLayoutParams.weight = 1; LinearLayout.LayoutParams rightLayoutParams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ApiCompatibilityUtils.setMarginStart( rightLayoutParams, getContext().getResources().getDimensionPixelSize( R.dimen.payments_section_small_spacing)); // The summary section displays up to two TextViews side by side. mSummaryLayout = new LinearLayout(getContext()); mSummaryLayout.addView(mSummaryLeftTextView, leftLayoutParams); mSummaryLayout.addView(mSummaryRightTextView, rightLayoutParams); mainSectionLayout.addView(mSummaryLayout, new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); setSummaryText(null, null); createMainSectionContent(mainSectionLayout); return mainSectionLayout; }
Example 18
Source File: PaymentRequestSection.java From 365browser with Apache License 2.0 | 4 votes |
/** Expand the separator to be the full width of the dialog. */ public void expand() { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLayoutParams(); ApiCompatibilityUtils.setMarginStart(params, 0); ApiCompatibilityUtils.setMarginEnd(params, 0); }
Example 19
Source File: PaymentRequestSection.java From delion with Apache License 2.0 | 4 votes |
/** * Creates the main section. Subclasses must call super#createMainSection() immediately to * guarantee that Views are added in the correct order. * * @param sectionName Title to display for the section. */ private final LinearLayout prepareMainSection(String sectionName) { // The main section is a vertical linear layout that subclasses can append to. LinearLayout mainSectionLayout = new LinearLayout(getContext()); mainSectionLayout.setOrientation(VERTICAL); LinearLayout.LayoutParams mainParams = new LayoutParams(0, LayoutParams.WRAP_CONTENT); mainParams.weight = 1; addView(mainSectionLayout, mainParams); // The title is always displayed for the row at the top of the main section. mTitleView = new TextView(getContext()); mTitleView.setText(sectionName); ApiCompatibilityUtils.setTextAppearance( mTitleView, R.style.PaymentsUiSectionHeader); mainSectionLayout.addView( mTitleView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); // Create the two TextViews for showing the summary text. mSummaryLeftTextView = new TextView(getContext()); mSummaryLeftTextView.setId(R.id.payments_left_summary_label); ApiCompatibilityUtils.setTextAppearance( mSummaryLeftTextView, R.style.PaymentsUiSectionDefaultText); mSummaryRightTextView = new TextView(getContext()); ApiCompatibilityUtils.setTextAppearance( mSummaryRightTextView, R.style.PaymentsUiSectionDefaultText); ApiCompatibilityUtils.setTextAlignment(mSummaryRightTextView, TEXT_ALIGNMENT_TEXT_END); // The main TextView sucks up all the available space. LinearLayout.LayoutParams leftLayoutParams = new LinearLayout.LayoutParams( 0, LayoutParams.WRAP_CONTENT); leftLayoutParams.weight = 1; LinearLayout.LayoutParams rightLayoutParams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ApiCompatibilityUtils.setMarginStart( rightLayoutParams, getContext().getResources().getDimensionPixelSize( R.dimen.payments_section_small_spacing)); // The summary section displays up to two TextViews side by side. mSummaryLayout = new LinearLayout(getContext()); mSummaryLayout.addView(mSummaryLeftTextView, leftLayoutParams); mSummaryLayout.addView(mSummaryRightTextView, rightLayoutParams); mainSectionLayout.addView(mSummaryLayout, new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); setSummaryText(null, null); createMainSectionContent(mainSectionLayout); return mainSectionLayout; }
Example 20
Source File: PaymentRequestSection.java From 365browser with Apache License 2.0 | 4 votes |
/** * Updates the total and how it's broken down. * * @param cart The shopping cart contents and the total. */ public void update(ShoppingCart cart) { Context context = mBreakdownLayout.getContext(); CharSequence totalPrice = createValueString( cart.getTotal().getCurrency(), cart.getTotal().getPrice(), true); // Show the updated text view if the total changed. showUpdateIfTextChanged(totalPrice); // Update the summary to display information about the total. setSummaryText(cart.getTotal().getLabel(), totalPrice); mBreakdownLayout.removeAllViews(); if (cart.getContents() == null) return; int maximumDescriptionWidthPx = ((View) mBreakdownLayout.getParent()).getWidth() * 2 / 3; // Update the breakdown, using one row per {@link LineItem}. int numItems = cart.getContents().size(); mBreakdownLayout.setRowCount(numItems); for (int i = 0; i < numItems; i++) { LineItem item = cart.getContents().get(i); TextView description = new TextView(context); ApiCompatibilityUtils.setTextAppearance(description, item.getIsPending() ? R.style.PaymentsUiSectionPendingTextEndAligned : R.style.PaymentsUiSectionDescriptiveTextEndAligned); description.setText(item.getLabel()); description.setEllipsize(TruncateAt.END); description.setMaxLines(2); if (maximumDescriptionWidthPx > 0) { description.setMaxWidth(maximumDescriptionWidthPx); } TextView amount = new TextView(context); ApiCompatibilityUtils.setTextAppearance(amount, item.getIsPending() ? R.style.PaymentsUiSectionPendingTextEndAligned : R.style.PaymentsUiSectionDescriptiveTextEndAligned); amount.setText(createValueString(item.getCurrency(), item.getPrice(), false)); // Each item is represented by a row in the GridLayout. GridLayout.LayoutParams descriptionParams = new GridLayout.LayoutParams( GridLayout.spec(i, 1, GridLayout.END), GridLayout.spec(0, 1, GridLayout.END)); GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams( GridLayout.spec(i, 1, GridLayout.END), GridLayout.spec(1, 1, GridLayout.END)); ApiCompatibilityUtils.setMarginStart(amountParams, context.getResources().getDimensionPixelSize( R.dimen.payments_section_descriptive_item_spacing)); mBreakdownLayout.addView(description, descriptionParams); mBreakdownLayout.addView(amount, amountParams); } }