Android Launcher分析和修改10——HotSeat深入进阶
来源:互联网 发布:工装夹克 知乎 编辑:程序博客网 时间:2024/06/05 16:52
(PS:新建的QQ群,有兴趣可以加入一起讨论:Android群:322599434)
默认Hotseat里面的元素都没有标题
1、Hotseat隐藏文件夹标题
刚开始想解决这个问题的想法是找到按钮对象生成的地方,修改一下就好了。因为我上次分析Hotseat的时候,记得有一个地方把Hotseat的按钮文字屏蔽了,我想只要打开就好。
//Edited by mythou//http://www.cnblogs.com/mythou/
if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { if(OWLLauncherDebug.HotSeat) Log.d(mythou, "addInScreen------->CONTAINER_HOTSEAT"); layout = mLauncher.getHotseat().getLayout(); child.setOnKeyListener(null); //隐藏Hotseat里面文件夹的名称 if (child instanceof FolderIcon) { ((FolderIcon) child).setTextVisible(false); } //......... }
上面这段代码是在Workspace里面addInScreen()的部分代码,是绑定workspace元素的时候调用的方法,里面的确有一个判断是否隐藏文件夹的名称,但是没看到隐藏普通快捷方式的代码。我先把文件夹标题隐藏的功能去掉,但是hotseat里面的文件夹还是没有名称。没办法,只能从头看看Hotseat上面那些快捷方式如何添加和加载。
2、Hotseat上Item如何生成
Hotseat上面的快捷方式可以分为两种,一种是普通快捷方式,可以在default_workspace里面配置。另外一个是全部应用列表的按钮,这个实在Hotseat.java里面动态生成的。我们先看看普通的快捷方式如何生成,一般的快捷方式,通过加载default_workspace,这个过程跟workspace上面的按钮一样,前面已经有详细分析,这里不多说。我们主要看看如何生成快捷方式的对象,其实这个跟workspace也是一样,我们看看下面代码:
//Edited by mythou//http://www.cnblogs.com/mythou/
public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) { //.........for (int i=start; i<end; i++) { //.........if(OWLLauncherDebug.HotSeat) Log.d("OWL_Launcher", "bindItems------->item="+item); switch (item.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: //生成Item的View对象 View shortcut = createShortcut((ShortcutInfo)item); //添加到对应的screen里面 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX, item.cellY, 1, 1, false); break; } } }
上面是Launcher里面的bindItems()方法的部分代码,bindItems()这个方法,看过我前面分析Launcher数据加载的朋友应该不会陌生,这是绑定Launcher数据时候Launcher回调的一个方法,Hotseat的Item对象就在这里生成。调用了createShortcut()方法,下面我们看看createShortcut()是如何生成Item对象。
//Edited by mythou//http://www.cnblogs.com/mythou/
View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { if(OWLLauncherDebug.HotSeat) Log.d("OWL_Lancher", "addInScreen------->info="+info); //生成Item的快捷方式,Hotseat里面的按钮也是BubbleTextView BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); favorite.applyFromShortcutInfo(info, mIconCache); favorite.setOnClickListener(this); return favorite; }
从这里可以看出,其实Hotseat里面的按钮也是BubbleTextView的对象,也就是跟一般的workspace里面的按钮一样。对象生成以后会添加到对应的Screen里面。前面Hotseat的文章我也说过,Hotseat其实也是一个CellLayout的screen。在程序里面是标记为最后一个screen。
3、Item添加到Hotseat
//Edited by mythou//http://www.cnblogs.com/mythou/
void addInScreen(View child, long container, int screen, int x, int y, int spanX, int spanY, boolean insert) { if(OWLLauncherDebug.HotSeat) Log.d(OWL, "addInScreen------->screen="+screen); final CellLayout layout; //针对Hotseat的对象做特殊处理 mythou if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { if(OWLLauncherDebug.HotSeat) Log.d(OWL, "addInScreen------->CONTAINER_HOTSEAT"); layout = mLauncher.getHotseat().getLayout(); child.setOnKeyListener(null); //隐藏Hotseat文件夹标题 if (child instanceof FolderIcon) { // ((FolderIcon) child).setTextVisible(false); }if(OWLLauncherDebug.HotSeat) Log.d(OWL, "addInScreen------->CONTAINER_HOTSEAT screen="+screen); if (screen < 0) { screen = mLauncher.getHotseat().getOrderInHotseat(x, y); } else {//获取child的位置,返回true添加成功,false失败 这里其实是Hotseat里面Item的位置 x = mLauncher.getHotseat().getCellXFromOrder(screen); y = mLauncher.getHotseat().getCellYFromOrder(screen); } if(OWLLauncherDebug.HotSeat) Log.d(OWL, "addInScreen-------> x="+x + " y="+y); } }
上面就是把Hotseat里面元素添加到Hotseat对应的CellLayout里面去,里面有一部分针对Hotseat元素的特殊处理,也就是刚开始说的隐藏文件夹标题以及技术元素位置的代码。除了这些,我并没有找到隐藏按钮文字的方法。后来只能看看Hotseat里面另外一个按钮(AllAPP)能不能显示文字。
4、Hotseat的AllAPP按钮
//Edited by mythou//http://www.cnblogs.com/mythou/
void resetLayout() { //清空Hotseat里面所有的元素 mContent.removeAllViewsInLayout(); //添加ALLAPP按钮 Context context = getContext(); LayoutInflater inflater = LayoutInflater.from(context); //修改为自己定义的button配置application, mythou BubbleTextView allAppsButton = (BubbleTextView) inflater.inflate(R.layout.application, mContent, false); //设置allapp按钮的图片 allAppsButton.setCompoundDrawablesWithIntrinsicBounds(null, context.getResources().getDrawable(R.drawable.all_apps_button_icon), null, null); allAppsButton.setText(context.getString(R.string.all_apps_button_label)); allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label)); int width = allAppsButton.getWidth(); int heigh = allAppsButton.getHeight(); Log.d("OWL_HOTSEAT", "allAppsButton width="+width+" heigh="+heigh); //......... }
上面是Hotseat.java里面的resetLayout()方法,前面也说了Hotseat里面的按钮分为两种,其中AllAPP按钮是代码里面生成的。最后也是调用addViewToCellLayout()方法,addViewToCellLayout()是CellLayout里面的方法,跟前面一样,会添加到CellLayout里面。
5、Hotseat显示Item标题
前面说了半天都没说到如何修改显示标题。其实这个说起来很简单,Hotseat里面的元素,每个都保存了Item的标题,我还特意把数据打印出来看了,因为刚开始以为系统直接把标题数据删除了。之所以没有显示出来是因为Hotseat设置的高度太低,导致标题部分显示被屏蔽了,很实用也很囧的方法。另外可能会有人要问,既然从显示空间上限制了,为何还要加个判断文件夹标题隐藏?这个问题答案,只要你看看文件夹高度就知道了,自己实践一下才能印象深刻。
我对Launcher的分析也有一段时间了,不过现在看来对这个程序还不了解,后面还是多花点时间,达到能随心所欲地修改才行!最后谢谢女朋友大人给我提醒,让我省了不少时间,O(∩_∩)O哈!
系列文章:
Android Launcher分析和修改1——Launcher默认界面配置(default_workspace)
Android Launcher分析和修改2——Icon修改、界面布局调整、壁纸设置
Android Launcher分析和修改3——Launcher启动和初始化
Android Launcher分析和修改4——初始化加载数据
Android Launcher分析和修改5——HotSeat分析
Android Launcher分析和修改6——页面滑动(PagedView)
Android Launcher分析和修改7——AllApp全部应用列表(AppsCustomizeTabHost)
Android Launcher分析和修改8——AllAPP界面拖拽元素(PagedViewWithDraggableItems)
Android Launcher分析和修改9——Launcher启动APP流程
Edited by mythou
原创博文,转载请标明出处:http://www.cnblogs.com/mythou/p/3211443.html
- Android Launcher分析和修改10——HotSeat深入进阶
- Android Launcher分析和修改10——HotSeat深入进阶
- Android Launcher分析和修改5——HotSeat分析
- Android Launcher分析和修改5——HotSeat分析
- Android Launcher分析和修改5——HotSeat分析
- Android Launcher分析和修改5——HotSeat分析
- Android Launcher分析和修改5——HotSeat分析
- Android Launcher分析和修改5——HotSeat分析
- Android Launcher分析和修改5——HotSeat分析
- Android Launcher分析和修改5——HotSeat分析
- Android Launcher分析和修改5——HotSeat分析
- Android Launcher分析和修改5——HotSeat分析
- Android之Launcher分析和修改5——HotSeat分析
- Android Launcher分析和修改
- Android Launcher分析和修改3——Launcher启动和初始化
- Android Launcher分析和修改3——Launcher启动和初始化
- Android Launcher分析和修改3——Launcher启动和初始化
- Android Launcher分析和修改3——Launcher启动和初始化
- 屏幕适配的那些坑
- win8.1如何删除“设备和驱动器”里的无效项?
- ios8 定位问题解决思路
- linux stat函数讲解
- 十年一梦 血泪史3
- Android Launcher分析和修改10——HotSeat深入进阶
- cocos2d-x-3.3rc2-002 cocos里的两段构造
- Eclipse的SVN插件移动中文名称文件提示org.tigris.subversion.javahl.ClientException: Bogus URL
- fiddler添加过滤条件
- Django的前端页面显示
- Android Launcher分析和修改11——自定义分页指示器(paged_view_indicator)
- 券商的xx系统节点的VIP异常案例介绍及深入分析
- 今天公司新环境重启网卡时候的报错
- EffectiveJava-Methods