}
}
- // Throws AssertionError if the input is false.
- public static void assertTrue(boolean cond, String message, Object ... args) {
- if (!cond) {
- throw new AssertionError(
- args.length == 0 ? message : String.format(message, args));
- }
+ // Throws AssertionError with the message. We had a method having the form
+ // assertTrue(boolean cond, String message, Object ... args);
+ // However a call to that method will cause memory allocation even if the
+ // condition is false (due to autoboxing generated by "Object ... args"),
+ // so we don't use that anymore.
+ public static void fail(String message, Object ... args) {
+ throw new AssertionError(
+ args.length == 0 ? message : String.format(message, args));
}
// Throws NullPointerException if the input is null.
private void initializeData(Bundle data) {
mMediaSetPath = Path.fromString(data.getString(KEY_MEDIA_PATH));
mMediaSet = mActivity.getDataManager().getMediaSet(mMediaSetPath);
- Utils.assertTrue(mMediaSet != null,
- "MediaSet is null. Path = %s", mMediaSetPath);
+ if (mMediaSet == null) {
+ Utils.fail("MediaSet is null. Path = %s", mMediaSetPath);
+ }
mSelectionManager.setSourceMediaSet(mMediaSet);
mAlbumDataAdapter = new AlbumDataAdapter(mActivity, mMediaSet);
mAlbumDataAdapter.setLoadingListener(new MyLoadingListener());
}
public AlbumSetItem get(int slotIndex) {
- Utils.assertTrue(isActiveSlot(slotIndex),
- "invalid slot: %s outsides (%s, %s)",
- slotIndex, mActiveStart, mActiveEnd);
+ if (!isActiveSlot(slotIndex)) {
+ Utils.fail("invalid slot: %s outsides (%s, %s)",
+ slotIndex, mActiveStart, mActiveEnd);
+ }
return mData[slotIndex % mData.length];
}
}
public void setActiveWindow(int start, int end) {
- Utils.assertTrue(
- start <= end && end - start <= mData.length && end <= mSize,
- "start = %s, end = %s, length = %s, size = %s",
- start, end, mData.length, mSize);
+ if (!(start <= end && end - start <= mData.length && end <= mSize)) {
+ Utils.fail("start = %s, end = %s, length = %s, size = %s",
+ start, end, mData.length, mSize);
+ }
AlbumSetItem data[] = mData;
}
public DisplayItem get(int slotIndex) {
- Utils.assertTrue(isActiveSlot(slotIndex),
- "invalid slot: %s outsides (%s, %s)",
- slotIndex, mActiveStart, mActiveEnd);
+ if (!isActiveSlot(slotIndex)) {
+ Utils.fail("invalid slot: %s outsides (%s, %s)",
+ slotIndex, mActiveStart, mActiveEnd);
+ }
return mData[slotIndex % mData.length];
}
}
public void setActiveWindow(int start, int end) {
- Utils.assertTrue(start <= end
- && end - start <= mData.length && end <= mSize,
- "%s, %s, %s, %s", start, end, mData.length, mSize);
+ if (!(start <= end && end - start <= mData.length && end <= mSize)) {
+ Utils.fail("%s, %s, %s, %s", start, end, mData.length, mSize);
+ }
DisplayItem data[] = mData;
mActiveStart = start;
default: {
Object valueObj = detail.getValue();
// This shouldn't happen, log its key to help us diagnose the problem.
- Utils.assertTrue(valueObj != null, "%s's value is Null",
- DetailsHelper.getDetailsName(context, detail.getKey()));
+ if (valueObj == null) {
+ Utils.fail("%s's value is Null",
+ DetailsHelper.getDetailsName(context, detail.getKey()));
+ }
value = valueObj.toString();
}
}
// Pushes the configuration state (matrix, alpha, and clip) onto
// a private stack.
- public int save();
+ public void save();
// Same as save(), but only save those specified in saveFlags.
- public int save(int saveFlags);
+ public void save(int saveFlags);
public static final int SAVE_FLAG_ALL = 0xFFFFFFFF;
public static final int SAVE_FLAG_CLIP = 0x01;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
-import java.util.Stack;
+import java.util.ArrayList;
import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;
import javax.microedition.khronos.opengles.GL11Ext;
private float mAlpha;
private final Rect mClipRect = new Rect();
- private final Stack<ConfigState> mRestoreStack =
- new Stack<ConfigState>();
+ private final ArrayList<ConfigState> mRestoreStack =
+ new ArrayList<ConfigState>();
private ConfigState mRecycledRestoreAction;
private final RectF mDrawTextureSourceRect = new RectF();
}
public void rotate(float angle, float x, float y, float z) {
+ if (angle == 0) return;
float[] temp = mTempMatrix;
Matrix.setRotateM(temp, 0, angle, x, y, z);
Matrix.multiplyMM(temp, 16, mMatrixValues, 0, temp, 0);
// draw the rect from bottom-left to top-right
float points[] = mapPoints(
mMatrixValues, x, y + height, x + width, y);
- x = Math.round(points[0]);
- y = Math.round(points[1]);
- width = Math.round(points[2]) - x;
- height = Math.round(points[3]) - y;
+ x = (int) (points[0] + 0.5f);
+ y = (int) (points[1] + 0.5f);
+ width = (int) (points[2] + 0.5f) - x;
+ height = (int) (points[3] + 0.5f) - y;
if (width > 0 && height > 0) {
((GL11Ext) mGL).glDrawTexiOES(x, y, 0, width, height);
mCountTextureOES++;
}
}
- public int save() {
- return save(SAVE_FLAG_ALL);
+ public void save() {
+ save(SAVE_FLAG_ALL);
}
- public int save(int saveFlags) {
+ public void save(int saveFlags) {
ConfigState config = obtainRestoreConfig();
if ((saveFlags & SAVE_FLAG_ALPHA) != 0) {
config.mMatrix[0] = Float.NEGATIVE_INFINITY;
}
- mRestoreStack.push(config);
- return mRestoreStack.size() - 1;
+ mRestoreStack.add(config);
}
public void restore() {
if (mRestoreStack.isEmpty()) throw new IllegalStateException();
- ConfigState config = mRestoreStack.pop();
+ ConfigState config = mRestoreStack.remove(mRestoreStack.size() - 1);
config.restore(this);
freeRestoreConfig(config);
}
public boolean clipRect(int left, int top, int right, int bottom) {
throw new UnsupportedOperationException();
}
- public int save() {
+ public void save() {
throw new UnsupportedOperationException();
}
- public int save(int saveFlags) {
+ public void save(int saveFlags) {
throw new UnsupportedOperationException();
}
public void setBlendEnabled(boolean enabled) {}