Skip to content

Commit

Permalink
npe after sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
renard314 committed Mar 30, 2012
1 parent 74e01bb commit b4fdf77
Showing 1 changed file with 75 additions and 50 deletions.
125 changes: 75 additions & 50 deletions src/de/inovex/mtc/ListView3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Transformation;
import android.widget.ListView;

public class ListView3d extends ListView {
Expand All @@ -30,61 +31,85 @@ public class ListView3d extends ListView {
/** Paint object to draw with */
private Paint mPaint;

private final Transformation mTransformation;

public ListView3d(Context context, AttributeSet attrs) {
super(context, attrs);
if (!isInEditMode()) {
setStaticTransformationsEnabled(true);
mTransformation = new Transformation();
mTransformation.setTransformationType(Transformation.TYPE_MATRIX);
} else {
mTransformation = null;
}
}

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
// get top left coordinates
final int top = child.getTop();
final int left = child.getLeft();
Bitmap bitmap = child.getDrawingCache();
if (bitmap == null) {
child.setDrawingCacheEnabled(true);
child.buildDrawingCache();
bitmap = child.getDrawingCache();
}

final int centerY = child.getHeight() / 2;
final int centerX = child.getWidth() / 2;
final int radius = getHeight() / 2;
final int absParentCenterY = getTop() + getHeight() / 2;
final int absChildCenterY = child.getTop() + centerX;
final int distanceY = absParentCenterY - absChildCenterY;
final int absDistance = Math.min(radius, Math.abs(distanceY));

final float translateZ = (float) Math.sqrt((radius * radius) - (absDistance * absDistance));

double radians = Math.acos((float) absDistance / radius);
double degree = 90 - (180 / Math.PI) * radians;

mCamera.save();
mCamera.translate(0, 0, radius - translateZ);
mCamera.rotateX((float) degree); // remove this line..
if (distanceY < 0) {
degree = 360 - degree;
}
mCamera.rotateY((float) degree); // and change this to rotateX() to get a
// wheel like effect
mCamera.getMatrix(mMatrix);
mCamera.restore();

// create and initialize the paint object
if (mPaint == null) {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setFilterBitmap(true);
}
//highlight elements in the middle
mPaint.setColorFilter(calculateLight((float) degree));

mMatrix.preTranslate(-centerX, -centerY);
mMatrix.postTranslate(centerX, centerY);
mMatrix.postTranslate(left, top);
canvas.drawBitmap(bitmap, mMatrix, mPaint);
return false;
protected boolean getChildStaticTransformation(View child, Transformation t) {
mTransformation.getMatrix().reset();
final float scale = 1-((float)getHeight()/child.getTop());
final float px = child.getLeft() + (child.getWidth()) / 2;
final float py = child.getTop() + (child.getHeight()) / 2;
mTransformation.getMatrix().postScale(scale, scale, px, py);
t.compose(mTransformation);
return true;
}


//
// @Override
// protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
// // get top left coordinates
// final int top = child.getTop();
// final int left = child.getLeft();
// Bitmap bitmap = child.getDrawingCache();
// if (bitmap == null) {
// child.setDrawingCacheEnabled(true);
// child.buildDrawingCache();
// bitmap = child.getDrawingCache();
// }
//
// final int centerY = child.getHeight() / 2;
// final int centerX = child.getWidth() / 2;
// final int radius = getHeight() / 2;
// final int absParentCenterY = getTop() + getHeight() / 2;
// final int absChildCenterY = child.getTop() + centerX;
// final int distanceY = absParentCenterY - absChildCenterY;
// final int absDistance = Math.min(radius, Math.abs(distanceY));
//
// final float translateZ = (float) Math.sqrt((radius * radius) - (absDistance * absDistance));
//
// double radians = Math.acos((float) absDistance / radius);
// double degree = 90 - (180 / Math.PI) * radians;
//
// mCamera.save();
// mCamera.translate(0, 0, radius - translateZ);
// mCamera.rotateX((float) degree); // remove this line..
// if (distanceY < 0) {
// degree = 360 - degree;
// }
// mCamera.rotateY((float) degree); // and change this to rotateX() to get a
// // wheel like effect
// mCamera.getMatrix(mMatrix);
// mCamera.restore();
//
// // create and initialize the paint object
// if (mPaint == null) {
// mPaint = new Paint();
// mPaint.setAntiAlias(true);
// mPaint.setFilterBitmap(true);
// }
// //highlight elements in the middle
// mPaint.setColorFilter(calculateLight((float) degree));
//
// mMatrix.preTranslate(-centerX, -centerY);
// mMatrix.postTranslate(centerX, centerY);
// mMatrix.postTranslate(left, top);
// canvas.drawBitmap(bitmap, mMatrix, mPaint);
// return false;
// }
//


private LightingColorFilter calculateLight(final float rotation) {
final double cosRotation = Math.cos(Math.PI * rotation / 180);
Expand Down

0 comments on commit b4fdf77

Please sign in to comment.