---
layout: presentation
title: Getting Started With Undo --Week 9, Thursday--
description: Introduction to the Undo assignment
class: middle, center, inverse
---
# CSE 340 Week 9 (Winter 2020)
## Undo Assignment
---
## Agenda
- Understanding Undo Assignment

- Practice Undo Exam Question

- Review Lecture Slides / General Questions
---
## The Undo feature

- Incredibly useful interaction technique

- Reverts the application to an older state

  - Mistakes can easily be undone

  - *"Ugh...that was definitely not right, but manually erasing all this work is going to take forever"*
---
## The Redo feature

- Inverse to the Undo feature
- "Undoes" an undo

  - Work previously undone is reapplied

  - *"Huh, maybe I made the right decision after all..."*
---
## Codebase: Application

- `ReversibleDrawingActivity`, class contains the entire interactor hierarchy

  - Floating Action Buttons (FAB), buttons that allow for actions supported by AbstractReversibleDrawingActivity

  - References DrawingView in AbstractDrawingActivity

- `AbstractReversibleDrawingActivity`, abstract class that extends AbstractDrawingActivity

  - adds support for undo/redo

  - includes buttons for undo/redo

  - `doAction()`, `undo()`, `redo()`
---
## Codebase: Application
- `AbstractDrawingActivity` - abstract class for app that supports drawing without history

  - Wrapper around a `DrawingView`

  - `doAction()`

  - contains methods for adding menus and changing visibility
---
## Codebase: DrawingView
- `AbstractDrawingActivity` is a wrapper around a `DrawingView`

  - Sets behavior for how strokes are drawn 

- DrawingView, a drawing canvas that handles strokes

  - Strokes are just `StrokeView`'s in the `DrawingView`

  - `onTouchEvent()` implements a PPS that describes lifetime of a stroke being created
---

## Codebase: Actions
- `AbstractAction` abstract class defines basic behavior any Action should have

- `AbstractReversibleAction` abstract class defines interface for actions that can be undone

- doAction() chain AbstractReversibleDrawingActivity.doAction()->AbstractDrawingActivity.doAction()->AbstractAction.doAction()

- `AbstractReversibleDrawingActivity`'s `undo()` and `redo()` call methods on ReversibleAction to undo/redo 

- Actions:
  - `ChangeColorAction`
  - `ChangeThicknessAction`, implement for homework
  - `StrokeAction`
  - (more!), create your own action!

---

## Codebase: History

- The `AbstractReversibleDrawingActivity` uses an StackHistory interface to manage the undo/redo history

  - You will implement the concrete StackHistory which implements AbstractHistory

  - Think: What data structures are used? Why does this make sense?

      -- What happens to the redo history if you take a new action after undoing a couple times?

      -- What happens to the undo history if you redo an action?

      -- What happens to the redo history if you undo an action?
---
End