blob: 6efb5541461be55299bb6431788384ff7e70be5e [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
Jeff Hamilton84029622010-08-05 14:29:28 -050019import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080020import android.database.Cursor;
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.graphics.Bitmap;
22import android.graphics.BitmapFactory;
The Android Open Source Project0c908882009-03-03 19:32:16 -080023import android.view.View;
Leon Scroggins892df312009-07-14 14:48:02 -040024import android.widget.ImageView;
Jeff Hamilton84029622010-08-05 14:29:28 -050025import android.widget.ResourceCursorAdapter;
Leon Scroggins892df312009-07-14 14:48:02 -040026import android.widget.TextView;
The Android Open Source Project0c908882009-03-03 19:32:16 -080027
Jeff Hamilton84029622010-08-05 14:29:28 -050028class BrowserBookmarksAdapter extends ResourceCursorAdapter {
The Android Open Source Project0c908882009-03-03 19:32:16 -080029 /**
30 * Create a new BrowserBookmarksAdapter.
The Android Open Source Project0c908882009-03-03 19:32:16 -080031 */
Jeff Hamilton84029622010-08-05 14:29:28 -050032 public BrowserBookmarksAdapter(Context context) {
33 // Make sure to tell the CursorAdapter to avoid the observer and auto-requery
34 // since the Loader will do that for us.
35 super(context, R.layout.bookmark_thumbnail, null);
The Android Open Source Project0c908882009-03-03 19:32:16 -080036 }
Jeff Hamilton84029622010-08-05 14:29:28 -050037
38 @Override
39 public void bindView(View view, Context context, Cursor cursor) {
Jeff Hamilton84029622010-08-05 14:29:28 -050040 ImageView thumb = (ImageView) view.findViewById(R.id.thumb);
41 TextView tv = (TextView) view.findViewById(R.id.label);
42
Jeff Hamilton84029622010-08-05 14:29:28 -050043 tv.setText(cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE));
44
45 Bitmap thumbnail = null;
46 byte[] data = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_THUMBNAIL);
The Android Open Source Project0c908882009-03-03 19:32:16 -080047 if (data != null) {
Jeff Hamilton84029622010-08-05 14:29:28 -050048 thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
The Android Open Source Project0c908882009-03-03 19:32:16 -080049 }
50
Jeff Hamilton84029622010-08-05 14:29:28 -050051 if (thumbnail == null) {
52 thumb.setImageResource(R.drawable.browser_thumbnail);
The Android Open Source Project0c908882009-03-03 19:32:16 -080053 } else {
Jeff Hamilton84029622010-08-05 14:29:28 -050054 thumb.setImageBitmap(thumbnail);
The Android Open Source Project0c908882009-03-03 19:32:16 -080055 }
56 }
57}