Example usage for android.view View startDrag

List of usage examples for android.view View startDrag

Introduction

In this page you can find the example usage for android.view View startDrag.

Prototype

@Deprecated
public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, Object myLocalState, int flags) 

Source Link

Usage

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

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    //Current position should survive screen rotations.
    if (savedInstanceState != null) {
        mCategory = savedInstanceState.getInt("category");
        mCurPosition = savedInstanceState.getInt("listPosition");
    }/*  ww w .  j a v  a 2  s .  c  o  m*/

    populateTitles(mCategory);
    ListView lv = getListView();
    lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    lv.setCacheColorHint(Color.TRANSPARENT);
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
            final String title = (String) ((TextView) v).getText();

            // Set up clip data with the category||entry_id format.
            final String textData = String.format("%d||%d", mCategory, pos);
            ClipData data = ClipData.newPlainText(title, textData);
            v.startDrag(data, new MyDragShadowBuilder(v), null, 0);
            return true;
        }
    });

    selectPosition(mCurPosition);
}

From source file:com.z299studio.pb.EditFragment.java

@Override
public boolean onLongClick(View v) {
    ClipData not_used_clip = ClipData.newPlainText("", "");
    v.startDrag(not_used_clip, new View.DragShadowBuilder(v), v, 0);
    // DragEvent.ACTION_DRAG_STARTED not called in drag event dispatch.
    // Handle it here.
    mDragListener.startDrag(v);//from ww w . ja  va 2 s.  c o  m
    return true;
}

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

private int addDraggableNote(float x, float y) {
    int viewId = getChildCount();
    TextView textView = new TextView(getContext());
    textView.setTextColor(mColor);//  w  ww.  ja v  a  2 s .c  o m
    textView.setTextSize(10 + mSize * 2);
    textView.setX(x);
    textView.setY(y);
    textView.setId(viewId);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showTextInputDialog(v.getId(), ((TextView) v).getText().toString());
        }
    });
    textView.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            ClipData data = ClipData.newPlainText(String.valueOf(v.getId()), "");
            View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
            v.startDrag(data, shadowBuilder, null, 0);
            return true;
        }
    });
    addView(textView);
    return viewId;
}

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

@SuppressWarnings("deprecation")
private void setClickListeners(View view, final String appName, final int appIndex) {

    // Start a drag action when icon is long clicked
    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override/*from ww  w .j a v a 2  s.com*/
        public boolean onLongClick(View view) {

            // Add data to the clipboard
            String[] mime_type = { ClipDescription.MIMETYPE_TEXT_PLAIN };
            ClipData data = new ClipData(Constants.DRAG_APP_MOVE, mime_type, new ClipData.Item(appName));
            data.addItem(new ClipData.Item(Integer.toString(appIndex)));
            data.addItem(new ClipData.Item(getTag()));

            // The drag shadow is simply the app's  icon
            View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
                    view.findViewById(R.id.item_app_icon));

            // "This method was deprecated in API level 24. Use startDragAndDrop()
            // for newer platform versions."
            if (Build.VERSION.SDK_INT < 24) {
                view.startDrag(data, shadowBuilder, view, 0);
            } else {
                view.startDragAndDrop(data, shadowBuilder, view, 0);
            }
            return true;

        }
    });

    // Start the app activity when icon is clicked.
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = mPacMan.getLaunchIntentForPackage(appName);
            startActivity(i);
        }
    });
}

From source file:com.svpino.longhorn.fragments.StockListFragment.java

@TargetApi(11)
private void startDraggingTile(View tile) {
    StockTileViewHolder stockTileViewHolder = (StockTileViewHolder) tile.getTag();
    this.selectedTiles.remove((Integer) stockTileViewHolder.getPosition());
    updateContextualActionBar();//from   w  w w  .jav a2s  . c o  m

    ClipData.Item item = new ClipData.Item(stockTileViewHolder.toString());
    ClipData clipData = new ClipData(stockTileViewHolder.toString(), new String[0], item);

    View.DragShadowBuilder dragShadowBuilder = new DragShadowBuilder(tile);
    tile.startDrag(clipData, dragShadowBuilder, tile, 0);
}

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

