Skip to content

1.2 Using DrawView

Oscar Gilberto Medina Cruz edited this page May 6, 2017 · 2 revisions

Add to your layout

For using DrawView you need to add to your layout file

<com.byox.drawview.views.DrawView
        android:id="@+id/draw_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

Initialize instance

From your java code, get the view from your layout for using later.

public class MainActivity extends AppCompatActivity {

   private DrawView mDrawView;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      ...

      mDrawView = (DrawView) findViewById(R.id.draw_view);
      ...
   }
}

And you can set the OnDrawViewListener for controlling draw life cycle, in order:

  1. onStartDrawing when you tap down in screen.
  2. onEndDrawing when you tap up in screen.
  3. onClearDrawing when your screen has been cleared.
  4. onRequestText is executed when your DrawView has configured with text mode, and you tap up your screen for requesting for a text.
  5. onAllMovesPainted is triggered when all the user actions are completely drawn
mDrawView.setOnDrawViewListener(new DrawView.OnDrawViewListener() {
            @Override 
            public void onStartDrawing() { 
                 // Your stuff here 
            }
            @Override 
            public void onEndDrawing() { 
                // Your stuff here  
            }
            @Override 
            public void onClearDrawing() { 
                // Your stuff here  
            }
            @Override
            public void onRequestText() {
                // Your stuff here 
            }
            @Override
            public void onAllMovesPainted() {
                // Your stuff here
            }
}

Clone this wiki locally