Backout of 6b0ef2ef3b95 in bug 898197.

This commit is contained in:
Sriram Ramasubramanian 2013-07-29 12:07:56 -07:00
parent 237f7e2fc4
commit e27d00ab92

View File

@ -33,7 +33,7 @@ import android.os.Bundle;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import android.support.v4.widget.SimpleCursorAdapter;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@ -110,6 +110,9 @@ public class BrowserSearch extends HomeFragment
// Callbacks used for the search suggestion loader
private SuggestionLoaderCallbacks mSuggestionLoaderCallbacks;
// Inflater used by the adapter
private LayoutInflater mInflater;
// Autocomplete handler used when filtering results
private AutocompleteHandler mAutocompleteHandler;
@ -168,12 +171,15 @@ public class BrowserSearch extends HomeFragment
throw new ClassCastException(activity.toString()
+ " must implement BrowserSearch.OnEditSuggestionListener");
}
mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public void onDetach() {
super.onDetach();
mInflater = null;
mAutocompleteHandler = null;
mUrlOpenListener = null;
mSearchListener = null;
@ -617,7 +623,7 @@ public class BrowserSearch extends HomeFragment
}
}
private class SearchAdapter extends CursorAdapter {
private class SearchAdapter extends SimpleCursorAdapter {
private static final int ROW_SEARCH = 0;
private static final int ROW_STANDARD = 1;
private static final int ROW_SUGGEST = 2;
@ -625,7 +631,7 @@ public class BrowserSearch extends HomeFragment
private static final int ROW_TYPE_COUNT = 3;
public SearchAdapter(Context context) {
super(context, null);
super(context, -1, null, new String[] {}, new int[] {});
}
@Override
@ -690,11 +696,9 @@ public class BrowserSearch extends HomeFragment
final int type = getItemViewType(position);
if (type == ROW_SEARCH || type == ROW_SUGGEST) {
// Cursor doesn't know about search suggestions.
// Hence overriding getView() to handle this special case.
final SearchEngineRow row;
if (convertView == null) {
row = (SearchEngineRow) LayoutInflater.from(parent.getContext()).inflate(R.layout.home_search_item_row, parent, false);
row = (SearchEngineRow) mInflater.inflate(R.layout.home_search_item_row, mList, false);
row.setOnUrlOpenListener(mUrlOpenListener);
row.setOnSearchListener(mSearchListener);
row.setOnEditSuggestionListener(mEditSuggestionListener);
@ -714,22 +718,27 @@ public class BrowserSearch extends HomeFragment
return row;
} else {
final TwoLinePageRow row;
if (convertView == null) {
row = (TwoLinePageRow) mInflater.inflate(R.layout.home_item_row, mList, false);
} else {
row = (TwoLinePageRow) convertView;
}
// Account for the search engines
position -= getSuggestEngineCount();
return super.getView(position, convertView, parent);
final Cursor c = getCursor();
if (!c.moveToPosition(position)) {
throw new IllegalStateException("Couldn't move cursor to position " + position);
}
row.updateFromCursor(c);
return row;
}
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
((TwoLinePageRow) view).updateFromCursor(cursor);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.home_item_row, parent, false);
}
private int getSuggestEngineCount() {
return (TextUtils.isEmpty(mSearchTerm) || mSuggestClient == null || !mSuggestionsEnabled) ? 0 : 1;
}
@ -868,4 +877,4 @@ public class BrowserSearch extends HomeFragment
}
}
}
}
}