01.
public
class
DockView
extends
LinearLayout
implements
DropTarget,DragSource, DragController.DragListener,OnClickListener, View.OnLongClickListener {
02.
/**
03.
* @author jezz
04.
*
05.
*/
06.
07.
public
DockView(Context context){
08.
super
(context);
09.
}
10.
11.
public
DockView(Context context, AttributeSet attrs) {
12.
super
(context, attrs);
13.
mDockBgId = R.drawable.shortcut_selector;
14.
}
15.
16.
public
void
init(){
17.
//初始化操作
18.
}
19.
20.
21.
public
boolean
acceptDrop(DragSource source,
int
x,
int
y,
int
xOffset,
int
yOffset, Object dragInfo) {
22.
//接受什么类型的图标
23.
final
ItemInfo item = (ItemInfo) dragInfo;
24.
if
(item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET
25.
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER
26.
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER
27.
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_WIDGET_PHOTO_FRAME
28.
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH
29.
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_WIDGET_CLOCK) {
30.
return
false
;
31.
}
32.
}
33.
34.
public
void
onDragEnter(DragSource source,
int
x,
int
y,
int
xOffset,
int
yOffset, Object dragInfo) {
35.
//拖入进入区域
36.
setBackgroundResource(R.drawable.dock_press_bg);
37.
}
38.
39.
public
void
onDragExit(DragSource source,
int
x,
int
y,
int
xOffset,
int
yOffset, Object dragInfo) {
40.
//拖动离开区域
41.
setBackgroundResource(R.drawable.dock_bg);
42.
}
43.
44.
public
void
onDragOver(DragSource source,
int
x,
int
y,
int
xOffset,
int
yOffset, Object dragInfo) {
45.
}
46.
47.
public
void
onDrop(DragSource source,
int
x,
int
y,
int
xOffset,
int
yOffset, Object dragInfo) {
48.
//拖动释放
49.
}
50.
51.
public
void
onDragEnd() {
52.
}
53.
54.
public
void
onDragStart(View v, DragSource source, Object info,
int
dragAction) {
55.
//开始拖动
56.
}
57.
58.
public
void
onClick(View v) {
59.
//单击打开app
60.
ImageView view=(ImageView)v;
61.
DockInfo dockInfo=(DockInfo)view.getTag();
62.
try
{
63.
Intent i = Intent.getIntent(dockInfo.info.intent.toUri(
));
64.
mLauncher.startActivitySafely(i);
65.
}
catch
(URISyntaxException e) {
66.
e.printStackTrace();
67.
}
68.
}
69.
70.
public
boolean
onLongClick(View v) {
71.
//长按实现拖动
72.
}
73.
74.
public
void
onDropCompleted(View target,
boolean
success) {
75.
//拖动释放事件
76.
}
77.
}
1.
<
com.android.launcher.DockView
2.
android:id
=
"@+id/dock_view"
3.
android:background
=
"@drawable/dock_bg"
4.
android:layout_width
=
"wrap_content"
5.
android:layout_height
=
"wrap_content"
6.
android:layout_gravity
=
"bottom|center_horizontal"
7.
/>
01.
<
com.android.launcher.CellLayout
02.
xmlns:android
=
""
03.
xmlns:launcher
=
""
04.
05.
android:layout_width
=
"fill_parent"
06.
android:layout_height
=
"fill_parent"
07.
08.
launcher:cellWidth
=
"106dip"
09.
launcher:cellHeight
=
"73dip"
10.
launcher:longAxisStartPadding
=
"0dip"
11.
launcher:longAxisEndPadding
=
"55dip"
12.
launcher:shortAxisStartPadding
=
"0dip"
13.
launcher:shortAxisEndPadding
=
"70dip"
14.
launcher:shortAxisCells
=
"6"
15.
launcher:longAxisCells
=
"8"
/>