android.view.DragEvent Java Examples

The following examples show how to use android.view.DragEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DragState.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void sendDragStartedLocked(WindowState newWin, float touchX, float touchY,
        ClipDescription desc) {
    if (mDragInProgress && isValidDropTarget(newWin)) {
        DragEvent event = obtainDragEvent(newWin, DragEvent.ACTION_DRAG_STARTED,
                touchX, touchY, null, desc, null, null, false);
        try {
            newWin.mClient.dispatchDragEvent(event);
            // track each window that we've notified that the drag is starting
            mNotifiedWindows.add(newWin);
        } catch (RemoteException e) {
            Slog.w(TAG_WM, "Unable to drag-start window " + newWin);
        } finally {
            // if the callee was local, the dispatch has already recycled the event
            if (Process.myPid() != newWin.mSession.mPid) {
                event.recycle();
            }
        }
    }
}
 
Example #2
Source File: QuickRow.java    From LaunchTime with GNU General Public License v3.0 6 votes vote down vote up
public QuickRow(final View.OnDragListener dragListener, MainActivity mainActivity) {

        mMainActivity = mainActivity;
        mStyle = GlobState.getStyle(mMainActivity);

        mQuickRow = mMainActivity.findViewById(R.id.layout_quickrow);

        mQuickRowScroller = mMainActivity.findViewById(R.id.layout_quickrow_scroll);

        mQuickRow.setOnDragListener(dragListener);
        mQuickRowScroller.setOnDragListener(new View.OnDragListener() {
            @Override
            public boolean onDrag(View view, DragEvent dragEvent) {
                return dragListener.onDrag(mQuickRow, dragEvent);
            }
        });
    }
 
Example #3
Source File: DragListenerGridView.java    From PlusDemo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onDrag(View v, DragEvent event) {
    switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
            if (event.getLocalState() == v) {
                v.setVisibility(INVISIBLE);
            }
            break;
        case DragEvent.ACTION_DRAG_ENTERED:
            System.out.println("draggg");
            if (event.getLocalState() != v) {
                sort(v);
            }
            break;
        case DragEvent.ACTION_DRAG_EXITED:
            break;
        case DragEvent.ACTION_DRAG_ENDED:
            v.setVisibility(VISIBLE);
            break;
    }
    return true;
}
 
Example #4
Source File: RecipientEditTextView.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * Handles drag event.
 */
@Override
public boolean onDragEvent(DragEvent event) {
    switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
            // Only handle plain text drag and drop.
            return event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
        case DragEvent.ACTION_DRAG_ENTERED:
            requestFocus();
            return true;
        case DragEvent.ACTION_DROP:
            handlePasteClip(event.getClipData());
            return true;
    }
    return false;
}
 
Example #5
Source File: TextChipsEditView.java    From talk-android with MIT License 6 votes vote down vote up
/**
 * Handles drag event.
 */
@Override
public boolean onDragEvent(DragEvent event) {
    switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
            // Only handle plain text drag and drop.
            return event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
        case DragEvent.ACTION_DRAG_ENTERED:
            requestFocus();
            return true;
        case DragEvent.ACTION_DROP:
            handlePasteClip(event.getClipData());
            return true;
    }
    return false;
}
 
Example #6
Source File: PasswordButton.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
@Override
public boolean onDragEvent(DragEvent event) {
    PasswordStateObject state = (PasswordStateObject) event.getLocalState();
    if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
        if (!state.toString().contains((String) getTag())) {
            state.append((String) getTag());
            ((PasswordListener) getParent()).onPasswordButtonTouched(this);
            setBackgroundResource(R.drawable.loginbuttonpressed);
        }
    }
    if (event.getAction() == DragEvent.ACTION_DRAG_ENDED)
        if (state != null) {
            state.passwordComplete();
        }
    return true;
}
 
Example #7
Source File: PasswordGrid.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
@Override
public boolean onDragEvent(DragEvent event) {
    if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
        Point p = new Point((int) event.getX(), (int) event.getY());
        if (!roaming) {
            roaming = true;
            points.add(p);
        } else {
            try {
                points.set(points.size() - 1, p);
            } catch (Exception e) {
                Reset();
                FileLog.e("Yahala", e);
            }
        }
        invalidate();
    }
    return true;
}
 
