当前位置: 首页>>代码示例>>Java>>正文


Java View.startDragAndDrop方法代码示例

本文整理汇总了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;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:52,代码来源:AddItemActivity.java

示例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);
}
 
开发者ID:elimu-ai,项目名称:egma-shapi,代码行数:13,代码来源:DragStarterPostNougatImpl.java


注:本文中的android.view.View.startDragAndDrop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。