mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Issue 838: Fixed the bookmark picker crashing on Honeycomb.
git-svn-id: https://zxing.googlecode.com/svn/trunk@1785 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
d7e9842e47
commit
9f519ac146
|
@ -0,0 +1,62 @@
|
|||
// Copyright 2011 Google Inc. All Rights Reserved.
|
||||
|
||||
package com.google.zxing.client.android.share;
|
||||
|
||||
import com.google.zxing.client.android.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* A custom adapter designed to fetch bookmarks from a cursor. Before Honeycomb we used
|
||||
* SimpleCursorAdapter, but it assumes the existence of an _id column, and the bookmark schema was
|
||||
* rewritten for HC without one. This caused the app to crash, hence this new class, which is
|
||||
* forwards and backwards compatible.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class BookmarkAdapter extends BaseAdapter {
|
||||
private Context context;
|
||||
private Cursor cursor;
|
||||
|
||||
public BookmarkAdapter(Context context, Cursor cursor) {
|
||||
this.context = context;
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return cursor.getCount();
|
||||
}
|
||||
|
||||
public Object getItem(int index) {
|
||||
// Not used, so no point in retrieving it.
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getItemId(int index) {
|
||||
return index;
|
||||
}
|
||||
|
||||
public View getView(int index, View view, ViewGroup viewGroup) {
|
||||
LinearLayout layout;
|
||||
if (view == null || !(view instanceof LinearLayout)) {
|
||||
LayoutInflater factory = LayoutInflater.from(context);
|
||||
layout = (LinearLayout) factory.inflate(R.layout.bookmark_picker_list_item, viewGroup, false);
|
||||
} else {
|
||||
layout = (LinearLayout) view;
|
||||
}
|
||||
|
||||
cursor.moveToPosition(index);
|
||||
String title = cursor.getString(BookmarkPickerActivity.TITLE_COLUMN);
|
||||
((TextView) layout.findViewById(R.id.bookmark_title)).setText(title);
|
||||
String url = cursor.getString(BookmarkPickerActivity.URL_COLUMN);
|
||||
((TextView) layout.findViewById(R.id.bookmark_url)).setText(url);
|
||||
return layout;
|
||||
}
|
||||
}
|
|
@ -16,17 +16,13 @@
|
|||
|
||||
package com.google.zxing.client.android.share;
|
||||
|
||||
import com.google.zxing.client.android.R;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Browser;
|
||||
import android.view.View;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
|
||||
/**
|
||||
* This class is only needed because I can't successfully send an ACTION_PICK intent to
|
||||
|
@ -40,18 +36,13 @@ public final class BookmarkPickerActivity extends ListActivity {
|
|||
Browser.BookmarkColumns.URL
|
||||
};
|
||||
|
||||
private static final int[] TWO_LINE_VIEW_IDS = {
|
||||
R.id.bookmark_title,
|
||||
R.id.bookmark_url
|
||||
};
|
||||
|
||||
private static final int TITLE_COLUMN = 0;
|
||||
private static final int URL_COLUMN = 1;
|
||||
static final int TITLE_COLUMN = 0;
|
||||
static final int URL_COLUMN = 1;
|
||||
|
||||
// Without this selection, we'd get all the history entries too
|
||||
private static final String BOOKMARK_SELECTION = "bookmark = 1";
|
||||
|
||||
private Cursor cursor;
|
||||
private Cursor cursor = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
|
@ -60,10 +51,7 @@ public final class BookmarkPickerActivity extends ListActivity {
|
|||
cursor = getContentResolver().query(Browser.BOOKMARKS_URI, BOOKMARK_PROJECTION,
|
||||
BOOKMARK_SELECTION, null, null);
|
||||
startManagingCursor(cursor);
|
||||
|
||||
ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.bookmark_picker_list_item,
|
||||
cursor, BOOKMARK_PROJECTION, TWO_LINE_VIEW_IDS);
|
||||
setListAdapter(adapter);
|
||||
setListAdapter(new BookmarkAdapter(this, cursor));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue