summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/util
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-04-23 14:50:09 -0700
committerJohn Reck <jreck@google.com>2012-04-23 17:57:54 -0700
commit3ad8d5cf0911ba015e019bc75e8fb13c091efe0e (patch)
treed5effce7657453109ca3ec4b9be83bc4bf4441e9 /src/com/android/browser/util
parentd6207eee8f87bbbfbc57bb4674b29e80c92e9d3b (diff)
downloadpackages_apps_Browser-3ad8d5cf0911ba015e019bc75e8fb13c091efe0e.tar.gz
packages_apps_Browser-3ad8d5cf0911ba015e019bc75e8fb13c091efe0e.tar.bz2
packages_apps_Browser-3ad8d5cf0911ba015e019bc75e8fb13c091efe0e.zip
Bookmark page changes
Bug: 6372933 Fix a race condition between update & destroy Fix update path Add some extra debug support Change-Id: I66a450e175b22d992de97d5bc24200961144412a
Diffstat (limited to 'src/com/android/browser/util')
-rw-r--r--src/com/android/browser/util/ThreadedCursorAdapter.java47
1 files changed, 37 insertions, 10 deletions
diff --git a/src/com/android/browser/util/ThreadedCursorAdapter.java b/src/com/android/browser/util/ThreadedCursorAdapter.java
index fe59ad1c9..d0bf71522 100644
--- a/src/com/android/browser/util/ThreadedCursorAdapter.java
+++ b/src/com/android/browser/util/ThreadedCursorAdapter.java
@@ -21,8 +21,8 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.Process;
+import android.os.SystemProperties;
import android.util.Log;
-import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
@@ -32,12 +32,12 @@ import android.widget.CursorAdapter;
import com.android.browser.R;
import java.lang.ref.WeakReference;
-import java.util.HashMap;
public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
- private static final String LOGTAG = "tca";
+ private static final String LOGTAG = "BookmarksThreadedAdapter";
private static final boolean DEBUG = false;
+ private static boolean sEnableBitmapRecycling = true;
private Context mContext;
private Object mCursorLock = new Object();
@@ -46,6 +46,15 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
private Handler mLoadHandler;
private Handler mHandler;
private int mSize;
+ private boolean mHasCursor;
+ private long mGeneration;
+
+ static {
+ // TODO: Remove this once recycling is either stabilized or scrapped
+ sEnableBitmapRecycling = SystemProperties
+ .getBoolean("com.android.browser.recycling", sEnableBitmapRecycling);
+ Log.d(LOGTAG, "Bitmap recycling enabled: " + sEnableBitmapRecycling);
+ }
private class LoadContainer {
WeakReference<View> view;
@@ -53,10 +62,12 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
T bind_object;
Adapter owner;
boolean loaded;
+ long generation;
}
public ThreadedCursorAdapter(Context context, Cursor c) {
mContext = context;
+ mHasCursor = (c != null);
mCursorAdapter = new CursorAdapter(context, c, 0) {
@Override
@@ -73,6 +84,7 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
mSize = getCount();
+ mGeneration++;
ThreadedCursorAdapter.this.notifyDataSetChanged();
}
@@ -80,6 +92,7 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
public void notifyDataSetInvalidated() {
super.notifyDataSetInvalidated();
mSize = getCount();
+ mGeneration++;
ThreadedCursorAdapter.this.notifyDataSetInvalidated();
}
@@ -109,7 +122,9 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
View view = container.view.get();
if (view == null
|| container.owner != ThreadedCursorAdapter.this
- || container.position != msg.what) {
+ || container.position != msg.what
+ || view.getWindowToken() == null
+ || container.generation != mGeneration) {
return;
}
container.loaded = true;
@@ -142,7 +157,12 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
}
synchronized (mCursorLock) {
Cursor c = (Cursor) mCursorAdapter.getItem(position);
- container.bind_object = getRowObject(c, container.bind_object);
+ if (c == null || c.isClosed()) {
+ return;
+ }
+ final T recycleObject = sEnableBitmapRecycling
+ ? container.bind_object : null;
+ container.bind_object = getRowObject(c, recycleObject);
}
mHandler.obtainMessage(position, container).sendToTarget();
}
@@ -161,14 +181,18 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
}
if (container.position == position
&& container.owner == this
- && container.loaded) {
+ && container.loaded
+ && container.generation == mGeneration) {
bindView(convertView, container.bind_object);
} else {
bindView(convertView, cachedLoadObject());
- container.position = position;
- container.loaded = false;
- container.owner = this;
- mLoadHandler.obtainMessage(position, container).sendToTarget();
+ if (mHasCursor) {
+ container.position = position;
+ container.loaded = false;
+ container.owner = this;
+ container.generation = mGeneration;
+ mLoadHandler.obtainMessage(position, container).sendToTarget();
+ }
}
return convertView;
}
@@ -181,7 +205,10 @@ public abstract class ThreadedCursorAdapter<T> extends BaseAdapter {
}
public void changeCursor(Cursor cursor) {
+ mLoadHandler.removeCallbacksAndMessages(null);
+ mHandler.removeCallbacksAndMessages(null);
synchronized (mCursorLock) {
+ mHasCursor = (cursor != null);
mCursorAdapter.changeCursor(cursor);
}
}