From 906abfc507f1f4ba9bbb19adf864b032d56ea70b Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Thu, 27 Oct 2011 14:26:13 +0100 Subject: [PATCH] Bug 697120 - Show favicon on AwesomeBar's history tab (r=mfinkle) --- embedding/android/AwesomeBarTabs.java | 52 +++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/embedding/android/AwesomeBarTabs.java b/embedding/android/AwesomeBarTabs.java index 84be3f2dbf5..e70f51baf17 100644 --- a/embedding/android/AwesomeBarTabs.java +++ b/embedding/android/AwesomeBarTabs.java @@ -50,6 +50,7 @@ import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ExpandableListView; import android.widget.FilterQueryProvider; @@ -88,6 +89,41 @@ public class AwesomeBarTabs extends TabHost { public abstract void onUrlOpen(AwesomeBarTabs tabs, String url); } + private class HistoryListAdapter extends SimpleExpandableListAdapter { + public HistoryListAdapter(Context context, List> groupData, + int groupLayout, String[] groupFrom, int[] groupTo, + List>> childData, + int childLayout, String[] childFrom, int[] childTo) { + + super(context, groupData, groupLayout, groupFrom, groupTo, + childData, childLayout, childFrom, childTo); + } + + @Override + public View getChildView(int groupPosition, int childPosition, boolean isLastChild, + View convertView, ViewGroup parent) { + + View childView = + super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent); + + @SuppressWarnings("unchecked") + Map historyItem = + (Map) mHistoryAdapter.getChild(groupPosition, childPosition); + + byte[] b = (byte[]) historyItem.get(Browser.BookmarkColumns.FAVICON); + ImageView favicon = (ImageView) childView.findViewById(R.id.favicon); + + if (b == null) { + favicon.setImageResource(R.drawable.favicon); + } else { + Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length); + favicon.setImageBitmap(bitmap); + } + + return childView; + } + } + private class FaviconCursorViewBinder implements SimpleCursorAdapter.ViewBinder { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { @@ -169,16 +205,18 @@ public class AwesomeBarTabs extends TabHost { } public Map createHistoryItem(Cursor cursor) { - Map historyItem = new HashMap(); - - // FIXME: Load favicon as well + Map historyItem = new HashMap(); String url = cursor.getString(cursor.getColumnIndexOrThrow(AwesomeBar.URL_KEY)); String title = cursor.getString(cursor.getColumnIndexOrThrow(AwesomeBar.TITLE_KEY)); + byte[] favicon = cursor.getBlob(cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.FAVICON)); historyItem.put(AwesomeBar.URL_KEY, url); historyItem.put(AwesomeBar.TITLE_KEY, title); + if (favicon != null) + historyItem.put(Browser.BookmarkColumns.FAVICON, favicon); + return historyItem; } @@ -285,7 +323,7 @@ public class AwesomeBarTabs extends TabHost { // Close the query cursor as we won't use it anymore cursor.close(); - mHistoryAdapter = new SimpleExpandableListAdapter( + mHistoryAdapter = new HistoryListAdapter( mContext, groups, R.layout.awesomebar_header_row, @@ -430,10 +468,10 @@ public class AwesomeBarTabs extends TabHost { private void handleHistoryItemClick(int groupPosition, int childPosition) { @SuppressWarnings("unchecked") - Map historyItem = - (Map) mHistoryAdapter.getChild(groupPosition, childPosition); + Map historyItem = + (Map) mHistoryAdapter.getChild(groupPosition, childPosition); - String url = historyItem.get(AwesomeBar.URL_KEY); + String url = (String) historyItem.get(AwesomeBar.URL_KEY); if (mUrlOpenListener != null) mUrlOpenListener.onUrlOpen(this, url);