本文整理汇总了Java中android.view.DragEvent类的典型用法代码示例。如果您正苦于以下问题:Java DragEvent类的具体用法?Java DragEvent怎么用?Java DragEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DragEvent类属于android.view包,在下文中一共展示了DragEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDrag
import android.view.DragEvent; //导入依赖的package包/类
@Override
public boolean onDrag(View view, DragEvent event) {
if (mLauncher == null || mDragController == null) {
postCleanup();
return false;
}
if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) {
if (onDragStart(event)) {
return true;
} else {
postCleanup();
return false;
}
}
return mDragController.onDragEvent(mDragStartTime, event);
}
示例2: recordDragEvent
import android.view.DragEvent; //导入依赖的package包/类
/**
* Same as {@link #recordMotionEvent}. It creates a temporary {@link MotionEvent} object
* using {@param event} for tracking velocity.
*/
void recordDragEvent(long dragStartTime, DragEvent event) {
final int motionAction;
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
motionAction = MotionEvent.ACTION_DOWN;
break;
case DragEvent.ACTION_DRAG_LOCATION:
motionAction = MotionEvent.ACTION_MOVE;
break;
case DragEvent.ACTION_DRAG_ENDED:
motionAction = MotionEvent.ACTION_UP;
break;
default:
return;
}
MotionEvent emulatedEvent = MotionEvent.obtain(dragStartTime, SystemClock.uptimeMillis(),
motionAction, event.getX(), event.getY(), 0);
recordMotionEvent(emulatedEvent);
emulatedEvent.recycle();
}
示例3: dispatchDragEvent
import android.view.DragEvent; //导入依赖的package包/类
@Override
public boolean dispatchDragEvent(DragEvent e) {
ContentViewCore contentViewCore = mTabVisible.getContentViewCore();
if (contentViewCore == null) return false;
if (mLayoutManager != null) mLayoutManager.getViewportPixel(mCacheViewport);
contentViewCore.setCurrentTouchEventOffsets(-mCacheViewport.left, -mCacheViewport.top);
boolean ret = super.dispatchDragEvent(e);
int action = e.getAction();
if (action == DragEvent.ACTION_DRAG_EXITED || action == DragEvent.ACTION_DRAG_ENDED
|| action == DragEvent.ACTION_DROP) {
contentViewCore.setCurrentTouchEventOffsets(0.f, 0.f);
}
return ret;
}
示例4: continueDragging
import android.view.DragEvent; //导入依赖的package包/类
/**
* Continue dragging the currently moving block. Called during ACTION_DRAG_LOCATION.
*
* @param event The next drag event to handle, as received by the {@link WorkspaceView}.
*/
private void continueDragging(DragEvent event) {
updateBlockPosition(event);
// highlight as we go
BlockView highlightedBlockView = mHighlightedBlockViewRef.get();
if (highlightedBlockView != null) {
highlightedBlockView.setHighlightedConnection(null);
}
Pair<Connection, Connection> connectionCandidate =
findBestConnection(mPendingDrag.getRootDraggedBlock());
if (connectionCandidate != null) {
highlightedBlockView = mViewHelper.getView(connectionCandidate.second.getBlock());
mHighlightedBlockViewRef = new WeakReference<>(highlightedBlockView);
highlightedBlockView.setHighlightedConnection(connectionCandidate.second);
}
mPendingDrag.getDragGroup().requestLayout();
}
示例5: updateBlockPosition
import android.view.DragEvent; //导入依赖的package包/类
/**
* Move the currently dragged block in response to a new {@link MotionEvent}.
* <p/>
* 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;
mViewHelper.virtualViewToWorkspaceCoordinates(
curDragLocationPixels, curDragPositionWorkspace);
WorkspacePoint touchDownWorkspace = mPendingDrag.getTouchDownWorkspaceCoordinates();
// Subtract original drag location from current location to get delta
float workspaceDeltaX = curDragPositionWorkspace.x - touchDownWorkspace.x;
float workspaceDeltaY = curDragPositionWorkspace.y - touchDownWorkspace.y;
WorkspacePoint blockOrigPosition = mPendingDrag.getOriginalBlockPosition();
mPendingDrag.getRootDraggedBlock().setPosition(blockOrigPosition.x + workspaceDeltaX,
blockOrigPosition.y + workspaceDeltaY);
mPendingDrag.getDragGroup().requestLayout();
}
示例6: setOnDragListener
import android.view.DragEvent; //导入依赖的package包/类
@Override
public void setOnDragListener(final View.OnDragListener dragListener) {
View.OnDragListener wrapper = new OnDragListener() {
@Override
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);
}
示例7: QuickRow
import android.view.DragEvent; //导入依赖的package包/类
public QuickRow(final View.OnDragListener dragListener, MainActivity mainActivity) {
mMainActivity = mainActivity;
mQuickRow = mMainActivity.findViewById(R.id.layout_quickrow);
mQuickRowScroller = mMainActivity.findViewById(R.id.layout_quickrow_scroll);
mQuickRow.setOnDragListener(dragListener);
mQuickRowScroller.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View view, DragEvent dragEvent) {
return dragListener.onDrag(mQuickRow, dragEvent);
}
});
}
示例8: onCreate
import android.view.DragEvent; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setWindowAnimations(R.style.animation_baseDialog);
setContentView(R.layout.video_edit_text_input);
mEditText = (EditText) findViewById(android.R.id.edit);
mConfirmButton = (ImageView) findViewById(R.id.text_edit_confirm_button);
mBackImg = (ImageView) findViewById(R.id.back_img);
mEditText.setText(mExistText);
mEditText.setSelection(mExistText.length());
mEditText.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
return true;
}
});
}
示例9: onDrag
import android.view.DragEvent; //导入依赖的package包/类
@Override
public boolean onDrag(View view, DragEvent dragEvent) {
switch (dragEvent.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
AttachmentsProvider provider =
AttachmentsProviderFactory.getAttachmentProvider(getContext());
return mCallback != null && provider.isSupported();
case DragEvent.ACTION_DRAG_ENTERED:
setBackgroundColor(ContextCompat.getColor(getContext(), R.color.attachmentOverlay));
return isValidDragEvent(dragEvent.getClipData());
case DragEvent.ACTION_DRAG_ENDED:
setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
return true;
case DragEvent.ACTION_DRAG_EXITED:
case DragEvent.ACTION_DRAG_LOCATION:
return true;
case DragEvent.ACTION_DROP:
if (isValidDragEvent(dragEvent.getClipData())) {
final List<Attachment> attachments = extractAttachments(dragEvent.getClipData());
post(() -> mCallback.onAttachmentsDropped(attachments));
return true;
}
// Fallback
}
return false;
}
示例10: onDragEvent
import android.view.DragEvent; //导入依赖的package包/类
/**
* Handles drag event.
*/
@Override
public boolean onDragEvent(DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// Only handle plain text drag and drop.
return event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
case DragEvent.ACTION_DRAG_ENTERED:
requestFocus();
return true;
case DragEvent.ACTION_DROP:
handlePasteClip(event.getClipData());
return true;
}
return false;
}
示例11: dispatchDragEvent
import android.view.DragEvent; //导入依赖的package包/类
@Override
public boolean dispatchDragEvent(DragEvent ev) {
final DragEvent event = ev;
boolean r = super.dispatchDragEvent(ev);
if (r && (ev.getAction() == DragEvent.ACTION_DRAG_STARTED || ev.getAction() == DragEvent.ACTION_DRAG_ENDED)) {
// If we got a start or end and the return value is true, our
// onDragEvent wasn't called by ViewGroup.dispatchDragEvent
// So we do it here.
this.post(new Runnable() {
@Override
public void run() {
onDragEvent(event);
}
});
// fix crash on older versions of android
try {
super.dispatchDragEvent(ev);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
return r;
}
示例12: handleDragEvent
import android.view.DragEvent; //导入依赖的package包/类
private boolean handleDragEvent(final View v, final DragEvent event) {
switch(event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
case DragEvent.ACTION_DRAG_ENTERED:
case DragEvent.ACTION_DRAG_LOCATION:
case DragEvent.ACTION_DRAG_EXITED:
case DragEvent.ACTION_DRAG_ENDED:
return true;
case DragEvent.ACTION_DROP:
final String phrase = event.getClipData().getItemAt(0).getText().toString();
moveViewToCorrectLocationFromDrag(v, phrase);
return true;
default:
return false;
}
}
示例13: onDragEvent
import android.view.DragEvent; //导入依赖的package包/类
@Override
public boolean onDragEvent(DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
return mEditor != null && mEditor.hasInsertionController();
case DragEvent.ACTION_DRAG_ENTERED:
TextView.this.requestFocus();
return true;
case DragEvent.ACTION_DRAG_LOCATION:
final int offset = getOffsetForPosition(event.getX(), event.getY());
Selection.setSelection((Spannable)mText, offset);
return true;
case DragEvent.ACTION_DROP:
if (mEditor != null) mEditor.onDrop(event);
return true;
case DragEvent.ACTION_DRAG_ENDED:
case DragEvent.ACTION_DRAG_EXITED:
default:
return true;
}
}
示例14: getDragEventType
import android.view.DragEvent; //导入依赖的package包/类
/**
* 获取拖拽触发的执行事件类型
*
* @param draggedViewPager 最外层 {@link com.bigfat.draggedviewpager.view.MDA_DraggedViewPager}
* @param currentPageIndex 当前页索引
* @param pageIndex 响应拖拽事件item所在页索引
* @param view 响应拖拽事件的item
* @param event 拖拽事件
* @return 拖拽事件类型
*/
public static DragEventType getDragEventType(MDA_DraggedViewPager draggedViewPager, int currentPageIndex, int pageIndex,
View view, DragEvent event) {
if (currentPageIndex > 0//有上一页
&& (draggedViewPager.getPageDragSetting() == null || draggedViewPager.getPageDragSetting()
.canBeSwiped(currentPageIndex - 1))//上一页可被交换
//触摸至上一页//或至触摸至当前页左边界,则切换到上一页
&& (pageIndex < currentPageIndex || (pageIndex == currentPageIndex && event.getX() < view.getWidth() / 8))) {
return DragEventType.SCROLL_PREVIOUS;
} else if (currentPageIndex < (draggedViewPager.getContainer().getChildCount() - 1)//在有下一页的前提下
&& (draggedViewPager.getPageDragSetting() == null || draggedViewPager.getPageDragSetting()
.canBeSwiped(currentPageIndex + 1))//下一页可被交换
//触摸至下一页//或至触摸至当前页右边界,则切换到下一页
&& (pageIndex > currentPageIndex || (pageIndex == currentPageIndex && event.getX() > view.getWidth() / 8 * 7))) {
return DragEventType.SCROLL_NEXT;
}
return DragEventType.DEFAULT;
}
示例15: dragLocation
import android.view.DragEvent; //导入依赖的package包/类
private boolean dragLocation(View v, DragEvent event) {
Projection p = mapView.getProjection();
LatLng latLng = (LatLng) p.fromPixels(event.getX(), event.getY());
this.activeVertex.getOwner().setLatLng(this.activeIndex, latLng);
// Let implementing classes perform reset action.
this.activeVertex.getOwner().reset();
Vertex vertex = vertices.get(selected);
Vertex prev = vertex.getPrev();
Vertex next = vertex.getNext();
if (prev != null && !prev.equals(vertex)) {
vertex.getMiddleLeft().setPoint(getMiddleLatLng(prev.getPoint(), latLng));
}
if (next != null && !next.equals(vertex)) {
vertex.getMiddleRight().setPoint(getMiddleLatLng(latLng, next.getPoint()));
}
// Invalidating the view causes a redraw.
v.invalidate();
return true;
}