blob: e29ca1868ae3087dcaf2dfa5e652cd745cf89d2e [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) {
40 View holder = view.findViewById(R.id.holder);
41 ImageView thumb = (ImageView) view.findViewById(R.id.thumb);
42 TextView tv = (TextView) view.findViewById(R.id.label);
43
44 holder.setVisibility(View.GONE);
45 tv.setText(cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE));
46
47 Bitmap thumbnail = null;
48 byte[] data = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_THUMBNAIL);
The Android Open Source Project0c908882009-03-03 19:32:16 -080049 if (data != null) {
Jeff Hamilton84029622010-08-05 14:29:28 -050050 thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
The Android Open Source Project0c908882009-03-03 19:32:16 -080051 }
52
Jeff Hamilton84029622010-08-05 14:29:28 -050053 if (thumbnail == null) {
54 thumb.setImageResource(R.drawable.browser_thumbnail);
The Android Open Source Project0c908882009-03-03 19:32:16 -080055 } else {
Jeff Hamilton84029622010-08-05 14:29:28 -050056 thumb.setImageBitmap(thumbnail);
The Android Open Source Project0c908882009-03-03 19:32:16 -080057 }
58 }
59}