當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。