List of usage examples for android.view DragEvent ACTION_DRAG_ENDED
int ACTION_DRAG_ENDED
To view the source code for android.view DragEvent ACTION_DRAG_ENDED.
Click Source Link
From source file:com.google.blockly.android.ui.TrashCanView.java
@Override public void setOnDragListener(final View.OnDragListener dragListener) { View.OnDragListener wrapper = new OnDragListener() { @Override//from w w w .j av a2s .c o m public boolean onDrag(View view, DragEvent dragEvent) { int action = dragEvent.getAction(); // Whether the dragged object can be handled by the trash. boolean result = dragListener.onDrag(view, dragEvent); if (action == DragEvent.ACTION_DRAG_ENDED) { setState(STATE_DEFAULT); } else if (result) { switch (action) { case DragEvent.ACTION_DRAG_ENTERED: setState(STATE_ON_HOVER); break; case DragEvent.ACTION_DROP: case DragEvent.ACTION_DRAG_EXITED: setState(STATE_DEFAULT); break; } } return result; } }; super.setOnDragListener(wrapper); }
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. ja v a 2s.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.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 ww. j av a2 s. co 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:rosmi.acagild.alarmclock.ringing.AlarmRingingFragment.java
@Nullable @Override//w w w. j a v a2 s. co m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Logger.init(getActivity()); Bundle args = getArguments(); UUID alarmId = UUID.fromString(args.getString(ARGS_ALARM_ID)); mAlarm = AlarmList.get(getContext()).getAlarm(alarmId); View view = inflater.inflate(R.layout.fragment_alarm_ringing, container, false); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) { TextView timeField = (TextView) view.findViewById(R.id.alarm_ringing_time); timeField.setText(DateTimeUtilities.getUserTimeString(getContext(), mAlarm.getTimeHour(), mAlarm.getTimeMinute())); } TextView dateField = (TextView) view.findViewById(R.id.alarm_ringing_date); dateField.setText(DateTimeUtilities.getFullDateStringForNow()); String name = mAlarm.getTitle(); TextView titleField = (TextView) view.findViewById(R.id.alarm_ringing_title); titleField.setText(name); ImageView dismissButton = (ImageView) view.findViewById(R.id.alarm_ringing_dismiss); dismissButton.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: dismissAlarm(); break; case DragEvent.ACTION_DRAG_ENDED: if (mShowClockOnDragEnd) { mAlarmRingingClock.postDelayed(new Runnable() { @Override public void run() { mAlarmRingingClock.setVisibility(View.VISIBLE); } }, SHOW_CLOCK_AFTER_UNSUCCESSFUL_DRAG_DELAY); } break; default: break; } return true; } }); // Dismiss ringing if someone presses the dismiss button directly dismissButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismissAlarm(); } }); ImageView snoozeButton = (ImageView) view.findViewById(R.id.alarm_ringing_snooze); snoozeButton.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: mCallback.onRingingSnooze(); break; default: break; } return true; } }); // Snooze ringing if someone presses the snooze button directly snoozeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mCallback.onRingingSnooze(); } }); // Allow the view to listen to the drag event to update arrow animations accordingly view.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_LOCATION: // Update the left/right arrow visibility based on the current drag location. onClockDragLocation(event.getX(), event.getY(), v.getWidth() / 2); break; case DragEvent.ACTION_DROP: // The user has dropped the drag, but it is dropped within the view, instead of the target // drop zones to dismiss or snooze. // Restore to show both left arrow and right arrow animations. mDragZone = DragZone.NEAR_MIDDLE_OF_VIEW; updateArrowsBasedOnDragZone(mDragZone); break; default: break; } return true; } }); mAlarmRingingClock = (ImageView) view.findViewById(R.id.alarm_ringing_clock); mAlarmRingingClock.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ClipData dragData = ClipData.newPlainText("", ""); View.DragShadowBuilder shadow = new View.DragShadowBuilder(mAlarmRingingClock); mAlarmRingingClock.startDrag(dragData, shadow, null, 0); mAlarmRingingClock.setVisibility(View.INVISIBLE); return true; } else { return false; } } }); initializeClockAnimation(view); Loggable.AppAction appAction = new Loggable.AppAction(Loggable.Key.APP_ALARM_RINGING); appAction.putJSON(mAlarm.toJSON()); Logger.track(appAction); return view; }
From source file:com.microsoft.mimickeralarm.ringing.AlarmRingingFragment.java
@Nullable @Override//w w w . j a va 2s . c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Logger.init(getActivity()); Bundle args = getArguments(); UUID alarmId = UUID.fromString(args.getString(ARGS_ALARM_ID)); mAlarm = AlarmList.get(getContext()).getAlarm(alarmId); View view = inflater.inflate(R.layout.fragment_alarm_ringing, container, false); if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) { TextView timeField = (TextView) view.findViewById(R.id.alarm_ringing_time); timeField.setText(DateTimeUtilities.getUserTimeString(getContext(), mAlarm.getTimeHour(), mAlarm.getTimeMinute())); } TextView dateField = (TextView) view.findViewById(R.id.alarm_ringing_date); dateField.setText(DateTimeUtilities.getFullDateStringForNow()); String name = mAlarm.getTitle(); TextView titleField = (TextView) view.findViewById(R.id.alarm_ringing_title); titleField.setText(name); ImageView dismissButton = (ImageView) view.findViewById(R.id.alarm_ringing_dismiss); dismissButton.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: dismissAlarm(); break; case DragEvent.ACTION_DRAG_ENDED: if (mShowClockOnDragEnd) { mAlarmRingingClock.postDelayed(new Runnable() { @Override public void run() { mAlarmRingingClock.setVisibility(View.VISIBLE); } }, SHOW_CLOCK_AFTER_UNSUCCESSFUL_DRAG_DELAY); } break; default: break; } return true; } }); // Dismiss ringing if someone presses the dismiss button directly dismissButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismissAlarm(); } }); ImageView snoozeButton = (ImageView) view.findViewById(R.id.alarm_ringing_snooze); snoozeButton.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: mCallback.onRingingSnooze(); break; default: break; } return true; } }); // Snooze ringing if someone presses the snooze button directly snoozeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mCallback.onRingingSnooze(); } }); // Allow the view to listen to the drag event to update arrow animations accordingly view.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_LOCATION: // Update the left/right arrow visibility based on the current drag location. onClockDragLocation(event.getX(), event.getY(), v.getWidth() / 2); break; case DragEvent.ACTION_DROP: // The user has dropped the drag, but it is dropped within the view, instead of the target // drop zones to dismiss or snooze. // Restore to show both left arrow and right arrow animations. mDragZone = DragZone.NEAR_MIDDLE_OF_VIEW; updateArrowsBasedOnDragZone(mDragZone); break; default: break; } return true; } }); mAlarmRingingClock = (ImageView) view.findViewById(R.id.alarm_ringing_clock); mAlarmRingingClock.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ClipData dragData = ClipData.newPlainText("", ""); View.DragShadowBuilder shadow = new View.DragShadowBuilder(mAlarmRingingClock); mAlarmRingingClock.startDrag(dragData, shadow, null, 0); mAlarmRingingClock.setVisibility(View.INVISIBLE); return true; } else { return false; } } }); initializeClockAnimation(view); Loggable.AppAction appAction = new Loggable.AppAction(Loggable.Key.APP_ALARM_RINGING); appAction.putJSON(mAlarm.toJSON()); Logger.track(appAction); return view; }
From source file:com.launcher.silverfish.launcher.LauncherActivity.java
private void setDragListener() { mViewPager.setOnDragListener(new View.OnDragListener() { @Override/* w w w . java2s . co m*/ 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./*from www . j a 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;// w ww .ja v a 2 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/*from ww w. j ava2 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.HomeScreenFragment.java
private void setOnDragListener() { rootView.setOnDragListener(new View.OnDragListener() { @Override/*from w w w. j a va 2s .c om*/ 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; } }); }