Example #8
Source File: CompositorViewHolder.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchDragEvent(DragEvent e) {
    ContentViewCore contentViewCore = mTabVisible.getContentViewCore();
    if (contentViewCore == null) return false;

    if (mLayoutManager != null) mLayoutManager.getViewportPixel(mCacheViewport);
    contentViewCore.setCurrentTouchEventOffsets(-mCacheViewport.left, -mCacheViewport.top);
    boolean ret = super.dispatchDragEvent(e);

    int action = e.getAction();
    if (action == DragEvent.ACTION_DRAG_EXITED || action == DragEvent.ACTION_DRAG_ENDED
            || action == DragEvent.ACTION_DROP) {
        contentViewCore.setCurrentTouchEventOffsets(0.f, 0.f);
    }
    return ret;
}
 
Example #9
Source File: CompositorViewHolder.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchDragEvent(DragEvent e) {
    ContentViewCore contentViewCore = mTabVisible.getContentViewCore();
    if (contentViewCore == null) return false;

    if (mLayoutManager != null) mLayoutManager.getViewportPixel(mCacheViewport);
    contentViewCore.setCurrentTouchEventOffsets(-mCacheViewport.left, -mCacheViewport.top);
    boolean ret = super.dispatchDragEvent(e);

    int action = e.getAction();
    if (action == DragEvent.ACTION_DRAG_EXITED || action == DragEvent.ACTION_DRAG_ENDED
            || action == DragEvent.ACTION_DROP) {
        contentViewCore.setCurrentTouchEventOffsets(0.f, 0.f);
    }
    return ret;
}
 
Example #10
Source File: DragUtils.java    From DraggedViewPager with Apache License 2.0 6 votes vote down vote up
/**
 * 获取拖拽触发的执行事件类型
 *
 * @param draggedViewPager 最外层 {@link com.bigfat.draggedviewpager.view.MDA_DraggedViewPager}
 * @param currentPageIndex 当前页索引
 * @param pageIndex        响应拖拽事件item所在页索引
 * @param view             响应拖拽事件的item
 * @param event            拖拽事件
 * @return 拖拽事件类型
 */
public static DragEventType getDragEventType(MDA_DraggedViewPager draggedViewPager, int currentPageIndex, int pageIndex,
    View view, DragEvent event) {
    if (currentPageIndex > 0//有上一页
        && (draggedViewPager.getPageDragSetting() == null || draggedViewPager.getPageDragSetting()
        .canBeSwiped(currentPageIndex - 1))//上一页可被交换
        //触摸至上一页//或至触摸至当前页左边界,则切换到上一页
        && (pageIndex < currentPageIndex || (pageIndex == currentPageIndex && event.getX() < view.getWidth() / 8))) {
        return DragEventType.SCROLL_PREVIOUS;
    } else if (currentPageIndex < (draggedViewPager.getContainer().getChildCount() - 1)//在有下一页的前提下
        && (draggedViewPager.getPageDragSetting() == null || draggedViewPager.getPageDragSetting()
        .canBeSwiped(currentPageIndex + 1))//下一页可被交换
        //触摸至下一页//或至触摸至当前页右边界,则切换到下一页
        && (pageIndex > currentPageIndex || (pageIndex == currentPageIndex && event.getX() > view.getWidth() / 8 * 7))) {
        return DragEventType.SCROLL_NEXT;
    }
    return DragEventType.DEFAULT;
}
 
Example #11
Source File: PinItemDragListener.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onDrag(View view, DragEvent event) {
    if (mLauncher == null || mDragController == null) {
        postCleanup();
        return false;
    }
    if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) {
        if (onDragStart(event)) {
            return true;
        } else {
            postCleanup();
            return false;
        }
    }
    return mDragController.onDragEvent(mDragStartTime, event);
}
 
Example #12
Source File: LauncherDragListener.java    From DistroHopper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onDrag (View view, DragEvent event)
{
	try
	{
		switch (event.getAction ())
		{
			case DragEvent.ACTION_DRAG_ENTERED:
				this.appManager.startedDraggingPinnedApp ();
				break;
			case DragEvent.ACTION_DROP:
			case DragEvent.ACTION_DRAG_EXITED:
				this.appManager.stoppedDraggingPinnedApp ();
				break;
		}
	}
	catch (Exception ex)
	{
		ExceptionHandler exh = new ExceptionHandler (ex);
		exh.show (this.appManager.getContext ());
	}

	return true;
}
 
