如果想控制用户长按空白处,不进入OverviewMode模式,只需修改Laucnher类中的onLongClick方法。
长按workspace的空白处进入OverviewMode模式,如果不想进入,注释掉enterOverviewMode这行代码
if(v instanceof Workspace){
if (!mWorkspace.isInOverviewMode()) {
if (mWorkspace.enterOverviewMode()) {
mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
return true;
} else {
return false;
}
} else {
return false;
}
}
同样,长按Hostseat空白处,也要控制是否进入OverviewMode模式,处理同上。
// The hotseat touch handling does not go through Workspace, and we always allow long press
// on hotseat items.
final boolean inHotseat = isHotseatLayout(v);
boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
if (allowLongPress && !mDragController.isDragging()) {
if (itemUnderLongClick == null) {
// User long pressed on empty space
mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
if (mWorkspace.isInOverviewMode()) {
mWorkspace.startReordering(v);
} else {
mWorkspace.enterOverviewMode();
}
} else {
final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
mHotseat.getOrderInHotseat(
longClickCellInfo.cellX,
longClickCellInfo.cellY));
if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
// User long pressed on an item
mWorkspace.startDrag(longClickCellInfo);
}
}
}
进入OverviewMode模式,点击Home无法复原,一直处于OverviewMode模式,无法退出。造成这个问题的原因是
因为Launcher中的hideAppsCustomizeHelper方法判断是否需要退出OverviewMode模式时, boolean initialized = get
AllAppsButton() != null;这里这个参数会一直都是false,以为赋值给该参数的方法判定条件是!LauncherAppState.isDis
ableAllApps(),我修改了这里永远返回true。所以我们从新修改hideAppsCustomizeHelper方法中退出OverviewMode
模式的条件即可。同时也把showAppsCustomizeHelper中的判断方法的initialized 去掉去掉。以免造成不必要的麻烦
/**
* Zoom the camera back into the workspace, hiding 'fromView'.
* This is the opposite of showAppsCustomizeHelper.
* @param animated If true, the transition will be animated.
*/
private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
final boolean springLoaded, final Runnable onCompleteRunnable) {
if (mStateAnimation != null) {
mStateAnimation.setDuration(0);
mStateAnimation.cancel();
mStateAnimation = null;
}
boolean material = Utilities.isLmpOrAbove();
Resources res = getResources();
final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
final int itemsAlphaStagger =
res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
final float scaleFactor = (float)
res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
final View fromView = mAppsCustomizeTabHost;
final View toView = mWorkspace;
Animator workspaceAnim = null;
final ArrayList<View> layerViews = new ArrayList<View>();
if (toState == Workspace.State.NORMAL) {
workspaceAnim = mWorkspace.getChangeStateAnimation(
toState, animated, layerViews);
} else if (toState == Workspace.State.SPRING_LOADED ||
toState == Workspace.State.OVERVIEW) {
workspaceAnim = mWorkspace.getChangeStateAnimation(
toState, animated, layerViews);
}
// If for some reason our views aren't initialized, don't animate
boolean initialized = getAllAppsButton() != null;
/**
* 修改此处,解决长按空白处显示修改壁纸后点击Home键无法恢复的bug
*
* 因为在HotSeat方法中的setAllAppsButton()的条件是!LauncherAppState.isDisableAllApps()
*
* 修改默认返回为true后,就不会总setAllAppsButton的方法,所以getAllAppsButton()永远为空
*
*/
// if (animated && initialized) {
if (animated ) {
mStateAnimation = LauncherAnimUtils.createAnimatorSet();
if (workspaceAnim != null) {
mStateAnimation.play(workspaceAnim);
}
final AppsCustomizePagedView content = (AppsCustomizePagedView)
fromView.findViewById(R.id.apps_customize_pane_content);