Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.shell.omnibox; | 5 package org.chromium.chrome.shell.omnibox; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.view.LayoutInflater; | 8 import android.view.LayoutInflater; |
| 9 import android.view.View; | 9 import android.view.View; |
| 10 import android.view.ViewGroup; | 10 import android.view.ViewGroup; |
| 11 import android.widget.AbsListView.LayoutParams; | 11 import android.widget.AbsListView.LayoutParams; |
| 12 import android.widget.ArrayAdapter; | 12 import android.widget.ArrayAdapter; |
| 13 import android.widget.EditText; | |
| 14 import android.widget.ImageView; | |
| 13 import android.widget.TextView; | 15 import android.widget.TextView; |
| 14 | 16 |
| 15 import org.chromium.chrome.browser.omnibox.OmniboxSuggestion; | 17 import org.chromium.chrome.browser.omnibox.OmniboxSuggestion; |
| 16 import org.chromium.chrome.shell.R; | 18 import org.chromium.chrome.shell.R; |
| 17 | 19 |
| 18 import java.util.List; | 20 import java.util.List; |
| 19 | 21 |
| 20 /** | 22 /** |
| 21 * Adapter that provides suggestion views for the suggestion popup. | 23 * Adapter that provides suggestion views for the suggestion popup. |
| 22 */ | 24 */ |
| 23 class SuggestionArrayAdapter extends ArrayAdapter<OmniboxSuggestion> { | 25 class SuggestionArrayAdapter extends ArrayAdapter<OmniboxSuggestion> { |
| 24 private final List<OmniboxSuggestion> mSuggestions; | 26 private final List<OmniboxSuggestion> mSuggestions; |
| 27 private EditText mUrlTextView; | |
| 25 | 28 |
| 26 public SuggestionArrayAdapter(Context context, int res, List<OmniboxSuggesti on> suggestions) { | 29 public SuggestionArrayAdapter(Context context, int res, List<OmniboxSuggesti on> suggestions, |
| 30 EditText urlTextView) { | |
| 27 super(context, res, suggestions); | 31 super(context, res, suggestions); |
| 28 mSuggestions = suggestions; | 32 mSuggestions = suggestions; |
| 33 mUrlTextView = urlTextView; | |
| 29 } | 34 } |
| 30 | 35 |
| 31 @Override | 36 @Override |
| 32 public View getView(int position, View convertView, ViewGroup parent) { | 37 public View getView(int position, View convertView, ViewGroup parent) { |
| 33 View v = convertView; | 38 View v = convertView; |
| 34 if (v == null) { | 39 if (v == null) { |
| 35 LayoutInflater vi = (LayoutInflater) getContext().getSystemService( | 40 LayoutInflater vi = (LayoutInflater) getContext().getSystemService( |
| 36 Context.LAYOUT_INFLATER_SERVICE); | 41 Context.LAYOUT_INFLATER_SERVICE); |
| 37 v = vi.inflate(R.layout.dropdown_item, null); | 42 v = vi.inflate(R.layout.suggestion_item, null); |
| 38 int height = getContext().getResources().getDimensionPixelSize( | 43 int height = getContext().getResources().getDimensionPixelSize( |
| 39 R.dimen.dropdown_item_height); | 44 R.dimen.dropdown_item_height); |
| 40 v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height )); | 45 v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height )); |
| 41 } | 46 } |
| 42 TextView t1 = (TextView) v.findViewById(R.id.dropdown_label); | 47 TextView t1 = (TextView) v.findViewById(R.id.suggestion_item_label); |
| 43 t1.setText(mSuggestions.get(position).getDisplayText()); | 48 final String suggestionText = mSuggestions.get(position).getDisplayText( ); |
| 49 t1.setText(suggestionText); | |
|
Bernhard Bauer
2014/09/10 07:53:31
I think you could directly inline this.
ankit
2014/09/10 09:15:52
In onClickListener I am using the same variable su
Bernhard Bauer
2014/09/10 10:40:34
Oh, didn't see that. Okay, let's keep it as it is.
| |
| 44 | 50 |
| 45 TextView t2 = (TextView) v.findViewById(R.id.dropdown_sublabel); | 51 TextView t2 = (TextView) v.findViewById(R.id.suggestion_item_sublabel); |
| 46 t2.setText(mSuggestions.get(position).getUrl()); | 52 t2.setText(mSuggestions.get(position).getUrl()); |
| 53 | |
| 54 ImageView arrow = (ImageView) v.findViewById(R.id.suggestion_item_arrow) ; | |
| 55 arrow.setOnClickListener(new View.OnClickListener() { | |
| 56 @Override | |
| 57 public void onClick(View v) { | |
| 58 mUrlTextView.setText(suggestionText); | |
| 59 mUrlTextView.setSelection(suggestionText.length()); | |
| 60 } | |
| 61 }); | |
| 47 return v; | 62 return v; |
| 48 } | 63 } |
| 49 } | 64 } |
| OLD | NEW |