OLD | NEW |
---|---|
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 Loading... | |
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, /* m ainLabelOnly */ |
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 Loading... | |
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 /** Indicates whether the main label and the sub-label of summary should be separated | |
1065 * in DISPLAY_MODE_NORMAL. */ | |
1066 private boolean mSeparateMainAndSubLabelInNormalMode = false; | |
gogerald1
2017/05/31 20:34:47
To make this feature more general instead of putti
gogerald1
2017/05/31 20:34:47
"=false" is not needed here,
wuandy1
2017/06/01 17:17:56
Done.
wuandy1
2017/06/01 17:17:57
Done.
| |
1067 | |
1064 /** Indicates whether the summary is set to R.style.PaymentsUiSectionDes criptiveText. */ | 1068 /** Indicates whether the summary is set to R.style.PaymentsUiSectionDes criptiveText. */ |
1065 private boolean mSummaryInDescriptiveText; | 1069 private boolean mSummaryInDescriptiveText; |
1066 | 1070 |
1067 private FocusChangedObserver mFocusChangedObserver; | 1071 private FocusChangedObserver mFocusChangedObserver; |
1068 | 1072 |
1069 /** | 1073 /** |
1070 * Constructs an OptionSection. | 1074 * Constructs an OptionSection. |
1071 * | 1075 * |
1072 * @param context Context to pull resources from. | 1076 * @param context Context to pull resources from. |
1073 * @param sectionName Title of the section to display. | 1077 * @param sectionName Title of the section to display. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1166 | 1170 |
1167 /** | 1171 /** |
1168 * @param singleLine If true, sets the summary text to display in a sing le line | 1172 * @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 | 1173 * in {@link #DISPLAY_MODE_NORMAL} when there is a val id selected |
1170 * option, otherwise sets the summary text to display in multiple lines. | 1174 * option, otherwise sets the summary text to display in multiple lines. |
1171 */ | 1175 */ |
1172 public void setDisplaySummaryInSingleLineInNormalMode(boolean singleLine ) { | 1176 public void setDisplaySummaryInSingleLineInNormalMode(boolean singleLine ) { |
1173 mSetDisplaySummaryInSingleLineInNormalMode = singleLine; | 1177 mSetDisplaySummaryInSingleLineInNormalMode = singleLine; |
1174 } | 1178 } |
1175 | 1179 |
1180 /** | |
1181 * @param separateMainAndSubLabelInNormalMode set to true if the main la bel and the | |
gogerald1
2017/05/31 20:34:47
splitSummary?
wuandy1
2017/06/01 17:17:56
Done.
| |
1182 * sub-label(eg, shipping opt ion name and cost) | |
1183 * should be displayed seprat ely when in | |
gogerald1
2017/05/31 20:34:47
"If true, sets to split and display the summary in
wuandy1
2017/06/01 17:17:56
Done.
| |
1184 * DISPLAY_MODE_NORMAL. | |
1185 */ | |
1186 public void setSeparateMainAndSubLabelInNormalMode( | |
gogerald1
2017/05/31 20:34:47
setSplitSummaryInNormalMode()?
wuandy1
2017/06/01 17:17:56
Done.
| |
1187 boolean separateMainAndSubLabelInNormalMode) { | |
1188 mSeparateMainAndSubLabelInNormalMode = separateMainAndSubLabelInNorm alMode; | |
1189 } | |
1190 | |
1176 /** Updates the View to account for the new {@link SectionInformation} b eing passed in. */ | 1191 /** Updates the View to account for the new {@link SectionInformation} b eing passed in. */ |
1177 public void update(SectionInformation information) { | 1192 public void update(SectionInformation information) { |
1178 mSectionInformation = information; | 1193 mSectionInformation = information; |
1179 PaymentOption selectedItem = information.getSelectedItem(); | 1194 PaymentOption selectedItem = information.getSelectedItem(); |
1180 updateSelectedItem(selectedItem); | 1195 updateSelectedItem(selectedItem); |
1181 updateOptionList(information, selectedItem); | 1196 updateOptionList(information, selectedItem); |
1182 updateControlLayout(); | 1197 updateControlLayout(); |
1183 } | 1198 } |
1184 | 1199 |
1185 private View createLoadingSpinner() { | 1200 private View createLoadingSpinner() { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1283 getContext(), mSectionInformation, getSummaryLeftTextVie w()); | 1298 getContext(), mSectionInformation, getSummaryLeftTextVie w()); |
1284 } else { | 1299 } else { |
1285 setLogoDrawable(selectedItem.getDrawableIcon()); | 1300 setLogoDrawable(selectedItem.getDrawableIcon()); |
1286 // Selected item summary should be displayed as | 1301 // Selected item summary should be displayed as |
1287 // R.style.PaymentsUiSectionDefaultText. | 1302 // R.style.PaymentsUiSectionDefaultText. |
1288 if (mSummaryInDescriptiveText) { | 1303 if (mSummaryInDescriptiveText) { |
1289 ApiCompatibilityUtils.setTextAppearance( | 1304 ApiCompatibilityUtils.setTextAppearance( |
1290 getSummaryLeftTextView(), R.style.PaymentsUiSectionD efaultText); | 1305 getSummaryLeftTextView(), R.style.PaymentsUiSectionD efaultText); |
1291 mSummaryInDescriptiveText = false; | 1306 mSummaryInDescriptiveText = false; |
1292 } | 1307 } |
1293 setSummaryText(convertOptionToString(selectedItem, false /* useB oldLabel */, | 1308 // Align main label to the left and sub label to the right if ca ller specified and |
gogerald1
2017/05/31 20:34:47
no need to comment on alignment, the left summary
wuandy1
2017/06/01 17:17:56
Done.
| |
1294 mSummaryInSingleLine), | 1309 // section is in DISPLAY_MODE_NORMAL |
1295 null); | 1310 boolean separateMainAndSubLabel = mSeparateMainAndSubLabelInNorm alMode |
1311 && (mDisplayMode == DISPLAY_MODE_NORMAL); | |
1312 setSummaryText( | |
1313 convertOptionToString(selectedItem, | |
gogerald1
2017/05/31 20:34:47
"setSummaryText(selectedItem.getLabel(), convertOp
wuandy1
2017/06/01 17:17:57
changed to excludeMainLabel.
| |
1314 /* convert only main label if it is displayed se parately from sub | |
1315 label*/ | |
1316 separateMainAndSubLabel, false /* useBoldLabel * /, | |
1317 mSummaryInSingleLine), | |
1318 separateMainAndSubLabel ? selectedItem.getSublabel() : n ull); | |
1296 } | 1319 } |
1297 | 1320 |
1298 updateControlLayout(); | 1321 updateControlLayout(); |
1299 } | 1322 } |
1300 | 1323 |
1301 private void updateOptionList(SectionInformation information, PaymentOpt ion selectedItem) { | 1324 private void updateOptionList(SectionInformation information, PaymentOpt ion selectedItem) { |
1302 mOptionLayout.removeAllViews(); | 1325 mOptionLayout.removeAllViews(); |
1303 mOptionRows.clear(); | 1326 mOptionRows.clear(); |
1304 mLabelsForTest.clear(); | 1327 mLabelsForTest.clear(); |
1305 | 1328 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 // If the user is allowed to add new options, show the button for it . | 1363 // If the user is allowed to add new options, show the button for it . |
1341 if (information.getAddStringId() != 0 && mCanAddItems) { | 1364 if (information.getAddStringId() != 0 && mCanAddItems) { |
1342 OptionRow addRow = new OptionRow(mOptionLayout, mOptionLayout.ge tChildCount(), | 1365 OptionRow addRow = new OptionRow(mOptionLayout, mOptionLayout.ge tChildCount(), |
1343 OptionRow.OPTION_ROW_TYPE_ADD, null, false); | 1366 OptionRow.OPTION_ROW_TYPE_ADD, null, false); |
1344 addRow.setLabel(information.getAddStringId()); | 1367 addRow.setLabel(information.getAddStringId()); |
1345 addRow.setButtonId(R.id.payments_add_option_button); | 1368 addRow.setButtonId(R.id.payments_add_option_button); |
1346 mOptionRows.add(addRow); | 1369 mOptionRows.add(addRow); |
1347 } | 1370 } |
1348 } | 1371 } |
1349 | 1372 |
1350 private CharSequence convertOptionToString( | 1373 private CharSequence convertOptionToString(PaymentOption item, boolean m ainLabelOnly, |
gogerald1
2017/05/31 20:34:47
excludeMainLabel?
wuandy1
2017/06/01 17:17:57
Done.
| |
1351 PaymentOption item, boolean useBoldLabel, boolean singleLine) { | 1374 boolean useBoldLabel, boolean singleLine) { |
1352 SpannableStringBuilder builder = new SpannableStringBuilder(item.get Label()); | 1375 SpannableStringBuilder builder = new SpannableStringBuilder(item.get Label()); |
1353 String labelSeparator = singleLine | 1376 |
1354 ? getContext().getString(R.string.autofill_address_summary_s eparator) | |
1355 : "\n"; | |
1356 if (useBoldLabel) { | 1377 if (useBoldLabel) { |
1357 builder.setSpan( | 1378 builder.setSpan( |
1358 new StyleSpan(android.graphics.Typeface.BOLD), 0, builde r.length(), 0); | 1379 new StyleSpan(android.graphics.Typeface.BOLD), 0, builde r.length(), 0); |
1359 } | 1380 } |
1360 | 1381 |
1361 if (!TextUtils.isEmpty(item.getSublabel())) { | 1382 String labelSeparator = singleLine |
1362 if (builder.length() > 0) builder.append(labelSeparator); | 1383 ? getContext().getString(R.string.autofill_address_summary_s eparator) |
1363 builder.append(item.getSublabel()); | 1384 : "\n"; |
1364 } | 1385 if (!mainLabelOnly) { // build for sublabel and tertiary label |
1386 if (!TextUtils.isEmpty(item.getSublabel())) { | |
1387 if (builder.length() > 0) builder.append(labelSeparator); | |
1388 builder.append(item.getSublabel()); | |
1389 } | |
1365 | 1390 |
1366 if (!TextUtils.isEmpty(item.getTertiaryLabel())) { | 1391 if (!TextUtils.isEmpty(item.getTertiaryLabel())) { |
1367 if (builder.length() > 0) builder.append(labelSeparator); | 1392 if (builder.length() > 0) builder.append(labelSeparator); |
1368 builder.append(item.getTertiaryLabel()); | 1393 builder.append(item.getTertiaryLabel()); |
1394 } | |
1369 } | 1395 } |
1370 | 1396 |
1371 if (!item.isComplete() && !TextUtils.isEmpty(item.getEditMessage())) { | 1397 if (!item.isComplete() && !TextUtils.isEmpty(item.getEditMessage())) { |
1372 if (builder.length() > 0) builder.append(labelSeparator); | 1398 if (builder.length() > 0) builder.append(labelSeparator); |
1373 String editMessage = item.getEditMessage(); | 1399 String editMessage = item.getEditMessage(); |
1374 builder.append(editMessage); | 1400 builder.append(editMessage); |
1375 Object foregroundSpanner = new ForegroundColorSpan(ApiCompatibil ityUtils.getColor( | 1401 Object foregroundSpanner = new ForegroundColorSpan(ApiCompatibil ityUtils.getColor( |
1376 getContext().getResources(), R.color.google_blue_700)); | 1402 getContext().getResources(), R.color.google_blue_700)); |
1377 Object sizeSpanner = new AbsoluteSizeSpan(14, true); | 1403 Object sizeSpanner = new AbsoluteSizeSpan(14, true); |
1378 int startIndex = builder.length() - editMessage.length(); | 1404 int startIndex = builder.length() - editMessage.length(); |
(...skipping 10 matching lines...) Expand all Loading... | |
1389 */ | 1415 */ |
1390 @VisibleForTesting | 1416 @VisibleForTesting |
1391 public TextView getOptionLabelsForTest(int labelIndex) { | 1417 public TextView getOptionLabelsForTest(int labelIndex) { |
1392 return mLabelsForTest.get(labelIndex); | 1418 return mLabelsForTest.get(labelIndex); |
1393 } | 1419 } |
1394 | 1420 |
1395 /** | 1421 /** |
1396 * Returns the label of the section summary. | 1422 * Returns the label of the section summary. |
1397 */ | 1423 */ |
1398 @VisibleForTesting | 1424 @VisibleForTesting |
1399 public TextView getSummaryLabelForTest() { | 1425 public TextView getSummaryLabelForTest() { |
gogerald1
2017/05/31 20:34:47
rename it to getLeftSummaryLabelForTest,
wuandy1
2017/06/01 17:17:56
Done.
| |
1400 return getSummaryLeftTextView(); | 1426 return getSummaryLeftTextView(); |
1401 } | 1427 } |
1402 | 1428 |
1429 /** | |
1430 * Returns the label of the summary for the OptionSection. | |
1431 */ | |
1432 @VisibleForTesting | |
1433 public TextView getSummarySubLabelForTest() { | |
gogerald1
2017/05/31 20:34:47
rename it to getRightSummaryLabelForTest
wuandy1
2017/06/01 17:17:57
Done.
| |
1434 return getSummaryRightTextView(); | |
1435 } | |
1436 | |
1403 /** Returns the number of option labels. */ | 1437 /** Returns the number of option labels. */ |
1404 @VisibleForTesting | 1438 @VisibleForTesting |
1405 public int getNumberOfOptionLabelsForTest() { | 1439 public int getNumberOfOptionLabelsForTest() { |
1406 return mLabelsForTest.size(); | 1440 return mLabelsForTest.size(); |
1407 } | 1441 } |
1408 | 1442 |
1409 /** Returns the OptionRow at the specified |index|. */ | 1443 /** Returns the OptionRow at the specified |index|. */ |
1410 @VisibleForTesting | 1444 @VisibleForTesting |
1411 public OptionRow getOptionRowAtIndex(int index) { | 1445 public OptionRow getOptionRowAtIndex(int index) { |
1412 return mOptionRows.get(index); | 1446 return mOptionRows.get(index); |
(...skipping 27 matching lines...) Expand all Loading... | |
1440 } | 1474 } |
1441 | 1475 |
1442 /** Expand the separator to be the full width of the dialog. */ | 1476 /** Expand the separator to be the full width of the dialog. */ |
1443 public void expand() { | 1477 public void expand() { |
1444 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLa youtParams(); | 1478 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLa youtParams(); |
1445 ApiCompatibilityUtils.setMarginStart(params, 0); | 1479 ApiCompatibilityUtils.setMarginStart(params, 0); |
1446 ApiCompatibilityUtils.setMarginEnd(params, 0); | 1480 ApiCompatibilityUtils.setMarginEnd(params, 0); |
1447 } | 1481 } |
1448 } | 1482 } |
1449 } | 1483 } |
OLD | NEW |