android 1.6 launcher研究之Drag&Drop模型

 参考:http://blog.csdn.net/stonecao/archive/2011/06/02/6462357.aspx
http://blog.csdn.net/hmg25/archive/2011/03/02/6217659.aspx

研究了launcher的拖拽模型 里面重要的类 如下:

DragLayer:

public class DragLayer extends FrameLayout implements DragController {     }

DragController:

/*  * Copyright (C) 2008 The Android Open Source Project  *  * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *      http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */  package com.lp.launcher;  import android.view.View;  /**  * Interface for initiating a drag within a view or across multiple views.  *  */ public interface DragController {          /**      * Interface to receive notifications when a drag starts or stops      */     interface DragListener {                  /**          * A drag has begun          *           * @param v The view that is being dragged          * @param source An object representing where the drag originated          * @param info The data associated with the object that is being dragged          * @param dragAction The drag action: either {@link DragController#DRAG_ACTION_MOVE}          *        or {@link DragController#DRAG_ACTION_COPY}          */         void onDragStart(View v, DragSource source, Object info, int dragAction);                  /**          * The drag has eneded          */         void onDragEnd();     }          /**      * Indicates the drag is a move.      */     public static int DRAG_ACTION_MOVE = 0;      /**      * Indicates the drag is a copy.      */     public static int DRAG_ACTION_COPY = 1;      /**      * Starts a drag      *       * @param v The view that is being dragged      * @param source An object representing where the drag originated      * @param info The data associated with the object that is being dragged      * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or      *        {@link #DRAG_ACTION_COPY}      */     void startDrag(View v, DragSource source, Object info, int dragAction);          /**      * Sets the drag listner which will be notified when a drag starts or ends.      */     void setDragListener(DragListener l);          /**      * Remove a previously installed drag listener.      */     void removeDragListener(DragListener l); }

DragSource:

/*  * Copyright (C) 2008 The Android Open Source Project  *  * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *      http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */  package com.lp.launcher;  import android.view.View;  /**  * Interface defining an object that can originate a drag.  *  */ public interface DragSource {     void setDragger(DragController dragger);     void onDropCompleted(View target, boolean success); }

DropTarget:

/*  * Copyright (C) 2008 The Android Open Source Project  *  * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *      http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */  package com.lp.launcher;  import android.graphics.Rect;  /**  * Interface defining an object that can receive a drag.  *  */ public interface DropTarget {      /**      * Handle an object being dropped on the DropTarget      *       * @param source DragSource where the drag started      * @param x X coordinate of the drop location      * @param y Y coordinate of the drop location      * @param xOffset Horizontal offset with the object being dragged where the original touch happened      * @param yOffset Vertical offset with the object being dragged where the original touch happened      * @param dragInfo Data associated with the object being dragged      *       */     void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo);          void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo);      void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo);      void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo);      /**      * Check if a drop action can occur at, or near, the requested location.      * This may be called repeatedly during a drag, so any calls should return      * quickly.      *       * @param source DragSource where the drag started      * @param x X coordinate of the drop location      * @param y Y coordinate of the drop location      * @param xOffset Horizontal offset with the object being dragged where the      *            original touch happened      * @param yOffset Vertical offset with the object being dragged where the      *            original touch happened      * @param dragInfo Data associated with the object being dragged      * @return True if the drop will be accepted, false otherwise.      */     boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo);      /**      * Estimate the surface area where this object would land if dropped at the      * given location.      *       * @param source DragSource where the drag started      * @param x X coordinate of the drop location      * @param y Y coordinate of the drop location      * @param xOffset Horizontal offset with the object being dragged where the      *            original touch happened      * @param yOffset Vertical offset with the object being dragged where the      *            original touch happened      * @param dragInfo Data associated with the object being dragged      * @param recycle {@link Rect} object to be possibly recycled.      * @return Estimated area that would be occupied if object was dropped at      *         the given location. Should return null if no estimate is found,      *         or if this target doesn't provide estimations.      */     Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo, Rect recycle); }


这几个类 是必须的类  

大致的处理流程 我以把应用拖到桌面上为例 :


 

 


 

2011-8-15 09:16:30 上传
下载附件 (0 Bytes)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值