0

Show icons in Android web autofill dropdown

BUG=402131

Review URL: https://codereview.chromium.org/443193006

Cr-Commit-Position: refs/heads/master@{#303297}
This commit is contained in:
estade
2014-11-07 13:35:22 -08:00
committed by Commit bot
parent dd6819b152
commit e37f822491
13 changed files with 116 additions and 45 deletions
android_webview/java/src/org/chromium/android_webview
chrome
android
java
src
org
chromium
chrome
javatests
src
org
chromium
chrome
browser
browser
chrome_browser.gypi
content/public/android/java/src/org/chromium/content/browser/input
ui/android/java

@ -9,6 +9,7 @@ import android.view.ViewGroup;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.ui.DropdownItem;
import org.chromium.ui.autofill.AutofillPopup;
import org.chromium.ui.autofill.AutofillSuggestion;
@ -84,7 +85,7 @@ public class AwAutofillClient {
@CalledByNative
private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
String name, String label, int uniqueId) {
array[index] = new AutofillSuggestion(name, label, uniqueId);
array[index] = new AutofillSuggestion(name, label, DropdownItem.NO_ICON, uniqueId);
}
private native void nativeSuggestionSelected(long nativeAwAutofillClient,

@ -9,6 +9,8 @@ import android.os.Handler;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.chrome.browser.ResourceId;
import org.chromium.ui.DropdownItem;
import org.chromium.ui.autofill.AutofillPopup;
import org.chromium.ui.autofill.AutofillPopup.AutofillPopupDelegate;
import org.chromium.ui.autofill.AutofillSuggestion;
@ -101,12 +103,14 @@ public class AutofillPopupBridge implements AutofillPopupDelegate{
* @param index Index in the array where to place a new suggestion.
* @param label First line of the suggestion.
* @param sublabel Second line of the suggestion.
* @param uniqueId Unique suggestion id.
* @param iconId The resource ID for the icon associated with the suggestion, or 0 for no icon.
* @param suggestionId Identifier for the suggestion type.
*/
@CalledByNative
private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
String label, String sublabel, int uniqueId) {
array[index] = new AutofillSuggestion(label, sublabel, uniqueId);
String label, String sublabel, int iconId, int suggestionId) {
int drawableId = iconId == 0 ? DropdownItem.NO_ICON : ResourceId.mapToDrawableId(iconId);
array[index] = new AutofillSuggestion(label, sublabel, drawableId, suggestionId);
}
private native void nativePopupDismissed(long nativeAutofillPopupViewAndroid);

@ -15,6 +15,7 @@ import org.chromium.chrome.shell.ChromeShellTestBase;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.TouchCommon;
import org.chromium.ui.DropdownItem;
import org.chromium.ui.autofill.AutofillPopup;
import org.chromium.ui.autofill.AutofillPopup.AutofillPopupDelegate;
import org.chromium.ui.autofill.AutofillSuggestion;
@ -88,18 +89,20 @@ public class AutofillTest extends ChromeShellTestBase {
private AutofillSuggestion[] createTwoAutofillSuggestionArray() {
return new AutofillSuggestion[] {
new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", 42),
new AutofillSuggestion("Arthur Dent", "West Country", 43),
new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", DropdownItem.NO_ICON,
42),
new AutofillSuggestion("Arthur Dent", "West Country", DropdownItem.NO_ICON, 43),
};
}
private AutofillSuggestion[] createFiveAutofillSuggestionArray() {
return new AutofillSuggestion[] {
new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", 42),
new AutofillSuggestion("Arthur Dent", "West Country", 43),
new AutofillSuggestion("Arthos", "France", 44),
new AutofillSuggestion("Porthos", "France", 45),
new AutofillSuggestion("Aramis", "France", 46),
new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", DropdownItem.NO_ICON,
42),
new AutofillSuggestion("Arthur Dent", "West Country", DropdownItem.NO_ICON, 43),
new AutofillSuggestion("Arthos", "France", DropdownItem.NO_ICON, 44),
new AutofillSuggestion("Porthos", "France", DropdownItem.NO_ICON, 45),
new AutofillSuggestion("Aramis", "France", DropdownItem.NO_ICON, 46),
};
}

@ -509,6 +509,7 @@ static_library("browser") {
"//components/cdm/browser",
"//components/enhanced_bookmarks",
"//components/history/core/android",
"//components/resources:components_resources",
"//components/web_contents_delegate_android",
"//third_party/android_opengl/etc1",
]

@ -42,4 +42,13 @@ DEFINE_RESOURCE_ID(IDR_PAGEINFO_WARNING_MAJOR,\
DEFINE_RESOURCE_ID(IDR_PAGEINFO_WARNING_MINOR,\
R.drawable.pageinfo_warning_minor)
// Autofill popup images.
DEFINE_RESOURCE_ID(IDR_AUTOFILL_CC_AMEX, R.drawable.amex_card)
DEFINE_RESOURCE_ID(IDR_AUTOFILL_CC_DINERS, R.drawable.generic_card)
DEFINE_RESOURCE_ID(IDR_AUTOFILL_CC_DISCOVER, R.drawable.discover_card)
DEFINE_RESOURCE_ID(IDR_AUTOFILL_CC_GENERIC, R.drawable.generic_card)
DEFINE_RESOURCE_ID(IDR_AUTOFILL_CC_JCB, R.drawable.generic_card)
DEFINE_RESOURCE_ID(IDR_AUTOFILL_CC_MASTERCARD, R.drawable.mc_card)
DEFINE_RESOURCE_ID(IDR_AUTOFILL_CC_VISA, R.drawable.visa_card)
#endif // CHROME_BROWSER_ANDROID_RESOURCE_ID_H_

@ -8,6 +8,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "grit/components_scaled_resources.h"
#include "grit/theme_resources.h"
namespace {

@ -6,12 +6,15 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "chrome/browser/android/resource_mapper.h"
#include "chrome/browser/ui/android/window_android_helper.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller.h"
#include "content/public/browser/android/content_view_core.h"
#include "jni/AutofillPopupBridge_jni.h"
#include "ui/base/android/view_android.h"
#include "ui/base/android/window_android.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/rect.h"
namespace autofill {
@ -65,12 +68,19 @@ void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() {
ScopedJavaLocalRef<jstring> subtext =
base::android::ConvertUTF16ToJavaString(env,
controller_->subtexts()[i]);
int android_icon_id = 0;
if (!controller_->icons()[i].empty()) {
android_icon_id = ResourceMapper::MapFromChromiumId(
controller_->GetIconResourceID(controller_->icons()[i]));
}
Java_AutofillPopupBridge_addToAutofillSuggestionArray(
env,
data_array.obj(),
i,
name.obj(),
subtext.obj(),
android_icon_id,
controller_->identifiers()[i]);
}

@ -3303,6 +3303,7 @@
'../components/components.gyp:enhanced_bookmarks',
'../components/components.gyp:history_core_android',
'../components/components.gyp:web_contents_delegate_android',
'../components/components_resources.gyp:components_resources',
'../third_party/android_opengl/etc1/etc1.gyp:etc1',
'chrome_browser_jni_headers',
],

@ -29,6 +29,11 @@ public class SelectPopupItem implements DropdownItem {
return null;
}
@Override
public int getIconId() {
return NO_ICON;
}
@Override
public boolean isEnabled() {
return mType == PopupItemType.ENABLED || mType == PopupItemType.GROUP;

@ -6,29 +6,43 @@
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dropdown_menu_text"
android:orientation="vertical"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView android:id="@+id/dropdown_label"
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/dropdown_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:ellipsize="end"
android:singleLine="true"
android:textAlignment="viewStart"
android:textSize="18sp"
android:includeFontPadding="false"/>
<TextView android:id="@+id/dropdown_sublabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:textSize="14sp"
android:textColor="#8b8b8b"
android:ellipsize="end"
android:singleLine="true"
android:textAlignment="viewStart"
android:includeFontPadding="false"/>
</LinearLayout>
<ImageView android:id="@+id/dropdown_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:ellipsize="end"
android:singleLine="true"
android:textAlignment="viewStart"
android:textSize="18sp"
android:includeFontPadding="false"/>
<TextView android:id="@+id/dropdown_sublabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:textSize="14sp"
android:textColor="#8b8b8b"
android:ellipsize="end"
android:singleLine="true"
android:textAlignment="viewStart"
android:includeFontPadding="false"/>
android:layout_margin="8dp"/>
</LinearLayout>

@ -13,6 +13,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
@ -62,18 +63,6 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
ApiCompatibilityUtils.setBackgroundForView(layout, new DropdownDividerDrawable());
}
DropdownItem item = getItem(position);
TextView labelView = (TextView) layout.findViewById(R.id.dropdown_label);
labelView.setText(item.getLabel());
labelView.setEnabled(item.isEnabled());
if (item.isGroupHeader()) {
labelView.setTypeface(null, Typeface.BOLD);
} else {
labelView.setTypeface(null, Typeface.NORMAL);
}
DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBackground();
int height = mContext.getResources().getDimensionPixelSize(R.dimen.dropdown_item_height);
if (position == 0) {
@ -93,6 +82,17 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
}
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height));
DropdownItem item = getItem(position);
TextView labelView = (TextView) layout.findViewById(R.id.dropdown_label);
labelView.setText(item.getLabel());
labelView.setEnabled(item.isEnabled());
if (item.isGroupHeader()) {
labelView.setTypeface(null, Typeface.BOLD);
} else {
labelView.setTypeface(null, Typeface.NORMAL);
}
TextView sublabelView = (TextView) layout.findViewById(R.id.dropdown_sublabel);
CharSequence sublabel = item.getSublabel();
if (TextUtils.isEmpty(sublabel)) {
@ -102,6 +102,14 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
sublabelView.setVisibility(View.VISIBLE);
}
ImageView iconView = (ImageView) layout.findViewById(R.id.dropdown_icon);
if (item.getIconId() == DropdownItem.NO_ICON) {
iconView.setVisibility(View.GONE);
} else {
iconView.setImageResource(item.getIconId());
iconView.setVisibility(View.VISIBLE);
}
return layout;
}

