List of usage examples for android.view DragEvent getX
public float getX()
From source file:com.launcher.silverfish.launcher.LauncherActivity.java
private void changePage(DragEvent dragEvent) { // Change page mid drag if drag is within threshold int threshold = Constants.SCREEN_CORNER_THRESHOLD; // Get display size int width = Utils.getScreenDimensions(this).x; // Change page if (mViewPager.getCurrentItem() == 0 && dragEvent.getX() >= width - threshold) { mViewPager.setCurrentItem(1);/*from w w w.j a v a2s. c o m*/ } else if (mViewPager.getCurrentItem() == 1 && dragEvent.getX() <= threshold) { mViewPager.setCurrentItem(0); } }
From source file:com.jaspersoft.android.jaspermobile.widget.DraggableViewsContainer.java
@Override public boolean onDrag(View v, DragEvent event) { int viewId;/*w w w . j a v a 2s . c o m*/ View noteView; switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: viewId = Integer.parseInt(event.getClipDescription().getLabel().toString()); noteView = findViewById(viewId); noteView.setVisibility(View.GONE); return true; case DragEvent.ACTION_DROP: viewId = Integer.parseInt(event.getClipDescription().getLabel().toString()); noteView = findViewById(viewId); noteView.setX(event.getX() - noteView.getWidth() / 2); noteView.setY(event.getY() - noteView.getHeight() / 2); noteView.setVisibility(View.VISIBLE); return true; default: return false; } }
From source file:com.google.blockly.android.ui.Dragger.java
/** * Move the currently dragged block in response to a new {@link MotionEvent}. * <p/>//from w ww .j a va2 s. c om * All of the child blocks move with the root block based on its position during layout. * * @param event The {@link MotionEvent} to react to. */ private void updateBlockPosition(DragEvent event) { // The event is relative to the WorkspaceView. Grab the pixel offset within. ViewPoint curDragLocationPixels = mTempViewPoint; curDragLocationPixels.set((int) event.getX(), (int) event.getY()); WorkspacePoint curDragPositionWorkspace = mTempWorkspacePoint; mHelper.virtualViewToWorkspaceCoordinates(curDragLocationPixels, curDragPositionWorkspace); WorkspacePoint touchDownWorkspace = mPendingDrag.getTouchDownWorkspaceCoordinates(); // Subtract original drag location from current location to get delta int workspaceDeltaX = curDragPositionWorkspace.x - touchDownWorkspace.x; int workspaceDeltaY = curDragPositionWorkspace.y - touchDownWorkspace.y; WorkspacePoint blockOrigPosition = mPendingDrag.getOriginalBlockPosition(); mPendingDrag.getRootDraggedBlock().setPosition(blockOrigPosition.x + workspaceDeltaX, blockOrigPosition.y + workspaceDeltaY); mPendingDrag.getDragGroup().requestLayout(); }
From source file:com.google.blockly.android.ui.Dragger.java
/** * Check whether the given event occurred on top of the trash can button. Should be called from * {@link WorkspaceView}.// ww w . j ava 2 s. co m * * @param event The event whose location should be checked, with position in WorkspaceView * coordinates. * @return Whether the event was on top of the trash can button. */ // TODO(#210): Generalize this to other possible block drop targets. private boolean touchingTrashView(DragEvent event) { if (mTrashView == null) { return false; } mTrashView.getLocationOnScreen(mTempScreenCoord1); mTrashView.getHitRect(mTrashRect); mTrashRect.offset((mTempScreenCoord1[0] - mTrashRect.left), (mTempScreenCoord1[1] - mTrashRect.top)); // Get the touch location on the screen mTempViewPoint.set((int) event.getX(), (int) event.getY()); mHelper.virtualViewToScreenCoordinates(mTempViewPoint, mTempViewPoint); // Check if the touch location was on the trash return mTrashRect.contains(mTempViewPoint.x, mTempViewPoint.y); }
From source file:com.launcher.silverfish.HomeScreenFragment.java
private void setOnDragListener() { rootView.setOnDragListener(new View.OnDragListener() { @Override//from w ww. j av a 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; } }); }
From source file:com.launcher.silverfish.TabbedAppDrawerFragment.java
private void setOnDragListener() { rootView.setOnDragListener(new View.OnDragListener() { @Override//from ww w .j a v a 2 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//w w w .j ava 2 s. co 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; // 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; } }); }
From source file:rosmi.acagild.alarmclock.ringing.AlarmRingingFragment.java
@Nullable @Override/*from ww w . j a v a 2 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//from w w w . j a v a2 s . c om 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:app.umitems.greenclock.widget.sgv.StaggeredGridView.java
@Override public boolean onDragEvent(DragEvent ev) { if (!isDragReorderingSupported()) { // If the consumer of this StaggeredGridView has not registered a ReorderListener, // don't bother handling drag events. return false; }// ww w . ja v a 2 s . c o m final int x = (int) ev.getX(); final int y = (int) ev.getY(); switch (ev.getAction()) { case DragEvent.ACTION_DRAG_LOCATION: if (mDragState == ReorderUtils.DRAG_STATE_DRAGGING) { handleDrag(x, y); mLastTouchY = y; } // Kick off the scroll handler on the first drag location event, // if it's not already running if (!mIsDragScrollerRunning && // And if the distance traveled while dragging exceeds the touch slop ((Math.abs(x - mTouchDownForDragStartX) >= 4 * mTouchSlop) || (Math.abs(y - mTouchDownForDragStartY) >= 4 * mTouchSlop))) { // Set true because that the scroller is running now mIsDragScrollerRunning = true; if (mScrollHandler == null) { mScrollHandler = getHandler(); } mScrollHandler.postDelayed(mDragScroller, SCROLL_HANDLER_DELAY); } return true; case DragEvent.ACTION_DROP: case DragEvent.ACTION_DRAG_ENDED: // We can either expect to receive: // 1. Both {@link DragEvent#ACTION_DROP} and then // {@link DragEvent#ACTION_DRAG_ENDED} if the drop is over this view. // 2. Only {@link DragEvent#ACTION_DRAG_ENDED} if the drop happened over a // different view. // For this reason, we should always handle the drop. In case #1, if this code path // gets executed again then nothing will happen because we will have already // updated {@link #mDragState} to not be {@link ReorderUtils#DRAG_STATE_DRAGGING}. if (mScrollHandler != null) { mScrollHandler.removeCallbacks(mDragScroller); // Scroller is no longer running mIsDragScrollerRunning = false; } return true; } return false; }