I try to apply the similar technique found in Swing over Android's
SurfaceView

http://download.oracle.com/javase/tutorial/uiswing/painting/step3.html

"An important point worth noting is that although we have invoked
repaint twice in a row in the same event handler, Swing is smart
enough to take that information and repaint those sections of the
screen all in one single paint operation. In other words, Swing will
not repaint the component twice in a row, even if that is what the
code appears to be doing. "

Here is the code. Swing only repaint area which involves object
movement, but NOT entire client screen area.


private void moveSquare(int x, int y) {
        int OFFSET = 1;
        if ((squareX!=x) || (squareY!=y)) {
            repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET);
            squareX=x;
            squareY=y;
            repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET);
        }
}

I try to mimic the technique, by having the following code.



private void moveSquare(int x, int y) {
        int OFFSET = 1;
        if ((squareX!=x) || (squareY!=y)) {

        try {
                c = mSurfaceHolder.lockCanvas(new Rect(squareX,squareY,squareX
+squareW+OFFSET,squareY+squareH+OFFSET));
                synchronized (mSurfaceHolder) {
                        doDraw(c);
                }
        } finally {
                if (c != null) {
                        mSurfaceHolder.unlockCanvasAndPost(c);
                }
        }

        squareX=x;
        squareY=y;

        try {
                c = mSurfaceHolder.lockCanvas(new Rect(squareX,squareY,squareX
+squareW+OFFSET,squareY+squareH+OFFSET));
                synchronized (mSurfaceHolder) {
                        doDraw(c);
                }
        } finally {
                if (c != null) {
                        mSurfaceHolder.unlockCanvasAndPost(c);
                }
        }
        }
}

But it doesn't work. Does anyone know what is the correct technique,
or, this technique cannot be applied on SurfaceView, but only
conventional View by using postInvalidate?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to