Example usage for android.view DragEvent ACTION_DRAG_STARTED

List of usage examples for android.view DragEvent ACTION_DRAG_STARTED

Introduction

In this page you can find the example usage for android.view DragEvent ACTION_DRAG_STARTED.

Prototype

int ACTION_DRAG_STARTED

To view the source code for android.view DragEvent ACTION_DRAG_STARTED.

Click Source Link

Document

Action constant returned by #getAction() : Signals the start of a drag and drop operation.

Usage

From source file:com.actionbarsherlock.sample.hcgallery.ContentFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContentView = inflater.inflate(R.layout.content_welcome, null);
    final ImageView imageView = (ImageView) mContentView.findViewById(R.id.image);
    mContentView.setDrawingCacheEnabled(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mContentView.setOnDragListener(new View.OnDragListener() {
            public boolean onDrag(View v, DragEvent event) {
                switch (event.getAction()) {
                case DragEvent.ACTION_DRAG_ENTERED:
                    mContentView.setBackgroundColor(getResources().getColor(R.color.drag_active_color));
                    break;

                case DragEvent.ACTION_DRAG_EXITED:
                    mContentView.setBackgroundColor(Color.TRANSPARENT);
                    break;

                case DragEvent.ACTION_DRAG_STARTED:
                    return processDragStarted(event);

                case DragEvent.ACTION_DROP:
                    mContentView.setBackgroundColor(Color.TRANSPARENT);
                    return processDrop(event, imageView);
                }//from  w w w . j  ava  2s  .co  m
                return false;
            }
        });

        // Keep the action bar visibility in sync with the system status bar. That is, when entering
        // 'lights out mode,' hide the action bar, and when exiting this mode, show the action bar.

        final Activity activity = getActivity();
        mContentView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            public void onSystemUiVisibilityChange(int visibility) {
                ActionBar actionBar = activity.getActionBar();
                if (actionBar != null) {
                    mContentView.setSystemUiVisibility(visibility);
                    if (visibility == View.STATUS_BAR_VISIBLE) {
                        actionBar.show();
                    } else {
                        actionBar.hide();
                    }
                }
            }
        });

        // Show/hide the system status bar when single-clicking a photo. This is also called
        // 'lights out mode.' Activating and deactivating this mode also invokes the listener
        // defined above, which will show or hide the action bar accordingly.

        mContentView.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (mContentView.getSystemUiVisibility() == View.STATUS_BAR_VISIBLE) {
                    mContentView.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
                } else {
                    mContentView.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
                }
            }
        });
    }

    // When long-pressing a photo, activate the action mode for selection, showing the
    // contextual action bar (CAB).

    mContentView.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            if (mCurrentActionMode != null) {
                return false;
            }

            mCurrentActionMode = getActivity().startActionMode(mContentSelectionActionModeCallback);
            mContentView.setSelected(true);
            return true;
        }
    });

    return mContentView;
}

From source file:com.heneryh.aquanotes.ui.livestock.ContentFragment.java

/** This is where we initialize the fragment's UI and attach some
 * event listeners to UI components.//from   w ww  .  j a  v a 2s . c  o  m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContentView = inflater.inflate(R.layout.content_welcome, null);
    final ImageView imageView = (ImageView) mContentView.findViewById(R.id.image);
    mContentView.setDrawingCacheEnabled(false);

    // Handle drag events when a list item is dragged into the view
    mContentView.setOnDragListener(new View.OnDragListener() {
        public boolean onDrag(View view, DragEvent event) {
            switch (event.getAction()) {
            case DragEvent.ACTION_DRAG_ENTERED:
                view.setBackgroundColor(getResources().getColor(R.color.drag_active_color));
                break;

            case DragEvent.ACTION_DRAG_EXITED:
                view.setBackgroundColor(Color.TRANSPARENT);
                break;

            case DragEvent.ACTION_DRAG_STARTED:
                return processDragStarted(event);

            case DragEvent.ACTION_DROP:
                view.setBackgroundColor(Color.TRANSPARENT);
                return processDrop(event, imageView);
            }
            return false;
        }
    });

    // Show/hide the system status bar when single-clicking a photo.
    mContentView.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (mCurrentActionMode != null) {
                // If we're in an action mode, don't toggle the action bar
                return;
            }

            if (mSystemUiVisible) {
                setSystemUiVisible(false);
            } else {
                setSystemUiVisible(true);
            }
        }
    });

    // When long-pressing a photo, activate the action mode for selection, showing the
    // contextual action bar (CAB).
    mContentView.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            if (mCurrentActionMode != null) {
                return false;
            }

            mCurrentActionMode = getActivity().startActionMode(mContentSelectionActionModeCallback);
            view.setSelected(true);
            return true;
        }
    });

    return mContentView;
}

From source file:com.jaspersoft.android.jaspermobile.widget.DraggableViewsContainer.java

@Override
public boolean onDrag(View v, DragEvent event) {
    int viewId;/*from w  ww . j  av a2s.c  o  m*/
    View noteView;
    switch (event.getAction()) {
    case DragEvent.ACTION_DRAG_STARTED:
        viewId = Integer.parseInt(event.getClipDescription().getLabel().toString());
        noteView = findViewById(viewId);
        noteView.setVisibility(View.GONE);
        return true;
    case DragEvent.ACTION_DROP:
        viewId = Integer.parseInt(event.getClipDescription().getLabel().toString());
        noteView = findViewById(viewId);
        noteView.setX(event.getX() - noteView.getWidth() / 2);
        noteView.setY(event.getY() - noteView.getHeight() / 2);
        noteView.setVisibility(View.VISIBLE);
        return true;
    default:
        return false;
    }
}

From source file:com.commonsware.android.dragdrop.MainActivity.java

@Override
public boolean onDrag(View v, DragEvent event) {
    boolean result = true;

    switch (event.getAction()) {
    case DragEvent.ACTION_DRAG_STARTED:
        if (event.getLocalState() == null) {
            result = false;//ww  w.  j  a v a  2  s .c  o m
        } else {
            applyDropHint(v, R.drawable.droppable);
        }
        break;

    case DragEvent.ACTION_DRAG_ENTERED:
        applyDropHint(v, R.drawable.drop);
        break;

    case DragEvent.ACTION_DRAG_EXITED:
        applyDropHint(v, R.drawable.droppable);
        break;

    case DragEvent.ACTION_DRAG_ENDED:
        applyDropHint(v, -1);
        break;

    case DragEvent.ACTION_DROP:
        ClipData.Item clip = event.getClipData().getItemAt(0);
        Uri videoUri = clip.getUri();

        if (v == player) {
            player.setVideoURI(videoUri);
            player.start();
        } else {
            Picasso.with(thumbnailLarge.getContext()).load(videoUri.toString()).fit().centerCrop()
                    .placeholder(R.drawable.ic_media_video_poster).into(thumbnailLarge);
        }

        break;
    }

    return (result);
}

From source file:com.commonsware.android.kbmouse.hotkeys.MainActivity.java

@Override
public boolean onDrag(View v, DragEvent event) {
    boolean result = true;

    switch (event.getAction()) {
    case DragEvent.ACTION_DRAG_STARTED:
        applyDropHint(v, R.drawable.droppable);
        break;//w w  w  .  j  a v  a2  s. c om

    case DragEvent.ACTION_DRAG_ENTERED:
        applyDropHint(v, R.drawable.drop);
        break;

    case DragEvent.ACTION_DRAG_EXITED:
        applyDropHint(v, R.drawable.droppable);
        break;

    case DragEvent.ACTION_DRAG_ENDED:
        applyDropHint(v, -1);
        break;

    case DragEvent.ACTION_DROP:
        ClipData.Item clip = event.getClipData().getItemAt(0);
        Uri videoUri = clip.getUri();

        if (v == player) {
            playVideo(videoUri);
        } else {
            showLargeThumbnail(videoUri);
        }

        break;
    }

    return (result);
}

From source file:com.launcher.silverfish.launcher.LauncherActivity.java

private void setDragListener() {
    mViewPager.setOnDragListener(new View.OnDragListener() {
        @Override//from   w w  w  .jav  a2 s.c  om
        public boolean onDrag(View view, DragEvent dragEvent) {
            switch (dragEvent.getAction()) {
            case DragEvent.ACTION_DRAG_STARTED:
                // Only care about the DRAG_APP_MOVE description.
                ClipDescription cd = dragEvent.getClipDescription();
                if (!cd.getLabel().toString().equals(Constants.DRAG_APP_MOVE))
                    return false;
                break;
            case DragEvent.ACTION_DRAG_ENTERED:
                // Don't do anything
                break;
            case DragEvent.ACTION_DRAG_LOCATION:
                changePage(dragEvent);
                break;
            case DragEvent.ACTION_DROP:
                dropItem(dragEvent);
                break;
            case DragEvent.ACTION_DRAG_ENDED:
                // Don't do anything
                break;

            }
            return true;
        }
    });
}