@SuppressWarnings("deprecation")
private void updateShortcuts() {
    int count = appsList.size();
    int size = (int) Math.ceil(Math.sqrt(count));
    shortcutLayout.removeAllViews();//from w  w  w  .j  a v  a  2  s  .co m

    if (size == 0) {
        size = 1;
    }

    // Redraw the layout
    shortcutLayout.setSize(size);
    shortcutLayout.requestLayout();
    shortcutLayout.invalidate();

    for (int i = 0; i < appsList.size(); i++) {
        final AppDetail app = appsList.get(i);
        View convertView = getActivity().getLayoutInflater().inflate(R.layout.shortcut_item, null);

        // load the app icon in an async task
        ImageView im = (ImageView) convertView.findViewById(R.id.item_app_icon);
        Utils.loadAppIconAsync(mPacMan, app.name.toString(), im);

        TextView tv = (TextView) convertView.findViewById(R.id.item_app_label);
        tv.setText(app.label);
        shortcutLayout.addView(convertView);

        convertView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
                switch (MotionEventCompat.getActionMasked(event)) {
                case MotionEvent.ACTION_DOWN:
                    updateTouchDown(event);
                    break;

                case MotionEvent.ACTION_MOVE:
                    tryConsumeSwipe(event);
                    break;

                case MotionEvent.ACTION_UP:
                    // We only want to launch the activity if the touch was not consumed yet!
                    if (!touchConsumed) {
                        Intent i = mPacMan.getLaunchIntentForPackage(app.name.toString());
                        startActivity(i);
                    }
                    break;
                }

                return touchConsumed;
            }
        });

        // start a drag when an app has been long clicked
        final long appId = app.id;
        final int appIndex = i;
        convertView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                String[] mime_types = { ClipDescription.MIMETYPE_TEXT_PLAIN };
                ClipData data = new ClipData(Constants.DRAG_SHORTCUT_REMOVAL, mime_types,
                        new ClipData.Item(Long.toString(appId)));

                data.addItem(new ClipData.Item(Integer.toString(appIndex)));

                View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
                        view.findViewById(R.id.item_app_icon));

                // "This method was deprecated in API level 24. Use startDragAndDrop()
                // for newer platform versions."
                if (Build.VERSION.SDK_INT < 24) {
                    view.startDrag(data, shadowBuilder, view, 0);
                } else {
                    view.startDragAndDrop(data, shadowBuilder, view, 0);
                }

                // Show removal indicator
                FrameLayout rem_ind = (FrameLayout) rootView.findViewById(R.id.remove_indicator);
                rem_ind.setVisibility(View.VISIBLE);
                AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
                animation.setDuration(500);
                rem_ind.startAnimation(animation);
                return true;

            }
        });
    }
}

From source file:com.android.systemui.qs.QSDragPanel.java

@Override
public boolean onLongClick(View v) {
    final DragTileRecord record = (DragTileRecord) getRecord(v);
    if (record == null) {
        // TODO couldn't find a matching tag?
        Log.e(TAG, "got a null record on touch down.");
        return false;
    }/* w w  w.ja va2s  .  c  om*/

    mDraggingRecord = record;

    mDraggingRecord.tileView.setAlpha(0);
    mDraggingRecord.tileView.setDual(false, false);
    TileShadow mTileShadow = new TileShadow(mDraggingRecord.tileView);

    v.startDrag(null, mTileShadow, null, 0);

    mViewPager.requestDisallowInterceptTouchEvent(true);

    onStartDrag();
    mDragging = true;
    return true;
}

From source file:com.launcher.silverfish.launcher.homescreen.HomeScreenFragment.java

@SuppressWarnings("deprecation")
private void updateShortcuts() {
    int count = appsList.size();
    int size = (int) Math.ceil(Math.sqrt(count));
    shortcutLayout.removeAllViews();/*from w ww.j a v a  2s .  c  o  m*/

    if (size == 0) {
        size = 1;
    }

    // Redraw the layout
    shortcutLayout.setSize(size);
    shortcutLayout.requestLayout();
    shortcutLayout.invalidate();

    for (int i = 0; i < appsList.size(); i++) {
        final AppDetail app = appsList.get(i);
        View convertView = getActivity().getLayoutInflater().inflate(R.layout.shortcut_item, null);

        // load the app icon in an async task
        ImageView im = (ImageView) convertView.findViewById(R.id.item_app_icon);
        Utils.loadAppIconAsync(mPacMan, app.packageName.toString(), im);

        TextView tv = (TextView) convertView.findViewById(R.id.item_app_label);
        tv.setText(app.label);
        shortcutLayout.addView(convertView);

        convertView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
                switch (MotionEventCompat.getActionMasked(event)) {
                case MotionEvent.ACTION_DOWN:
                    updateTouchDown(event);
                    break;

                case MotionEvent.ACTION_MOVE:
                    tryConsumeSwipe(event);
                    break;

                case MotionEvent.ACTION_UP:
                    // We only want to launch the activity if the touch was not consumed yet!
                    if (!touchConsumed) {
                        Intent i = mPacMan.getLaunchIntentForPackage(app.packageName.toString());
                        if (i != null) {
                            // Sanity check (application may have been uninstalled)
                            // TODO Remove it from the database
                            startActivity(i);
                        } else {
                            Toast.makeText(getContext(), R.string.application_not_installed, Toast.LENGTH_SHORT)
                                    .show();
                        }
                    }
                    break;
                }

                return touchConsumed;
            }
        });

        // start a drag when an app has been long clicked
        final long appId = app.id;
        final int appIndex = i;
        convertView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                String[] mime_types = { ClipDescription.MIMETYPE_TEXT_PLAIN };
                ClipData data = new ClipData(Constants.DRAG_SHORTCUT_REMOVAL, mime_types,
                        new ClipData.Item(Long.toString(appId)));

                data.addItem(new ClipData.Item(Integer.toString(appIndex)));

                View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
                        view.findViewById(R.id.item_app_icon));

                // "This method was deprecated in API level 24. Use startDragAndDrop()
                // for newer platform versions."
                if (Build.VERSION.SDK_INT < 24) {
                    view.startDrag(data, shadowBuilder, view, 0);
                } else {
                    view.startDragAndDrop(data, shadowBuilder, view, 0);
                }

                // Show removal indicator
                FrameLayout rem_ind = (FrameLayout) rootView.findViewById(R.id.remove_indicator);
                rem_ind.setVisibility(View.VISIBLE);
                AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
                animation.setDuration(500);
                rem_ind.startAnimation(animation);
                return true;

            }
        });
    }
}