修改位置
vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\Workspace.java
注释 bindAndInitFirstWorkspaceScreen() 中 if (qsb == null) 开始到结尾
public void bindAndInitFirstWorkspaceScreen(View qsb) {
if (!FeatureFlags.QSB_ON_FIRST_SCREEN) {
return;
}
// Add the first page
CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, 0);
if (FeatureFlags.PULLDOWN_SEARCH) {
.....
}
//add don't show google quick search box[qsb]
// Always add a QSB on the first screen.
/*if (qsb == null) {
// In transposed layout, we add the QSB in the Grid. As workspace does not touch the
// edges, we do not need a full width QSB.
qsb = LayoutInflater.from(getContext())
.inflate(R.layout.search_container_workspace,firstPage, false);
}
CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(), 1);
lp.canReorder = false;
if (!firstPage.addViewToCellLayout(qsb, 0, R.id.search_container_workspace, lp, true)) {
Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout");
}*/
//add don't show google quick search box[qsb]
}
修改位置
vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\allapps\AllAppsContainerView.java
在 onFinishInflate() 中添加一行 mSearchContainer.setVisibility(View.GONE);
@Override
protected void onFinishInflate() {
super.onFinishInflate();
....
mSearchContainer = findViewById(R.id.search_container_all_apps);
mSearchUiManager = (SearchUiManager) mSearchContainer;
mSearchUiManager.initialize(mApps, mAppsRecyclerView);
/// add this code don't show all app quick search box
mSearchContainer.setVisibility(View.GONE);
......
}
vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\allapps\AllAppsTransitionController.java
注释 setAlphas() 中的 mAppsView.getSearchView() 这一行,因为最终会调用到 AlphaUpdateListener 中的 updateVisibility() 将 setVisibility 改成 VISIBLE,导致上面添加的 GONE 不生效
private void setAlphas(LauncherState toState, PropertySetter setter) {
int visibleElements = toState.getVisibleElements(mLauncher);
boolean hasHeader = (visibleElements & ALL_APPS_HEADER) != 0;
boolean hasHeaderExtra = (visibleElements & ALL_APPS_HEADER_EXTRA) != 0;
boolean hasContent = (visibleElements & ALL_APPS_CONTENT) != 0;
///annotation for don't show all app quick search box
//setter.setViewAlpha(mAppsView.getSearchView(), hasHeader ? 1 : 0, LINEAR);
setter.setViewAlpha(mAppsView.getContentView(), hasContent ? 1 : 0, LINEAR);
setter.setViewAlpha(mAppsView.getScrollBar(), hasContent ? 1 : 0, LINEAR);
mAppsView.getFloatingHeaderView().setContentVisibility(hasHeaderExtra, hasContent, setter);
setter.setInt(mScrimView, ScrimView.DRAG_HANDLE_ALPHA,
(visibleElements & VERTICAL_SWIPE_INDICATOR) != 0 ? 255 : 0, LINEAR);
}
中添加老版本的所有应用图标,并去除上滑箭头和屏蔽 Drag 动画
修改位置
vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\Hotseat.java
在 resetLayout() 中将 FeatureFlags.NO_ALL_APPS_ICON 写成 true 则默认加载六个点按钮
void resetLayout() {
mContent.removeAllViewsInLayout();
//change true default add all app button
if (/*!FeatureFlags.NO_ALL_APPS_ICON*/true) {
// Add the Apps button
Context context = getContext();
DeviceProfile grid = mLauncher.getDeviceProfile();
int allAppsButtonRank = grid.inv.getAllAppsButtonRank();
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);
d.setBounds(0, 0, grid.iconSizePx, grid.iconSizePx);
...
}
}
vendor\mediatek\proprietary\packages\apps\Launcher3\res\layout-land\launcher.xml
给 PageIndicatorCaretLandscape 控件添加 gone 属性,注意我此处修改的是横屏的版本,若你是竖屏则修改
layout 文件夹下 launcher.xml
<com.android.launcher3.pageindicators.PageIndicatorCaretLandscape
android:id="@+id/page_indicator"
android:theme="@style/HomeScreenElementTheme"
android:layout_width="@dimen/dynamic_grid_min_page_indicator_size"
android:layout_height="@dimen/dynamic_grid_min_page_indicator_size"
android:layout_gravity="bottom|left"
android:visibility="gone"/>
此处添加完成后小箭头确实不显示了,但是当你在 workspace 长按时,小箭头又出现了,坑爹的找了半天,最终终
于搞定了。
vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\pageindicators\PageIndicatorCaretLandscape.java
@Override
protected void onDraw(Canvas canvas) {
//annotaion for longclick don't show up arrow
/*Rect drawableBounds = getCaretDrawable().getBounds();
int count = canvas.save();
canvas.translate((getWidth() - drawableBounds.width()) / 2,
getHeight() - drawableBounds.height());
getCaretDrawable().draw(canvas);
canvas.restoreToCount(count);*/
}
注释 onDraw() 的方法体就好了,因为当你长按 workSpace 时,触发长按事件,最终调用了 Launcher
中的 showOverviewMode(),通过 mWorkspace.setVisibility(View.VISIBLE);
PageIndicatorCaretLandscape 和 Workspace 是绑定的,导致 onDraw 执行,重新绘制。
vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\allapps\AllAppsTransitionController.java
@Override
public boolean onDrag(float displacement, float velocity) {
Log.e("Launcher3", "onDrag()");
if (true) return true;
//add for forbidden workspace drag change GradientView alph
if (mAppsView == null) {
return false; // early termination.
}
mContainerVelocity = velocity;
float shift = Math.min(Math.max(0, mShiftStart + displacement), mShiftRange);
setProgress(shift / mShiftRange);
return true;
}
@Override
public void onDragEnd(float velocity, boolean fling) {
Log.e("Launcher3", "onDragEnd()");
//add for forbidden workspace drag change GradientView alph
if (true){
if (velocity < 0) {
mLauncher.showWorkspace(true);
}
return;
}
//add for forbidden workspace drag change GradientView alph
if (mAppsView == null) {
return; // early termination.
}
final int containerType = mTouchEventStartedOnHotseat
? ContainerType.HOTSEAT : ContainerType.WORKSPACE;
if (fling) {
if (velocity < 0) {
calculateDuration(velocity, mAppsView.getTranslationY());
if (!mLauncher.isAllAppsVisible()) {
mLauncher.getUserEventDispatcher().logActionOnContainer(
Action.Touch.FLING,
Action.Direction.UP,
containerType);
}
mLauncher.showAppsView(true /* animated */, false /* updatePredictedApps */);
if (hasSpringAnimationHandler()) {
mSpringAnimationHandler.add(mSearchSpring, true /* setDefaultValues */);
// The icons are moving upwards, so we go to 0 from 1. (y-axis 1 is below 0.)
mSpringAnimationHandler.animateToFinalPosition(0 /* pos */, 1 /* startValue */);
}
} else {
calculateDuration(velocity, Math.abs(mShiftRange - mAppsView.getTranslationY()));
mLauncher.showWorkspace(true);
}
// snap to top or bottom using the release velocity
}
.....
}
分别在 onDrag() 和 onDragEnd() 回调方法中直接 return,需要注意的是在 onDragEnd 中需要将
workSpace 的状态复原,不然下一次点击所有APP 按钮时,会出现白屏现象。
alps\vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\DeviceProfile.java
public void layout(Launcher launcher, boolean notifyListeners) {
FrameLayout.LayoutParams lp;
boolean hasVerticalBarLayout = isVerticalBarLayout();
// Layout the search bar space
Point searchBarBounds = getSearchBarDimensForWidgetOpts();
View searchBar = launcher.getDropTargetBar();
lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
//lp.width = searchBarBounds.x;
//lp.height = searchBarBounds.y;
lp.width = 96;
lp.height = 720;
lp.topMargin = mInsets.top + edgeMarginPx;
searchBar.setLayoutParams(lp);
Log.i("Launcher3.profiles","lp.topMargin ="+lp.topMargin + " width="+lp.width+" height="+lp.height);
// Layout the workspace
PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
Rect workspacePadding = getWorkspacePadding(null);
workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right,
workspacePadding.bottom);
workspace.setPageSpacing(getWorkspacePageSpacing());
Log.e("Launcher3.profiles","left="+workspacePadding.left + " top="+workspacePadding.top
+" right="+workspacePadding.right + " bottom="+workspacePadding.bottom);
Log.d("Launcher3.profiles","setPageSpacing="+getWorkspacePageSpacing());
...
}
DeviceProfile 中的 layout() 方法很关键,你所有看到的界面都是走这来放置控件。通过打印日志发现,没横屏
状态下的宽高分别是 96720, 横屏状态下宽高为 112096,将 searchBar 的宽高强制写成 96*720
vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\BubbleTextView.java
public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mLauncher = Launcher.getLauncher(context);
DeviceProfile grid = mLauncher.getDeviceProfile();
mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.BubbleTextView, defStyle, 0);
mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
mDeferShadowGenerationOnTouch =
a.getBoolean(R.styleable.BubbleTextView_deferShadowGeneration, false);
int display = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
int defaultIconSize = grid.iconSizePx;
if (display == DISPLAY_WORKSPACE) {
setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
//cczheng add -11 for text show half
setCompoundDrawablePadding(grid.iconDrawablePaddingPx - 11);
} else if (display == DISPLAY_ALL_APPS) {
setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx);
setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
defaultIconSize = grid.allAppsIconSizePx;
} else if (display == DISPLAY_FOLDER) {
setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.folderChildTextSizePx);
setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
defaultIconSize = grid.folderChildIconSizePx;
}
.......
setCompoundDrawablePadding()方法 设置图片和 text 之间的间距 ,我们的问题是间距太大导致的,所以在 DISPLAY_WORKSPACE 语句块中,将间距减少 11,同样的当两个图标放置到一块成为文件夹时,对应修改的地方如下,而不是上面的 DISPLAY_FOLDER 语句块。
vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\folder\FolderIcon.java
public static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group,
FolderInfo folderInfo) {
@SuppressWarnings("all") // suppress dead code warning
final boolean error = INITIAL_ITEM_ANIMATION_DURATION >= DROP_IN_ANIMATION_DURATION;
if (error) {
throw new IllegalStateException("DROP_IN_ANIMATION_DURATION must be greater than " +
"INITIAL_ITEM_ANIMATION_DURATION, as sequencing of adding first two items " +
"is dependent on this");
}
DeviceProfile grid = launcher.getDeviceProfile();
FolderIcon icon = (FolderIcon) LayoutInflater.from(group.getContext())
.inflate(resId, group, false);
icon.setClipToPadding(false);
icon.mFolderName = (BubbleTextView) icon.findViewById(R.id.folder_icon_name);
icon.mFolderName.setText(folderInfo.title);
icon.mFolderName.setCompoundDrawablePadding(0);
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) icon.mFolderName.getLayoutParams();
//cczheng add -11 for folder text show half
lp.topMargin = grid.iconSizePx + grid.iconDrawablePaddingPx - 11;
icon.setTag(folderInfo);
icon.setOnClickListener(launcher);
icon.mInfo = folderInfo;
icon.mLauncher = launcher;
....
mFolderName 的 setCompoundDrawablePadding 已经是 0, 下面又增加了单独的 marginTop ,同理减去 11.