From source file:com.android.mail.ui.FolderItemView.java

/**
 * Handles the drag event.// ww  w. ja  va 2 s  .  c  o  m
 *
 * @param event the drag event to be handled
 */
@Override
public boolean onDragEvent(DragEvent event) {
    switch (event.getAction()) {
    case DragEvent.ACTION_DRAG_STARTED:
        // Set drag mode state to true now that we have entered drag mode.
        // This change updates the states of icons and text colors.
        // Additional drawable states are updated by the framework
        // based on the DragEvent.
        setDragMode(true);
    case DragEvent.ACTION_DRAG_ENTERED:
    case DragEvent.ACTION_DRAG_EXITED:
        // All of these states return based on isDroppableTarget's return value.
        // If modifying, watch the switch's drop-through effects.
        return isDroppableTarget(event);
    case DragEvent.ACTION_DRAG_ENDED:
        // Set drag mode to false since we're leaving drag mode.
        // Updates all the states of icons and text colors back to non-drag values.
        setDragMode(false);
        return true;

    case DragEvent.ACTION_DRAG_LOCATION:
        return true;

    case DragEvent.ACTION_DROP:
        if (mDropHandler == null) {
            return false;
        }

        mDropHandler.handleDrop(event, mFolder);
        return true;
    }
    return false;
}

From source file:it.vibin.sideswipe.drag.SwipeMenuManager.java

@Override
public boolean onDrag(View v, DragEvent event) {
    int action = event.getAction();
    final View dropView = (View) event.getLocalState();
    ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
    switch (action) {
    case DragEvent.ACTION_DRAG_STARTED:
        mY = (int) dropView.getY() - params.topMargin;
        break;//from w  w  w . j  av  a2  s  . c  o m
    case DragEvent.ACTION_DRAG_LOCATION:
        break;
    case DragEvent.ACTION_DROP:
    case DragEvent.ACTION_DRAG_EXITED:
        Iterator<DropZone> iter = mDropZones.keySet().iterator();
        while (iter.hasNext()) {
            DropZone dropZone = iter.next();
            View dropZoneView = mDropZones.get(dropZone);
            if (v.getId() == dropZoneView.getId()) {
                mEventListener.postback_drop(dropView, dropZone, v);
            }
            //mViewPager.requestDisallowInterceptTouchEvent(false);
        }
        mLockedOnX = false;
        mIsDragging = false;
        break;
    case DragEvent.ACTION_DRAG_ENDED:
        Log.d(TAG, "=============> DRAG ENDED!");
        dropView.post(new Runnable() {
            @Override
            public void run() {
                //dropView.setVisibility(View.VISIBLE);
                mLockedOnX = false;
                mIsDragging = false;
                //mViewPager.requestDisallowInterceptTouchEvent(false);
            }
        });
        break;
    }
    return true;
}

From source file:com.launcher.silverfish.TabbedAppDrawerFragment.java

