android 1.6 launcher研究之Drag&Drop模型
2011-09-07 22:34
239 查看
参考: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)
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)
相关文章推荐
- Android -- Drag&&Drop
- android 1.6 launcher研究之launcher的左右滑动
- android 1.6 launcher研究之launcher的左右滑动
- 2011.06.08——— android 1.6 launcher研究之launcher的左右滑动
- android 1.6 launcher研究之修改worksapce上的屏数
- Android开发之Drag&Drop框架实现拖放手势
- android 1.6 launcher研究之自定义ViewGroup (转 2011.06.03(二)——— android 1.6 launcher研究之自定义ViewGroup )
- android 1.6 launcher研究之launcher的左右滑动
- Android开发之Drag&Drop框架实现拖放手势
- Android Launcher3(二) -- Drag拖动实现
- Android研究-Android的init启动到launcher启动-主要分析zygote服务
- Android Launcher研究(二)-----------Launcher为何物,究竟是干什么的?
- Window下拖放操作Drag & Drop 全解析
- Drag &Drop
- Launcher研究1之AndroidManifest.xml分析(转载)
- 四两拨千斤——Dijit Tree 拖拽(DnD, Drag & Drop)的精细控制
- 史上第二走心的 iOS11-Drag & Drop 教程
- Drag & Drop 全解析
- Silverlight & Blend动画设计系列八:拖放(Drag-Drop)操作与拖放行为(DragBehavior)
- Android 用户界面ImageView拖动复制(Drag and Drop)