Remove memory allocation from onDraw in ColorChipView

Bug: 5933793 Agenda - Tablet: Scrolling Frame rate is way to low
Change-Id: Icd0e2526ceda22121fa31642c3e6177a468191c4
diff --git a/src/com/android/calendar/ColorChipView.java b/src/com/android/calendar/ColorChipView.java
index 776b928..daf0933 100644
--- a/src/com/android/calendar/ColorChipView.java
+++ b/src/com/android/calendar/ColorChipView.java
@@ -43,7 +43,9 @@
     public static final int DRAW_BORDER = 1;
     public static final int DRAW_FADED = 2;
 
-    int mDrawStyle = DRAW_FULL;
+    private int mDrawStyle = DRAW_FULL;
+    private float mDefStrokeWidth;
+    private Paint mPaint;
 
     private static final int DEF_BORDER_WIDTH = 4;
 
@@ -53,12 +55,21 @@
 
     public ColorChipView(Context context) {
         super(context);
+        init();
     }
 
     public ColorChipView(Context context, AttributeSet attrs) {
         super(context, attrs);
+        init();
     }
 
+    private void init() {
+        mPaint = new Paint();
+        mDefStrokeWidth = mPaint.getStrokeWidth();
+        mPaint.setStyle(Style.FILL_AND_STROKE);
+    }
+
+
     public void setDrawStyle(int style) {
         if (style != DRAW_FULL && style != DRAW_BORDER && style != DRAW_FADED) {
             return;
@@ -84,14 +95,14 @@
 
         int right = getWidth() - 1;
         int bottom = getHeight() - 1;
-        Paint p = new Paint();
-        p.setColor(mDrawStyle == DRAW_FADED ? Utils.getDeclinedColorFromColor(mColor) : mColor);
-        p.setStyle(Style.FILL_AND_STROKE);
+        mPaint.setColor(mDrawStyle == DRAW_FADED ?
+                Utils.getDeclinedColorFromColor(mColor) : mColor);
 
         switch (mDrawStyle) {
             case DRAW_FADED:
             case DRAW_FULL:
-                c.drawRect(0, 0, right, bottom, p);
+                mPaint.setStrokeWidth(mDefStrokeWidth);
+                c.drawRect(0, 0, right, bottom, mPaint);
                 break;
             case DRAW_BORDER:
                 if (mBorderWidth <= 0) {
@@ -100,7 +111,7 @@
                 int halfBorderWidth = mBorderWidth / 2;
                 int top = halfBorderWidth;
                 int left = halfBorderWidth;
-                p.setStrokeWidth(mBorderWidth);
+                mPaint.setStrokeWidth(mBorderWidth);
 
                 float[] lines = new float[16];
                 int ptr = 0;
@@ -120,7 +131,7 @@
                 lines [ptr++] = 0;
                 lines [ptr++] = right - halfBorderWidth;
                 lines [ptr++] = bottom;
-                c.drawLines(lines, p);
+                c.drawLines(lines, mPaint);
                 break;
         }
     }