| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.components.autofill; | 5 package org.chromium.components.autofill; |
| 6 | 6 |
| 7 import org.chromium.ui.DropdownItemBase; | 7 import org.chromium.ui.DropdownItemBase; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Autofill suggestion container used to store information needed for each Autof
ill popup entry. | 10 * Autofill suggestion container used to store information needed for each Autof
ill popup entry. |
| 11 */ | 11 */ |
| 12 public class AutofillSuggestion extends DropdownItemBase { | 12 public class AutofillSuggestion extends DropdownItemBase { |
| 13 /** | 13 /** |
| 14 * The constant used to specify a http warning message in a list of Autofill
suggestions. | 14 * The constant used to specify a http warning message in a list of Autofill
suggestions. |
| 15 * Has to be kept in sync with enum in popup_item_ids.h | 15 * Has to be kept in sync with {@code POPUP_ITEM_ID_SEPARATOR} enum in |
| 16 * TODO(crbug.com/666529): Generate java constants from C++ enum. | 16 * components/autofill/core/browser/popup_item_ids.h |
| 17 */ | 17 */ |
| 18 private static final int ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE = -10; | 18 private static final int ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE = -10; |
| 19 | 19 |
| 20 private final String mLabel; | 20 private final String mLabel; |
| 21 private final String mSublabel; | 21 private final String mSublabel; |
| 22 private final int mIconId; | 22 private final int mIconId; |
| 23 private final boolean mIsIconAtStart; |
| 23 private final int mSuggestionId; | 24 private final int mSuggestionId; |
| 24 private final boolean mDeletable; | 25 private final boolean mIsDeletable; |
| 25 private final boolean mIsMultilineLabel; | 26 private final boolean mIsMultilineLabel; |
| 27 private final boolean mIsBoldLabel; |
| 26 | 28 |
| 27 /** | 29 /** |
| 28 * Constructs a Autofill suggestion container. | 30 * Constructs a Autofill suggestion container. |
| 29 * @param label The main label of the Autofill suggestion. | 31 * @param label The main label of the Autofill suggestion. |
| 30 * @param sublabel The describing sublabel of the Autofill suggestion. | 32 * @param sublabel The describing sublabel of the Autofill suggestion. |
| 33 * @param iconId The resource ID for the icon associated with the suggestion
, or |
| 34 * {@code DropdownItem.NO_ICON} for no icon. |
| 35 * @param isIconAtStart {@code true} if {@param iconId} is displayed before
{@param label}. |
| 31 * @param suggestionId The type of suggestion. | 36 * @param suggestionId The type of suggestion. |
| 32 * @param deletable Whether the item can be deleted by the user. | 37 * @param isDeletable Whether the item can be deleted by the user. |
| 33 * @param multilineLabel Whether the label is displayed over multiple lines. | 38 * @param isMultilineLabel Whether the label is displayed over multiple line
s. |
| 39 * @param isBoldLabel Whether the label is displayed in {@code Typeface.BOLD
}. |
| 34 */ | 40 */ |
| 35 public AutofillSuggestion(String label, String sublabel, int iconId, int sug
gestionId, | 41 public AutofillSuggestion(String label, String sublabel, int iconId, boolean
isIconAtStart, |
| 36 boolean deletable, boolean multilineLabel) { | 42 int suggestionId, boolean isDeletable, boolean isMultilineLabel, boo
lean isBoldLabel) { |
| 37 mLabel = label; | 43 mLabel = label; |
| 38 mSublabel = sublabel; | 44 mSublabel = sublabel; |
| 39 mIconId = iconId; | 45 mIconId = iconId; |
| 46 mIsIconAtStart = isIconAtStart; |
| 40 mSuggestionId = suggestionId; | 47 mSuggestionId = suggestionId; |
| 41 mDeletable = deletable; | 48 mIsDeletable = isDeletable; |
| 42 mIsMultilineLabel = multilineLabel; | 49 mIsMultilineLabel = isMultilineLabel; |
| 50 mIsBoldLabel = isBoldLabel; |
| 43 } | 51 } |
| 44 | 52 |
| 45 @Override | 53 @Override |
| 46 public String getLabel() { | 54 public String getLabel() { |
| 47 return mLabel; | 55 return mLabel; |
| 48 } | 56 } |
| 49 | 57 |
| 50 @Override | 58 @Override |
| 51 public String getSublabel() { | 59 public String getSublabel() { |
| 52 return mSublabel; | 60 return mSublabel; |
| 53 } | 61 } |
| 54 | 62 |
| 55 @Override | 63 @Override |
| 56 public int getIconId() { | 64 public int getIconId() { |
| 57 return mIconId; | 65 return mIconId; |
| 58 } | 66 } |
| 59 | 67 |
| 60 @Override | 68 @Override |
| 69 public boolean isIconAtStart() { |
| 70 if (mIsIconAtStart |
| 71 || mSuggestionId == ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { |
| 72 return true; |
| 73 } |
| 74 return super.isIconAtStart(); |
| 75 } |
| 76 |
| 77 @Override |
| 61 public boolean isMultilineLabel() { | 78 public boolean isMultilineLabel() { |
| 62 return mIsMultilineLabel; | 79 return mIsMultilineLabel; |
| 63 } | 80 } |
| 64 | 81 |
| 65 @Override | 82 @Override |
| 83 public boolean isBoldLabel() { |
| 84 return mIsBoldLabel; |
| 85 } |
| 86 |
| 87 @Override |
| 66 public int getLabelFontColorResId() { | 88 public int getLabelFontColorResId() { |
| 67 if (mSuggestionId == ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { | 89 if (mSuggestionId == ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { |
| 68 return R.color.http_bad_warning_message_text; | 90 return R.color.http_bad_warning_message_text; |
| 69 } | 91 } |
| 70 return super.getLabelFontColorResId(); | 92 return super.getLabelFontColorResId(); |
| 71 } | 93 } |
| 72 | 94 |
| 73 @Override | 95 @Override |
| 74 public int getLabelFontSizeResId() { | 96 public int getLabelFontSizeResId() { |
| 75 if (mSuggestionId == ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { | 97 if (mSuggestionId == ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) { |
| 76 return R.dimen.dropdown_item_smaller_label_font_size; | 98 return R.dimen.dropdown_item_smaller_label_font_size; |
| 77 } | 99 } |
| 78 return super.getLabelFontSizeResId(); | 100 return super.getLabelFontSizeResId(); |
| 79 } | 101 } |
| 80 | 102 |
| 81 public int getSuggestionId() { | 103 public int getSuggestionId() { |
| 82 return mSuggestionId; | 104 return mSuggestionId; |
| 83 } | 105 } |
| 84 | 106 |
| 85 public boolean isDeletable() { | 107 public boolean isDeletable() { |
| 86 return mDeletable; | 108 return mIsDeletable; |
| 87 } | 109 } |
| 88 | 110 |
| 89 public boolean isFillable() { | 111 public boolean isFillable() { |
| 90 // Negative suggestion ID indiciates a tool like "settings" or "scan cre
dit card." | 112 // Negative suggestion ID indiciates a tool like "settings" or "scan cre
dit card." |
| 91 // Non-negative suggestion ID indicates suggestions that can be filled i
nto the form. | 113 // Non-negative suggestion ID indicates suggestions that can be filled i
nto the form. |
| 92 return mSuggestionId >= 0; | 114 return mSuggestionId >= 0; |
| 93 } | 115 } |
| 94 } | 116 } |
| OLD | NEW |