AOSP6.0.1 launcher3入门篇—hotseat相关实现

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a29562268/article/details/83038404

在安卓桌面程序的主界面我们可以看到是由QsbSearchBar(上方搜索框)、Workspace(页视图空间)、pageIndicator(页指示器)、hotseat(底部视图空间)四个部分组成,它们是基于DragLayer
层的基础上进行显示(注释掉 res/ 横屏模式layout-land 或 竖屏模式layout-port/launcher.xml中 android:id="@+id/drag_layer"对应的字段 会发现桌面上没有加载任何部件,DragLayer层属于最外层的布局,用来协调处理它的子view的动作事件,这里不再描述DragLayer层相关信息),下面说明关于hotseat布局的相关描述以及allapps调用的CellLayout的相关实现位置。

首先进入hotseat.java文件:

hotseat类继承于FrameLayout类型,在hotseat.java中可以到hotseat布局的相关信息(长按事件的绑定,hotseat事件的截获,X、Y坐标获取等),如果在launcher类(launcher.java)的事件函数中注释掉hotseat相关的点击、长按事件,那么hotseat布局内的app将变为摆设(无法触发事件)。

进入protected void onFinishInflate()函数:
DeviceProfile grid = mLauncher.getDeviceProfile();
首先获取设备的相关信息(行、列规格、桌面的方向等),桌面的排列方式和设备型号相关
(比如nexus5手机屏幕是1080P xxhdpi,规格为4*4 调用default_workspace_4x4.xml文件)


mContent = (CellLayout) findViewById(R.id.layout);
调用的是res/layout/hotseat.xml文件 android:id="@+id/layout"对应的是res/layout,
如果你想做hotseat(包括allapps调用的cellLayout布局)相关的修改
(比如修改默认图标、事件触发图标,这只是其中一小部分),
查看layout相关的文件夹内的xml将是不错的选择(layout、layout-land等,
所有包含layout名称的文件夹)


hotseat布局其实是一个CellLayout视图,桌面内所有的视图空间都有着相同的概念,
他们由相对应的控制器来管理...

继续向下看:
if (grid.isLandscape && !grid.isLargeTablet) {
            mContent.setGridSize(1, (int) grid.inv.numHotseatIcons);
        } else {
            mContent.setGridSize((int) grid.inv.numHotseatIcons, 1);
        }
这里设置了hotseat布局的行和列(可以设置成2行2列或者更多,默认是1行)


mContent.setIsHotseat(true);
这一句用来设置是否显示hotseat布局里的app是否显示对应的app名称,
修改为mContent.setIsHotseat(false);即可显示除allapps以外的所有app名称
后面描述allapps按钮名称的添加方法

进入void resetLayout()函数:

mContent.removeAllViewsInLayout();
首先清除掉allapps按钮和allapps按钮进入的CellLayout空间

// Add the Apps button
Context context = getContext();

LayoutInflater inflater = LayoutInflater.from(context);
TextView allAppsButton = (TextView)
 inflater.inflate(R.layout.all_apps_button, mContent, false);
Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);
mLauncher.resizeIconDrawable(d);
allAppsButton.setCompoundDrawables(null, d, null, null);
这些是关于allapps按钮的加载,
以及重设图标大小和图标的事件触发范围(感觉是整个桌面布局内的图标和范围都重新
刷新了一边),如果注释掉resetLayout()函数的调用将不会加载allapps按钮和刷新图标等相关工作


allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
这里调用res/layout/all_apps_search_bar.xml,
找到android:contentDescription="@string/all_apps_button_label"字段便可发现,
只要在res下搜索string相关的xml文件,即可找到想要的信息

下面重点来了,设置allapps名称的地方之一:
 if (mLauncher != null) {
mLauncher.setAllAppsButton(allAppsButton);
            allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
allAppsButton.setOnClickListener(mLauncher);
allAppsButton.setOnLongClickListener(mLauncher);
allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
            
allAppsButton.setText("allapps按钮");
在if (mLauncher != null) 中增加上面这段语句,即可增加allapps的应用名称
}

mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
这一条语句是把allAppsButton 按钮嵌入CellLayout布局

下面解析AllAppsContainerView.java文件(管理allapps按钮进入的桌面):

进入public void setSearchBarController(AllAppsSearchBarController searchController)函数:

 mSearchBarContainerView.setVisibility(/*View.VISIBLE*/View.GONE);
 这句话修改为View.GONE即可隐藏QsbSearchBar(allapps内的上方搜索框)
 
进入public boolean onLongClick(View v)函数:
在函数内最上方增加 if (true)return true;
取消长按按钮
在allapps内的CellLayout空间里长按屏幕中的app会出现一个新的拖动页面,用来把指定
app拖动到主桌面,如果不需要这个功能隐藏掉即可

关于allapps按钮进入的桌面目前只需要修改这么多,如果需要修改其他功能,参考相应的函数进行修改即可。

AOSP6.0.1相关文章:
AOSP6.0.1 launcher3入门篇—解析launcher.java文件
AOSP6.0.1 launcher3入门篇-解析DeviceProject.java及相关文件

猜你喜欢

转载自blog.csdn.net/a29562268/article/details/83038404