Program: 55551
Project: 55551
Buggy source:
@Override public boolean onTouch(View v,MotionEvent event){
  WindowManager.LayoutParams layoutParams=(WindowManager.LayoutParams)chatheadView.getLayoutParams();
  int x_cord=(int)event.getRawX();
  int y_cord=(int)event.getRawY();
  int x_cord_Destination, y_cord_Destination;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
    time_start=System.currentTimeMillis();
  handler_longClick.postDelayed(runnable_longClick,600);
remove_img_width=removeImg.getLayoutParams().width;
remove_img_height=removeImg.getLayoutParams().height;
x_init_cord=x_cord;
y_init_cord=y_cord;
x_init_margin=layoutParams.x;
y_init_margin=layoutParams.y;
if (txtView != null) {
txtView.setVisibility(View.GONE);
myHandler.removeCallbacks(myRunnable);
}
break;
case MotionEvent.ACTION_MOVE:
int x_diff_move=x_cord - x_init_cord;
int y_diff_move=y_cord - y_init_cord;
x_cord_Destination=x_init_margin + x_diff_move;
y_cord_Destination=y_init_margin + y_diff_move;
if (isLongclick) {
int x_bound_left=(szWindow.x - removeView.getWidth()) / 2 - 250;
int x_bound_right=(szWindow.x + removeView.getWidth()) / 2 + 100;
int y_bound_top=szWindow.y - (removeView.getHeight() + getStatusBarHeight()) - 200;
if ((x_cord_Destination >= x_bound_left && x_cord_Destination <= x_bound_right) && y_cord_Destination >= y_bound_top) {
inBounded=true;
layoutParams.x=(szWindow.x - chatheadView.getWidth()) / 2;
layoutParams.y=szWindow.y - (removeView.getHeight() + getStatusBarHeight()) + 70;
if (removeImg.getLayoutParams().height == remove_img_height) {
removeImg.getLayoutParams().height=(int)(remove_img_height * 1.5);
removeImg.getLayoutParams().width=(int)(remove_img_width * 1.5);
WindowManager.LayoutParams param_remove=(WindowManager.LayoutParams)removeView.getLayoutParams();
int x_cord_remove=(int)((szWindow.x - (remove_img_height * 1.5)) / 2);
int y_cord_remove=(int)(szWindow.y - ((remove_img_width * 1.5) + getStatusBarHeight()));
param_remove.x=x_cord_remove;
param_remove.y=y_cord_remove;
windowManager.updateViewLayout(removeView,param_remove);
}
windowManager.updateViewLayout(chatheadView,layoutParams);
break;
}
 else {
inBounded=false;
removeImg.getLayoutParams().height=remove_img_height;
removeImg.getLayoutParams().width=remove_img_width;
WindowManager.LayoutParams param_remove=(WindowManager.LayoutParams)removeView.getLayoutParams();
int x_cord_remove=(szWindow.x - removeView.getWidth()) / 2;
int y_cord_remove=szWindow.y - (removeView.getHeight() + getStatusBarHeight());
param_remove.x=x_cord_remove;
param_remove.y=y_cord_remove;
windowManager.updateViewLayout(removeView,param_remove);
}
}
layoutParams.x=x_cord_Destination;
layoutParams.y=y_cord_Destination;
windowManager.updateViewLayout(chatheadView,layoutParams);
break;
case MotionEvent.ACTION_UP:
isLongclick=false;
removeView.setVisibility(View.GONE);
removeImg.getLayoutParams().height=remove_img_height;
removeImg.getLayoutParams().width=remove_img_width;
handler_longClick.removeCallbacks(runnable_longClick);
if (inBounded) {
if (MyDialog.active) {
MyDialog.myDialog.finish();
}
stopService(new Intent(ChatHeadService.this,ChatHeadService.class));
inBounded=false;
break;
}
int x_diff=x_cord - x_init_cord;
int y_diff=y_cord - y_init_cord;
if (x_diff < 5 && y_diff < 5) {
time_end=System.currentTimeMillis();
if ((time_end - time_start) < 300) {
chathead_click();
}
}
x_cord_Destination=x_init_margin + x_diff;
y_cord_Destination=y_init_margin + y_diff;
int x_start;
x_start=x_cord_Destination;
int BarHeight=getStatusBarHeight();
if (y_cord_Destination < 0) {
y_cord_Destination=0;
}
 else if (y_cord_Destination + (chatheadView.getHeight() + BarHeight) > szWindow.y) {
y_cord_Destination=szWindow.y - (chatheadView.getHeight() + BarHeight);
}
layoutParams.y=y_cord_Destination;
inBounded=false;
resetPosition(x_start);
break;
default :
Log.d(Utils.LogTag,"String_Node_Str");
break;
}
return true;
}

