Achieve similar hardware acceleration optimization in Android 2.3 - Avoid multiple onDraw call
<p>By referring to <a href="http://developer.android.com/training/custom-views/optimizing-view.html#accelerate" rel="nofollow">http://developer.android.com/training/custom-views/optimizing-view.html#accelerate</a>, I know that I can avoid multiple system call on busy <code>onDraw</code> by using <code>setLayerType(View.LAYER_TYPE_HARDWARE, null);</code>.</p>

<p>I tested on Android 4, by performing home -> restore -> home. I realize <code>onDraw</code> will only be called once as stated in the above android documentation.</p>

<p>However, how can I achieve the similar optimization in Android 2.3? As Android 2.3 doesn't support hardware optimization.</p>

<pre><code>public class PieChart extends View {

    @SuppressLint("NewApi")
    public PieChart(Context context) {
        super(context);

        mPiePaint = new Paint();
        mPiePaint.setAntiAlias(true);
        mPiePaint.setStyle(Paint.Style.FILL);
        mPiePaint.setColor(0x88FF0000);

        if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.HONEYCOMB) {
            if (!isInEditMode()) {
                setLayerType(View.LAYER_TYPE_HARDWARE, null);
            }
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Log.i("CHEOK", "Busy onDraw is called");

        canvas.drawArc(mBounds,
                0,
                200,
                true, mPiePaint);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        mBounds = new RectF(0, 0, w, h);
    }

    private RectF mBounds;    
    private Paint mPiePaint;
}
</code></pre>
