blob: a5d51dda1584ca7c9a07d7fffb0f40526d618206 [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));
Jeff Hamilton84029622010-08-05 14:29:28 -050044 Bitmap thumbnail = null;
Michael Kolbfa314072010-09-17 11:33:58 -070045 if (cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0) {
46 // folder
47 thumb.setImageResource(R.drawable.ic_folder);
The Android Open Source Project0c908882009-03-03 19:32:16 -080048 } else {
Michael Kolbfa314072010-09-17 11:33:58 -070049 byte[] data = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_THUMBNAIL);
50 if (data != null) {
51 thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
52 }
53
54 if (thumbnail == null) {
55 thumb.setImageResource(R.drawable.browser_thumbnail);
56 } else {
57 thumb.setImageBitmap(thumbnail);
58 }
The Android Open Source Project0c908882009-03-03 19:32:16 -080059 }
60 }
61}