Android Open Source - bdb-simple Main Activity






From Project

Back to project page bdb-simple.

License

The source code is released under:

MIT License

If you think the Android project bdb-simple listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.liaufscar.simplebdb;
//  w  w w  .  jav  a  2  s .  c  om
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

/**
*** This code is based on the Mobiletuts+ tutorial
*** Android SDK: Create a Drawing App, by Sue Smith
**/

public class MainActivity extends Activity implements OnClickListener {

  // Custom Drawing View
  private DrawingView drawView;
  
  // Buttons
  private ImageButton drawBtn, eraseBtn, clearBtn;
  
  // Local variables
  private int brushSize = 6;
  private int eraserSize = 70;

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

    //
    // Drawing view initialization
    //
    
    // Get drawing view
    drawView = (DrawingView) findViewById(R.id.drawing);

    // Set initial size
    drawView.setBrushSize(brushSize);
    
    //
    // Button Listeners
    //
    
    // Draw button
    drawBtn = (ImageButton) findViewById(R.id.draw_btn);
    drawBtn.setOnClickListener(this);

    // Erase button
    eraseBtn = (ImageButton) findViewById(R.id.erase_btn);
    eraseBtn.setOnClickListener(this);
    
    // Clear button
    clearBtn = (ImageButton) findViewById(R.id.clear_btn);
    clearBtn.setOnClickListener(this);
    
    // Set drawBtn as active because it is the starting tool
    drawBtn.setBackgroundResource(R.drawable.button_active);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }

  @Override
  public void onClick(View view) {

    if (view.getId() == R.id.draw_btn) {
      drawView.setErase(false);
      drawView.setBrushSize(brushSize);
      drawBtn.setBackgroundResource(R.drawable.button_active);
      eraseBtn.setBackgroundResource(R.drawable.button);
    }
    else if (view.getId() == R.id.erase_btn) {
      drawView.setErase(true);
      drawView.setBrushSize(eraserSize);
      eraseBtn.setBackgroundResource(R.drawable.button_active);
      drawBtn.setBackgroundResource(R.drawable.button);
    }
    else if (view.getId() == R.id.clear_btn)
      drawView.startNew();
  }

}




Java Source Code List

com.liaufscar.simplebdb.DrawingView.java
com.liaufscar.simplebdb.MainActivity.java