Java Code Examples for android.view.DragEvent#getLocalState()

The following examples show how to use android.view.DragEvent#getLocalState() . 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: 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 2
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 3
Source File: HomeActivityDelegate.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onDrag(View v, DragEvent event) {
    switch(event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
        default:
            // do nothing
            break;
        case DragEvent.ACTION_DRAG_ENTERED:
            FrameLayout container = (FrameLayout) v;
            if(container.getChildCount() == 0
                    || startDragIndex == desktopIcons.indexOfChild(container)) {
                v.setBackgroundColor(U.getAccentColor(HomeActivityDelegate.this));
                v.setAlpha(0.5f);
            }
            break;
        case DragEvent.ACTION_DRAG_ENDED:
            View view = (View) event.getLocalState();
            view.setVisibility(View.VISIBLE);
            // fall through
        case DragEvent.ACTION_DRAG_EXITED:
            v.setBackground(null);
            v.setAlpha(1);
            break;
        case DragEvent.ACTION_DROP:
            FrameLayout container2 = (FrameLayout) v;
            if(container2.getChildCount() == 0) {
                // Dropped, reassign View to ViewGroup
                View view2 = (View) event.getLocalState();
                ViewGroup owner = (ViewGroup) view2.getParent();
                owner.removeView(view2);
                container2.addView(view2);

                endDragIndex = desktopIcons.indexOfChild(container2);
                reassignDroppedIcon();
            }
            break;
    }
    return true;
}
 
Example 4
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 5
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) {
	int action = event.getAction();
	switch (event.getAction()) {
	case DragEvent.ACTION_DRAG_STARTED:
		// Do nothing
		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
		View view = (View) event.getLocalState();
		ViewGroup owner = (ViewGroup) view.getParent();
		// TODO 1 removeView from owner
		// TODO 2 add to v which is a LinearLayout
		// TODO 3 set view to View.Visible
		
		break;
	case DragEvent.ACTION_DRAG_ENDED:
		v.setBackgroundDrawable(normalShape);
	default:
		break;
	}
	return true;
}
 
Example 6
Source File: DraggableDot.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private void processDrop(DragEvent event) {
    final ClipData data = event.getClipData();
    final int N = data.getItemCount();
    for (int i = 0; i < N; i++) {
        ClipData.Item item = data.getItemAt(i);
        Log.i(TAG, "Dropped item " + i + " : " + item);
        if (mReportView != null) {
            String text = item.coerceToText(getContext()).toString();
            if (event.getLocalState() == (Object) this) {
                text += " : Dropped on self!";
            }
            mReportView.setText(text);
        }
    }
}
 
Example 7
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 8
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 9
Source File: ViewDragListenerView.java    From Android_UE with Apache License 2.0 4 votes vote down vote up
@Override
    public boolean onDrag(View view, DragEvent dragEvent) {
        switch (dragEvent.getAction()) {
            case DragEvent.ACTION_DRAG_STARTED:
                if (dragEvent.getLocalState() == view) {
                    view.setVisibility(View.INVISIBLE);
                }
                // 开始拖拽
                Log.e(TAG, "开始拖拽");
                break;
            case DragEvent.ACTION_DRAG_LOCATION:
                // 主要是感觉是在拖动中就会回调
//                Log.e(TAG, "主要是感觉是在拖动中就会回调");
                break;
            case DragEvent.ACTION_DROP:
                // 向用户已释放拖动阴影的视图发出信号,拖动点位于视图的边界框内,而不在可接受数据的后代视图中。
                Log.e(TAG, "向用户已释放拖动阴影的视图发出信号,拖动点位于视图的边界框内,而不在可接受数据的后代视图中。");
                break;
            case DragEvent.ACTION_DRAG_ENDED:
                // 拖拽已结束
                Log.e(TAG, "拖拽已结束");
                if (dragEvent.getLocalState() == view) {
                    view.setVisibility(View.VISIBLE);
                }
                break;
            case DragEvent.ACTION_DRAG_ENTERED:
                // 拖拽的View已经到了其他View的范围,判断点为手指触摸的位置
                if (dragEvent.getLocalState() != view) {
                    // 每个View都会收到的,所以要排除掉自己
                    sortView(view);
                    Log.e(TAG, "拖拽的View已经到了其他View的范围");

                }
                break;
            case DragEvent.ACTION_DRAG_EXITED:
                // 移出了当前View的范围,判断点为手指触摸的位置
                Log.e(TAG, "移出了当前View的范围");
                break;
        }
        return true;
    }
 
