Bug 697120 - Show favicons on AwesomeBar's All Pages and Bookmarks tabs (r=mfinkle)

This commit is contained in:
Lucas Rocha 2011-10-27 14:26:13 +01:00
parent f070e7c85f
commit a11c44d83f
2 changed files with 50 additions and 7 deletions

View File

@ -41,6 +41,8 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.provider.Browser;
@ -51,12 +53,15 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.ExpandableListView;
import android.widget.FilterQueryProvider;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TabHost;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
@ -83,6 +88,31 @@ public class AwesomeBarTabs extends TabHost {
public abstract void onUrlOpen(AwesomeBarTabs tabs, String url);
}
private class FaviconCursorViewBinder implements SimpleCursorAdapter.ViewBinder {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
int faviconIndex =
cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.FAVICON);
// We only need to handle favicon column here. The other text
// columns are handled by the adapter automatically.
if (faviconIndex != columnIndex)
return false;
byte[] b = cursor.getBlob(faviconIndex);
ImageView favicon = (ImageView) view;
if (b == null) {
favicon.setImageResource(R.drawable.favicon);
} else {
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
favicon.setImageBitmap(bitmap);
}
return true;
}
}
private class BookmarksQueryTask extends AsyncTask<Void, Void, Cursor> {
protected Cursor doInBackground(Void... arg0) {
ContentResolver resolver = mContext.getContentResolver();
@ -100,10 +130,14 @@ public class AwesomeBarTabs extends TabHost {
mContext,
R.layout.awesomebar_row,
cursor,
new String[] { AwesomeBar.TITLE_KEY, AwesomeBar.URL_KEY },
new int[] { R.id.title, R.id.url }
new String[] { AwesomeBar.TITLE_KEY,
AwesomeBar.URL_KEY,
Browser.BookmarkColumns.FAVICON },
new int[] { R.id.title, R.id.url, R.id.favicon }
);
mBookmarksAdapter.setViewBinder(new FaviconCursorViewBinder());
final ListView bookmarksList = (ListView) findViewById(R.id.bookmarks_list);
bookmarksList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@ -340,10 +374,14 @@ public class AwesomeBarTabs extends TabHost {
mContext,
R.layout.awesomebar_row,
null,
new String[] { AwesomeBar.TITLE_KEY, AwesomeBar.URL_KEY },
new int[] { R.id.title, R.id.url }
new String[] { AwesomeBar.TITLE_KEY,
AwesomeBar.URL_KEY,
Browser.BookmarkColumns.FAVICON },
new int[] { R.id.title, R.id.url, R.id.favicon }
);
mAllPagesAdapter.setViewBinder(new FaviconCursorViewBinder());
mAllPagesAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
ContentResolver resolver = mContext.getContentResolver();

View File

@ -6,9 +6,14 @@
android:padding="6dip">
<ImageView android:id="@+id/favicon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="6dip"/>
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_marginRight="10dip"
android:layout_centerVertical="true"
android:minWidth="32dip"
android:minHeight="32dip"
android:src="@drawable/favicon"
android:scaleType="fitCenter"/>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"