1cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// found in the LICENSE file. 4cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 5cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)package org.chromium.chrome.shell.omnibox; 6cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 7cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)import android.content.Context; 8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)import android.view.LayoutInflater; 9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)import android.view.View; 10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)import android.view.ViewGroup; 11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)import android.widget.AbsListView.LayoutParams; 12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)import android.widget.ArrayAdapter; 131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciimport android.widget.EditText; 141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciimport android.widget.ImageView; 15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)import android.widget.TextView; 16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)import org.chromium.chrome.browser.omnibox.OmniboxSuggestion; 18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)import org.chromium.chrome.shell.R; 19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)import java.util.List; 21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)/** 23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * Adapter that provides suggestion views for the suggestion popup. 24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) */ 25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class SuggestionArrayAdapter extends ArrayAdapter<OmniboxSuggestion> { 26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private final List<OmniboxSuggestion> mSuggestions; 271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci private EditText mUrlTextView; 28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public SuggestionArrayAdapter(Context context, int res, List<OmniboxSuggestion> suggestions, 301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci EditText urlTextView) { 31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) super(context, res, suggestions); 32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) mSuggestions = suggestions; 331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci mUrlTextView = urlTextView; 34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) @Override 37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public View getView(int position, View convertView, ViewGroup parent) { 38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) View v = convertView; 39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (v == null) { 40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) LayoutInflater vi = (LayoutInflater) getContext().getSystemService( 41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) Context.LAYOUT_INFLATER_SERVICE); 421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci v = vi.inflate(R.layout.suggestion_item, null); 43cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) int height = getContext().getResources().getDimensionPixelSize( 44cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) R.dimen.dropdown_item_height); 45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height)); 46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci TextView t1 = (TextView) v.findViewById(R.id.suggestion_item_label); 481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci final String suggestionText = mSuggestions.get(position).getDisplayText(); 491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci t1.setText(suggestionText); 50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci TextView t2 = (TextView) v.findViewById(R.id.suggestion_item_sublabel); 52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) t2.setText(mSuggestions.get(position).getUrl()); 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ImageView arrow = (ImageView) v.findViewById(R.id.suggestion_item_arrow); 551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci arrow.setOnClickListener(new View.OnClickListener() { 561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci @Override 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public void onClick(View v) { 581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci mUrlTextView.setText(suggestionText); 591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci mUrlTextView.setSelection(suggestionText.length()); 601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci }); 62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return v; 63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 64cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 65