Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestSection.java

Issue 2914503002: align shipping option name to left and shipping cost to right on bottom sheet (Closed)
Patch Set: more comments addressing Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.payments.ui; 5 package org.chromium.chrome.browser.payments.ui;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.res.Resources; 8 import android.content.res.Resources;
9 import android.graphics.Color; 9 import android.graphics.Color;
10 import android.graphics.Typeface; 10 import android.graphics.Typeface;
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 int columnSpan = 1; 928 int columnSpan = 1;
929 if (!optionIconExists) columnSpan++; 929 if (!optionIconExists) columnSpan++;
930 if (!editIconExists) columnSpan++; 930 if (!editIconExists) columnSpan++;
931 931
932 TextView labelView = new TextView(context); 932 TextView labelView = new TextView(context);
933 if (mRowType == OPTION_ROW_TYPE_OPTION) { 933 if (mRowType == OPTION_ROW_TYPE_OPTION) {
934 // Show the string representing the PaymentOption. 934 // Show the string representing the PaymentOption.
935 ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled 935 ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled
936 ? R.style.PaymentsUiSectionDefaultText 936 ? R.style.PaymentsUiSectionDefaultText
937 : R.style.PaymentsUiSectionDisabledText); 937 : R.style.PaymentsUiSectionDisabledText);
938 labelView.setText(convertOptionToString(mOption, 938 labelView.setText(convertOptionToString(mOption, false, /* e xcludeMainLabel */
939 mDelegate.isBoldLabelNeeded(OptionSection.this), 939 mDelegate.isBoldLabelNeeded(OptionSection.this),
940 false /* singleLine */)); 940 false /* singleLine */));
941 labelView.setEnabled(isEnabled); 941 labelView.setEnabled(isEnabled);
942 } else if (mRowType == OPTION_ROW_TYPE_ADD) { 942 } else if (mRowType == OPTION_ROW_TYPE_ADD) {
943 // Shows string saying that the user can add a new option, e .g. credit card no. 943 // Shows string saying that the user can add a new option, e .g. credit card no.
944 String typeface = resources.getString(R.string.roboto_medium _typeface); 944 String typeface = resources.getString(R.string.roboto_medium _typeface);
945 int textStyle = resources.getInteger(R.integer.roboto_medium _textstyle); 945 int textStyle = resources.getInteger(R.integer.roboto_medium _textstyle);
946 int buttonHeight = resources.getDimensionPixelSize( 946 int buttonHeight = resources.getDimensionPixelSize(
947 R.dimen.payments_section_add_button_height); 947 R.dimen.payments_section_add_button_height);
948 948
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 private SectionInformation mSectionInformation; 1054 private SectionInformation mSectionInformation;
1055 1055
1056 /** Indicates whether the summary is displayed in a single line. */ 1056 /** Indicates whether the summary is displayed in a single line. */
1057 private boolean mSummaryInSingleLine; 1057 private boolean mSummaryInSingleLine;
1058 1058
1059 /** Indicates whether the summary is set to display in a single line in DISPLAY_MODE_NORMAL 1059 /** Indicates whether the summary is set to display in a single line in DISPLAY_MODE_NORMAL
1060 * by caller. 1060 * by caller.
1061 */ 1061 */
1062 boolean mSetDisplaySummaryInSingleLineInNormalMode = true; 1062 boolean mSetDisplaySummaryInSingleLineInNormalMode = true;
1063 1063
1064 /**
1065 * Indicates whether the summary should be split to display in left and right summary
1066 * text views in {@link DISPLAY_MODE_NORMAL}.
1067 */
1068 private boolean mSplitSummaryInDisplayModeNormal;
1069
1064 /** Indicates whether the summary is set to R.style.PaymentsUiSectionDes criptiveText. */ 1070 /** Indicates whether the summary is set to R.style.PaymentsUiSectionDes criptiveText. */
1065 private boolean mSummaryInDescriptiveText; 1071 private boolean mSummaryInDescriptiveText;
1066 1072
1067 private FocusChangedObserver mFocusChangedObserver; 1073 private FocusChangedObserver mFocusChangedObserver;
1068 1074
1069 /** 1075 /**
1070 * Constructs an OptionSection. 1076 * Constructs an OptionSection.
1071 * 1077 *
1072 * @param context Context to pull resources from. 1078 * @param context Context to pull resources from.
1073 * @param sectionName Title of the section to display. 1079 * @param sectionName Title of the section to display.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 1172
1167 /** 1173 /**
1168 * @param singleLine If true, sets the summary text to display in a sing le line 1174 * @param singleLine If true, sets the summary text to display in a sing le line
1169 * in {@link #DISPLAY_MODE_NORMAL} when there is a val id selected 1175 * in {@link #DISPLAY_MODE_NORMAL} when there is a val id selected
1170 * option, otherwise sets the summary text to display in multiple lines. 1176 * option, otherwise sets the summary text to display in multiple lines.
1171 */ 1177 */
1172 public void setDisplaySummaryInSingleLineInNormalMode(boolean singleLine ) { 1178 public void setDisplaySummaryInSingleLineInNormalMode(boolean singleLine ) {
1173 mSetDisplaySummaryInSingleLineInNormalMode = singleLine; 1179 mSetDisplaySummaryInSingleLineInNormalMode = singleLine;
1174 } 1180 }
1175 1181
1182 /**
1183 * Specify if the summary should be displayed split under DISPLAY_MODE_N ORMAL.
gogerald1 2017/06/06 16:55:19 Specify whether.........should be split to display
gogerald1 2017/06/06 16:55:20 one space line below
wuandy1 2017/06/07 01:58:04 Done.
wuandy1 2017/06/07 01:58:04 Done.
1184 * @param splitSummary set to true to split the display of summary in le ft and right
gogerald1 2017/06/06 16:55:19 If true, split the display..... or at least upperc
wuandy1 2017/06/07 01:58:04 Done.
1185 * text views in {@link DISPLAY_MODE_NORMAL}. Otherw ise the entire
1186 * summary is displayed in left text view. Note that summary is
gogerald1 2017/06/06 16:55:20 Move this sentence before 'Otherwise' and replace
wuandy1 2017/06/07 01:58:04 Done.
1187 * split into 'label' and the rest('sublabel', 'Tert iary label').
1188 */
1189 public void setSplitSummaryInDisplayModeNormal(boolean splitSummary) {
1190 mSplitSummaryInDisplayModeNormal = splitSummary;
1191 }
1192
1176 /** Updates the View to account for the new {@link SectionInformation} b eing passed in. */ 1193 /** Updates the View to account for the new {@link SectionInformation} b eing passed in. */
1177 public void update(SectionInformation information) { 1194 public void update(SectionInformation information) {
1178 mSectionInformation = information; 1195 mSectionInformation = information;
1179 PaymentOption selectedItem = information.getSelectedItem(); 1196 PaymentOption selectedItem = information.getSelectedItem();
1180 updateSelectedItem(selectedItem); 1197 updateSelectedItem(selectedItem);
1181 updateOptionList(information, selectedItem); 1198 updateOptionList(information, selectedItem);
1182 updateControlLayout(); 1199 updateControlLayout();
1183 } 1200 }
1184 1201
1185 private View createLoadingSpinner() { 1202 private View createLoadingSpinner() {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 getContext(), mSectionInformation, getSummaryLeftTextVie w()); 1300 getContext(), mSectionInformation, getSummaryLeftTextVie w());
1284 } else { 1301 } else {
1285 setLogoDrawable(selectedItem.getDrawableIcon()); 1302 setLogoDrawable(selectedItem.getDrawableIcon());
1286 // Selected item summary should be displayed as 1303 // Selected item summary should be displayed as
1287 // R.style.PaymentsUiSectionDefaultText. 1304 // R.style.PaymentsUiSectionDefaultText.
1288 if (mSummaryInDescriptiveText) { 1305 if (mSummaryInDescriptiveText) {
1289 ApiCompatibilityUtils.setTextAppearance( 1306 ApiCompatibilityUtils.setTextAppearance(
1290 getSummaryLeftTextView(), R.style.PaymentsUiSectionD efaultText); 1307 getSummaryLeftTextView(), R.style.PaymentsUiSectionD efaultText);
1291 mSummaryInDescriptiveText = false; 1308 mSummaryInDescriptiveText = false;
1292 } 1309 }
1293 setSummaryText(convertOptionToString(selectedItem, false /* useB oldLabel */, 1310 // Split summary in DISPLAY_MODE_NORMAL if caller specified. The first part is
1294 mSummaryInSingleLine), 1311 // displayed on the left summary text view aligned to the left. The second part is
1295 null); 1312 // displayed on the right summary text view aligned to the right .
1313 boolean splitSummary =
1314 mSplitSummaryInDisplayModeNormal && (mDisplayMode == DIS PLAY_MODE_NORMAL);
1315 if (splitSummary) {
1316 setSummaryText(selectedItem.getLabel(),
1317 convertOptionToString(selectedItem, true /* excludeM ainLabel */,
1318 false /* useBoldLabel */, mSummaryInSingleLi ne));
1319 } else {
1320 setSummaryText(convertOptionToString(selectedItem, false /* excludeMainLabel */,
1321 false /* useBoldLabel */, mSummaryInS ingleLine),
1322 null);
1323 }
1296 } 1324 }
1297 1325
1298 updateControlLayout(); 1326 updateControlLayout();
1299 } 1327 }
1300 1328
1301 private void updateOptionList(SectionInformation information, PaymentOpt ion selectedItem) { 1329 private void updateOptionList(SectionInformation information, PaymentOpt ion selectedItem) {
1302 mOptionLayout.removeAllViews(); 1330 mOptionLayout.removeAllViews();
1303 mOptionRows.clear(); 1331 mOptionRows.clear();
1304 mLabelsForTest.clear(); 1332 mLabelsForTest.clear();
1305 1333
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 // If the user is allowed to add new options, show the button for it . 1368 // If the user is allowed to add new options, show the button for it .
1341 if (information.getAddStringId() != 0 && mCanAddItems) { 1369 if (information.getAddStringId() != 0 && mCanAddItems) {
1342 OptionRow addRow = new OptionRow(mOptionLayout, mOptionLayout.ge tChildCount(), 1370 OptionRow addRow = new OptionRow(mOptionLayout, mOptionLayout.ge tChildCount(),
1343 OptionRow.OPTION_ROW_TYPE_ADD, null, false); 1371 OptionRow.OPTION_ROW_TYPE_ADD, null, false);
1344 addRow.setLabel(information.getAddStringId()); 1372 addRow.setLabel(information.getAddStringId());
1345 addRow.setButtonId(R.id.payments_add_option_button); 1373 addRow.setButtonId(R.id.payments_add_option_button);
1346 mOptionRows.add(addRow); 1374 mOptionRows.add(addRow);
1347 } 1375 }
1348 } 1376 }
1349 1377
1350 private CharSequence convertOptionToString( 1378 private CharSequence convertOptionToString(PaymentOption item, boolean e xcludeMainLabel,
1351 PaymentOption item, boolean useBoldLabel, boolean singleLine) { 1379 boolean useBoldLabel, boolean singleLine) {
1352 SpannableStringBuilder builder = new SpannableStringBuilder(item.get Label()); 1380 SpannableStringBuilder builder = new SpannableStringBuilder();
1353 String labelSeparator = singleLine 1381 if (!excludeMainLabel) builder.append(item.getLabel());
1354 ? getContext().getString(R.string.autofill_address_summary_s eparator) 1382
1355 : "\n";
1356 if (useBoldLabel) { 1383 if (useBoldLabel) {
1357 builder.setSpan( 1384 builder.setSpan(
1358 new StyleSpan(android.graphics.Typeface.BOLD), 0, builde r.length(), 0); 1385 new StyleSpan(android.graphics.Typeface.BOLD), 0, builde r.length(), 0);
1359 } 1386 }
1360 1387
1388 String labelSeparator = singleLine
1389 ? getContext().getString(R.string.autofill_address_summary_s eparator)
1390 : "\n";
1361 if (!TextUtils.isEmpty(item.getSublabel())) { 1391 if (!TextUtils.isEmpty(item.getSublabel())) {
1362 if (builder.length() > 0) builder.append(labelSeparator); 1392 if (builder.length() > 0) builder.append(labelSeparator);
1363 builder.append(item.getSublabel()); 1393 builder.append(item.getSublabel());
1364 } 1394 }
1365 1395
1366 if (!TextUtils.isEmpty(item.getTertiaryLabel())) { 1396 if (!TextUtils.isEmpty(item.getTertiaryLabel())) {
1367 if (builder.length() > 0) builder.append(labelSeparator); 1397 if (builder.length() > 0) builder.append(labelSeparator);
1368 builder.append(item.getTertiaryLabel()); 1398 builder.append(item.getTertiaryLabel());
1369 } 1399 }
1370 1400
(...skipping 18 matching lines...) Expand all
1389 */ 1419 */
1390 @VisibleForTesting 1420 @VisibleForTesting
1391 public TextView getOptionLabelsForTest(int labelIndex) { 1421 public TextView getOptionLabelsForTest(int labelIndex) {
1392 return mLabelsForTest.get(labelIndex); 1422 return mLabelsForTest.get(labelIndex);
1393 } 1423 }
1394 1424
1395 /** 1425 /**
1396 * Returns the label of the section summary. 1426 * Returns the label of the section summary.
1397 */ 1427 */
1398 @VisibleForTesting 1428 @VisibleForTesting
1399 public TextView getSummaryLabelForTest() { 1429 public TextView getLeftSummaryLabelForTest() {
1400 return getSummaryLeftTextView(); 1430 return getSummaryLeftTextView();
1401 } 1431 }
1402 1432
1433 /**
1434 * Returns the right summary text view.
1435 */
1436 @VisibleForTesting
1437 public TextView getRightSummaryLabelForTest() {
1438 return getSummaryRightTextView();
1439 }
1440
1403 /** Returns the number of option labels. */ 1441 /** Returns the number of option labels. */
1404 @VisibleForTesting 1442 @VisibleForTesting
1405 public int getNumberOfOptionLabelsForTest() { 1443 public int getNumberOfOptionLabelsForTest() {
1406 return mLabelsForTest.size(); 1444 return mLabelsForTest.size();
1407 } 1445 }
1408 1446
1409 /** Returns the OptionRow at the specified |index|. */ 1447 /** Returns the OptionRow at the specified |index|. */
1410 @VisibleForTesting 1448 @VisibleForTesting
1411 public OptionRow getOptionRowAtIndex(int index) { 1449 public OptionRow getOptionRowAtIndex(int index) {
1412 return mOptionRows.get(index); 1450 return mOptionRows.get(index);
(...skipping 27 matching lines...) Expand all
1440 } 1478 }
1441 1479
1442 /** Expand the separator to be the full width of the dialog. */ 1480 /** Expand the separator to be the full width of the dialog. */
1443 public void expand() { 1481 public void expand() {
1444 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLa youtParams(); 1482 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLa youtParams();
1445 ApiCompatibilityUtils.setMarginStart(params, 0); 1483 ApiCompatibilityUtils.setMarginStart(params, 0);
1446 ApiCompatibilityUtils.setMarginEnd(params, 0); 1484 ApiCompatibilityUtils.setMarginEnd(params, 0);
1447 } 1485 }
1448 } 1486 }
1449 } 1487 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698