The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.browser; |
| 18 | |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 19 | import android.content.Context; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 20 | import android.database.Cursor; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
| 22 | import android.graphics.BitmapFactory; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 23 | import android.view.View; |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 24 | import android.widget.ImageView; |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 25 | import android.widget.ResourceCursorAdapter; |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 26 | import android.widget.TextView; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 27 | |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 28 | class BrowserBookmarksAdapter extends ResourceCursorAdapter { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Create a new BrowserBookmarksAdapter. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 31 | */ |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 32 | 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 Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 36 | } |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 37 | |
| 38 | @Override |
| 39 | public void bindView(View view, Context context, Cursor cursor) { |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 40 | ImageView thumb = (ImageView) view.findViewById(R.id.thumb); |
| 41 | TextView tv = (TextView) view.findViewById(R.id.label); |
| 42 | |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 43 | tv.setText(cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE)); |
Jeff Hamilton | 8402962 | 2010-08-05 14:29:28 -0500 | [diff] [blame] | 44 | Bitmap thumbnail = null; |
Michael Kolb | fa31407 | 2010-09-17 11:33:58 -0700 | [diff] [blame^] | 45 | if (cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0) { |
| 46 | // folder |
| 47 | thumb.setImageResource(R.drawable.ic_folder); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 48 | } else { |
Michael Kolb | fa31407 | 2010-09-17 11:33:58 -0700 | [diff] [blame^] | 49 | 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 Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | } |