谷歌官方笔记之 User Interface

UML Sequence

Critical Sectiion

private static class MyDragShadowBuilder extends View.DragShadowBuilder {

        private static Drawable shadow;

        public MyDragShadowBuilder(View v) {
            super(v);
            // Creates a draggable image that will fill the Canvas provided by the system.
            shadow = new ColorDrawable(Color.LTGRAY);
        }
        
        @Override
        public void onProvideShadowMetrics(Point size, Point touch) {
             int width, height;

            // Sets the width of the shadow to half the width of the original View
            width = getView().getWidth() / 2;

            // Sets the height of the shadow to half the height of the original View
            height = getView().getHeight() / 2;

            // The drag shadow is a ColorDrawable. This sets its dimensions to be the same as the
            // Canvas that the system will provide. As a result, the drag shadow will fill the
            // Canvas.
            shadow.setBounds(0, 0, width, height);

            // Sets the size parameter's width and height values. These get back to the system
            // through the size parameter.
            size.set(width, height);

            // Sets the touch point's position to be in the middle of the drag shadow
            touch.set(width / 2, height / 2);
        }

        @Override
        public void onDrawShadow(Canvas canvas) {
            shadow.draw(canvas);
        }
    }
imageView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
//              ClipData.Item item = new ClipData.Item(v.getTag().toString());
                // Create a new ClipData using the tag as a label, the plain text MIME type, and
                // the already-created item. This will create a new ClipDescription object within the
                // ClipData, and set its MIME type entry to "text/plain"
                ClipData data = ClipData.newPlainText("dot", "Dot : " + v.toString());
                v.startDrag(data, new MyDragShadowBuilder(v), v, 0);
                return false;
            }
        });
  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);
            String text = item.coerceToText(getContext()).toString();
            if (event.getLocalState() == (Object) this) {
                text += " : Dropped on self!";
            }
        }
    }

Valid DragEvent data by action type

getAction() getClipDescription() getLocalState() getX() getY() getClipData() getResult()
DRAG_STARTED
DRAG_ENTERED
DRAG_LOCATION
DRAG_EXITED
ACTION_DROP
DRAG_ENDED
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,665评论 2 45
  • 《浮生若梦》 运城学院 牛天志 鹂音初啼,譬如朝露,宛风微扬,融霭裹雾。 笑靥双花,粹比玉璞,飞翼若即,灵犀相护。...
    陈侠女阅读 2,844评论 0 8
  • 都说家长是孩子的第一任老师,因为家长的一言一行对孩子的影响往往是不教而学。 性教育一直是主流教育的忌讳尴尬之处,但...
    儿童性教育映尔阅读 7,895评论 0 0
  • 只有失去了,才知道拥有是多么值得珍惜。 之前听说过这样一句话:科技能够带来生活的便利,但带不来生活的意义。时至今日...
    菩灵阅读 3,332评论 0 0
  • BaseAdapter之ArrayAdapter ArrayAdapter是BaseAdapter的一个具体实现,...
    侯蛋蛋_阅读 19,182评论 1 10