Android DragEvent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android DragEvent class.

This code example shows how to use the following methods: getAction, getClipData
        } 
 
        @Override 
        public boolean onDragEvent(DragEvent event) {
            if (DEBUG) Slog.d(TAG, "onDragEvent: " + event);
            switch (event.getAction()) {
                // We want to appear whenever a potential drag takes off from anywhere in the UI. 
                case DragEvent.ACTION_DRAG_STARTED:
                    show(true); 
                    break; 
                case DragEvent.ACTION_DRAG_ENTERED:
                    if (DEBUG) Slog.d(TAG, "entered!");
                    // XXX: TODO 
                    break; 
                case DragEvent.ACTION_DRAG_EXITED:
                    if (DEBUG) Slog.d(TAG, "exited!");
                    break; 
                case DragEvent.ACTION_DROP:
                    if (DEBUG) Slog.d(TAG, "dropped!");
                    mPocket.stash(event.getClipData());

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAction, getClipData, getLocalState, getX, getY
	} 
 
	@Override 
	public boolean onDrag(View v, DragEvent event)
	{ 
		switch (event.getAction())
		{ 
		case DragEvent.ACTION_DRAG_STARTED: 
			Log.d("drag", "registered");
			break; 
			 
		case DragEvent.ACTION_DRAG_ENTERED:
				 
			break; 
 
		case DragEvent.ACTION_DRAG_LOCATION:
			break; 
 
		case DragEvent.ACTION_DRAG_ENDED:
			 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAction, getLocalState, getX, getY
    } 
	 
	private class PlaceDragListener implements OnDragListener {
		@Override 
		public boolean onDrag(View v, DragEvent event) {
			switch (event.getAction()) {
			    case DragEvent.ACTION_DROP:
			    	Toast.makeText(contextt, "ACTION_DROP", Toast.LENGTH_LONG).show();
			    	View view = (View) event.getLocalState();
			    	ViewGroup owner = (ViewGroup) view.getParent();
			    	owner.removeView(view);
			    	 
			    	FrameLayout container = (FrameLayout) v.getParent();
			        container.addView(view);
			        container.bringChildToFront(view);
			        view.setX((int)event.getX() + 5 - view.getWidth() / 2);
			        view.setY((int)event.getY() + 5 - view.getHeight() / 2);
			        view.setVisibility(View.VISIBLE);			        
			        break; 
			    default : 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAction, getClipData, getX, getY
    	    private static final String DROPTAG = "DropTarget";
    		private int dropCount = 0;
			private ObjectAnimator anim;
 
			public boolean onDrag(View v, DragEvent event) {
				int action = event.getAction();
				boolean result = true;
				switch(action) {
				case DragEvent.ACTION_DRAG_STARTED:
					Log.v(DROPTAG, "drag started in dropTarget");
		            break; 
				case DragEvent.ACTION_DRAG_ENTERED:
					Log.v(DROPTAG, "drag entered dropTarget");
				    anim = ObjectAnimator.ofFloat((Object)v, "alpha", 1f, 0.5f);
				    anim.setInterpolator(new CycleInterpolator(40));
				    anim.setDuration(30*1000); // 30 seconds
				    anim.start();
		            break; 
				case DragEvent.ACTION_DRAG_EXITED:
					Log.v(DROPTAG, "drag exited dropTarget");

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAction, getClipData, getX, getY
			private static final String DROPTAG = "DropTarget";
			private int dropCount = 0;
			private ObjectAnimator anim;
 
			public boolean onDrag(View v, DragEvent event) {
				int action = event.getAction();
				boolean result = true;
				switch (action) {
				case DragEvent.ACTION_DRAG_STARTED:
					Log.v(DROPTAG, "drag started in dropTarget");
					break; 
				case DragEvent.ACTION_DRAG_ENTERED:
					Log.v(DROPTAG, "drag entered dropTarget");
					anim = ObjectAnimator
							.ofFloat((Object) v, "alpha", 1f, 0.5f);
					anim.setInterpolator(new CycleInterpolator(40));
					anim.setDuration(30 * 1000); // 30 seconds
					anim.start();
					break; 
				case DragEvent.ACTION_DRAG_EXITED:

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAction, getLocalState, getResult
		textData = (TextView)findViewById(R.id.textView1);
	} 
 
	@Override 
    public boolean onDrag(View view, DragEvent dragEvent) {
        int dragAction = dragEvent.getAction();
        ListViewItem lView = (ListViewItem) view;
        ListViewItem dragView = (ListViewItem) dragEvent.getLocalState();
        if (dragAction == DragEvent.ACTION_DRAG_EXITED) {
            containsDragable = false;
        } else if (dragAction == DragEvent.ACTION_DRAG_ENTERED) {
            containsDragable = true;
        } else if (dragAction == DragEvent.ACTION_DRAG_ENDED) {
            if (dropEventNotHandled(dragEvent)) {
                dragView.setVisibility(View.VISIBLE);
            } 
        } else if (dragAction == DragEvent.ACTION_DROP && containsDragable) {
        	adapter.replace(lView.getData(), dragView.getData());
        } 
        return true; 

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAction
        return super.onTouch(v, event);
    } 
     
    @Override 
    public boolean onDrag(View v, DragEvent event) {
        boolean flag = super.onDrag(v, event);
        switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_EXITED:
        case DragEvent.ACTION_DROP:
        case DragEvent.ACTION_DRAG_ENDED:
            v.setBackgroundColor(Color.TRANSPARENT);
        } 
        return flag;
    } 
     
    @Override 
    public int getFirstVisiblePosition() { 
		return mSimpleListView.getFirstVisiblePosition();
	} 
     
Full Snippet Info
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAction, getX, getY
			 
			@Override 
			public boolean onDrag(View v, DragEvent event) {
 
			    boolean result = true;
			    int action = event.getAction();
			    float x = event.getX();
			    float y = event.getY();
			    v.setX(x);
			    v.setY(y);
			    switch (action) {
			    case DragEvent.ACTION_DRAG_STARTED:
			    	Log.d("START", "START");
			      break; 
			    case DragEvent.ACTION_DRAG_LOCATION:
			    	Log.d("LOCATION", "LOCATION");
			      break; 
			    case DragEvent.ACTION_DRAG_ENTERED:
			      break; 
			    case DragEvent.ACTION_DRAG_EXITED:
Full Snippet Info
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAction, getLocalState, getY
	} 
 
	// Drag and Drop 
	@Override 
	public boolean onDragEvent(DragEvent event) {
		int action = event.getAction();
		int vCenter = getHeight() / 2;
		switch (action) {
		case DragEvent.ACTION_DRAG_STARTED:
			return true; 
		case DragEvent.ACTION_DRAG_ENTERED:
			return true; 
		case DragEvent.ACTION_DRAG_LOCATION:
			if (event.getY() < vCenter) {
				// TODO: Highlight top borderline 
				setBackgroundResource(android.R.drawable.divider_horizontal_dark);
			} 
			else { 
				// TODO: Highlight bottom borderline 
				setBackgroundResource(android.R.drawable.divider_horizontal_dark);

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getAction, getLocalState, getResult
        Drawable normalShape = getResources().getDrawable(R.drawable.shape);
 
        @Override 
        public boolean onDrag(View v, DragEvent event) {
        	FrameLayout container = null;
            View view = (View) event.getLocalState();
        	ViewGroup owner = null;
        	 
            switch (event.getAction()) {
             
            case DragEvent.ACTION_DRAG_STARTED:
            	try { 
	            	container = (FrameLayout) v;
	            	if (container.getChildCount() < 1) {
	                    v.setBackgroundDrawable(validDropShape);
	            		return true; 
	            	} 
            	} 
            	catch (Exception e) {
            		Log.e("MainActivity", "ACTION DRAG STARTED failed", e);

5
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android DragEvent Questions & Answers:

Other Android DragEvent Examples

49:	
50:	    @Override
51:	    public boolean onDrag(View v, DragEvent event) {
52:	      int action = event.getAction();
53:	      switch (event.getAction()) {

Read More

See Code Examples for Android DragEvent Methods: