Commit 7d5e80c8 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Use MarginLayoutParamsCompat instead of ApiCompatibilityUtils

This CL replaces getMarginStart/setMarginStart and
getMarginEnd/setMarginEnd from ApiCompatibilityUtils with their
equivalents from MarginLayoutParamsCompat.

Bug: 852891
Change-Id: Ibb1e357a054b339c411a793ce64e85c70298e813
Reviewed-on: https://chromium-review.googlesource.com/1102462Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567893}
parent dbcc5ece
......@@ -35,7 +35,6 @@ import android.support.annotation.NonNull;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodSubtype;
......@@ -189,50 +188,6 @@ public class ApiCompatibilityUtils {
}
}
/**
* @see android.view.ViewGroup.MarginLayoutParams#setMarginEnd(int)
*/
public static void setMarginEnd(MarginLayoutParams layoutParams, int end) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
layoutParams.setMarginEnd(end);
} else {
layoutParams.rightMargin = end;
}
}
/**
* @see android.view.ViewGroup.MarginLayoutParams#getMarginEnd()
*/
public static int getMarginEnd(MarginLayoutParams layoutParams) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return layoutParams.getMarginEnd();
} else {
return layoutParams.rightMargin;
}
}
/**
* @see android.view.ViewGroup.MarginLayoutParams#setMarginStart(int)
*/
public static void setMarginStart(MarginLayoutParams layoutParams, int start) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
layoutParams.setMarginStart(start);
} else {
layoutParams.leftMargin = start;
}
}
/**
* @see android.view.ViewGroup.MarginLayoutParams#getMarginStart()
*/
public static int getMarginStart(MarginLayoutParams layoutParams) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return layoutParams.getMarginStart();
} else {
return layoutParams.leftMargin;
}
}
/**
* @see android.widget.TextView#getCompoundDrawablesRelative()
*/
......
......@@ -10,6 +10,7 @@ import android.graphics.Bitmap;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v7.content.res.AppCompatResources;
import android.text.TextUtils;
import android.text.format.Formatter;
......@@ -231,7 +232,7 @@ public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap
mItem = item;
setItem(item);
ApiCompatibilityUtils.setMarginStart(
MarginLayoutParamsCompat.setMarginStart(
(MarginLayoutParams) mLayoutContainer.getLayoutParams(),
item.isSuggested() ? mMarginSubsection : mMargin);
......@@ -304,12 +305,12 @@ public class DownloadItemView extends SelectableItemView<DownloadHistoryItemWrap
// to 0 by removing its text and eliminating the margin.
if (progress.isIndeterminate()) {
mDownloadPercentageView.setText(null);
ApiCompatibilityUtils.setMarginEnd(
MarginLayoutParamsCompat.setMarginEnd(
(MarginLayoutParams) mDownloadPercentageView.getLayoutParams(), 0);
} else {
mDownloadPercentageView.setText(
DownloadUtils.getPercentageString(progress.getPercentage()));
ApiCompatibilityUtils.setMarginEnd(
MarginLayoutParamsCompat.setMarginEnd(
(MarginLayoutParams) mDownloadPercentageView.getLayoutParams(), mMargin);
}
}
......
......@@ -11,6 +11,7 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.AdapterDataObserver;
......@@ -416,7 +417,7 @@ public class NewTabPageView
if (SuggestionsConfig.useModernLayout()
&& !DeviceFormFactor.isWindowOnTablet(mTab.getWindowAndroid())) {
ApiCompatibilityUtils.setMarginEnd(
MarginLayoutParamsCompat.setMarginEnd(
(MarginLayoutParams) mVoiceSearchButton.getLayoutParams(),
getResources().getDimensionPixelSize(
R.dimen.ntp_search_box_voice_search_margin_end_modern));
......
......@@ -20,6 +20,7 @@ import android.os.SystemClock;
import android.provider.Settings;
import android.support.annotation.DrawableRes;
import android.support.annotation.IntDef;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v7.content.res.AppCompatResources;
import android.text.Editable;
import android.text.InputType;
......@@ -1171,8 +1172,8 @@ public class LocationBarLayout
ViewGroup.MarginLayoutParams childLayoutParams =
(ViewGroup.MarginLayoutParams) childView.getLayoutParams();
urlContainerMarginEnd += childLayoutParams.width
+ ApiCompatibilityUtils.getMarginStart(childLayoutParams)
+ ApiCompatibilityUtils.getMarginEnd(childLayoutParams);
+ MarginLayoutParamsCompat.getMarginStart(childLayoutParams)
+ MarginLayoutParamsCompat.getMarginEnd(childLayoutParams);
}
}
return urlContainerMarginEnd;
......@@ -1187,8 +1188,8 @@ public class LocationBarLayout
View childView = getChildAt(i);
if (childView.getVisibility() != GONE) {
LayoutParams childLayoutParams = (LayoutParams) childView.getLayoutParams();
if (ApiCompatibilityUtils.getMarginStart(childLayoutParams) != startMargin) {
ApiCompatibilityUtils.setMarginStart(childLayoutParams, startMargin);
if (MarginLayoutParamsCompat.getMarginStart(childLayoutParams) != startMargin) {
MarginLayoutParamsCompat.setMarginStart(childLayoutParams, startMargin);
childView.setLayoutParams(childLayoutParams);
}
if (childView == mUrlBar) break;
......@@ -1222,8 +1223,8 @@ public class LocationBarLayout
int urlContainerMarginEnd = getUrlContainerMarginEnd();
LayoutParams urlLayoutParams = (LayoutParams) mUrlBar.getLayoutParams();
if (ApiCompatibilityUtils.getMarginEnd(urlLayoutParams) != urlContainerMarginEnd) {
ApiCompatibilityUtils.setMarginEnd(urlLayoutParams, urlContainerMarginEnd);
if (MarginLayoutParamsCompat.getMarginEnd(urlLayoutParams) != urlContainerMarginEnd) {
MarginLayoutParamsCompat.setMarginEnd(urlLayoutParams, urlContainerMarginEnd);
mUrlBar.setLayoutParams(urlLayoutParams);
}
}
......
......@@ -9,6 +9,7 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.animation.FastOutLinearInInterpolator;
import android.util.AttributeSet;
......@@ -18,7 +19,6 @@ import android.view.WindowManager;
import android.view.animation.Interpolator;
import android.widget.FrameLayout;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.WindowDelegate;
import org.chromium.chrome.browser.ntp.NewTabPage;
......@@ -228,8 +228,9 @@ public class LocationBarPhone extends LocationBarLayout {
// Shrink the margin down to 50% minus half of the G width (in the end state).
final float finalGoogleGMargin = (mGoogleGMargin - mGoogleGWidth * finalGScale) / 2f;
ApiCompatibilityUtils.setMarginEnd(layoutParams, Math.round(MathUtils.interpolate(
mGoogleGMargin, finalGoogleGMargin, animationProgress)));
MarginLayoutParamsCompat.setMarginEnd(layoutParams,
Math.round(MathUtils.interpolate(
mGoogleGMargin, finalGoogleGMargin, animationProgress)));
// Just calling requestLayout() would not resolve the end margin.
mGoogleG.setLayoutParams(layoutParams);
......
......@@ -9,6 +9,7 @@ import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.support.v7.widget.GridLayout;
import android.text.SpannableStringBuilder;
......@@ -365,7 +366,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
LinearLayout.LayoutParams rightLayoutParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ApiCompatibilityUtils.setMarginStart(rightLayoutParams,
MarginLayoutParamsCompat.setMarginStart(rightLayoutParams,
getContext().getResources().getDimensionPixelSize(
R.dimen.editor_dialog_section_small_spacing));
......@@ -390,7 +391,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
// The logo has a pre-defined height and width.
LayoutParams params =
new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ApiCompatibilityUtils.setMarginStart(params, startMargin);
MarginLayoutParamsCompat.setMarginStart(params, startMargin);
parent.addView(view, params);
return view;
}
......@@ -403,7 +404,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
LayoutParams params =
new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing);
MarginLayoutParamsCompat.setMarginStart(params, mLargeSpacing);
parent.addView(view, params);
return view;
}
......@@ -418,7 +419,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
// Wrap whatever image is passed in.
LayoutParams params =
new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing);
MarginLayoutParamsCompat.setMarginStart(params, mLargeSpacing);
parent.addView(view, params);
return view;
}
......@@ -585,10 +586,10 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
ApiCompatibilityUtils.setTextAlignment(mUpdatedView, TEXT_ALIGNMENT_TEXT_END);
mUpdatedView.setTextColor(ApiCompatibilityUtils.getColor(
context.getResources(), R.color.google_green_700));
ApiCompatibilityUtils.setMarginStart(updatedLayoutParams,
MarginLayoutParamsCompat.setMarginStart(updatedLayoutParams,
context.getResources().getDimensionPixelSize(
R.dimen.editor_dialog_section_small_spacing));
ApiCompatibilityUtils.setMarginEnd(updatedLayoutParams,
MarginLayoutParamsCompat.setMarginEnd(updatedLayoutParams,
context.getResources().getDimensionPixelSize(
R.dimen.editor_dialog_section_small_spacing));
......@@ -653,7 +654,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams(
GridLayout.spec(i, 1, GridLayout.END),
GridLayout.spec(1, 1, GridLayout.END));
ApiCompatibilityUtils.setMarginStart(amountParams,
MarginLayoutParamsCompat.setMarginStart(amountParams,
context.getResources().getDimensionPixelSize(
R.dimen.payments_section_descriptive_item_spacing));
......@@ -907,7 +908,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
GridLayout.spec(0, 1, GridLayout.CENTER));
buttonParams.topMargin = mVerticalMargin;
ApiCompatibilityUtils.setMarginEnd(buttonParams, mLargeSpacing);
MarginLayoutParamsCompat.setMarginEnd(buttonParams, mLargeSpacing);
parent.addView(view, buttonParams);
view.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
......@@ -977,7 +978,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
// end margin) when edit icon exits in that row, like below:
// ---Label---------------------[label margin]|---option icon---|
// ---Label---[label margin]|---option icon---|----edit icon----|
ApiCompatibilityUtils.setMarginEnd(labelParams, mLargeSpacing);
MarginLayoutParamsCompat.setMarginEnd(labelParams, mLargeSpacing);
}
parent.addView(labelView, labelParams);
......@@ -1481,16 +1482,16 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
int margin =
resources.getDimensionPixelSize(R.dimen.editor_dialog_section_large_spacing);
ApiCompatibilityUtils.setMarginStart(params, margin);
ApiCompatibilityUtils.setMarginEnd(params, margin);
MarginLayoutParamsCompat.setMarginStart(params, margin);
MarginLayoutParamsCompat.setMarginEnd(params, margin);
parent.addView(this, index, params);
}
/** 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);
MarginLayoutParamsCompat.setMarginStart(params, 0);
MarginLayoutParamsCompat.setMarginEnd(params, 0);
}
}
}
......@@ -6,13 +6,13 @@ package org.chromium.chrome.browser.payments.ui;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.widget.BoundedLinearLayout;
......@@ -44,7 +44,7 @@ public class PaymentRequestUiErrorView extends BoundedLinearLayout {
int titleEndMargin = getContext().getResources().getDimensionPixelSize(
R.dimen.editor_dialog_section_large_spacing);
View pageInfoGroup = findViewById(R.id.page_info);
ApiCompatibilityUtils.setMarginEnd(
MarginLayoutParamsCompat.setMarginEnd(
(MarginLayoutParams) pageInfoGroup.getLayoutParams(), titleEndMargin);
}
......
......@@ -20,6 +20,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.v4.text.BidiFormatter;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
......@@ -607,8 +608,8 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
R.dimen.custom_tabs_toolbar_horizontal_margin_no_close);
} else if (childView.getVisibility() != GONE) {
LayoutParams childLayoutParams = (LayoutParams) childView.getLayoutParams();
if (ApiCompatibilityUtils.getMarginStart(childLayoutParams) != startMargin) {
ApiCompatibilityUtils.setMarginStart(childLayoutParams, startMargin);
if (MarginLayoutParamsCompat.getMarginStart(childLayoutParams) != startMargin) {
MarginLayoutParamsCompat.setMarginStart(childLayoutParams, startMargin);
childView.setLayoutParams(childLayoutParams);
}
if (childView == mLocationBarFrameLayout) {
......@@ -652,8 +653,8 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
}
LayoutParams urlLayoutParams = (LayoutParams) mLocationBarFrameLayout.getLayoutParams();
if (ApiCompatibilityUtils.getMarginEnd(urlLayoutParams) != locationBarLayoutEndMargin) {
ApiCompatibilityUtils.setMarginEnd(urlLayoutParams, locationBarLayoutEndMargin);
if (MarginLayoutParamsCompat.getMarginEnd(urlLayoutParams) != locationBarLayoutEndMargin) {
MarginLayoutParamsCompat.setMarginEnd(urlLayoutParams, locationBarLayoutEndMargin);
mLocationBarFrameLayout.setLayoutParams(urlLayoutParams);
}
......
......@@ -27,6 +27,7 @@ import android.os.Build;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.support.v7.graphics.drawable.DrawableWrapper;
import android.text.TextUtils;
......@@ -478,8 +479,8 @@ public class ToolbarPhone extends ToolbarLayout
MeasureSpec.makeMeasureSpec(screenSize.x, MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(screenSize.y, MeasureSpec.AT_MOST));
ApiCompatibilityUtils.setMarginEnd(getFrameLayoutParams(mNewTabButton),
mToolbarButtonsContainer.getMeasuredWidth());
MarginLayoutParamsCompat.setMarginEnd(
getFrameLayoutParams(mNewTabButton), mToolbarButtonsContainer.getMeasuredWidth());
}
private void enableTabSwitchingResources() {
......
......@@ -14,6 +14,7 @@ import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v4.view.animation.FastOutLinearInInterpolator;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.support.v7.widget.Toolbar.OnMenuItemClickListener;
......@@ -385,7 +386,7 @@ public class EditorDialog
firstParams.width = 0;
firstParams.weight = 1;
ApiCompatibilityUtils.setMarginEnd(firstParams, mHalfRowMargin);
MarginLayoutParamsCompat.setMarginEnd(firstParams, mHalfRowMargin);
lastParams.width = 0;
lastParams.weight = 1;
......
......@@ -8,6 +8,7 @@ import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
......@@ -15,8 +16,6 @@ import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import org.chromium.base.ApiCompatibilityUtils;
/**
* The adapter used to populate ColorPickerSimple.
*/
......@@ -108,9 +107,9 @@ public class ColorSuggestionListAdapter extends BaseAdapter implements View.OnCl
View button = new View(mContext);
LinearLayout.LayoutParams layoutParams =
new LinearLayout.LayoutParams(0, buttonHeight, 1f);
ApiCompatibilityUtils.setMarginStart(layoutParams, -1);
MarginLayoutParamsCompat.setMarginStart(layoutParams, -1);
if (i == COLORS_PER_ROW - 1) {
ApiCompatibilityUtils.setMarginEnd(layoutParams, -1);
MarginLayoutParamsCompat.setMarginEnd(layoutParams, -1);
}
button.setLayoutParams(layoutParams);
button.setBackgroundResource(R.drawable.color_button_background);
......
......@@ -7,6 +7,7 @@ package org.chromium.ui;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.content.res.AppCompatResources;
import android.text.TextUtils;
......@@ -163,8 +164,8 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
iconLayoutParams.height = iconSize;
int iconMargin =
mContext.getResources().getDimensionPixelSize(item.getIconMarginResId());
ApiCompatibilityUtils.setMarginStart(iconLayoutParams, iconMargin);
ApiCompatibilityUtils.setMarginEnd(iconLayoutParams, iconMargin);
MarginLayoutParamsCompat.setMarginStart(iconLayoutParams, iconMargin);
MarginLayoutParamsCompat.setMarginEnd(iconLayoutParams, iconMargin);
iconView.setLayoutParams(iconLayoutParams);
iconView.setImageDrawable(AppCompatResources.getDrawable(mContext, item.getIconId()));
iconView.setVisibility(View.VISIBLE);
......
......@@ -8,6 +8,7 @@ import android.annotation.TargetApi;
import android.content.ClipData;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.View;
......@@ -151,7 +152,7 @@ public class ViewAndroidDelegate {
widthInt = containerView.getWidth() - startMargin;
}
LayoutParams lp = new LayoutParams(widthInt, heightInt);
ApiCompatibilityUtils.setMarginStart(lp, startMargin);
MarginLayoutParamsCompat.setMarginStart(lp, startMargin);
lp.topMargin = topMargin;
view.setLayoutParams(lp);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment