今天主要是分析一下Launcher里面的所有应用列表。Android4.0 Launcher的所有应用列表跟2.X比较大的区别就是多了Widget的显示。下面会详细分析Launcher里面有关所有应用列表配置和代码分析。

1、AllApp列表配置文件

配置AllAPP应用列表界面的配置文件是\res\Layout\apps_customize_pane.xml文件。AllAPP列表使用了一个TabHost组织了两个页面(全部应用和Widget),通过界面上面的TabHost进行切换。下面是TabHost的配置和AllAPP界面配置,我这里需要把Widget部分功能取消,因为我做的Launcher把Widget放到workspace里面实现了。


//Edited by mythou
//http://www.cnblogs.com/mythou/
<!-- 取消TabHost的显示,把TabHost设置为0dp高,避免影响all app显示 mythou -->
<com.android.launcher2.AppsCustomizeTabHost
android:background="@android:color/transparent">
<LinearLayout
android:id="@+id/apps_customize_content"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- TabHost栏,配置TahHost栏的高度宽度
        我这里把TabHost取消了,因为我的Launcher需要把Widget反正workspace里面实现,
        所以全部应用列表修改成和2.X的Launcher一样 mythou-->

<FrameLayout
android:id="@+id/tabs_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
android:layout_gravity="center_horizontal">
       <!-- TabHost上面Widget 的按钮-->
<com.android.launcher2.FocusOnlyTabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@android:color/transparent"
android:tabStripEnabled="false"
android:tabStripLeft="@null"
android:tabStripRight="@null"
android:divider="@null" />
       <!--TabHost 右边的Android市场的图标,不需要可以去掉-->
<include
android:id="@+id/market_button"
layout="@layout/market_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right" /> </FrameLayout>

     <!--下面这里就是我们所有应用列表的选项和所有应用列表的显示View
        需要注意的是AppsCustomizePagedView同时支持显示所有应用列表和Widget列表 mythou-->

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
       <!-- 所有应用列表是通过自定义VIewAppsCustomizePagedView显示,后面会详细分析这个View
          下面只对部分重要属性加入注释-->

<com.android.launcher2.AppsCustomizePagedView
android:id="@+id/apps_customize_pane_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
         //MaxAppCellCountX 和MaxAppCellCounY指的是所有App图标排列的最大行列数。
         //一般设置为-1,表示无限制

launcher:maxAppCellCountX="@integer/apps_customize_maxCellCountX"
launcher:maxAppCellCountY="@integer/apps_customize_maxCellCountY"
         //pageLayoutWidthGap和pageLayoutHeightGap分别表示菜单界面与屏幕边缘的距离,
         //一般小屏幕这里设置为-1。避免边框太窄误触屏幕才需要设置。

launcher:pageLayoutWidthGap="@dimen/apps_customize_pageLayoutWidthGap"
launcher:pageLayoutHeightGap="@dimen/apps_customize_pageLayoutHeightGap"
launcher:pageLayoutPaddingTop="50dp"
         //pageLayoutPaddingXXX指的是内填充,这个和系统的padding一样
launcher:pageLayoutPaddingBottom="@dimen/apps_customize_pageLayoutPaddingBottom"
launcher:pageLayoutPaddingLeft="@dimen/apps_customize_pageLayoutPaddingLeft"
launcher:pageLayoutPaddingRight="@dimen/apps_customize_pageLayoutPaddingRight"
         //widgetCellWithGap和widgetCellHeightGap指的是widget列表界面各个widget之间的间隔,
         //和系统的margin属性类似

launcher:widgetCellWidthGap="@dimen/apps_customize_widget_cell_width_gap"
launcher:widgetCellHeightGap="@dimen/apps_customize_widget_cell_height_gap"
         //widgetCountX和WidgetCountY都是表示Widget界面每行每列显示多少Widget
launcher:widgetCountX="@integer/apps_customize_widget_cell_count_x"
launcher:widgetCountY="@integer/apps_customize_widget_cell_count_y"
         //提示界面的焦点
launcher:clingFocusedX="@integer/apps_customize_cling_focused_x"
launcher:clingFocusedY="@integer/apps_customize_cling_focused_y"
launcher:maxGap="@dimen/workspace_max_gap" />
       <!-- 加载全部应用时的旋转动画 -->
<FrameLayout
android:id="@+id/animation_buffer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF000000"
android:visibility="gone" />
       <!-- 分页符,代表多少页和当前页面-->
<include
android:id="@+id/paged_view_indicator"
layout="@layout/scroll_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</FrameLayout>
</LinearLayout>
  <!--第一次进入所有应用列表的提示界面,和workspace提示界面一样-->