private void setOnDragListener() {

    rootView.setOnDragListener(new View.OnDragListener() {
        @Override/*  w  w w  .  j a  v  a  2  s.  c om*/
        public boolean onDrag(View view, DragEvent dragEvent) {

            switch (dragEvent.getAction()) {
            case DragEvent.ACTION_DRAG_STARTED: {

                // Care only about DRAG_APP_MOVE drags.
                ClipDescription cd = dragEvent.getClipDescription();
                if (!cd.getLabel().toString().equals(Constants.DRAG_APP_MOVE))
                    return false;

                // Show the uninstall indicator
                showUninstallIndicator();
                break;
            }

            case DragEvent.ACTION_DRAG_ENTERED: {
                // Don't do anything
                break;
            }

            case DragEvent.ACTION_DRAG_LOCATION: {
                // If drag is on the way out of this page then stop receiving drag events
                int threshold = Constants.SCREEN_CORNER_THRESHOLD;
                // Get display size
                int screen_width = Utils.getScreenDimensions(getActivity()).x;
                if (dragEvent.getX() > screen_width - threshold) {
                    return false;

                } else {

                    // Check if the drag is hovering over a tab button
                    int i = tabHandler.getHoveringTab(dragEvent.getX(), dragEvent.getY());

                    // If so, change to that tab
                    if (i > -1)
                        tabHandler.setTab(i);
                }
                break;
            }

            case DragEvent.ACTION_DROP: {

                // If app is dropped on the uninstall indicator uninstall the app
                if (Utils.onBottomCenterScreenEdge(getActivity(), dragEvent.getX(), dragEvent.getY())) {
                    String app_name = dragEvent.getClipData().getItemAt(0).getText().toString();
                    launchUninstallIntent(app_name);

                } else {
                    // retrieve tha drop information  and remove it from the original tab
                    int app_index = Integer.parseInt(dragEvent.getClipData().getItemAt(1).getText().toString());

                    String tab_tag = dragEvent.getClipData().getItemAt(2).getText().toString();

                    removeAppFromTab(app_index, tab_tag);

                    // add it to the new tab
                    String app_name = dragEvent.getClipData().getItemAt(0).getText().toString();
                    dropAppInTab(app_name);

                }
                break;
            }

            case DragEvent.ACTION_DRAG_ENDED: {
                // Just hide the uninstall indicator
                hideUninstallIndicator();
                break;
            }

            }
            return true;
        }

    });
}

From source file:com.launcher.silverfish.launcher.appdrawer.TabbedAppDrawerFragment.java

private void setOnDragListener() {

    rootView.setOnDragListener(new View.OnDragListener() {
        @Override//ww  w . java  2  s .c  o  m
        public boolean onDrag(View view, DragEvent dragEvent) {

            switch (dragEvent.getAction()) {
            case DragEvent.ACTION_DRAG_STARTED: {
                // Care only about DRAG_APP_MOVE drags.
                ClipDescription cd = dragEvent.getClipDescription();
                if (!cd.getLabel().toString().equals(Constants.DRAG_APP_MOVE))
                    return false;

                // Starting movement, drag offset is now reset to 0
                dragOffsetX = 0;
                dragOffsetY = 0;

                // Show the uninstall indicator
                showUninstallIndicator();
                break;
            }

            case DragEvent.ACTION_DRAG_ENTERED: {
                // Don't do anything
                break;
            }

            case DragEvent.ACTION_DRAG_LOCATION: {
                // getX() and getY() now return relative offsets,
                // so accumulate them to get the total movement
                dragOffsetX += dragEvent.getX();
                dragOffsetY += dragEvent.getY();

                // If drag is on the way out of this page then stop receiving drag events
                int threshold = Constants.SCREEN_CORNER_THRESHOLD;
                // Get display size
                int screen_width = Utils.getScreenDimensions(getActivity()).x;
                if (dragEvent.getX() > screen_width - threshold) {
                    return false;

                } else {

                    // Check if the drag is hovering over a tab button
                    int i = tabHandler.getHoveringTab(dragEvent.getX(), dragEvent.getY());

                    // If so, change to that tab
                    if (i > -1)
                        tabHandler.setTab(i);
                }
                break;
            }

            case DragEvent.ACTION_DROP: {
                String appName = dragEvent.getClipData().getItemAt(0).getText().toString();

                // If app is dropped on the uninstall indicator uninstall the app
                if (Utils.onBottomCenterScreenEdge(getActivity(), dragEvent.getX(), dragEvent.getY())) {
                    launchUninstallIntent(appName);
                } else {
                    // If the user didn't move the application from its original
                    // place (too much), then they might want to show a menu with more options
                    float distSq = (dragOffsetX * dragOffsetX) + (dragOffsetY * dragOffsetY);
                    if (distSq < Constants.NO_DRAG_THRESHOLD_SQ) {
                        showExtraOptionsMenu(appName);
                    } else {
                        // Retrieve tha drop information  and remove it from the original tab
                        int appIndex = Integer
                                .parseInt(dragEvent.getClipData().getItemAt(1).getText().toString());

                        String tabTag = dragEvent.getClipData().getItemAt(2).getText().toString();

                        removeAppFromTab(appIndex, tabTag);

                        // add it to the new tab
                        String app_name = dragEvent.getClipData().getItemAt(0).getText().toString();
                        dropAppInTab(app_name);
                    }
                }
                break;
            }

            case DragEvent.ACTION_DRAG_ENDED: {
                // Just hide the uninstall indicator
                hideUninstallIndicator();
                break;
            }

            }
            return true;
        }

    });
}