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, /* 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 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 summary should be split to display in left and right summary | |
1065 * text views in {@link PaymentRequestSection.DISPLAY_MODE_NORMAL}. */ | |
gogerald1
2017/06/02 15:05:10
This is not a public interface or variable, so you
wuandy1
2017/06/02 19:53:12
Done.
| |
1066 private boolean mSplitSummaryInNormalMode; | |
gogerald1
2017/06/02 15:05:10
looks 'mSplitSummaryInDisplayModeNormal' is better
wuandy1
2017/06/02 19:53:12
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 splitSummary set to true to split the display of summary in le ft and right | |
gogerald1
2017/06/02 15:05:10
Uppercase the first character to comment a param.
wuandy1
2017/06/02 19:53:12
Done.
| |
1182 * text views in {@link DISPLAY_MODE_NORMAL}. Otherw ise the entire | |
1183 * summary is displayed in left text view. Note that summary is | |
1184 * split into 'label' and the rest('sublabel', 'Tert iary label'). | |
1185 */ | |
1186 public void setSplitSummaryInNormalMode(boolean splitSummary) { | |
gogerald1
2017/06/02 15:05:10
setSplitSummaryInDisplayNormalMode?
wuandy1
2017/06/02 19:53:12
Done.
| |
1187 mSplitSummaryInNormalMode = splitSummary; | |
1188 } | |
1189 | |
1176 /** Updates the View to account for the new {@link SectionInformation} b eing passed in. */ | 1190 /** Updates the View to account for the new {@link SectionInformation} b eing passed in. */ |
1177 public void update(SectionInformation information) { | 1191 public void update(SectionInformation information) { |
1178 mSectionInformation = information; | 1192 mSectionInformation = information; |
1179 PaymentOption selectedItem = information.getSelectedItem(); | 1193 PaymentOption selectedItem = information.getSelectedItem(); |
1180 updateSelectedItem(selectedItem); | 1194 updateSelectedItem(selectedItem); |
1181 updateOptionList(information, selectedItem); | 1195 updateOptionList(information, selectedItem); |
1182 updateControlLayout(); | 1196 updateControlLayout(); |
1183 } | 1197 } |
1184 | 1198 |
1185 private View createLoadingSpinner() { | 1199 private View createLoadingSpinner() { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1283 getContext(), mSectionInformation, getSummaryLeftTextVie w()); | 1297 getContext(), mSectionInformation, getSummaryLeftTextVie w()); |
1284 } else { | 1298 } else { |
1285 setLogoDrawable(selectedItem.getDrawableIcon()); | 1299 setLogoDrawable(selectedItem.getDrawableIcon()); |
1286 // Selected item summary should be displayed as | 1300 // Selected item summary should be displayed as |
1287 // R.style.PaymentsUiSectionDefaultText. | 1301 // R.style.PaymentsUiSectionDefaultText. |
1288 if (mSummaryInDescriptiveText) { | 1302 if (mSummaryInDescriptiveText) { |
1289 ApiCompatibilityUtils.setTextAppearance( | 1303 ApiCompatibilityUtils.setTextAppearance( |
1290 getSummaryLeftTextView(), R.style.PaymentsUiSectionD efaultText); | 1304 getSummaryLeftTextView(), R.style.PaymentsUiSectionD efaultText); |
1291 mSummaryInDescriptiveText = false; | 1305 mSummaryInDescriptiveText = false; |
1292 } | 1306 } |
1293 setSummaryText(convertOptionToString(selectedItem, false /* useB oldLabel */, | 1307 // Align main label to the left and sub label to the right if ca ller specified and |
1294 mSummaryInSingleLine), | 1308 // section is in DISPLAY_MODE_NORMAL |
gogerald1
2017/06/02 15:05:10
// Split summary in DISPLAY_MODE_NORMAL if caller
wuandy1
2017/06/02 19:53:12
Done.
| |
1295 null); | 1309 boolean splitSummary = |
1310 mSplitSummaryInNormalMode && (mDisplayMode == DISPLAY_MO DE_NORMAL); | |
1311 if (splitSummary) { | |
1312 setSummaryText(selectedItem.getLabel(), | |
1313 convertOptionToString(selectedItem, true /* excludeM ainLabel */, | |
1314 false /* useBoldLabel */, mSummaryInSingleLi ne)); | |
1315 } else { | |
1316 setSummaryText(convertOptionToString(selectedItem, false /* excludeMainLabel */, | |
1317 false /* useBoldLabel */, mSummaryInS ingleLine), | |
1318 null); | |
1319 } | |
1296 } | 1320 } |
1297 | 1321 |
1298 updateControlLayout(); | 1322 updateControlLayout(); |
1299 } | 1323 } |
1300 | 1324 |
1301 private void updateOptionList(SectionInformation information, PaymentOpt ion selectedItem) { | 1325 private void updateOptionList(SectionInformation information, PaymentOpt ion selectedItem) { |
1302 mOptionLayout.removeAllViews(); | 1326 mOptionLayout.removeAllViews(); |
1303 mOptionRows.clear(); | 1327 mOptionRows.clear(); |
1304 mLabelsForTest.clear(); | 1328 mLabelsForTest.clear(); |
1305 | 1329 |
(...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 . | 1364 // If the user is allowed to add new options, show the button for it . |
1341 if (information.getAddStringId() != 0 && mCanAddItems) { | 1365 if (information.getAddStringId() != 0 && mCanAddItems) { |
1342 OptionRow addRow = new OptionRow(mOptionLayout, mOptionLayout.ge tChildCount(), | 1366 OptionRow addRow = new OptionRow(mOptionLayout, mOptionLayout.ge tChildCount(), |
1343 OptionRow.OPTION_ROW_TYPE_ADD, null, false); | 1367 OptionRow.OPTION_ROW_TYPE_ADD, null, false); |
1344 addRow.setLabel(information.getAddStringId()); | 1368 addRow.setLabel(information.getAddStringId()); |
1345 addRow.setButtonId(R.id.payments_add_option_button); | 1369 addRow.setButtonId(R.id.payments_add_option_button); |
1346 mOptionRows.add(addRow); | 1370 mOptionRows.add(addRow); |
1347 } | 1371 } |
1348 } | 1372 } |
1349 | 1373 |
1350 private CharSequence convertOptionToString( | 1374 private CharSequence convertOptionToString(PaymentOption item, boolean e xcludeMainLabel, |
1351 PaymentOption item, boolean useBoldLabel, boolean singleLine) { | 1375 boolean useBoldLabel, boolean singleLine) { |
1352 SpannableStringBuilder builder = new SpannableStringBuilder(item.get Label()); | 1376 SpannableStringBuilder builder = new SpannableStringBuilder(); |
1353 String labelSeparator = singleLine | 1377 if (!excludeMainLabel) builder.append(item.getLabel()); |
1354 ? getContext().getString(R.string.autofill_address_summary_s eparator) | 1378 |
1355 : "\n"; | |
1356 if (useBoldLabel) { | 1379 if (useBoldLabel) { |
gogerald1
2017/06/02 15:05:10
useBoldLabel is used for main label only
wuandy1
2017/06/02 19:53:12
I think this is something better left to the calle
gogerald1
2017/06/06 16:55:19
Yes, but previously useBoldLabel is only apply for
wuandy1
2017/06/07 01:58:04
absolutely! good catch!
| |
1357 builder.setSpan( | 1380 builder.setSpan( |
1358 new StyleSpan(android.graphics.Typeface.BOLD), 0, builde r.length(), 0); | 1381 new StyleSpan(android.graphics.Typeface.BOLD), 0, builde r.length(), 0); |
1359 } | 1382 } |
1360 | 1383 |
1384 String labelSeparator = singleLine | |
1385 ? getContext().getString(R.string.autofill_address_summary_s eparator) | |
1386 : "\n"; | |
1361 if (!TextUtils.isEmpty(item.getSublabel())) { | 1387 if (!TextUtils.isEmpty(item.getSublabel())) { |
1362 if (builder.length() > 0) builder.append(labelSeparator); | 1388 if (builder.length() > 0) builder.append(labelSeparator); |
1363 builder.append(item.getSublabel()); | 1389 builder.append(item.getSublabel()); |
1364 } | 1390 } |
1365 | 1391 |
1366 if (!TextUtils.isEmpty(item.getTertiaryLabel())) { | 1392 if (!TextUtils.isEmpty(item.getTertiaryLabel())) { |
1367 if (builder.length() > 0) builder.append(labelSeparator); | 1393 if (builder.length() > 0) builder.append(labelSeparator); |
1368 builder.append(item.getTertiaryLabel()); | 1394 builder.append(item.getTertiaryLabel()); |
1369 } | 1395 } |
1370 | 1396 |
(...skipping 18 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 getLeftSummaryLabelForTest() { |
1400 return getSummaryLeftTextView(); | 1426 return getSummaryLeftTextView(); |
1401 } | 1427 } |
1402 | 1428 |
1429 /** | |
1430 * Returns the label of the summary right text view for the OptionSectio n. | |
gogerald1
2017/06/02 15:05:10
*the right summary text view* to be consistent
wuandy1
2017/06/02 19:53:12
Done.
| |
1431 */ | |
1432 @VisibleForTesting | |
1433 public TextView getRightSummaryLabelForTest() { | |
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 |