<include layout="@layout/all_apps_cling"
android:id="@+id/all_apps_cling"
android:layout_width="match_parent"
android:layout_height="match_parent"/> </com.android.launcher2.AppsCustomizeTabHost>

  上面已经针对TabHost的配置文件给了详细注释,这里需要说明的一点是,不管是所有应用列表还是Widget列表都是通过AppsCustomizedPagedView显示出来,也就是说这个自定义View支持两种形式显示。下面我们先对AppsCustomizeTabHost做个简单分析。

2、AppsCustomizeTabHost分析

AppsCustomizeTabHost是继承了TabHost的之类,主要是对TabHost进行扩展,增加一些功能。AppsCustomizeTabHost的代码不多,这里主要对生成AllAPP和Widget页面选项部分介绍一下。

//Edited by mythou
//http://www.cnblogs.com/mythou/
  protected void onFinishInflate()
{
//.......//创建所有应用列表Tab mythou
TextView tabView;
String label;
label = mContext.getString(R.string.all_apps_button_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
//Widget的Tab页面
label = mContext.getString(R.string.widgets_tab_label);
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(label);
tabView.setContentDescription(label);
addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
//设置监听器

setOnTabChangedListener(this); AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - );
lastTab.setOnKeyListener(keyListener); //Android商店按钮
View shopButton = findViewById(R.id.market_button);
shopButton.setOnKeyListener(keyListener); // Hide the tab bar until we measure
mTabsContainer.setAlpha(0f);
}

onFinishInflate回调函数里面执行了创建TabHost需要的Tab View,这个函数在View加载完配置文件的时候会执行。除了创建TabHost外,还有几个函数需要注意了解。

3、Tab变化时执行onTabChanged

在TabHost切换选项的时候,会执行onTabChanged回调函数,这里执行了切换页面的操作,具体切换其实是切换AppsCustomizedPagedView类里面的切换,因为所有应用和Widget都是依靠AppsCustomizedPagedView来显示。onTabChanged里面有两个地方需要注意一下:

