Code example for Canvas

Methods: getSaveCount, restoreToCount, save, translate

0
            mPosition = mSwitch ? available : 0;
        } 
        int offsetTop = getPaddingTop() + mPosition;
        int offsetLeft = (getWidth()
                - drawableWidth - getPaddingLeft() - getPaddingRight()) / 2;
        int saveCount = canvas.getSaveCount();
        canvas.save();
        canvas.translate(offsetLeft, offsetTop);
        drawable.draw(canvas);
        canvas.restoreToCount(saveCount);
    } 
 
    // Consume the touch events for the specified view. 
    public void addTouchView(View v) {
        v.setOnTouchListener(this);
    } 
 
    // This implements View.OnTouchListener so we intercept the touch events 
    // and pass them to ourselves. 
    public boolean onTouch(View v, MotionEvent event) {
        onTouchEvent(event);