Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 public void run() {
   if (mSelectionBounds != null) {
     mWebView.addView(mSelectionDragLayer);
     drawSelectionHandles();
     final int contentHeight =
         (int) Math.ceil(getDensityDependentValue(mWebView.getContentHeight(), mActivity));
     final int contentWidth = mWebView.getWidth();
     ViewGroup.LayoutParams layerParams = mSelectionDragLayer.getLayoutParams();
     layerParams.height = contentHeight;
     layerParams.width = Math.max(contentWidth, mContentWidth);
     mSelectionDragLayer.setLayoutParams(layerParams);
     if (mSelectionListener != null) {
       mSelectionListener.startSelection();
     }
   }
 }