本文整理匯總了Java中android.view.DragEvent.getClipDescription方法的典型用法代碼示例。如果您正苦於以下問題:Java DragEvent.getClipDescription方法的具體用法?Java DragEvent.getClipDescription怎麽用?Java DragEvent.getClipDescription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.DragEvent
的用法示例。
在下文中一共展示了DragEvent.getClipDescription方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validateDrag
import android.view.DragEvent; //導入方法依賴的package包/類
/**
* Tests to see if the drop will be accepted by Launcher, and if so, includes additional data
* in the returned structure related to the widgets that match the drop (or a null list if it is
* a shortcut drop). If the drop is not accepted then a null structure is returned.
*/
private Pair<Integer, List<WidgetMimeTypeHandlerData>> validateDrag(DragEvent event) {
final LauncherModel model = mLauncher.getModel();
final ClipDescription desc = event.getClipDescription();
final int mimeTypeCount = desc.getMimeTypeCount();
for (int i = 0; i < mimeTypeCount; ++i) {
final String mimeType = desc.getMimeType(i);
if (mimeType.equals(InstallShortcutReceiver.SHORTCUT_MIMETYPE)) {
return new Pair<Integer, List<WidgetMimeTypeHandlerData>>(i, null);
} else {
final List<WidgetMimeTypeHandlerData> widgets =
model.resolveWidgetsForMimeType(mContext, mimeType);
if (widgets.size() > 0) {
return new Pair<Integer, List<WidgetMimeTypeHandlerData>>(i, widgets);
}
}
}
return null;
}
示例2: processDragStarted
import android.view.DragEvent; //導入方法依賴的package包/類
boolean processDragStarted(DragEvent event) {
// Determine whether to continue processing drag and drop based on the
// plain text mime type.
ClipDescription clipDesc = event.getClipDescription();
if (clipDesc != null) {
return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
}
return false;
}
示例3: handleSystemDragStart
import android.view.DragEvent; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.N)
private void handleSystemDragStart(DragEvent event) {
if (!FeatureFlags.LAUNCHER3_USE_SYSTEM_DRAG_DRIVER || !Utilities.isNycOrAbove()) {
return;
}
if (mLauncher.isWorkspaceLocked()) {
return;
}
ClipDescription description = event.getClipDescription();
if (!description.hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
return;
}
ShortcutInfo info = new ShortcutInfo();
// Set a dummy intent until we get the final value
info.intent = new Intent();
// Since we are not going through the workspace for starting the drag, set drag related
// information on the workspace before starting the drag.
ExternalDragPreviewProvider previewProvider =
new ExternalDragPreviewProvider(mLauncher, info);
mLauncher.getWorkspace().prepareDragWithProvider(previewProvider);
DragOptions options = new DragOptions();
options.systemDndStartPoint = new Point((int) event.getX(), (int) event.getY());
int halfPadding = previewProvider.previewPadding / 2;
mDragController.startDrag(
Bitmap.createBitmap(1, 1, Config.ARGB_8888),
0, 0,
new AnotherWindowDragSource(mLauncher), info,
new Point(- halfPadding, halfPadding),
previewProvider.getPreviewBounds(), 1f, options);
}
示例4: onDragStart
import android.view.DragEvent; //導入方法依賴的package包/類
private boolean onDragStart(DragEvent event) {
if (!mRequest.isValid()) {
return false;
}
ClipDescription desc = event.getClipDescription();
if (desc == null || !desc.hasMimeType(getMimeType())) {
return false;
}
final PendingAddItemInfo item;
if (mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_SHORTCUT) {
item = new PendingAddShortcutInfo(
new PinShortcutRequestActivityInfo(mRequest, mLauncher));
} else {
// mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET
LauncherAppWidgetProviderInfo providerInfo =
LauncherAppWidgetProviderInfo.fromProviderInfo(
mLauncher, mRequest.getAppWidgetProviderInfo(mLauncher));
final PinWidgetFlowHandler flowHandler =
new PinWidgetFlowHandler(providerInfo, mRequest);
item = new PendingAddWidgetInfo(providerInfo) {
@Override
public WidgetAddFlowHandler getHandler() {
return flowHandler;
}
};
}
View view = new View(mLauncher);
view.setTag(item);
Point downPos = new Point((int) event.getX(), (int) event.getY());
DragOptions options = new DragOptions();
options.systemDndStartPoint = downPos;
options.preDragCondition = this;
// We use drag event position as the screenPos for the preview image. Since mPreviewRect
// already includes the view position relative to the drag event on the source window,
// and the absolute position (position relative to the screen) of drag event is same
// across windows, using drag position here give a good estimate for relative position
// to source window.
PendingItemDragHelper dragHelper = new PendingItemDragHelper(view);
if (mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET) {
dragHelper.setPreview(getPreview(mRequest));
}
dragHelper.startDrag(new Rect(mPreviewRect),
mPreviewBitmapWidth, mPreviewViewWidth, downPos, this, options);
mDragStartTime = SystemClock.uptimeMillis();
return true;
}
示例5: onDragEvent
import android.view.DragEvent; //導入方法依賴的package包/類
@Override
public boolean onDragEvent(@NonNull DragEvent event) {
PlenProgramAdapter adapter = mAdapter.orElseThrow(AssertionError::new);
ClipDescription clipDescription = event.getClipDescription();
if (clipDescription == null || !DRAG_DATA_LABEL.equals(clipDescription.getLabel())) {
return false;
}
int x = (int) event.getX();
int y = (int) event.getY();
int position = pointToPosition(x, y);
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_ENTERED:
if (adapter.positionOfBlankRow() == INVALID_POSITION) {
adapter.moveBlankRowToLast();
}
break;
case DragEvent.ACTION_DRAG_LOCATION:
removeCallbacks(mRemoveBlankRowCallback);
// ドロップ予定地に空白行
if (position != INVALID_POSITION) {
View view = getChildAt(position - getFirstVisiblePosition());
double viewCenter = view.getY() + view.getHeight() / 2.;
if (Math.abs(y - viewCenter) < view.getHeight() / 2.) {
adapter.moveBlankRow(position);
}
}
// 端にドラッグすると自動スクロール
View child = getChildAt(0);
double scrollZone = child != null ? child.getHeight() : 0;
final int firstPosition = getFirstVisiblePosition();
final int lastPosition = getLastVisiblePosition();
if (y < scrollZone) smoothScrollToPosition(firstPosition - 1);
if (y > getHeight() - scrollZone) smoothScrollToPosition(lastPosition + 1);
break;
case DragEvent.ACTION_DROP:
getDragData(event.getClipData()).ifPresent(adapter::dropToBlankRow);
break;
case DragEvent.ACTION_DRAG_ENDED:
case DragEvent.ACTION_DRAG_EXITED:
adapter.removeBlankRow();
break;
}
return true;
}
示例6: onDragEvent
import android.view.DragEvent; //導入方法依賴的package包/類
/**
* @see View#onDragEvent(DragEvent)
*/
@TargetApi(Build.VERSION_CODES.N)
public boolean onDragEvent(DragEvent event) {
if (mNativeContentViewCore == 0 || Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
return false;
}
ClipDescription clipDescription = event.getClipDescription();
// text/* will match text/uri-list, text/html, text/plain.
String[] mimeTypes =
clipDescription == null ? new String[0] : clipDescription.filterMimeTypes("text/*");
if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) {
// TODO(hush): support dragging more than just text.
return mimeTypes != null && mimeTypes.length > 0
&& nativeIsTouchDragDropEnabled(mNativeContentViewCore);
}
StringBuilder content = new StringBuilder("");
if (event.getAction() == DragEvent.ACTION_DROP) {
// TODO(hush): obtain dragdrop permissions, when dragging files into Chrome/WebView is
// supported. Not necessary to do so for now, because only text dragging is supported.
ClipData clipData = event.getClipData();
final int itemCount = clipData.getItemCount();
for (int i = 0; i < itemCount; i++) {
ClipData.Item item = clipData.getItemAt(i);
content.append(item.coerceToStyledText(mContainerView.getContext()));
}
}
int[] locationOnScreen = new int[2];
mContainerView.getLocationOnScreen(locationOnScreen);
float xPix = event.getX() + mCurrentTouchOffsetX;
float yPix = event.getY() + mCurrentTouchOffsetY;
int xCss = (int) mRenderCoordinates.fromPixToDip(xPix);
int yCss = (int) mRenderCoordinates.fromPixToDip(yPix);
int screenXCss = (int) mRenderCoordinates.fromPixToDip(xPix + locationOnScreen[0]);
int screenYCss = (int) mRenderCoordinates.fromPixToDip(yPix + locationOnScreen[1]);
nativeOnDragEvent(mNativeContentViewCore, event.getAction(), xCss, yCss, screenXCss,
screenYCss, mimeTypes, content.toString());
return true;
}