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 /** | |
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 Loading... | |
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 whether the summary should be split to display under DISPLAY_ MODE_NORMAL. | |
1184 * | |
1185 * @param splitSummary If true split the display of summary in left and right | |
gogerald1
2017/06/07 15:40:42
If true, ....in the left and right text views.....
wuandy1
2017/06/07 16:45:15
Done.
| |
1186 * text views in {@link DISPLAY_MODE_NORMAL}, the su mmary is | |
1187 * split into 'label' and the rest('sublabel', 'Tert iary label'). | |
1188 * Otherwise the entire summary is displayed in left text view. | |
1189 */ | |
1190 public void setSplitSummaryInDisplayModeNormal(boolean splitSummary) { | |
1191 mSplitSummaryInDisplayModeNormal = splitSummary; | |
1192 } | |
1193 | |
1176 /** Updates the View to account for the new {@link SectionInformation} b eing passed in. */ | 1194 /** Updates the View to account for the new {@link SectionInformation} b eing passed in. */ |
1177 public void update(SectionInformation information) { | 1195 public void update(SectionInformation information) { |
1178 mSectionInformation = information; | 1196 mSectionInformation = information; |
1179 PaymentOption selectedItem = information.getSelectedItem(); | 1197 PaymentOption selectedItem = information.getSelectedItem(); |
1180 updateSelectedItem(selectedItem); | 1198 updateSelectedItem(selectedItem); |
1181 updateOptionList(information, selectedItem); | 1199 updateOptionList(information, selectedItem); |
1182 updateControlLayout(); | 1200 updateControlLayout(); |
1183 } | 1201 } |
1184 | 1202 |
1185 private View createLoadingSpinner() { | 1203 private View createLoadingSpinner() { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1283 getContext(), mSectionInformation, getSummaryLeftTextVie w()); | 1301 getContext(), mSectionInformation, getSummaryLeftTextVie w()); |
1284 } else { | 1302 } else { |
1285 setLogoDrawable(selectedItem.getDrawableIcon()); | 1303 setLogoDrawable(selectedItem.getDrawableIcon()); |
1286 // Selected item summary should be displayed as | 1304 // Selected item summary should be displayed as |
1287 // R.style.PaymentsUiSectionDefaultText. | 1305 // R.style.PaymentsUiSectionDefaultText. |
1288 if (mSummaryInDescriptiveText) { | 1306 if (mSummaryInDescriptiveText) { |
1289 ApiCompatibilityUtils.setTextAppearance( | 1307 ApiCompatibilityUtils.setTextAppearance( |
1290 getSummaryLeftTextView(), R.style.PaymentsUiSectionD efaultText); | 1308 getSummaryLeftTextView(), R.style.PaymentsUiSectionD efaultText); |
1291 mSummaryInDescriptiveText = false; | 1309 mSummaryInDescriptiveText = false; |
1292 } | 1310 } |
1293 setSummaryText(convertOptionToString(selectedItem, false /* useB oldLabel */, | 1311 // Split summary in DISPLAY_MODE_NORMAL if caller specified. The first part is |
1294 mSummaryInSingleLine), | 1312 // displayed on the left summary text view aligned to the left. The second part is |
1295 null); | 1313 // displayed on the right summary text view aligned to the right . |
1314 boolean splitSummary = | |
1315 mSplitSummaryInDisplayModeNormal && (mDisplayMode == DIS PLAY_MODE_NORMAL); | |
1316 if (splitSummary) { | |
1317 setSummaryText(selectedItem.getLabel(), | |
1318 convertOptionToString(selectedItem, true /* excludeM ainLabel */, | |
1319 false /* useBoldLabel */, mSummaryInSingleLi ne)); | |
1320 } else { | |
1321 setSummaryText(convertOptionToString(selectedItem, false /* excludeMainLabel */, | |
1322 false /* useBoldLabel */, mSummaryInS ingleLine), | |
1323 null); | |
1324 } | |
1296 } | 1325 } |
1297 | 1326 |
1298 updateControlLayout(); | 1327 updateControlLayout(); |
1299 } | 1328 } |
1300 | 1329 |
1301 private void updateOptionList(SectionInformation information, PaymentOpt ion selectedItem) { | 1330 private void updateOptionList(SectionInformation information, PaymentOpt ion selectedItem) { |
1302 mOptionLayout.removeAllViews(); | 1331 mOptionLayout.removeAllViews(); |
1303 mOptionRows.clear(); | 1332 mOptionRows.clear(); |
1304 mLabelsForTest.clear(); | 1333 mLabelsForTest.clear(); |
1305 | 1334 |
(...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 . | 1369 // If the user is allowed to add new options, show the button for it . |
1341 if (information.getAddStringId() != 0 && mCanAddItems) { | 1370 if (information.getAddStringId() != 0 && mCanAddItems) { |
1342 OptionRow addRow = new OptionRow(mOptionLayout, mOptionLayout.ge tChildCount(), | 1371 OptionRow addRow = new OptionRow(mOptionLayout, mOptionLayout.ge tChildCount(), |
1343 OptionRow.OPTION_ROW_TYPE_ADD, null, false); | 1372 OptionRow.OPTION_ROW_TYPE_ADD, null, false); |
1344 addRow.setLabel(information.getAddStringId()); | 1373 addRow.setLabel(information.getAddStringId()); |
1345 addRow.setButtonId(R.id.payments_add_option_button); | 1374 addRow.setButtonId(R.id.payments_add_option_button); |
1346 mOptionRows.add(addRow); | 1375 mOptionRows.add(addRow); |
1347 } | 1376 } |
1348 } | 1377 } |
1349 | 1378 |
1350 private CharSequence convertOptionToString( | 1379 private CharSequence convertOptionToString(PaymentOption item, boolean e xcludeMainLabel, |
1351 PaymentOption item, boolean useBoldLabel, boolean singleLine) { | 1380 boolean useBoldLabel, boolean singleLine) { |
1352 SpannableStringBuilder builder = new SpannableStringBuilder(item.get Label()); | 1381 SpannableStringBuilder builder = new SpannableStringBuilder(); |
1382 if (!excludeMainLabel) { | |
1383 builder.append(item.getLabel()); | |
1384 if (useBoldLabel) { | |
1385 builder.setSpan( | |
1386 new StyleSpan(android.graphics.Typeface.BOLD), 0, bu ilder.length(), 0); | |
1387 } | |
1388 } | |
1389 | |
1353 String labelSeparator = singleLine | 1390 String labelSeparator = singleLine |
1354 ? getContext().getString(R.string.autofill_address_summary_s eparator) | 1391 ? getContext().getString(R.string.autofill_address_summary_s eparator) |
1355 : "\n"; | 1392 : "\n"; |
1356 if (useBoldLabel) { | |
1357 builder.setSpan( | |
1358 new StyleSpan(android.graphics.Typeface.BOLD), 0, builde r.length(), 0); | |
1359 } | |
1360 | |
1361 if (!TextUtils.isEmpty(item.getSublabel())) { | 1393 if (!TextUtils.isEmpty(item.getSublabel())) { |
1362 if (builder.length() > 0) builder.append(labelSeparator); | 1394 if (builder.length() > 0) builder.append(labelSeparator); |
1363 builder.append(item.getSublabel()); | 1395 builder.append(item.getSublabel()); |
1364 } | 1396 } |
1365 | 1397 |
1366 if (!TextUtils.isEmpty(item.getTertiaryLabel())) { | 1398 if (!TextUtils.isEmpty(item.getTertiaryLabel())) { |
1367 if (builder.length() > 0) builder.append(labelSeparator); | 1399 if (builder.length() > 0) builder.append(labelSeparator); |
1368 builder.append(item.getTertiaryLabel()); | 1400 builder.append(item.getTertiaryLabel()); |
1369 } | 1401 } |
1370 | 1402 |
(...skipping 18 matching lines...) Expand all Loading... | |
1389 */ | 1421 */ |
1390 @VisibleForTesting | 1422 @VisibleForTesting |
1391 public TextView getOptionLabelsForTest(int labelIndex) { | 1423 public TextView getOptionLabelsForTest(int labelIndex) { |
1392 return mLabelsForTest.get(labelIndex); | 1424 return mLabelsForTest.get(labelIndex); |
1393 } | 1425 } |
1394 | 1426 |
1395 /** | 1427 /** |
1396 * Returns the label of the section summary. | 1428 * Returns the label of the section summary. |
1397 */ | 1429 */ |
1398 @VisibleForTesting | 1430 @VisibleForTesting |
1399 public TextView getSummaryLabelForTest() { | 1431 public TextView getLeftSummaryLabelForTest() { |
1400 return getSummaryLeftTextView(); | 1432 return getSummaryLeftTextView(); |
1401 } | 1433 } |
1402 | 1434 |
1435 /** | |
1436 * Returns the right summary text view. | |
1437 */ | |
1438 @VisibleForTesting | |
1439 public TextView getRightSummaryLabelForTest() { | |
1440 return getSummaryRightTextView(); | |
1441 } | |
1442 | |
1403 /** Returns the number of option labels. */ | 1443 /** Returns the number of option labels. */ |
1404 @VisibleForTesting | 1444 @VisibleForTesting |
1405 public int getNumberOfOptionLabelsForTest() { | 1445 public int getNumberOfOptionLabelsForTest() { |
1406 return mLabelsForTest.size(); | 1446 return mLabelsForTest.size(); |
1407 } | 1447 } |
1408 | 1448 |
1409 /** Returns the OptionRow at the specified |index|. */ | 1449 /** Returns the OptionRow at the specified |index|. */ |
1410 @VisibleForTesting | 1450 @VisibleForTesting |
1411 public OptionRow getOptionRowAtIndex(int index) { | 1451 public OptionRow getOptionRowAtIndex(int index) { |
1412 return mOptionRows.get(index); | 1452 return mOptionRows.get(index); |
(...skipping 27 matching lines...) Expand all Loading... | |
1440 } | 1480 } |
1441 | 1481 |
1442 /** Expand the separator to be the full width of the dialog. */ | 1482 /** Expand the separator to be the full width of the dialog. */ |
1443 public void expand() { | 1483 public void expand() { |
1444 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLa youtParams(); | 1484 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLa youtParams(); |
1445 ApiCompatibilityUtils.setMarginStart(params, 0); | 1485 ApiCompatibilityUtils.setMarginStart(params, 0); |
1446 ApiCompatibilityUtils.setMarginEnd(params, 0); | 1486 ApiCompatibilityUtils.setMarginEnd(params, 0); |
1447 } | 1487 } |
1448 } | 1488 } |
1449 } | 1489 } |
OLD | NEW |