Skip to content
Browse files

Small optimization

GraphDrawer object is not created/destroyed on each graph redraw
  • Loading branch information...
1 parent dc6e592 commit 27246e983dc6e21fd671341ef73ec83134be9424 @alekz committed Oct 18, 2011
Showing with 13 additions and 11 deletions.
  1. +13 −11 src/com/k10v/goaltracker/Panel.java
View
24 src/com/k10v/goaltracker/Panel.java
@@ -35,6 +35,8 @@
private float mPointer2X = 0;
private float mPointer2Y = 0;
+ private GraphDrawer mGraph;
+
/**
* When true, indicates that graph should be updated
*/
@@ -43,8 +45,9 @@
public Panel(Context context, AttributeSet attrs) {
super(context, attrs);
getHolder().addCallback(this);
-
setFocusable(true);
+
+ mGraph = new GraphDrawer(getContext());
}
@Override
@@ -115,16 +118,15 @@ public void onDraw(Canvas canvas) {
minValue = mTargetValue;
}
- GraphDrawer graph = new GraphDrawer(getContext());
- graph.setCanvas(canvas);
- graph.setCanvasRectangle(0, 0, canvas.getWidth() - 1, canvas.getHeight() - 1);
- graph.setValues(mValues);
- graph.setStartValue(mStartValue);
- graph.setLastValue(mLastValue);
- graph.setValueRange(minValue, maxValue);
- graph.setDateRange(mMinDate, maxDate);
- graph.setPointer(mIsTouched, mPointer1X, mPointer1Y, mPointer2X, mPointer2Y);
- graph.draw();
+ mGraph.setCanvas(canvas);
+ mGraph.setCanvasRectangle(0, 0, canvas.getWidth() - 1, canvas.getHeight() - 1);
+ mGraph.setValues(mValues);
+ mGraph.setStartValue(mStartValue);
+ mGraph.setLastValue(mLastValue);
+ mGraph.setValueRange(minValue, maxValue);
+ mGraph.setDateRange(mMinDate, maxDate);
+ mGraph.setPointer(mIsTouched, mPointer1X, mPointer1Y, mPointer2X, mPointer2Y);
+ mGraph.draw();
}
/**

0 comments on commit 27246e9

Please sign in to comment.
Something went wrong with that request. Please try again.