//Edited by mythou
//http://www.cnblogs.com/mythou/
    public void onTabChanged(String tabId)
{
    //使用Runnable执行一个切换的动画效果,因为切换的时候会存在数据加载导致的延时问题。
    //在加载切换数据的过程中,加入动画可以增强用户体验 mythou

post(new Runnable()
{
@Override
public void run()
{
ArrayList<View> visiblePages = new ArrayList<View>();
for (int i = visiblePageRange[]; i <= visiblePageRange[]; i++)
{
visiblePages.add(mAppsCustomizePane.getPageAt(i));
} //保证每个页面都是使用统一的动画效果
mAnimationBuffer.scrollTo(mAppsCustomizePane.getScrollX(), ); // mAppsCustomizePane显示子页面是使用相反的顺序,所以添加页面动画的时候,
//也是使用相反的添加顺序

for (int i = visiblePages.size() - ; i >= ; i--)
{
View child = visiblePages.get(i);
            //增加切换动画缓存,提供下面切换动画使用
mAnimationBuffer.addView(child, p);
} // Toggle the new content
onTabChangedStart();
onTabChangedEnd(type); //过渡动画开始
ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f);
         //。。。。。。。。
}

  onTabChanged主要是提供了一个切换页面的动画,以为切换TabHost的时候,会存在一个加载和切换数据的过程,这个过程需要消耗一定时间,所以开了一个线程来执行一个过渡动画,增强用户体验。Launcher里面很多切换操作都存在类似的操作,每个操作都伴随着一个动画效果。主要目的就是让用户觉得界面操作流畅。

4、onLauncherTransitionStart和onLauncherTransitionEnd

这两个方法是在Launcher.java类里面调用的,具体调用时机就是从workspace切换到AllAPP列表的时候,切换前会调用onLauncherTransitionStart方法,切换后也会调用onLauncherTransitionEnd。看名字我们大概也能猜出这两个方法的作用,也是提供一个过渡的动画效果。onLauncherTransitionEnd还会调用提示界面。

今天就讲到这里,下次会开始进入AppsCustomizedPagedView分析。

Launcher分析系列文章:

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)

Edited by mythou

原创博文,转载请标明出处:http://www.cnblogs.com/mythou/p/3182286.html 

Android Launcher分析和修改7——AllApp全部应用列表(AppsCustomizeTabHost)的更多相关文章

  1. Android Launcher分析和修改8——AllAPP界面拖拽元素(PagedViewWithDraggableItems)

    接着上一篇文章,继续分析AllAPP列表界面.上一篇文章分析了所有应用列表的界面构成以及如何通过配置文件修改属性.今天主要是分析PagedViewWithDraggableItems类,因为在我们分析 ...

  2. Android Launcher分析和修改13——实现Launcher编辑模式(1) 壁纸更换

    已经很久没更新Launcher系列文章,今天不分析源码,讲讲如何在Launcher里面添加桌面设置的功能.目前很多第三方Launcher或者定制Rom都有简单易用的桌面设置功能.例如小米MIUI的La ...

  3. Android Launcher分析和修改9——Launcher启动APP流程

    本来想分析AppsCustomizePagedView类,不过今天突然接到一个临时任务.客户反馈说机器界面的图标很难点击启动程序,经常点击了没有反应,Boss说要优先解决这问题.没办法,只能看看是怎么 ...

  4. Android Launcher分析和修改10——HotSeat深入进阶

    前面已经写过Hotseat分析的文章,主要是讲解如何在Launcher里面配置以及修改Hotseat的参数.今天主要是讲解一下如何在Hotseat里面的Item显示名称.这个小问题昨天折腾了半天,最后 ...

  5. Android Launcher分析和修改11——自定义分页指示器(paged_view_indicator)

    Android4.0的Launcher自带了一个简单的分页指示器,就是Hotseat上面那个线段,这个本质上是一个ImageView利用.9.png图片做,效果实在是不太美观,用测试人员的话,太丑了. ...

  6. Android Launcher分析和修改12——Widget列表信息收集

    很久没写Launcher分析的文章,最近实在太忙.今天七夕本来是想陪女朋友逛街 ,碰巧打台风呆在家里,就继续写一篇文章.今天主要是讲一下Launcher里面的Widget列表,这方面信息比较多,今天重 ...

  7. Android Launcher分析和修改3——Launcher启动和初始化

    前面两篇文章都是写有关Launcher配置文件的修改,代码方面涉及不多,今天开始进入Launcher代码分析. 我们开机启动Launcher,Launcher是由Activity Manager启动的 ...

  8. Android Launcher分析和修改4——初始化加载数据

    上面一篇文章说了Launcher是如何被启动的,Launcher启动的过程主要是加载界面数据然后显示出来, 界面数据都是系统APP有关的数据,都是从Launcher的数据库读取,下面我们详细分析Lau ...

  9. Android Launcher分析和修改5——HotSeat分析

    今天主要是分析一下Launcher里面的快捷方式导航条——HotSeat,一般我们使用手机底下都会有这个导航条,但是如果4.0的Launcher放到平板电脑里面运行,默认是没有HotSeat的,刚好我 ...

随机推荐

  1. [洛谷P2258][NOIP2014PJ]子矩阵(dfs)(dp)

    NOIP 2014普及组 T4(话说一道PJ组的题就把我卡了一个多小时诶) 这道题在我看第一次的时候是没有意识到这是一道DP题的,然后就摁着DFS敲了好长时间,结果敲了一个TLE 这是DP!!! 下面 ...

  2. go语言学习-常用命令

    前面的文章中记录了安装 golang 和配置开发环境,本文将学习的 go 命令行命令以及使用场景. 查看可用命令 直接在终端中输入 go help 即可显示所有的 go 命令以及相应命令功能简介,主要 ...

  3. java 同步 synchronized

    http://www.cnblogs.com/Qian123/p/5691705.html http://www.cnblogs.com/GnagWang/archive/2011/02/27/196 ...

  4. SpringMVC中ModelAndView对象与“视图解析器”

    摘要: spring MVC这个环境中,Spring MVC会依据controller(或者你叫它handler)中处理方法的返回值,进行解析,解析之后提供一个视图,作为响应. 标注了@Control ...

  5. 关于Git的总结

    首先我们先看一张图: 首先我们必须要先理解这几个概念:暂存区,本地仓库,远程仓库 暂存区:这个是我们每一次进行代码修改的地方,例如我们ieda的所编译的代码就是缓存区 本地仓库:是我们每一次pull, ...

  6. [Agc005D]K Perm Counting

    [Agc005D] K Perm Counting Description 糟糕爷特别喜爱排列.他正在构造一个长度为N的排列.但是他特别讨厌正整数K.因此他认为一个排列很糟糕,当且仅当存在至少一个i( ...

  7. Python3内置函数——reversed() = 翻转我的世界

    认识reversed单词 reversed 英[rɪ'vɜ:st] 美[rɪ'vɜst] adj. 颠倒的:相反的:(判决等)撤销的 v. 颠倒(reverse的过去式和过去分词):翻转 help(r ...

  8. Mysql数据库小结

    1. 基础概念 1.1 数据 描述事物的符号记录称为数据,描述事物的符号既可以是数字,也可以是文字.图片,图像.声音.语言等,数据由多种表现形式,它们都可以经过数字化后存入计算机 在计算机中描述一个事 ...

  9. [数据结构与算法分析(Mark Allen Weiss)]二叉树的插入与删除 @ Python

    二叉树的插入与删除,来自Mark Allen Weiss的<数据结构与算法分析>. # Definition for a binary tree node class TreeNode: ...

  10. 【ZH奶酪】如何用textgenrnn处理中文

    如何用textgenrnn处理中文 1. 什么是textgenrnn? textgenrnn是建立在Keras和TensorFlow之上的,可用于生成字级别和词级别文本.网络体系结构使用注意力加权来加 ...