Example 10
Source File: FeedbackCollectionOnDragListener.java    From ssj with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onDrag(final View v, DragEvent event)
{
	if (event.getLocalState() instanceof FeedbackComponentView)
	{
		final FeedbackComponentView feedbackComponentView = ((FeedbackComponentView) event.getLocalState());

		switch (event.getAction())
		{
			case ACTION_DRAG_STARTED:
				feedbackCollectionActivity.showDragIcons(feedbackComponentView.getWidth(), feedbackComponentView.getHeight());
				break;
			case ACTION_DROP:
				if (v instanceof FeedbackLevelLayout)
				{
					((FeedbackLevelLayout) v).addGridComponent(feedbackComponentView);
				}
				else if (v.equals(feedbackCollectionActivity.getRecycleBin()))
				{
					feedbackComponentView.post(new Runnable()
					{
						@Override
						public void run()
						{
							((ViewGroup) feedbackComponentView.getParent()).removeView(feedbackComponentView);
							feedbackCollectionActivity.requestReorder();
						}
					});
					PipelineBuilder.getInstance().remove(
							feedbackComponentView.getFeedbackLevelBehaviourEntry().getKey()
					);
				}
				break;
			case ACTION_DRAG_ENDED:
				// Set currently draged to false no matter where the drag ended, to force normal painting.
				feedbackComponentView.setCurrentlyDraged(false);
				feedbackCollectionActivity.hideDragIcons();
				break;
		}
		return true;
	}
	return false;
}
 
Example 11
Source File: PipeOnDragListener.java    From ssj with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param pipeView PipeView
 * @param event    DragEvent
 */
private void cleanup(final PipeView pipeView, final DragEvent event)
{
    //remove view from owner
    ComponentView componentView = (ComponentView) event.getLocalState();
    Result result = Result.NOTHING;
    try
    {
        result = handleCollision(pipeView, componentView);
    } finally
    {
        //remove recycle bin
        ViewParent viewParent = recycleBin.getParent();
        if (viewParent != null && viewParent instanceof ViewGroup)
        {
            ((ViewGroup) viewParent).removeView(recycleBin);
        }
        recycleBin.invalidate();
        recycleBin = null;
        componentView.invalidate();
        switch (result)
        {
            case NOTHING:
                break;
            case PLACED:
                pipeView.placeElements();
                break;
            case CONNECTED:
                pipeView.createElements();
                pipeView.placeElements();
                break;
            case DELETED:
                pipeView.createElements();
                pipeView.placeElements();
                //inform listeners after delay to avoid null pointer exception on tab deletion
                Handler handler = new Handler(Looper.getMainLooper());
                Runnable runnable = new Runnable()
                {
                    public void run()
                    {
                        pipeView.informListeners();
                    }
                };
                handler.postDelayed(runnable, 50);
                break;
            default:
                break;
        }
    }
}
 
Example 12
Source File: PipeOnDragListener.java    From ssj with GNU General Public License v3.0 4 votes vote down vote up
/**
     * @param v     View
     * @param event DragEvent
     * @return boolean
     */
    @Override
    public boolean onDrag(final View v, final DragEvent event)
    {
        if (v instanceof PipeView)
        {
            final PipeView pipeView = (PipeView) v;
            switch (event.getAction())
            {
                case DragEvent.ACTION_DRAG_STARTED:
                {
                    //init values
                    xCoord = 0;
                    yCoord = 0;
                    dropped = false;
                    createRecycleBin(pipeView);
                    break;
                }
                case DragEvent.ACTION_DRAG_ENTERED:
                    break;
                case DragEvent.ACTION_DRAG_EXITED:
                    break;
                case DragEvent.ACTION_DROP:
                    //update drop location
                    xCoord = event.getX();
                    yCoord = event.getY();
                    dropped = true;
                    ComponentView view = (ComponentView) event.getLocalState();
                    pipeView.getGrid().setGridValue(view.getGridX(), view.getGridY(), false);
                    break;
                case DragEvent.ACTION_DRAG_ENDED:
                    cleanup(pipeView, event);
                    break;
                case DragEvent.ACTION_DRAG_LOCATION:
                {
//                    //@todo add scroll behaviour to drag and drop
//                    HorizontalScrollView horizontalScrollView = (HorizontalScrollView) pipeView.getParent();
//                    if (horizontalScrollView != null)
//                    {
//                        ScrollView scrollView = (ScrollView) horizontalScrollView.getParent();
//                        if (scrollView != null)
//                        {
//                            //way one
//                            int y = Math.round(event.getY());
//                            int translatedY = y - scrollView.getScrollY();
//                            int threshold = 50;
//                            // make a scrolling up due the y has passed the threshold
//                            if (translatedY < threshold) {
//                                // make a scroll up by 30 px
//                                scrollView.smoothScrollBy(0, -30);
//                            }
//                            // make a autoscrolling down due y has passed the 500 px border
//                            if (translatedY + threshold > 500) {
//                                // make a scroll down by 30 px
//                                scrollView.smoothScrollBy(0, 30);
//                            }
//                            //way two
//                            int topOfDropZone = pipeView.getTop();
//                            int bottomOfDropZone = pipeView.getBottom();
//                            int scrollY = scrollView.getScrollY();
//                            int scrollViewHeight = scrollView.getMeasuredHeight();
//                            Log.d("location: Scroll Y: " + scrollY + " Scroll Y+Height: " + (scrollY + scrollViewHeight));
//                            Log.d(" top: " + topOfDropZone + " bottom: " + bottomOfDropZone);
//                            if (bottomOfDropZone > (scrollY + scrollViewHeight - 100))
//                            {
//                                scrollView.smoothScrollBy(0, 30);
//                            }
//                            if (topOfDropZone < (scrollY + 100))
//                            {
//                                scrollView.smoothScrollBy(0, -30);
//                            }
//                        }
//                    }
                    break;
                }
                default:
                    break;
            }
            return true;
        }
        return false;
    }