Code example for DragEvent

Methods: getAction, getClipData

0
    } 
 
    @Override 
    public boolean onDrag(View view, DragEvent event) {
        final TextView textView = (TextView) view;
        switch (event.getAction()) {
            case DragEvent.ACTION_DRAG_STARTED:
                if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                    setTextColor(textView, COLOR_VALID_DROPS);
                    return true; 
                } 
                return false; 
 
            case DragEvent.ACTION_DRAG_ENTERED:
                setTextColor(textView, COLOR_ACTIVE_DROP);
                return true; 
 
            case DragEvent.ACTION_DRAG_LOCATION:
                return true; 
 
            case DragEvent.ACTION_DRAG_EXITED:
                setTextColor(textView, COLOR_VALID_DROPS);
                return true; 
 
            case DragEvent.ACTION_DROP:
                ClipData.Item item = event.getClipData().getItemAt(0);
                final CharSequence dragData = item.getText();
 
                textView.setText(dragData);
                setTextColor(textView, COLOR_DEFAULT);
 
                return true; 
 
            case DragEvent.ACTION_DRAG_ENDED:
                setTextColor(textView, COLOR_DEFAULT);
                return true; 
 
            default: 
                throw new IllegalStateException("unrecognized event action: " + event.getAction());
        } 
    } 
 
    private TextView init(final int resource, final String tag) {
        final TextView textView = (TextView) findViewById(resource);