Example #13
Source File: DragDropTouchDragListener.java    From RecyclerViewExtensions with MIT License 6 votes vote down vote up
@Override
public boolean onDrag(View view, DragEvent event) {
    switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
            intercept = false;
            startTime = SystemClock.uptimeMillis();
            dispatchTouchEvent(view, MotionEvent.ACTION_DOWN, event.getX(), event.getY());
            // Return true to receive further events.
            return true;

        case DragEvent.ACTION_DRAG_LOCATION:
            dispatchTouchEvent(view, MotionEvent.ACTION_MOVE, event.getX(), event.getY());
            return false;

        case DragEvent.ACTION_DRAG_ENDED:
            dispatchTouchEvent(view, MotionEvent.ACTION_UP, event.getX(), event.getY());
            return false;

        default:
            return false;
    }
}
 
Example #14
Source File: ImageDragListener.java    From android-DragAndDropAcrossApps with Apache License 2.0 5 votes vote down vote up
protected boolean setImageUri(View view, DragEvent event, Uri uri) {
    if (!(view instanceof ImageView)) {
        return false;
    }
    ((ImageView) view).setImageURI(uri);
    return true;
}
 
Example #15
Source File: ContentFragment.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
boolean processDragStarted(DragEvent event) {
    // Determine whether to continue processing drag and drop based on the
    // plain text mime type.
    ClipDescription clipDesc = event.getClipDescription();
    if (clipDesc != null) {
        return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    }
    return false;
}
 
Example #16
Source File: DragActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean onDrag(View v, DragEvent event) {
	switch (event.getAction()) {
	case DragEvent.ACTION_DRAG_STARTED:
		// Do nothing
		break;
	case DragEvent.ACTION_DRAG_ENTERED:
		v.setBackground(enterShape);
		break;
	case DragEvent.ACTION_DRAG_EXITED:
		v.setBackground(normalShape);
		break;
	case DragEvent.ACTION_DROP:
		// view dropped, reassign the view to the new ViewGroup
		View view = (View) event.getLocalState();
		ViewGroup owner = (ViewGroup) view.getParent();
		owner.removeView(view);
		LinearLayout container = (LinearLayout) v;
		container.addView(view);
		view.setVisibility(View.VISIBLE);
		break;
	case DragEvent.ACTION_DRAG_ENDED:
		v.setBackground(normalShape);
	default:
		break;
	}
	return true;
}
 
Example #17
Source File: ContentFragment.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
boolean processDrop(DragEvent event, ImageView imageView) {
    // Attempt to parse clip data with expected format: category||entry_id.
    // Ignore event if data does not conform to this format.
    ClipData data = event.getClipData();
    if (data != null) {
        if (data.getItemCount() > 0) {
            Item item = data.getItemAt(0);
            String textData = (String) item.getText();
            if (textData != null) {
                StringTokenizer tokenizer = new StringTokenizer(textData, "||");
                if (tokenizer.countTokens() != 2) {
                    return false;
                }
                int category = -1;
                int entryId = -1;
                try {
                    category = Integer.parseInt(tokenizer.nextToken());
                    entryId = Integer.parseInt(tokenizer.nextToken());
                } catch (NumberFormatException exception) {
                    return false;
                }
                updateContentAndRecycleBitmap(category, entryId);
                // Update list fragment with selected entry.
                TitlesFragment titlesFrag = (TitlesFragment)
                        getFragmentManager().findFragmentById(R.id.titles_frag);
                titlesFrag.selectPosition(entryId);
                return true;
            }
        }
    }
    return false;
}
 
Example #18
Source File: ContentFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
boolean processDragStarted(DragEvent event) {
    // Determine whether to continue processing drag and drop based on the
    // plain text mime type.
    ClipDescription clipDesc = event.getClipDescription();
    if (clipDesc != null) {
        return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    }
    return false;
}
 
