Activity not launching on click
I want to add text in a bitmap through custom dialog. Bitmap is created
when i click on the screen but after the creation of first bitmap my app
crashes. Here is the code. Please help This is my main class
package com.example.svtutorial;
//imports
public class SurfaceViewEx extends Activity implements OnTouchListener {
DrawingView dv;
Bitmap bitmap;
Context context;
SurfaceHolder holder;
LinkedList<Node> nodes;
float x, y;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cloud);
dv = new DrawingView(this); //Passing the context of this class
dv.setOnTouchListener(this);
x = y = 0;
setContentView(dv);
nodes = new LinkedList<Node>();
//pointList = new ArrayList<MotionEvent.PointerCoords>();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
public class DrawingView extends SurfaceView {
public DrawingView(Context context) {
super(context);
holder = getHolder();
}
}
@Override
public boolean onTouch(View v, MotionEvent me) {
// TODO Auto-generated method stub
try {
Thread.sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
switch(me.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
x = me.getX();
y = me.getY();
Canvas c = holder.lockCanvas();
Node n = new Node(bitmap, c, x, y);
boolean collision = false;
if (!nodes.isEmpty()){
for (Node no : nodes) {
collision = no.isHere(x, y); //Checks the touch on
bitmap
if (collision){
break;
}
}
}
if(!collision){
nodes.add(n);
}
c.drawColor(Color.BLACK);
if (!nodes.isEmpty()){
for (Node no : nodes) {
no.Draw();
if(collision) { //I want to call dialog box here
Intent text = new
Intent(getBaseContext(),NodeMenu.class);
startActivity(text);
finish();
}
}
}
holder.unlockCanvasAndPost(c);
break;
}
return true;
}
}
The code given below is for the creation of dialog box and i want to it in
the class given above.
public class NodeMenu extends Activity{
Context context;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.nodemenu);
dialog.setTitle(R.id.textHeader);
final EditText et = (EditText) findViewById(R.id.editText1);
final TextView tv = (TextView) findViewById(R.id.textView);
Button addTextBtn = (Button) findViewById(R.id.addText);
addTextBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tv.setText(et.getText().toString());
}
});
dialog.show();
}
}
No comments:
Post a Comment