Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/autofill/AutofillKeyboardAccessory.java |
| diff --git a/ui/android/java/src/org/chromium/ui/autofill/AutofillKeyboardAccessory.java b/ui/android/java/src/org/chromium/ui/autofill/AutofillKeyboardAccessory.java |
| index 1c13938eba305a00eecbdfe18f691c03cd3f3bf8..8c26ff06f0aa4f22318ad2b5a7a0c9d6f986ced0 100644 |
| --- a/ui/android/java/src/org/chromium/ui/autofill/AutofillKeyboardAccessory.java |
| +++ b/ui/android/java/src/org/chromium/ui/autofill/AutofillKeyboardAccessory.java |
| @@ -5,26 +5,29 @@ |
| package org.chromium.ui.autofill; |
| import android.annotation.SuppressLint; |
| +import android.view.LayoutInflater; |
| import android.view.View; |
| import android.view.ViewGroup; |
| import android.view.accessibility.AccessibilityEvent; |
| -import android.widget.AdapterView; |
| -import android.widget.FrameLayout; |
| -import android.widget.ListAdapter; |
| -import android.widget.ListView; |
| +import android.widget.ImageView; |
| +import android.widget.LinearLayout; |
| +import android.widget.TextView; |
| import org.chromium.base.ApiCompatibilityUtils; |
| import org.chromium.ui.R; |
| import org.chromium.ui.base.WindowAndroid; |
| +import org.chromium.ui.gfx.DeviceDisplayInfo; |
| /** |
| * The Autofill suggestion view that lists relevant suggestions. It sits above the keyboard and |
| * below the content area. |
| */ |
| -public class AutofillKeyboardAccessory extends ListView implements AdapterView.OnItemClickListener, |
| - WindowAndroid.KeyboardVisibilityListener { |
| +public class AutofillKeyboardAccessory extends LinearLayout |
| + implements WindowAndroid.KeyboardVisibilityListener, View.OnClickListener { |
| private final WindowAndroid mWindowAndroid; |
| private final AutofillKeyboardAccessoryDelegate mAutofillCallback; |
| + private final int mMaximumNameWidthPx; |
| + private final int mMaximumLabelWidthPx; |
| /** |
| * An interface to handle the touch interaction with an AutofillKeyboardAccessory object. |
| @@ -56,12 +59,13 @@ public class AutofillKeyboardAccessory extends ListView implements AdapterView.O |
| mWindowAndroid = windowAndroid; |
| mAutofillCallback = autofillCallback; |
| + int deviceWidthPx = DeviceDisplayInfo.create(getContext()).getDisplayWidth(); |
| + mMaximumNameWidthPx = deviceWidthPx / 2; |
| + mMaximumLabelWidthPx = deviceWidthPx / 4; |
| + |
| mWindowAndroid.addKeyboardVisibilityListener(this); |
| - setOnItemClickListener(this); |
| - setContentDescription(getContext().getString( |
| - R.string.autofill_popup_content_description)); |
| - setBackgroundColor(getResources().getColor( |
| - R.color.keyboard_accessory_suggestion_background_color)); |
| + setContentDescription(getContext().getString(R.string.autofill_popup_content_description)); |
| + setHorizontalScrollBarEnabled(false); |
| } |
| /** |
| @@ -71,24 +75,39 @@ public class AutofillKeyboardAccessory extends ListView implements AdapterView.O |
| */ |
| @SuppressLint("InlinedApi") |
| public void showWithSuggestions(AutofillSuggestion[] suggestions, boolean isRtl) { |
| - setAdapter(new SuggestionAdapter(getContext(), suggestions)); |
| - ApiCompatibilityUtils.setLayoutDirection( |
| - this, isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR); |
| + removeAllViews(); |
| + for (int i = 0; i < suggestions.length; ++i) { |
|
aurimas (slooooooooow)
2015/07/28 00:10:28
How large do we anticipate suggestions array to be
please use gerrit instead
2015/07/28 21:07:46
Autofill.AddressSuggestionsCount histogram shows a
|
| + View touchTarget = LayoutInflater.from(getContext()).inflate( |
| + R.layout.autofill_keyboard_accessory_item, this, false); |
| + touchTarget.setOnClickListener(this); |
| + if (suggestions[i].getIconId() != 0) { |
| + ImageView icon = (ImageView) touchTarget.findViewById( |
| + R.id.autofill_keyboard_accessory_item_icon); |
| + icon.setImageResource(suggestions[i].getIconId()); |
| + icon.setVisibility(View.VISIBLE); |
| + } |
| + |
| + if (suggestions[i].getLabel() != null) { |
| + TextView name = (TextView) touchTarget.findViewById( |
| + R.id.autofill_keyboard_accessory_item_name); |
| + name.setText(suggestions[i].getLabel()); |
| + name.setVisibility(View.VISIBLE); |
| + name.setMaxWidth(mMaximumNameWidthPx); |
| - int height = ViewGroup.LayoutParams.WRAP_CONTENT; |
| - // Limit the visible number of suggestions (others are accessible via scrolling). |
| - final int suggestionLimit = 2; |
| - ListAdapter listAdapter = getAdapter(); |
| - if (listAdapter.getCount() > suggestionLimit) { |
| - height = 0; |
| - for (int i = 0; i < suggestionLimit; i++) { |
| - View listItem = listAdapter.getView(i, null, this); |
| - height += listItem.getLayoutParams().height; |
| + if (suggestions[i].getSublabel() != null) { |
| + TextView label = (TextView) touchTarget.findViewById( |
| + R.id.autofill_keyboard_accessory_item_label); |
| + label.setText(suggestions[i].getSublabel()); |
| + label.setVisibility(View.VISIBLE); |
| + label.setMaxWidth(mMaximumLabelWidthPx); |
| + } |
| } |
| + |
| + addView(touchTarget); |
| } |
| - setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, |
| - height)); |
| + ApiCompatibilityUtils.setLayoutDirection( |
| + this, isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR); |
| if (getParent() == null) { |
| ViewGroup container = mWindowAndroid.getKeyboardAccessoryView(); |
| @@ -110,15 +129,23 @@ public class AutofillKeyboardAccessory extends ListView implements AdapterView.O |
| } |
| @Override |
| - public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| - mAutofillCallback.suggestionSelected(position); |
| - } |
| - |
| - @Override |
| public void keyboardVisibilityChanged(boolean isShowing) { |
| if (!isShowing) { |
| dismiss(); |
| mAutofillCallback.dismissed(); |
| } |
| } |
| + |
| + @Override |
| + public void onClick(View v) { |
| + int count = getChildCount(); |
| + for (int i = 0; i < count; i++) { |
| + if (getChildAt(i) == v) { |
| + mAutofillCallback.suggestionSelected(i); |
| + return; |
| + } |
| + } |
| + |
| + assert false; |
| + } |
| } |