今天闲的无聊,研究了下launcher代码,看到Hotseat.java的时候,想起来以前有做过显示hotseat中应用名称,因为换了公司代码都没拿出来,就想在试着修改,看了很久发现无从下手,记得hotseat中默认是显示应用名称的,只是hotseat位置靠下所以名称显示不出来,只要把hotseat向上移一下就可以显示出来了,可是找了半天不知道修改那个位置,只能重新研究下hotseat的代码了。
看hotseat.java中
@Override
protected void onFinishInflate() {
super.onFinishInflate();
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
mAllAppsButtonRank = grid.hotseatAllAppsRank;
mContent = (CellLayout) findViewById(R.id.layout);
if (grid.isLandscape && !grid.isLargeTablet()) {
mContent.setGridSize(1, (int) grid.numHotseatIcons);
} else {
mContent.setGridSize((int) grid.numHotseatIcons, 1);
}
mContent.setIsHotseat(true);
Log.i(TAG, "onFinishInflate,(int) grid.numHotseatIcons: " + (int) grid.numHotseatIcons);
resetLayout();
}
mContent.setIsHotseat(true); 这个是判断是否是Hotseat的地方,简便的做法是直接修改为false,意思是这个这个不是HotSeat,那么作为普通快捷图标肯定是能显示名称的,但是这有一个问题那个allapp的名称还是没显示出来,暂时的做法是allAppsButton.setText(context.getString(R.string.all_apps_button_label));
这样hotseat就可以正常显示应用名称了。
在cellLayout.java中
public void setIsHotseat(boolean isHotseat) {
mIsHotseat = isHotseat;
mShortcutsAndWidgets.setIsHotseat(false);}
public boolean addViewToCellLayout(View child, int index, int childId, LayoutParams params,
boolean markCells) {
final LayoutParams lp = params;
// Hotseat icons - remove text
if (child instanceof BubbleTextView) {
BubbleTextView bubbleChild = (BubbleTextView) child;
bubbleChild.setTextVisibility(!mIsHotseat);
}
...
}
发现 addview的时候会根据是否是HotSeat去显示和隐藏,但是只改这里会发现字体只显示了一半,继续跟踪mShortcutsAndWidgets.setIsHotseat(false);
终于明白了
public void setIsHotseat(boolean isHotseat) {
mIsHotseatLayout = isHotseat;
}
int getCellContentWidth() {
final LauncherAppState app = LauncherAppState.getInstance();
final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
return Math.min(getMeasuredHeight(), mIsHotseatLayout ?
grid.hotseatCellWidthPx: grid.cellWidthPx);
}
int getCellContentHeight() {
final LauncherAppState app = LauncherAppState.getInstance();
final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
return Math.min(getMeasuredHeight(), mIsHotseatLayout ?
grid.hotseatCellHeightPx : grid.cellHeightPx);
}
原来这里会通过会通过判断是否是HotSeat而去设置icon的宽高。到这里Hotseat显示名称的分析就结束了。