Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid implement undo stack in drawing app
    primarykey
    data
    text
    <p>I started working on the sample Finger Paint app in the Android SDK to get more familiar with graphics. Lately I've been trying to implement undo/redo, and I've ran into road blocks every way I've tried. I've found a few threads about this, but none have gotten me past these issues. Here are my main 2 trials:</p> <p>Strategy 1: </p> <p>Save a stack of the paths (or canvases) and on undo clear the screen and redraw each path except the last one (or reinstate the most recent canvas). </p> <p>The problem here is likely simple, but I just can't get the view to redraw anything. How do I draw saved paths (or restore a saved canvas)?</p> <p>Strategy 2:</p> <p>Save a stack of Bitmaps using getDrawingCache() after each touch. On undo, put the last bitmap back. </p> <p>The saving has to be ran via post() from a runnable so it executes after onDraw() finishes (post adds it to the system message line after invalidate()). The issue is that when ran from the runnable getDrawingCache() always returns the initial version of the painting, like it can't see any changes after the first. </p> <p>Why does getDrawingCache(), when called from a runnable, not see the current state of the view?</p> <p>I've been fighting with this a while. Thanks.</p> <pre><code>case MotionEvent.ACTION_UP: touch_up(); invalidate(); Runnable r = new Runnable(){ @Override public void run() { myView.storeView(); } }; myView.post(r); } public void storeView(){ historyCount++; if(historyCount &gt; historySize) historyCount = 6; //We don't want more than 6 history.add(Bitmap.createBitmap(myView.getDrawingCache()),historyCount); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload