本文整理汇总了Java中android.view.View.startDragAndDrop方法的典型用法代码示例。如果您正苦于以下问题:Java View.startDragAndDrop方法的具体用法?Java View.startDragAndDrop怎么用?Java View.startDragAndDrop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.startDragAndDrop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onLongClick
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onLongClick(View view) {
// Find the position of the preview relative to the touch location.
WidgetImageView img = mWidgetCell.getWidgetView();
// If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and
// we abort the drag.
if (img.getBitmap() == null) {
return false;
}
Rect bounds = img.getBitmapBounds();
bounds.offset(img.getLeft() - (int) mLastTouchPos.x, img.getTop() - (int) mLastTouchPos.y);
// Start home and pass the draw request params
PinItemDragListener listener = new PinItemDragListener(mRequest, bounds,
img.getBitmap().getWidth(), img.getWidth());
Intent homeIntent = new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME)
.setPackage(getPackageName())
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(PinItemDragListener.EXTRA_PIN_ITEM_DRAG_LISTENER, listener);
if (!PreferencesState.isAllowRotationPrefEnabled(this) &&
(getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE && !isInMultiWindowMode())) {
// If we are starting the drag in landscape even though home is locked in portrait,
// restart the home activity to temporarily allow rotation.
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
startActivity(homeIntent,
ActivityOptions.makeCustomAnimation(this, 0, android.R.anim.fade_out).toBundle());
// Start a system drag and drop. We use a transparent bitmap as preview for system drag
// as the preview is handled internally by launcher.
ClipDescription description = new ClipDescription("", new String[]{listener.getMimeType()});
ClipData data = new ClipData(description, new ClipData.Item(""));
view.startDragAndDrop(data, new DragShadowBuilder(view) {
@Override
public void onDrawShadow(Canvas canvas) { }
@Override
public void onProvideShadowMetrics(Point outShadowSize, Point outShadowTouchPoint) {
outShadowSize.set(SHADOW_SIZE, SHADOW_SIZE);
outShadowTouchPoint.set(SHADOW_SIZE / 2, SHADOW_SIZE / 2);
}
}, null, View.DRAG_FLAG_GLOBAL);
return false;
}
示例2: startDrag
import android.view.View; //导入方法依赖的package包/类
/**
* Used to start a drag on the given view.
*
* @param source view from which the drag motion is started.
* @param clipData data linked to the drag motion.
* @param shadow shadow displayed during the drag.
* @param token token.
* @param i flags.
*/
public static void startDrag(View source, ClipData clipData, View.DragShadowBuilder shadow, int token, int i) {
source.startDragAndDrop(clipData, shadow, token, i);
}