private void createSelectionLayer(Context context) { final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mSelectionDragLayer = (DragLayer) inflater.inflate(R.layout.selection_drag_layer, null); mDragController = new DragController(context); mDragController.setDragListener(this); mDragController.addDropTarget(mSelectionDragLayer); mSelectionDragLayer.setDragController(mDragController); mStartSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.startHandle); mStartSelectionHandle.setTag(HandleType.START); mEndSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.endHandle); mEndSelectionHandle.setTag(HandleType.END); final OnTouchListener handleTouchListener = new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { boolean handledHere = false; if (event.getAction() == MotionEvent.ACTION_DOWN) { handledHere = startDrag(v); mLastTouchedSelectionHandle = (HandleType) v.getTag(); } return handledHere; } }; mStartSelectionHandle.setOnTouchListener(handleTouchListener); mEndSelectionHandle.setOnTouchListener(handleTouchListener); }
public void stopDrag() { mDragController.cancelDrag(); }
private boolean startDrag(View v) { Object dragInfo = v; mDragController.startDrag(v, mSelectionDragLayer, dragInfo, DragBehavior.MOVE); return true; }