Example #19
Source File: ContentFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
boolean processDrop(DragEvent event, ImageView imageView) {
    // Attempt to parse clip data with expected format: category||entry_id.
    // Ignore event if data does not conform to this format.
    ClipData data = event.getClipData();
    if (data != null) {
        if (data.getItemCount() > 0) {
            Item item = data.getItemAt(0);
            String textData = (String) item.getText();
            if (textData != null) {
                StringTokenizer tokenizer = new StringTokenizer(textData, "||");
                if (tokenizer.countTokens() != 2) {
                    return false;
                }
                int category = -1;
                int entryId = -1;
                try {
                    category = Integer.parseInt(tokenizer.nextToken());
                    entryId = Integer.parseInt(tokenizer.nextToken());
                } catch (NumberFormatException exception) {
                    return false;
                }
                updateContentAndRecycleBitmap(category, entryId);
                // Update list fragment with selected entry.
                TitlesFragment titlesFrag = (TitlesFragment)
                        getFragmentManager().findFragmentById(R.id.frag_title);
                titlesFrag.selectPosition(entryId);
                return true;
            }
        }
    }
    return false;
}
 
Example #20
Source File: ContentFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
boolean processDragStarted(DragEvent event) {
    // Determine whether to continue processing drag and drop based on the
    // plain text mime type.
    ClipDescription clipDesc = event.getClipDescription();
    if (clipDesc != null) {
        return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    }
    return false;
}
 
Example #21
Source File: StoreExampleActivity.java    From android-profile with Apache License 2.0 5 votes vote down vote up
@Override
        public boolean onDrag(View v, DragEvent event) {
            View view = (View) event.getLocalState();
//            ViewGroup owner = (ViewGroup) view.getParent();
//            LinearLayout container = (LinearLayout) v;
            switch (event.getAction()) {
                case DragEvent.ACTION_DRAG_STARTED:
                    break;
                case DragEvent.ACTION_DRAG_ENTERED:
                    v.setBackgroundDrawable(enterShape);
                    break;
                case DragEvent.ACTION_DRAG_EXITED:
                    v.setBackgroundDrawable(normalShape);
                    break;
                case DragEvent.ACTION_DROP:

                    // Dropped, reassign View to ViewGroup

                    ViewGroup left = (ViewGroup)findViewById(R.id.leftbox);
                    ViewGroup right = (ViewGroup)findViewById(R.id.rightbox);

                    if (right == v){
                        left.removeView(view);
                        right.addView(view);
                        view.setVisibility(View.VISIBLE);

                        // Once the user drags the SOOMBOT to the empty box, we open the store.
                        openStore();
                    }
                    break;
                case DragEvent.ACTION_DRAG_ENDED:
                    view.setVisibility(View.VISIBLE);

                    v.setBackgroundDrawable(normalShape);
                default:
                    break;
            }
            return true;
        }
 
Example #22
Source File: ImageDragListener.java    From android-DragAndDropAcrossApps with Apache License 2.0 5 votes vote down vote up
private boolean processDrop(View view, DragEvent event) {
    ClipData clipData = event.getClipData();
    if (clipData == null || clipData.getItemCount() == 0) {
        return false;
    }
    ClipData.Item item = clipData.getItemAt(0);
    if (item == null) {
        return false;
    }
    Uri uri = item.getUri();
    if (uri == null) {
        return false;
    }
    return setImageUri(view, event, uri);
}
 
Example #23
Source File: ContentFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
boolean processDrop(DragEvent event, ImageView imageView) {
    // Attempt to parse clip data with expected format: category||entry_id.
    // Ignore event if data does not conform to this format.
    ClipData data = event.getClipData();
    if (data != null) {
        if (data.getItemCount() > 0) {
            Item item = data.getItemAt(0);
            String textData = (String) item.getText();
            if (textData != null) {
                StringTokenizer tokenizer = new StringTokenizer(textData, "||");
                if (tokenizer.countTokens() != 2) {
                    return false;
                }
                int category = -1;
                int entryId = -1;
                try {
                    category = Integer.parseInt(tokenizer.nextToken());
                    entryId = Integer.parseInt(tokenizer.nextToken());
                } catch (NumberFormatException exception) {
                    return false;
                }
                updateContentAndRecycleBitmap(category, entryId);
                // Update list fragment with selected entry.
                TitlesFragment titlesFrag = (TitlesFragment)
                        getFragmentManager().findFragmentById(R.id.frag_title);
                titlesFrag.selectPosition(entryId);
                return true;
            }
        }
    }
    return false;
}
 