Fixed version (ground truth):
@Override public boolean onTouch(View v,MotionEvent event){
  WindowManager.LayoutParams layoutParams=(WindowManager.LayoutParams)chatheadView.getLayoutParams();
  int x_cord=(int)event.getRawX();
  int y_cord=(int)event.getRawY();
  int x_cord_Destination, y_cord_Destination;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
    time_start=System.currentTimeMillis();
  handler_longClick.postDelayed(runnable_longClick,600);
remove_img_width=removeImg.getLayoutParams().width;
remove_img_height=removeImg.getLayoutParams().height;
x_init_cord=x_cord;
y_init_cord=y_cord;
x_init_margin=layoutParams.x;
y_init_margin=layoutParams.y;
if (txtView != null) {
txtView.setVisibility(View.GONE);
myHandler.removeCallbacks(myRunnable);
}
break;
case MotionEvent.ACTION_MOVE:
int x_diff_move=x_cord - x_init_cord;
int y_diff_move=y_cord - y_init_cord;
x_cord_Destination=x_init_margin + x_diff_move;
y_cord_Destination=y_init_margin + y_diff_move;
if (isLongclick) {
int x_bound_left=(szWindow.x - removeView.getWidth()) / 2 - 250;
int x_bound_right=(szWindow.x + removeView.getWidth()) / 2 + 100;
int y_bound_top=szWindow.y - (removeView.getHeight() + getStatusBarHeight()) - 200;
if ((x_cord_Destination >= x_bound_left && x_cord_Destination <= x_bound_right) && y_cord_Destination >= y_bound_top) {
inBounded=true;
layoutParams.x=(szWindow.x - chatheadView.getWidth()) / 2;
layoutParams.y=szWindow.y - (removeView.getHeight() + getStatusBarHeight()) + 70;
if (removeImg.getLayoutParams().height == remove_img_height) {
removeImg.getLayoutParams().height=(int)(remove_img_height * 1.5);
removeImg.getLayoutParams().width=(int)(remove_img_width * 1.5);
WindowManager.LayoutParams param_remove=(WindowManager.LayoutParams)removeView.getLayoutParams();
int x_cord_remove=(int)((szWindow.x - (remove_img_height * 1.5)) / 2);
int y_cord_remove=(int)(szWindow.y - ((remove_img_width * 1.5) + getStatusBarHeight()));
param_remove.x=x_cord_remove;
param_remove.y=y_cord_remove;
windowManager.updateViewLayout(removeView,param_remove);
}
windowManager.updateViewLayout(chatheadView,layoutParams);
break;
}
 else {
inBounded=false;
removeImg.getLayoutParams().height=remove_img_height;
removeImg.getLayoutParams().width=remove_img_width;
WindowManager.LayoutParams param_remove=(WindowManager.LayoutParams)removeView.getLayoutParams();
int x_cord_remove=(szWindow.x - removeView.getWidth()) / 2;
int y_cord_remove=szWindow.y - (removeView.getHeight() + getStatusBarHeight());
param_remove.x=x_cord_remove;
param_remove.y=y_cord_remove;
windowManager.updateViewLayout(removeView,param_remove);
}
}
layoutParams.x=x_cord_Destination;
layoutParams.y=y_cord_Destination;
windowManager.updateViewLayout(chatheadView,layoutParams);
break;
case MotionEvent.ACTION_UP:
isLongclick=false;
removeView.setVisibility(View.GONE);
removeImg.getLayoutParams().height=remove_img_height;
removeImg.getLayoutParams().width=remove_img_width;
handler_longClick.removeCallbacks(runnable_longClick);
if (inBounded) {
if (MyDialog.active) {
MyDialog.myDialog.finish();
}
stopService(new Intent(ChatHeadService.this,ChatHeadService.class));
inBounded=false;
break;
}
int x_diff=x_cord - x_init_cord;
int y_diff=y_cord - y_init_cord;
if (Math.abs(x_diff) < 5 && Math.abs(y_diff) < 5) {
time_end=System.currentTimeMillis();
if ((time_end - time_start) < 300) {
chathead_click();
}
}
x_cord_Destination=x_init_margin + x_diff;
y_cord_Destination=y_init_margin + y_diff;
int x_start;
x_start=x_cord_Destination;
int BarHeight=getStatusBarHeight();
if (y_cord_Destination < 0) {
y_cord_Destination=0;
}
 else if (y_cord_Destination + (chatheadView.getHeight() + BarHeight) > szWindow.y) {
y_cord_Destination=szWindow.y - (chatheadView.getHeight() + BarHeight);
}
layoutParams.y=y_cord_Destination;
inBounded=false;
resetPosition(x_start);
break;
default :
Log.d(Utils.LogTag,"String_Node_Str");
break;
}
return true;
}