- 浏览: 199958 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
xumin_minzi:
我也在使用ndk编译,ffmpeg源码放在哪个目录里面?
[原创]Android ndkr8编译 FFmpeg 0.11.1 "Happiness" -
ericchan2012:
在Dialog调用show方法之后
【原创】Android 设置Dialog的长宽和位置 -
maohualei:
求解: 我设置的时候 位置居然没有反应 dial ...
【原创】Android 设置Dialog的长宽和位置
之前在网上看到有篇文章:Launcher之Dock细节篇http://news.wangmeng.cn/detailNews/2716-the-article-details-launcher-dock 它实现了一个仿Mac的dock。感觉蛮有意思的,所以就照着仿制了一个。
可以动态的添加快捷方式,默认包含AllApp按钮,图标居中显示。
文章后边附带的源码是基于android2.2自带的launcher2稍作修改而成,使用eclipse调试。
一、首先要在Launcher的setupViews函数里面初始化自己的layout(需增加3个地方)
[java] view plaincopy
1.
dockbar=(DockBar)dragLayer.findViewById(R.id.dockbar);
dockbar.setLauncher(this);
dockbar.setDragController(dragController);
2.
dragController.setDragScoller(workspace);
dragController.setDragListener(deleteZone);
dragController.setDockDragListener(dockbar); // hmg25 add for dock
setDockDragListener为自定义函数,添加在DragController的startDrag中,具体见源码
if(mDockListener!=null){
mDockListener.onDragStart(source, dragInfo, dragAction);
}
3.
// The order here is bottom to top.
dragController.addDropTarget(workspace);
dragController.addDropTarget(dockbar); //hmg25 add for dock
dragController.addDropTarget(deleteZone);
二、在layout-port的launcher.xml中增加
[xhtml] view plaincopy
<!--hmg add for dock { -->
<com.android.launcher2.DockBar
android:id="@+id/dockbar"
android:layout_width="fill_parent"
android:layout_height="@dimen/button_bar_height"
android:layout_gravity="bottom|center_horizontal"
android:background="@drawable/dock_bg"
launcher:direction="horizontal">
<HorizontalScrollView android:id="@+id/dock_scroll_view"
android:scrollbars="none"
android:fadingEdge="none"
android:saveEnabled="false"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:id="@+id/dock_item_holder"
android:saveEnabled="false"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.android.launcher2.HandleView //默认将allapp按钮添加进去
android:id="@+id/all_apps_button"
android:layout_centerHorizontal="true"
android:src="@drawable/all_apps_button"
launcher:direction="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:clickable="true"
/>
</LinearLayout>
</HorizontalScrollView>
</com.android.launcher2.DockBar>
<!--hmg add for dock } -->
三、创建自定义的类:
[java] view plaincopy
public class DockBar extends LinearLayout implements DropTarget, DragSource,
DragController.DragListener,View.OnLongClickListener {
@Override
public boolean acceptDrop(DragSource source, int x, int y, int xOffset,int yOffset,DragView dragView, Object dragInfo) {
//接受什么类型的图标
Log.i("hmg", "DockBar->acceptDrop");
final ItemInfo item = (ItemInfo) dragInfo;
if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_WIDGET_PHOTO_FRAME
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_WIDGET_CLOCK) {
return false;
}
return true;
}
//拖拽释放时响应下边函数
@Override
public void onDrop(DragSource source, int x, int y, int xOffset,
int yOffset, DragView dragView, Object dragInfo) {
int position=0;
position=getLocation(x); //根据释放时的坐标,获取插入位置
addItemAt((ItemInfo)dragInfo, position);
}
/*
* 传入x坐标,判断新图标的位置,此处仅判断竖屏
*/
public int getLocation(int x){
for(int i=0;i<mItemHolder.getChildCount();i++){
View iv = mItemHolder.getChildAt(i);
int[] position = new int[2];
//获取坐标,如果要适应横屏可以稍作修改,比较Y值
iv.getLocationOnScreen(position);
//判断释放时新增的图标在原图标的之前还是之后
if(x<=(position[0]+(iv.getWidth()/2))){
return i;
}
}
return mItemHolder.getChildCount();
}
private void addItemAt(ItemInfo itemInfo, int position)
{
View view=null;
switch (itemInfo.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
ShortcutInfo shortcutInfo;
// 拖拽图标来自于app list
if(itemInfo.container ==NO_ID&& itemInfo instanceof ApplicationInfo)
{
//与来自桌面的图标包含信息不一样,具体看源码
shortcutInfo= new ShortcutInfo((ApplicationInfo)itemInfo);
}
else
shortcutInfo = (ShortcutInfo)itemInfo; //拖拽图标来自桌面
//调用Launcher中的CreateDockShortcut生成一个imageView
view = mLauncher. CreateDockShortcut (shortcutInfo);
view.setOnLongClickListener(this);
break;
case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
break;
default:
throw new IllegalStateException("Unknown item type: "
+ itemInfo.itemType);
}
mItemHolder.addView(view, position);
}
之所以将新建view用Launcher. CreateDockShortcut是想直接使用Launcher中的单击事件。
View CreateDockShortcut (ShortcutInfo shortcutInfo)
{
Context context=getApplicationContext();
ImageView imageView =new ImageView(context);
imageView.setImageBitmap(shortcutInfo.mIcon);
imageView.setOnClickListener(this);
imageView.setFocusable(true);
imageView.setTag(shortcutInfo);
imageView.setMinimumWidth(100);
return imageView;
}
在dock上长按,拖拽交换位置或者拖拽出去
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
if (mLauncher.isAllAppsVisible())
mLauncher.closeAllApps(false);
mSelectedView = v;
//开始拖拽
mDragController.startDrag(v, this, v.getTag(),
DragController.DRAG_ACTION_MOVE);
removeSelectedItem();
return true;
}
private void removeSelectedItem()
{
if (mSelectedView == null)
return;
mItemHolder.removeView(mSelectedView);
}
代码修改了不少地方,具体看代码,修改的地方我都标注啦 ~~欢迎大家指教,相互交流~~
源码地址:http://download.csdn.net/source/3142047
可以动态的添加快捷方式,默认包含AllApp按钮,图标居中显示。
文章后边附带的源码是基于android2.2自带的launcher2稍作修改而成,使用eclipse调试。
一、首先要在Launcher的setupViews函数里面初始化自己的layout(需增加3个地方)
[java] view plaincopy
1.
dockbar=(DockBar)dragLayer.findViewById(R.id.dockbar);
dockbar.setLauncher(this);
dockbar.setDragController(dragController);
2.
dragController.setDragScoller(workspace);
dragController.setDragListener(deleteZone);
dragController.setDockDragListener(dockbar); // hmg25 add for dock
setDockDragListener为自定义函数,添加在DragController的startDrag中,具体见源码
if(mDockListener!=null){
mDockListener.onDragStart(source, dragInfo, dragAction);
}
3.
// The order here is bottom to top.
dragController.addDropTarget(workspace);
dragController.addDropTarget(dockbar); //hmg25 add for dock
dragController.addDropTarget(deleteZone);
二、在layout-port的launcher.xml中增加
[xhtml] view plaincopy
<!--hmg add for dock { -->
<com.android.launcher2.DockBar
android:id="@+id/dockbar"
android:layout_width="fill_parent"
android:layout_height="@dimen/button_bar_height"
android:layout_gravity="bottom|center_horizontal"
android:background="@drawable/dock_bg"
launcher:direction="horizontal">
<HorizontalScrollView android:id="@+id/dock_scroll_view"
android:scrollbars="none"
android:fadingEdge="none"
android:saveEnabled="false"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:id="@+id/dock_item_holder"
android:saveEnabled="false"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.android.launcher2.HandleView //默认将allapp按钮添加进去
android:id="@+id/all_apps_button"
android:layout_centerHorizontal="true"
android:src="@drawable/all_apps_button"
launcher:direction="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:clickable="true"
/>
</LinearLayout>
</HorizontalScrollView>
</com.android.launcher2.DockBar>
<!--hmg add for dock } -->
三、创建自定义的类:
[java] view plaincopy
public class DockBar extends LinearLayout implements DropTarget, DragSource,
DragController.DragListener,View.OnLongClickListener {
@Override
public boolean acceptDrop(DragSource source, int x, int y, int xOffset,int yOffset,DragView dragView, Object dragInfo) {
//接受什么类型的图标
Log.i("hmg", "DockBar->acceptDrop");
final ItemInfo item = (ItemInfo) dragInfo;
if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_WIDGET_PHOTO_FRAME
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH
|| item.itemType == LauncherSettings.Favorites.ITEM_TYPE_WIDGET_CLOCK) {
return false;
}
return true;
}
//拖拽释放时响应下边函数
@Override
public void onDrop(DragSource source, int x, int y, int xOffset,
int yOffset, DragView dragView, Object dragInfo) {
int position=0;
position=getLocation(x); //根据释放时的坐标,获取插入位置
addItemAt((ItemInfo)dragInfo, position);
}
/*
* 传入x坐标,判断新图标的位置,此处仅判断竖屏
*/
public int getLocation(int x){
for(int i=0;i<mItemHolder.getChildCount();i++){
View iv = mItemHolder.getChildAt(i);
int[] position = new int[2];
//获取坐标,如果要适应横屏可以稍作修改,比较Y值
iv.getLocationOnScreen(position);
//判断释放时新增的图标在原图标的之前还是之后
if(x<=(position[0]+(iv.getWidth()/2))){
return i;
}
}
return mItemHolder.getChildCount();
}
private void addItemAt(ItemInfo itemInfo, int position)
{
View view=null;
switch (itemInfo.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
ShortcutInfo shortcutInfo;
// 拖拽图标来自于app list
if(itemInfo.container ==NO_ID&& itemInfo instanceof ApplicationInfo)
{
//与来自桌面的图标包含信息不一样,具体看源码
shortcutInfo= new ShortcutInfo((ApplicationInfo)itemInfo);
}
else
shortcutInfo = (ShortcutInfo)itemInfo; //拖拽图标来自桌面
//调用Launcher中的CreateDockShortcut生成一个imageView
view = mLauncher. CreateDockShortcut (shortcutInfo);
view.setOnLongClickListener(this);
break;
case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
break;
default:
throw new IllegalStateException("Unknown item type: "
+ itemInfo.itemType);
}
mItemHolder.addView(view, position);
}
之所以将新建view用Launcher. CreateDockShortcut是想直接使用Launcher中的单击事件。
View CreateDockShortcut (ShortcutInfo shortcutInfo)
{
Context context=getApplicationContext();
ImageView imageView =new ImageView(context);
imageView.setImageBitmap(shortcutInfo.mIcon);
imageView.setOnClickListener(this);
imageView.setFocusable(true);
imageView.setTag(shortcutInfo);
imageView.setMinimumWidth(100);
return imageView;
}
在dock上长按,拖拽交换位置或者拖拽出去
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
if (mLauncher.isAllAppsVisible())
mLauncher.closeAllApps(false);
mSelectedView = v;
//开始拖拽
mDragController.startDrag(v, this, v.getTag(),
DragController.DRAG_ACTION_MOVE);
removeSelectedItem();
return true;
}
private void removeSelectedItem()
{
if (mSelectedView == null)
return;
mItemHolder.removeView(mSelectedView);
}
代码修改了不少地方,具体看代码,修改的地方我都标注啦 ~~欢迎大家指教,相互交流~~
源码地址:http://download.csdn.net/source/3142047
发表评论
-
拖拽滑动_有3D_有循环
2012-12-11 17:38 1105android桌面拖拽3d效果 -
三星通讯录滑动出发开关
2012-12-11 17:37 865下面的代码是仿三星9300中的滑动打电话和发短信的。 -
三星通讯录滑动触发开关以及StatusBar下拉快捷键的效果
2012-10-20 17:26 13571,三星通讯录滑动触发开关 你可以参考: http://gja ... -
android水波纹效果之一
2012-09-17 22:27 1133参考: http://www.apkbus.com/archi ... -
android桌面预览效果
2012-09-17 21:49 930主要改动的是:workspace.Java和launcher. ... -
Android 自定义滚动视图
2012-08-24 22:39 529MainActivity package org. ... -
实现通讯录的弹窗效果
2012-08-19 22:06 1669参考http://www.cnblogs.com/noTice ... -
【原创】android ViewPager控件的使用
2012-06-15 10:33 2316android4.0有个控件,就是viewpager,用来实现 ... -
【原创】android 实现气泡式listview
2012-06-14 13:33 1920iphone中短信聊天都是那种气泡式的,当然,android短 ... -
【原创】android中实现底部tabhost
2012-06-14 10:14 1713这个主要是实现底部的tabhost方式,tabhost就是有几 ... -
【原创】android中定义BaseActivity
2012-06-13 12:53 5601[size=medium] 需求: 如果一个应用程序中有许多a ... -
【原创】android进入应用程序时的动画实现
2012-06-12 11:34 1379相信玩过android应用的同学都看过进入应用程序时出现的短暂 ... -
【原创】android仿ucweb的菜单效果
2012-06-12 11:12 1109[size=medium]先看一张图 这里有几个要点 1,主 ... -
【原创】android2.3如何加入对wml的支持
2012-06-12 09:52 1263其实就是改makefile文件: 1,开启宏定义: 在exte ... -
【原创】dip与px
2012-06-11 10:38 834真正要做适配的,只有是当图片被拉抻后,是否变形了,如果变形了, ... -
【原创】Android aidl实现两个apk之间远程调用Service
2012-06-07 11:12 4881Aidl,android平台的IPC方式之一,基于系统的Ibi ... -
【转】Android-Action Bar使用方法
2012-06-06 14:49 1765转自http://disanji.net/2011/02/24 ... -
【原创】Android仿新浪微博的“更多”页面效果
2012-05-29 17:38 2200看到新浪微博那个“更多”页面的效果,感觉不错,所以拿来模仿一下 ... -
【原创】Android 设置Dialog的长宽和位置
2012-05-28 10:11 2669在Dialog调用show方法之后,加上以下代码: Wi ... -
【原创】Android 实现微博分享功能
2012-05-27 22:20 1429通过发送下面的intent: Intent intent = ...
相关推荐
仿Mac的dock android Launcher
仿小米电视桌面launcher源码Demo,改桌面采用 类似小米一样的metro风格的 设计,可以通过远程配置控制桌面显示 的内容,非常棒,成功用于多个机顶盒ott项目。无积分或者不想登陆点我头像发给你。
Android Launcher 源码修改可编译.zip源码资源下载Android Launcher 源码修改可编译.zip源码资源下载
Android系统桌面Launcher3源码,可直接在Android Studio中编译。
添加widget到界面,完成的源代码,实现可以动态添加widget
安卓Android源码——高仿小米launcher(ZAKER)跨屏拖动item.zip
1.适用android 盒子,1920*1080(密度240),1280*720(密度160),1280*720(密度...3,主页功能介绍(第一排,左边语音调起,右边时间,第二排,常用国外视频app,第三排所有apps,第四排设置,以太网,wifi 网络标识)
android源码的Launcher详细解析,分析Launcher的运行机制
android2.2 原生Launcher源码
Android项目源码-安卓Launcher原生桌面源码
Android Launcher源码下载,PagedView,PagedViewIcon
Android,高仿小米Launcher跨屏拖动,源代码。
安卓Android源码——Launcher2.rar
launcher添加动态时钟和动态日历. CalendarScript.java ClockScript.java IconScript.java 是新加入的类 其它的是launcher3本身有的 对比过去就好.在代码中搜索"动态时钟显示"就能找到我加入的东西
这个是android Launcher2.2 源码,我最近在学习,有人想跟我交流就到我的博客:http://blog.csdn.net/gqdy365
最新Launcher3 系统源码, 来自Google官方, 需要的拿去
Launcher3源码
Android桌面程序Launcher源码.
Android8.0 Launcher2源码,基于Android Studio工程源码,亲测可以在手机上运行。
Android 应用开发源码 参考与学习使用