Example #24
Source File: DropTargetFragment.java    From android-DragAndDropAcrossApps with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onDrag(View view, DragEvent event) {
    // DragTarget is peeking into the MIME types of the dragged event in order to ignore
    // non-image drags completely.
    // DragSource does not do that but rejects non-image content once a drop has happened.
    ClipDescription clipDescription = event.getClipDescription();
    if (clipDescription != null && !clipDescription.hasMimeType("image/*")) {
        return false;
    }
    // Callback received when image is being dragged.
    return super.onDrag(view, event);
}
 
Example #25
Source File: MainActivity.java    From LaunchTime with GNU General Public License v3.0 5 votes vote down vote up
private void hscrollOnDrag(View view, DragEvent event, HorizontalScrollView scrollView) {
    float tx = view.getLeft() + event.getX();

    if (isAncestor(scrollView, view)) {

        int thresh = scrollView.getWidth() / 6;

        if (tx < scrollView.getScrollX() + thresh) {
            scrollView.smoothScrollBy(-10, 0);
        } else if (tx > scrollView.getScrollX() + scrollView.getWidth() - thresh) {
            scrollView.smoothScrollBy(10,0);
        }
    }
}
 
Example #26
Source File: MainActivity.java    From LaunchTime with GNU General Public License v3.0 5 votes vote down vote up
private void scrollOnDrag(View view, DragEvent event, ScrollView scrollView) {
    float ty = view.getTop() + event.getY();

    if (isAncestor(scrollView, view)) {

        int thresh = scrollView.getHeight() / 6;

        if (ty < scrollView.getScrollY() + thresh) {
            scrollView.smoothScrollBy(0, -10);
        } else if (ty > scrollView.getScrollY() + scrollView.getHeight() - thresh) {
            scrollView.smoothScrollBy(0, 10);
        }
    }
}
 
Example #27
Source File: DropTargetFragment.java    From android-DragAndDropAcrossApps with Apache License 2.0 5 votes vote down vote up
/**
 * DragEvents can contain additional data packaged in a {@link PersistableBundle}.
 * Extract the extras from the event and return the String stored for the
 * {@link #EXTRA_IMAGE_INFO} entry.
 */
private String getExtra(DragEvent event) {
    // The extras are contained in the ClipDescription in the DragEvent.
    ClipDescription clipDescription = event.getClipDescription();
    if (clipDescription != null) {
        PersistableBundle extras = clipDescription.getExtras();
        if (extras != null) {
            return extras.getString(EXTRA_IMAGE_INFO);
        }
    }
    return null;
}
 
Example #28
Source File: ImageDragListener.java    From android-DragAndDropAcrossApps with Apache License 2.0 5 votes vote down vote up
protected boolean setImageUri(View view, DragEvent event, Uri uri) {
    if (!(view instanceof ImageView)) {
        return false;
    }
    ((ImageView) view).setImageURI(uri);
    return true;
}
 
Example #29
Source File: ImageDragListener.java    From android-DragAndDropAcrossApps with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onDrag(View view, DragEvent event) {
    switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
            setTargetColor(view, COLOR_ACTIVE);
            return true;

        case DragEvent.ACTION_DRAG_ENTERED:
            setTargetColor(view, COLOR_HOVER);
            return true;

        case DragEvent.ACTION_DRAG_LOCATION:
            processLocation(event.getX(), event.getY());
            return true;

        case DragEvent.ACTION_DRAG_EXITED:
            setTargetColor(view, COLOR_ACTIVE);
            return true;

        case DragEvent.ACTION_DROP:
            return processDrop(view, event);

        case DragEvent.ACTION_DRAG_ENDED:
            setTargetColor(view, COLOR_INACTIVE);
            return true;

        default:
            break;
    }

    return false;
}
 
Example #30
Source File: ImageDragListener.java    From android-DragAndDropAcrossApps with Apache License 2.0 5 votes vote down vote up
private boolean processDrop(View view, DragEvent event) {
    ClipData clipData = event.getClipData();
    if (clipData == null || clipData.getItemCount() == 0) {
        return false;
    }
    ClipData.Item item = clipData.getItemAt(0);
    if (item == null) {
        return false;
    }
    Uri uri = item.getUri();
    if (uri == null) {
        return false;
    }
    return setImageUri(view, event, uri);
}