edisondeng / markers-for-android

Automatically exported from code.google.com/p/markers-for-android
Apache License 2.0
0 stars 0 forks source link

"undo" deletes entire sketch #8

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Markers version:1.04
Device: Nexus 7
Android OS version: Jbean

What steps will reproduce the problem?
1. Draw 3 lines
2. "Accidentally" hit back instead of undo 
3. Return to Markers
4. Hit the marker to access the menu
5. Hit undo

What is the expected output? What do you see instead?
Expected undo.  Entire sketch deleted instead.

Please provide any additional information below.

Original issue reported on code.google.com by Steven.L...@gmail.com on 24 Jul 2012 at 7:24

GoogleCodeExporter commented 8 years ago
"Accidentally" :)

Yeah, what's happening here is that when you exit the app via Back, it doesn't 
retain undo state. What undo does in this case is undo the re-loading of the 
last drawing canvas.

Original comment by dan.sandler on 24 Jul 2012 at 4:52

GoogleCodeExporter commented 8 years ago
  The following patch will make the undo button do nothing if there have been no strokes made since the Slate object was created.  A more elegant solution might disable the undo button completely. 

--- a/src/com/google/android/apps/markers/Slate.java
+++ b/src/com/google/android/apps/markers/Slate.java
@@ -611,9 +611,10 @@ public class Slate extends View {
     }

     public void undo() {
-        mCurrentCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
-        mCurrentCanvas.drawBitmap(mPreviousBitmap, 0, 0, null);
-
+       if (mUndoEnabled) {
+               mCurrentCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
+               mCurrentCanvas.drawBitmap(mPreviousBitmap, 0, 0, null);
+       }
         invalidate();
     }

@@ -762,6 +763,7 @@ public class Slate extends View {

     float dbgX = -1, dbgY = -1;
     RectF dbgRect = new RectF();
+       private boolean mUndoEnabled;

     final static boolean hasPointerCoords() {
        return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1);
@@ -799,6 +801,7 @@ public class Slate extends View {
         // starting a new touch? commit the previous state of the canvas
         if (action == MotionEvent.ACTION_DOWN) {
             commitStroke();
+            enableUndo();
         }

         if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN
@@ -880,7 +883,11 @@ public class Slate extends View {
         return true;
     }

-    public static float lerp(float a, float b, float f) {
+    private void enableUndo() {
+       mUndoEnabled = true;
+       }
+
+       public static float lerp(float a, float b, float f) {
         return a + f * (b - a);
     }

Original comment by Steven.L...@gmail.com on 24 Jul 2012 at 5:45