DrawingView

com.j0h1.contour

## Class DrawingView

- java.lang.Object
- - ImageView
  - - com.j0h1.contour.DrawingView

-     public class DrawingView
      extends ImageView

  Custom View that holds a Canvas the user can drawn on. In the GameActivity the DrawingView's background is used for the edge image, the user has to retrace. The Bitmap of the DrawingView is the user drawing that is rendered by the Canvas.
  Author:
    Johannes Riedmann

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private Bitmap` | `bitmap`
    `private Canvas` | `canvas`
    `(package private) Context` | `context`
    `private CustomPath` | `currentPath`
    `static boolean` | `IS_PORTRAIT_MODE`
    `private boolean` | `isLocked`
    `private float` | `mX`
    `private float` | `mY`
    `private Paint` | `paint`
    `private java.util.ArrayList<CustomPath>` | `paths`
    `private int` | `recentScreenOrientation`
    `private boolean` | `sizeChanged`
    `private float` | `strokeWidth`
    `private static float` | `TOUCH_TOLERANCE`
    `private java.util.ArrayList<CustomPath>` | `undonePaths`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DrawingView(Context c)`
    `DrawingView(Context c, AttributeSet as)`
    `DrawingView(Context c, AttributeSet as, int defStyle)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private void` | `definePaintAndBg()`
    `private CustomMatrix` | `defineTransformationMatrix(float[] pathBounds, float scaleFactor)` Defines a transformation matrix for the given parameters.
    `void` | `drawPreviousPaths(java.util.ArrayList<CustomPath> previousPaths)` Draws paths from a previously paused session to the DrawingView.
    `Bitmap` | `getBitmap()`
    `boolean` | `getLocked()`
    `java.util.ArrayList<CustomPath>` | `getPaths()`
    `int` | `getRecentScreenOrientation()`
    `float` | `getStrokeWidth()`
    `boolean` | `isSizeChanged()`
    `boolean` | `onClickRedo()` Add the most recently deleted path from the deleted list to the paths list and make it available again for the onDraw method.
    `void` | `onClickReset()` Delete all removed and added paths and clear the canvas and bitmap, held by the DrawingView.
    `boolean` | `onClickUndo()` When the undo button is clicked, remove the last path that was added and add it to the deleted paths list.
    `protected void` | `onDraw(Canvas canvas)` Draw paths to the canvas.
    `protected void` | `onSizeChanged(int w, int h, int oldw, int oldh)` This method is called as soon as DrawingView changes it's size, which is at the start up and when the player changes the display orientation.
    `boolean` | `onTouchEvent(MotionEvent event)` Define which action to take when the user interacts with the DrawingView.
    `void` | `repaint()` Resets the canvas and bitmap held by the DrawingView and draws the paths manually.
    `private void` | `resetBitmapAndCanvas()` Resets the current Bitmap and Canvas object held by the DrawingView.
    `void` | `setBitmap(Bitmap bitmap)`
    `void` | `setHeight(int height)`
    `void` | `setLocked(boolean locked)`
    `void` | `setPaths(java.util.ArrayList<CustomPath> paths)`
    `void` | `setRecentScreenOrientation(int recentScreenOrientation)`
    `void` | `setSizeChanged(boolean sizeChanged)`
    `void` | `setStrokeWidth(float strokeWidth)`
    `void` | `setWidth(int width)`
    `private void` | `touch_move(float x, float y)` When the user moves his finger around the DrawingView, the path is drawn via the quadTo method.
    `private void` | `touch_start(float x, float y)` When the user starts a touch interaction with the DrawingView, initialize a path and add it to the path list
    `private void` | `touch_up()` When the user stops interacting with the DrawingView, the last line is drawn and the path is committed to the offscreen.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### bitmap

          private Bitmap bitmap

    - #### canvas

          private Canvas canvas

    - #### currentPath

          private CustomPath currentPath

    - #### paint

          private Paint paint

    - #### context

          Context context

    - #### sizeChanged

          private boolean sizeChanged

    - #### isLocked

          private boolean isLocked

    - #### recentScreenOrientation

          private int recentScreenOrientation

    - #### IS_PORTRAIT_MODE

          public static boolean IS_PORTRAIT_MODE

    - #### paths

          private java.util.ArrayList<CustomPath> paths

    - #### undonePaths

          private java.util.ArrayList<CustomPath> undonePaths

    - #### strokeWidth

          private float strokeWidth

    - #### mX

          private float mX

    - #### mY

          private float mY

    - #### TOUCH_TOLERANCE

          private static final float TOUCH_TOLERANCE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DrawingView

          public DrawingView(Context c)

    - #### DrawingView

          public DrawingView(Context c,
                             AttributeSet as)

    - #### DrawingView

          public DrawingView(Context c,
                             AttributeSet as,
                             int defStyle)

  - ### Method Detail

    - #### definePaintAndBg

          private void definePaintAndBg()

    - #### setHeight

          public void setHeight(int height)

    - #### setWidth

          public void setWidth(int width)

    - #### onSizeChanged

          protected void onSizeChanged(int w,
                                       int h,
                                       int oldw,
                                       int oldh)

      This method is called as soon as DrawingView changes it's size, which is at the start up and when the player changes the display orientation. When the display orientation changes, the paths have to be transformed according to the new dimensions of the DrawingView.

    - #### defineTransformationMatrix

          private CustomMatrix defineTransformationMatrix(float[] pathBounds,
                                                          float scaleFactor)

      Defines a transformation matrix for the given parameters.
      Parameters:
        `pathBounds` - Rectangular border of path object.
        `scaleFactor` - Factor the path object is scaled.
      Returns:

    - #### onDraw

          protected void onDraw(Canvas canvas)

      Draw paths to the canvas.

    - #### touch_start

          private void touch_start(float x,
                                   float y)

      When the user starts a touch interaction with the DrawingView, initialize a path and add it to the path list
      Parameters:
        `x` - X-coordinate of the users finger on the screen.
        `y` - Y-coordinate of the users finger on the screen.

    - #### touch_move

          private void touch_move(float x,
                                  float y)

      When the user moves his finger around the DrawingView, the path is drawn via the quadTo method.
      Parameters:
        `x` -
        `y` - Y-coordinate of the users finger on the screen.

    - #### touch_up

          private void touch_up()

      When the user stops interacting with the DrawingView, the last line is drawn and the path is committed to the offscreen.

    - #### onClickUndo

          public boolean onClickUndo()

      When the undo button is clicked, remove the last path that was added and add it to the deleted paths list.
      Returns:
        True, if a path was removed, false otherwise.

    - #### onClickRedo

          public boolean onClickRedo()

      Add the most recently deleted path from the deleted list to the paths list and make it available again for the onDraw method.
      Returns:
        True, if a path was added, false otherwise.

    - #### onClickReset

          public void onClickReset()

      Delete all removed and added paths and clear the canvas and bitmap, held by the DrawingView.

    - #### onTouchEvent

          public boolean onTouchEvent(MotionEvent event)

      Define which action to take when the user interacts with the DrawingView.

    - #### repaint

          public void repaint()

      Resets the canvas and bitmap held by the DrawingView and draws the paths manually.

    - #### drawPreviousPaths

          public void drawPreviousPaths(java.util.ArrayList<CustomPath> previousPaths)

      Draws paths from a previously paused session to the DrawingView.
      Parameters:
        `previousPaths` - List of paths from a previously paused session.

    - #### resetBitmapAndCanvas

          private void resetBitmapAndCanvas()

      Resets the current Bitmap and Canvas object held by the DrawingView.

    - #### getPaths

          public java.util.ArrayList<CustomPath> getPaths()

    - #### setPaths

          public void setPaths(java.util.ArrayList<CustomPath> paths)

    - #### getLocked

          public boolean getLocked()

    - #### setLocked

          public void setLocked(boolean locked)

    - #### getBitmap

          public Bitmap getBitmap()

    - #### setBitmap

          public void setBitmap(Bitmap bitmap)

    - #### getStrokeWidth

          public float getStrokeWidth()

    - #### setStrokeWidth

          public void setStrokeWidth(float strokeWidth)

    - #### getRecentScreenOrientation

          public int getRecentScreenOrientation()

    - #### setRecentScreenOrientation

          public void setRecentScreenOrientation(int recentScreenOrientation)

    - #### isSizeChanged

          public boolean isSizeChanged()

    - #### setSizeChanged

          public void setSizeChanged(boolean sizeChanged)