@ -8,6 +8,9 @@ package org.chromium.ui;
* Dropdown item interface used to access all the information needed to show the item.
*/
public interface DropdownItem {
// A stand in for a resource ID which indicates no icon should be shown.
public static final int NO_ICON = 0;
/**
* Returns the label that should be shown in the dropdown.
*/
@ -16,6 +19,10 @@ public interface DropdownItem {
* Returns the sublabel that should be shown in the dropdown.
*/
String getSublabel();
/**
* Returns the drawable id of the icon that should be shown in the dropdown, or NO_ICON.
*/
int getIconId();
/**
* Returns true if the item should be enabled in the dropdown.
*/

@ -12,6 +12,7 @@ import org.chromium.ui.DropdownItem;
public class AutofillSuggestion implements DropdownItem {
private final String mLabel;
private final String mSublabel;
private final int mIconId;
private final int mSuggestionId;
/**
@ -20,9 +21,10 @@ public class AutofillSuggestion implements DropdownItem {
* @param label The describing label of the Autofill suggestion.
* @param suggestionId The type of suggestion.
*/
public AutofillSuggestion(String name, String label, int suggestionId) {
public AutofillSuggestion(String name, String label, int iconId, int suggestionId) {
mLabel = name;
mSublabel = label;
mIconId = iconId;
mSuggestionId = suggestionId;
}
@ -36,6 +38,11 @@ public class AutofillSuggestion implements DropdownItem {
return mSublabel;
}
@Override
public int getIconId() {
return mIconId;
}
@Override
public boolean isEnabled() {
return true;