android - can't move minute hand on ontouch method of surfaceview -


i have tried many ways this.....and i'm able move minute hand on ontouch of view problem can move when not touch it.

public boolean ontouchevent(motionevent e) {      float x = e.getx();     float y = e.gety();   switch (e.getaction()) {  case motionevent.action_move:      //find approximate angle between them.      log.i("test", "value x is"+x);      log.i("test", "value y is"+y);      /*float dx = x-cx;      float dy = y-cy;*/      getrotationangle(x,y);      float dx = x-cx;      float dy = y-cy;      double a=math.atan2(dy,dx);      log.i("test",":: "+math.todegrees(a));      this.degree = math.todegrees(a);      this.invalidate();  }  return true;  } protected void ondraw(canvas canvas) {   super .ondraw(canvas);  boolean changed = true;   int availablewidth = getright() - getleft();  int availableheight = getbottom() - gettop();   int x = availablewidth / 2;  int y = availableheight / 2;  cx = x;  cy = y;  final drawable dial = mdial;   int w = dial.getintrinsicwidth() + 100;  int h = dial.getintrinsicheight() + 100;   boolean scaled = false;   if (availablewidth < w || availableheight < h) {      scaled = true;       float scale = math.min((float) availablewidth / (float) w, (float) availableheight / (float) h);       canvas.save();      canvas.scale(scale, scale, x, y);  }   if (changed)  {      dial.setbounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2));  }   dial.draw(canvas);   canvas.save();  float hour = 4 / 12.0f * 360.0f;   canvas.rotate((float) degree, x, y);   final drawable hourhand = hourhand;   if (changed) {       w = hourhand.getintrinsicwidth() + 30;      h = hourhand.getintrinsicheight() + 30;       hourhand.setbounds(x - (w / 2), y - (h / 2), x + (w / 2), y  + (h / 2));  }   hourhand.draw(canvas);  canvas.restore();   canvas.save();  float minute = minutes / 60.0f * 360.0f;   /*if (bearing == 0)  {      canvas.rotate(minute, x, y);  }  else  {      canvas.rotate((float)bearing, x, y);  }*/   final drawable minutehand = minutehand;   if (changed) {       w = minutehand.getintrinsicwidth() + 30;      h = minutehand.getintrinsicheight() + 30;       minutehand.setbounds(x - w, y - h, x + w, y  + h);  }   minutehand.draw(canvas);  canvas.restore();   if (scaled) {      canvas.restore();  } 

}

while touching anywhere in view, clockhand starts rotating when should not. there?


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -