需求:有些项目不要热座,要求去掉热座
以前的做法是把DeviceProfile里与hotseat有关的变量改为0之类的,改动比较大。为什么不通过简单的把mHotseat设置为GONE呢
因为在各种视图变化的时候,会把hotseat再次显示出来,因此尝试新的方法来实现。
step1:把hotseat默认改为GONE 在launcher.xml里把hotseat设为gone
<!--Kevin.Ye set hotseat as gone-->
<include
android:id="@+id/hotseat"
layout="@layout/hotseat"
android:visibility="gone"/>
step2:为了兼容其他项目需要保留hotseat的功能,在FeatureFlag.java中添加flag
java">public static final boolean REMOVE_HOTSEAT = true;//Kevin.Ye added for removing hotseat
step3:在Launcher.java里的setupViews(),把mHotseat设为GONE
java">/*** Finds all the views we need and configure them properly.*/protected void setupViews() {mDragLayer = findViewById(R.id.drag_layer);mFocusHandler = mDragLayer.getFocusIndicatorHelper();mWorkspace = mDragLayer.findViewById(R.id.workspace);mWorkspace.initParentViews(mDragLayer);mOverviewPanel = findViewById(R.id.overview_panel);mHotseat = findViewById(R.id.hotseat);mHotseat.setWorkspace(mWorkspace);mHotseatController = new HotseatController(this.getApplicationContext(),this);//Kevin.Yeif(FeatureFlags.REMOVE_HOTSEAT)mHotseat.setVisibility(View.GONE);//Kevin.Ye added for removing hotseat// Setup the drag layermDragLayer.setup(mDragController, mWorkspace);
setup4:在Hotseat.java中的onVisibilityAggregated屏蔽所有的setVisibility操作,也许前面的步骤也不需要!不确定
java">@Override
public void onVisibilityAggregated(boolean isVisible) {super.onVisibilityAggregated(isVisible);if(getVisibility() != View.GONE)//Kevin.Ye added for set hotseat always GONE!setVisibility(View.GONE);if (mOnVisibilityAggregatedCallback != null) {mOnVisibilityAggregatedCallback.accept(isVisible);}
}
step5: Workspace.java中不要允许hotseat作为拖拽图标的目的Layout
java">private boolean shouldUseHotseatAsDropLayout(DragObject dragObject) {if(FeatureFlags.REMOVE_HOTSEAT) return false;//Kevin.Ye not allow hotseat as dragTargetif(mLauncher.getHotseatContainer().getVisibility() != View.VISIBLE) return false;//Kevin.Ye added for not allow drag to hotseatif (mLauncher.getHotseat() == null|| mLauncher.getHotseat().getShortcutsAndWidgets() == null|| isDragWidget(dragObject)) {return false;}View hotseatShortcuts = mLauncher.getHotseat().getShortcutsAndWidgets();getViewBoundsRelativeToWorkspace(hotseatShortcuts, mTempRect);return mTempRect.contains(dragObject.x, dragObject.y);}
step6: WorkspacePageIndicator.java里的setInsets接口修改一下,不要影响页面指示器的位置
java"> if(FeatureFlags.REMOVE_HOTSEAT)lp.bottomMargin = insets.bottom;//there is no hotseatBarSizeelselp.bottomMargin = grid.hotseatBarSizePx + insets.bottom;lp.bottomMargin = insets.bottom + mMarginBottom;//Kevin.Ye modified end}setLayoutParams(lp);