Example usage for android.view DragEvent getClipData

List of usage examples for android.view DragEvent getClipData

Introduction

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

Prototype

public ClipData getClipData() 

Source Link

Document

Returns the android.content.ClipData object sent to the system as part of the call to android.view.View#startDragAndDrop(ClipData,View.DragShadowBuilder,Object,int) startDragAndDrop() .

Usage

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

private void dropItem(DragEvent dragEvent) {
    if (mViewPager.getCurrentItem() == 1) {
        String appName = dragEvent.getClipData().getItemAt(0).getText().toString();

        if (getFragShortcutAddListenerRefreshListener() != null) {
            getFragShortcutAddListenerRefreshListener().OnShortcutAdd(appName);
        }//from w  w w  .  j a va  2 s.co  m
    }
}

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

private void dropItem(DragEvent dragEvent) {
    if (mViewPager.getCurrentItem() == 1) {
        String appName = dragEvent.getClipData().getItemAt(0).getText().toString();
        addShortcut(appName);/*from  w ww .ja v  a2  s  . com*/
    }
}

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

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;
                }/*  w  w w.j a v  a 2  s  .c om*/
                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;
}

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

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;
                }//from  w ww  .  j  a v a 2s  .  c  o m
                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;
}

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;/*ww w.j  ava 2s .  c  o  m*/

    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.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;//from  w  w w  .  j  ava  2  s  .  c om
        } 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.launcher.silverfish.HomeScreenFragment.java

private void setOnDragListener() {
    rootView.setOnDragListener(new View.OnDragListener() {
        @Override// w w w .  ja v  a2s  .  c  o  m
        public boolean onDrag(View view, DragEvent dragEvent) {
            switch (dragEvent.getAction()) {
            case DragEvent.ACTION_DRAG_STARTED:
                // Check that it is a shortcut removal gesture
                ClipDescription cd = dragEvent.getClipDescription();
                if (!cd.getLabel().toString().equals(Constants.DRAG_SHORTCUT_REMOVAL)) {
                    return false;
                }
                break;
            case DragEvent.ACTION_DRAG_ENTERED:
                // Don't do anything
                break;
            case DragEvent.ACTION_DRAG_LOCATION:
                //Don't do anything
                break;
            case DragEvent.ACTION_DROP:

                // If outside of bound, remove the app
                if (Utils.onBottomCenterScreenEdge(getActivity(), dragEvent.getX(), dragEvent.getY())) {
                    String appId = dragEvent.getClipData().getItemAt(0).getText().toString();
                    String appIndex = dragEvent.getClipData().getItemAt(1).getText().toString();
                    removeApp(Integer.parseInt(appIndex), Long.parseLong(appId));
                    updateShortcuts();
                }

                break;
            case DragEvent.ACTION_DRAG_ENDED:
                // Hide the remove-indicator
                FrameLayout rem_ind = (FrameLayout) rootView.findViewById(R.id.remove_indicator);
                rem_ind.setVisibility(View.INVISIBLE);
                break;

            }
            return true;
        }
    });
}

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

private void setOnDragListener() {

    rootView.setOnDragListener(new View.OnDragListener() {
        @Override/*w w w .j  ava2  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;

                // 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//from 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;

                // 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;
        }

    });
}