summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Shuma <jshuma@google.com>2011-01-24 13:52:25 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-01-24 13:52:25 -0800
commitb713926766c4b342a881cb251964050a0d3d0a41 (patch)
tree74631840657e351410caa906084207eb2215f914
parent0de20d1ebd3dc8e766f7f4f4dbc3f77dd7326e30 (diff)
parentec18350090abbba03c3f0c9f0511cfde4afee66f (diff)
downloadandroid_frameworks_ex-b713926766c4b342a881cb251964050a0d3d0a41.tar.gz
android_frameworks_ex-b713926766c4b342a881cb251964050a0d3d0a41.tar.bz2
android_frameworks_ex-b713926766c4b342a881cb251964050a0d3d0a41.zip
Merge "Proper error checking for setting cards" into honeycomb
-rw-r--r--carousel/java/com/android/ex/carousel/CarouselRS.java38
1 files changed, 28 insertions, 10 deletions
diff --git a/carousel/java/com/android/ex/carousel/CarouselRS.java b/carousel/java/com/android/ex/carousel/CarouselRS.java
index 0d921a7..4467fb3 100644
--- a/carousel/java/com/android/ex/carousel/CarouselRS.java
+++ b/carousel/java/com/android/ex/carousel/CarouselRS.java
@@ -672,21 +672,39 @@ public class CarouselRS {
return allocation;
}
- private ScriptField_Card.Item getOrCreateCard(int n) {
+ private ScriptField_Card.Item getCard(int n) {
ScriptField_Card.Item item;
try {
item = mCards.get(n);
}
catch (ArrayIndexOutOfBoundsException e) {
+ if (DBG) Log.v(TAG, "getCard(): no item at index " + n);
item = null;
}
+ return item;
+ }
+
+ private ScriptField_Card.Item getOrCreateCard(int n) {
+ ScriptField_Card.Item item = getCard(n);
if (item == null) {
- if (DBG) Log.v(TAG, "getOrCreateItem(): no item at index " + n);
+ if (DBG) Log.v(TAG, "getOrCreateCard(): no item at index " + n + "; creating new");
item = new ScriptField_Card.Item();
}
return item;
}
+ private void setCard(int n, ScriptField_Card.Item item) {
+ try {
+ mCards.set(item, n, false); // This is primarily used for reference counting.
+ }
+ catch (ArrayIndexOutOfBoundsException e) {
+ // The specified index didn't exist. This can happen when a stale invalidate
+ // request outlived an array resize request. Something might be getting dropped,
+ // but there's not much we can do about this at this point to recover.
+ Log.w(TAG, "setCard(" + n + "): Texture " + n + " doesn't exist");
+ }
+ }
+
public void setTexture(int n, Bitmap bitmap)
{
if (n < 0) throw new IllegalArgumentException("Index cannot be negative");
@@ -701,7 +719,7 @@ public class CarouselRS {
item.texture = null;
}
}
- mCards.set(item, n, false); // This is primarily used for reference counting.
+ setCard(n, item);
mScript.invoke_setTexture(n, item.texture);
}
}
@@ -727,7 +745,7 @@ public class CarouselRS {
item.detailTexture = null;
}
}
- mCards.set(item, n, false); // This is primarily used for reference counting.
+ setCard(n, item);
mScript.invoke_setDetailTexture(n, offx, offy, loffx, loffy, item.detailTexture);
}
}
@@ -737,7 +755,7 @@ public class CarouselRS {
if (n < 0) throw new IllegalArgumentException("Index cannot be negative");
synchronized(this) {
- ScriptField_Card.Item item = mCards.get(n);
+ ScriptField_Card.Item item = getCard(n);
if (item == null) {
// This card was never created, so there's nothing to invalidate.
return;
@@ -749,7 +767,7 @@ public class CarouselRS {
item.texture.destroy();
item.texture = null;
}
- mCards.set(item, n, false); // This is primarily used for reference counting.
+ setCard(n, item);
mScript.invoke_invalidateTexture(n, eraseCurrent);
}
}
@@ -759,7 +777,7 @@ public class CarouselRS {
if (n < 0) throw new IllegalArgumentException("Index cannot be negative");
synchronized(this) {
- ScriptField_Card.Item item = mCards.get(n);
+ ScriptField_Card.Item item = getCard(n);
if (item == null) {
// This card was never created, so there's nothing to invalidate.
return;
@@ -771,7 +789,7 @@ public class CarouselRS {
item.detailTexture.destroy();
item.detailTexture = null;
}
- mCards.set(item, n, false); // This is primarily used for reference counting.
+ setCard(n, item);
mScript.invoke_invalidateDetailTexture(n, eraseCurrent);
}
}
@@ -792,7 +810,7 @@ public class CarouselRS {
item.geometry = null;
}
}
- mCards.set(item, n, false);
+ setCard(n, item);
mScript.invoke_setGeometry(n, item.geometry);
}
}
@@ -809,7 +827,7 @@ public class CarouselRS {
if (DBG) Log.v(TAG, "unloading matrix " + n);
item.matrix = null;
}
- mCards.set(item, n, false);
+ setCard(n, item);
mScript.invoke_setMatrix(n, item.matrix);
}
}