2 * Copyright (C) 2011 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package cz.cvut.fel.dce.barcodescanner.share;
19 import android.content.Context;
20 import android.database.Cursor;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.widget.BaseAdapter;
25 import android.widget.LinearLayout;
26 import android.widget.TextView;
28 import cz.cvut.fel.dce.barcodescanner.R;
31 * A custom adapter designed to fetch bookmarks from a cursor. Before Honeycomb we used
32 * SimpleCursorAdapter, but it assumes the existence of an _id column, and the bookmark schema was
33 * rewritten for HC without one. This caused the app to crash, hence this new class, which is
34 * forwards and backwards compatible.
36 * @author dswitkin@google.com (Daniel Switkin)
38 final class BookmarkAdapter extends BaseAdapter {
39 private final Context context;
40 private final Cursor cursor;
42 BookmarkAdapter(Context context, Cursor cursor) {
43 this.context = context;
48 public int getCount() {
49 return cursor.getCount();
53 public Object getItem(int index) {
54 // Not used, so no point in retrieving it.
59 public long getItemId(int index) {
64 public View getView(int index, View view, ViewGroup viewGroup) {
66 if (view instanceof LinearLayout) {
69 LayoutInflater factory = LayoutInflater.from(context);
70 layout = factory.inflate(R.layout.bookmark_picker_list_item, viewGroup, false);
73 if (!cursor.isClosed()) {
74 cursor.moveToPosition(index);
75 CharSequence title = cursor.getString(BookmarkPickerActivity.TITLE_COLUMN);
76 ((TextView) layout.findViewById(R.id.bookmark_title)).setText(title);
77 CharSequence url = cursor.getString(BookmarkPickerActivity.URL_COLUMN);
78 ((TextView) layout.findViewById(R.id.bookmark_url)).setText(url);
79 } // Otherwise... just don't update as the object is shutting down