在使用 stopSelf(); 激活侦听器后,我需要停止此服务;但是,即使没有 Drag 事件,服务也会结束...如何在调用 StopService 之前检测是否发生了 Drag 事件?
mainButton.setOnTouchListener(new MyTouchListener());
vTopLeft.setOnDragListener(new MyDragListener());
vTopRight.setOnDragListener(new MyDragListener());
vBottomLeft.setOnDragListener(new MyDragListener());
vBottomRight.setOnDragListener(new MyDragListener());
Log.d("tok", "add mview");
stopSelf(); ---> this should wait after draglistener is finish.
MyDragListener.java
Public class MyDragListener implements View.OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
String containerName = null;
int ID = 0;
int Dragaction = event.getAction();
int gravity2 = 1234567879;
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
break;
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DROP:
View view = (View) event.getLocalState();
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
owner.setVisibility(View.GONE);
FrameLayout container = (FrameLayout) v;
container.addView(view);
LocationSerializable ls = new LocationSerializable();
switch (v.getId()) {
case R.id.topLeft:
gravity2 = Gravity.LEFT | Gravity.TOP;
ls.setGravity(gravity2);
break;
case R.id.topRight:
gravity2 = Gravity.RIGHT | Gravity.TOP;
ls.setGravity(gravity2);
break;
case R.id.bottomLeft:
gravity2= Gravity.BOTTOM | Gravity.LEFT;
ls.setGravity(gravity2);
break;
case R.id.bottomRight:
gravity2 = Gravity.RIGHT | Gravity.BOTTOM;
ls.setGravity(gravity2);
break;
default:
throw new RuntimeException("Unknown ID");
}
LinearLayout containerParent = (LinearLayout) v.getParent();
LinearLayout conatainerGrandMother = (LinearLayout) containerParent.getParent();
conatainerGrandMother.setVisibility(View.GONE);
case DragEvent.ACTION_DRAG_ENDED:
default:
break;
}
return false;
}
}