Changing the state UI logic for normal build and quickStep build

> Creating ShareHandlers for managing UI
> In normal build, hotseat is hidden in overview, while in QuickStepBuild, it is visible

Change-Id: I5f8d35c75b861d912d93fce186b5dd74106184c3
This commit is contained in:
Sunny Goyal 2017-11-07 12:23:58 -08:00
parent 16764588c9
commit c4fa8c312b
13 changed files with 187 additions and 58 deletions

View File

@ -16,16 +16,11 @@
package com.android.launcher3.uioverrides;
import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
import static com.android.launcher3.Utilities.isAccessibilityEnabled;
import android.graphics.Rect;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Workspace;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.quickstep.RecentsView;
@ -37,7 +32,7 @@ public class OverviewState extends LauncherState {
// The percent to shrink the workspace during overview mode
public static final float SCALE_FACTOR = 0.7f;
private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_HIDE_HOTSEAT;
private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE;
public OverviewState(int id) {
super(id, ContainerType.WORKSPACE, OVERVIEW_TRANSITION_MS, 1f, STATE_FLAGS);
@ -46,7 +41,7 @@ public class OverviewState extends LauncherState {
@Override
public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
// TODO: Find a better transition
return new float[] {SCALE_FACTOR, 0};
return new float[] {0f, 0};
}
@Override

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.uioverrides;
import static com.android.launcher3.WorkspaceStateTransitionAnimation.NO_ANIM_PROPERTY_SETTER;
import android.animation.AnimatorSet;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherStateManager.AnimationConfig;
import com.android.launcher3.LauncherStateManager.StateHandler;
import com.android.launcher3.WorkspaceStateTransitionAnimation.AnimatedPropertySetter;
import com.android.launcher3.WorkspaceStateTransitionAnimation.PropertySetter;
import com.android.launcher3.anim.AnimationLayerSet;
public class RecentsViewStateController implements StateHandler {
private final Launcher mLauncher;
public RecentsViewStateController(Launcher launcher) {
mLauncher = launcher;
}
@Override
public void setState(LauncherState state) {
setState(state, NO_ANIM_PROPERTY_SETTER);
}
@Override
public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
AnimatorSet anim, AnimationConfig config) {
setState(toState, new AnimatedPropertySetter(config.duration, layerViews, anim));
}
private void setState(LauncherState state, PropertySetter setter) {
setter.setViewAlpha(null, mLauncher.getOverviewPanel(),
state == LauncherState.OVERVIEW ? 1 : 0);
}
}

View File

@ -19,6 +19,7 @@ package com.android.launcher3.uioverrides;
import android.view.View.AccessibilityDelegate;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherStateManager.StateHandler;
import com.android.launcher3.VerticalSwipeController;
import com.android.launcher3.util.TouchController;
@ -31,4 +32,10 @@ public class UiFactory {
public static AccessibilityDelegate newPageIndicatorAccessibilityDelegate() {
return null;
}
public static StateHandler[] getStateHandler(Launcher launcher) {
return new StateHandler[] {
launcher.getAllAppsController(), launcher.getWorkspace(),
new RecentsViewStateController(launcher)};
}
}

View File

@ -17,13 +17,19 @@
package com.android.quickstep;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.HorizontalScrollView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
/**
* A placeholder view for recents
*/
public class RecentsView extends HorizontalScrollView {
public class RecentsView extends HorizontalScrollView implements Insettable {
public RecentsView(Context context) {
this(context, null);
}
@ -35,7 +41,23 @@ public class RecentsView extends HorizontalScrollView {
public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setAlpha(0);
setVisibility(INVISIBLE);
}
public void setViewVisible(boolean isVisible) { }
@Override
public void setInsets(Rect insets) {
MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams();
lp.topMargin = insets.top;
lp.bottomMargin = insets.bottom;
lp.leftMargin = insets.left;
lp.rightMargin = insets.right;
DeviceProfile dp = Launcher.getLauncher(getContext()).getDeviceProfile();
if (!dp.isVerticalBarLayout()) {
lp.bottomMargin += dp.hotseatBarSizePx + getResources().getDimensionPixelSize(
R.dimen.dynamic_grid_min_page_indicator_size);
}
}
}

View File

@ -339,7 +339,7 @@ public class Launcher extends BaseActivity
mDragController = new DragController(this);
mAllAppsController = new AllAppsTransitionController(this);
mStateManager = new LauncherStateManager(this, mAllAppsController);
mStateManager = new LauncherStateManager(this);
mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
@ -1287,6 +1287,10 @@ public class Launcher extends BaseActivity
}
}
public AllAppsTransitionController getAllAppsController() {
return mAllAppsController;
}
public DragLayer getDragLayer() {
return mDragLayer;
}

View File

@ -36,9 +36,8 @@ public class LauncherState {
protected static final int FLAG_SHOW_SCRIM = 1 << 0;
protected static final int FLAG_MULTI_PAGE = 1 << 1;
protected static final int FLAG_HIDE_HOTSEAT = 1 << 2;
protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 3;
protected static final int FLAG_DO_NOT_RESTORE = 1 << 4;
protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 2;
protected static final int FLAG_DO_NOT_RESTORE = 1 << 3;
private static final LauncherState[] sAllStates = new LauncherState[4];
@ -80,7 +79,6 @@ public class LauncherState {
* @see WorkspaceStateTransitionAnimation
*/
public final boolean hasScrim;
public final boolean hideHotseat;
public final int transitionDuration;
/**
@ -97,7 +95,6 @@ public class LauncherState {
this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0;
this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0;
this.hideHotseat = (flags & FLAG_HIDE_HOTSEAT) != 0;
this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0
? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
: IMPORTANT_FOR_ACCESSIBILITY_AUTO;

View File

@ -29,6 +29,7 @@ import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.uioverrides.UiFactory;
/**
* TODO: figure out what kind of tests we can write for this
@ -78,21 +79,26 @@ public class LauncherStateManager {
private final AnimationConfig mConfig = new AnimationConfig();
private final Handler mUiHandler;
private final Launcher mLauncher;
private final AllAppsTransitionController mAllAppsController;
private StateHandler[] mStateHandlers;
private LauncherState mState = NORMAL;
public LauncherStateManager(
Launcher l, AllAppsTransitionController allAppsController) {
public LauncherStateManager(Launcher l) {
mUiHandler = new Handler(Looper.getMainLooper());
mLauncher = l;
mAllAppsController = allAppsController;
}
public LauncherState getState() {
return mState;
}
private StateHandler[] getStateHandlers() {
if (mStateHandlers == null) {
mStateHandlers = UiFactory.getStateHandler(mLauncher);
}
return mStateHandlers;
}
/**
* @see #goToState(LauncherState, boolean, Runnable)
*/
@ -148,8 +154,9 @@ public class LauncherStateManager {
if (!animated) {
setState(state);
mAllAppsController.setFinalProgress(state.verticalProgress);
mLauncher.getWorkspace().setState(state);
for (StateHandler handler : getStateHandlers()) {
handler.setState(state);
}
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
// Run any queued runnable
@ -190,14 +197,12 @@ public class LauncherStateManager {
protected AnimatorSet createAnimationToNewWorkspaceInternal(final LauncherState state,
final Runnable onCompleteRunnable) {
final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
final AnimationLayerSet layerViews = new AnimationLayerSet();
mAllAppsController.animateToFinalProgress(state.verticalProgress, animation, mConfig);
mLauncher.getWorkspace().setStateWithAnimation(state,
layerViews, animation, mConfig);
for (StateHandler handler : getStateHandlers()) {
handler.setStateWithAnimation(state, layerViews, animation, mConfig);
}
animation.addListener(layerViews);
animation.addListener(new AnimationSuccessListener() {
@ -285,4 +290,18 @@ public class LauncherStateManager {
mCurrentAnimation.addListener(this);
}
}
public interface StateHandler {
/**
* Updates the UI to {@param state} without any animations
*/
void setState(LauncherState state);
/**
* Sets the UI to {@param state} by animating any changes.
*/
void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
AnimatorSet anim, AnimationConfig config);
}
}

View File

@ -105,7 +105,7 @@ import java.util.Set;
public class Workspace extends PagedView
implements DropTarget, DragSource, View.OnTouchListener,
DragController.DragListener, ViewGroup.OnHierarchyChangeListener,
Insettable {
Insettable, LauncherStateManager.StateHandler {
private static final String TAG = "Launcher.Workspace";
/** The value that {@link #mTransitionProgress} must be greater than for
@ -1558,6 +1558,7 @@ public class Workspace extends PagedView
/**
* Sets the current workspace {@link LauncherState} and updates the UI without any animations
*/
@Override
public void setState(LauncherState toState) {
onStartStateTransition(toState);
mStateTransitionAnimation.setState(toState);
@ -1567,6 +1568,7 @@ public class Workspace extends PagedView
/**
* Sets the current workspace {@link LauncherState}, then animates the UI
*/
@Override
public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
AnimatorSet anim, AnimationConfig config) {
StateTransitionListener listener = new StateTransitionListener(toState);

View File

@ -90,7 +90,7 @@ class AlphaUpdateListener extends AnimatorListenerAdapter implements ValueAnimat
*/
public class WorkspaceStateTransitionAnimation {
private static final PropertySetter NO_ANIM_PROPERTY_SETTER = new PropertySetter();
public static final PropertySetter NO_ANIM_PROPERTY_SETTER = new PropertySetter();
public final int mWorkspaceScrimAlpha;
@ -141,14 +141,6 @@ public class WorkspaceStateTransitionAnimation {
propertySetter);
}
float finalHotseatAlpha = state.hideHotseat ? 0f : 1f;
// This is true when transitioning between:
// - Overview <-> Workspace
propertySetter.setViewAlpha(null, mLauncher.getOverviewPanel(), 1 - finalHotseatAlpha);
propertySetter.setViewAlpha(mWorkspace.createHotseatAlphaAnimator(finalHotseatAlpha),
mLauncher.getHotseat(), finalHotseatAlpha);
propertySetter.setFloat(mWorkspace, SCALE_PROPERTY, mNewScale, Interpolators.ZOOM_IN);
propertySetter.setFloat(mWorkspace, View.TRANSLATION_Y,
finalWorkspaceTranslationY, Interpolators.ZOOM_IN);
@ -176,7 +168,7 @@ public class WorkspaceStateTransitionAnimation {
}
}
private static class PropertySetter {
public static class PropertySetter {
public void setViewAlpha(Animator anim, View view, float alpha) {
if (anim != null) {
@ -204,13 +196,14 @@ public class WorkspaceStateTransitionAnimation {
}
}
private static class AnimatedPropertySetter extends PropertySetter {
public static class AnimatedPropertySetter extends PropertySetter {
private final long mDuration;
private final AnimationLayerSet mLayerViews;
private final AnimatorSet mStateAnimator;
AnimatedPropertySetter(long duration, AnimationLayerSet layerView, AnimatorSet anim) {
public AnimatedPropertySetter(
long duration, AnimationLayerSet layerView, AnimatorSet anim) {
mDuration = duration;
mLayerViews = layerView;
mStateAnimator = anim;

View File

@ -15,10 +15,12 @@ import android.view.animation.Interpolator;
import com.android.launcher3.Hotseat;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherStateManager;
import com.android.launcher3.LauncherStateManager.AnimationConfig;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.graphics.GradientView;
@ -35,7 +37,8 @@ import com.android.launcher3.util.Themes;
* If release velocity < THRES1, snap according to either top or bottom depending on whether it's
* closer to top or closer to the page indicator.
*/
public class AllAppsTransitionController implements SearchUiManager.OnScrollRangeChangeListener {
public class AllAppsTransitionController
implements SearchUiManager.OnScrollRangeChangeListener, LauncherStateManager.StateHandler {
private static final Property<AllAppsTransitionController, Float> PROGRESS =
new Property<AllAppsTransitionController, Float>(Float.class, "progress") {
@ -122,8 +125,8 @@ public class AllAppsTransitionController implements SearchUiManager.OnScrollRang
*
* @param progress value between 0 and 1, 0 shows all apps and 1 shows workspace
*
* @see #setFinalProgress(float)
* @see #animateToFinalProgress(float, AnimatorSet, AnimationConfig)
* @see #setState(LauncherState)
* @see #setStateWithAnimation(LauncherState, AnimationLayerSet, AnimatorSet, AnimationConfig)
*/
public void setProgress(float progress) {
mProgress = progress;
@ -161,33 +164,32 @@ public class AllAppsTransitionController implements SearchUiManager.OnScrollRang
}
/**
* Sets the vertical transition progress to {@param progress} and updates all the dependent UI
* Sets the vertical transition progress to {@param state} and updates all the dependent UI
* accordingly.
*/
public void setFinalProgress(float progress) {
setProgress(progress);
@Override
public void setState(LauncherState state) {
setProgress(state.verticalProgress);
onProgressAnimationEnd();
}
/**
* Creates an animation which updates the vertical transition progress and updates all the
* dependent UI using various animation events
*
* @param progress the final vertical progress at the end of the animation
* @param animationOut the target AnimatorSet where this animation should be added
* @param outConfig an in/out configuration which can be shared with other animations
*/
public void animateToFinalProgress(
float progress, AnimatorSet animationOut, AnimationConfig outConfig) {
if (Float.compare(mProgress, progress) == 0) {
@Override
public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
AnimatorSet animationOut, AnimationConfig config) {
if (Float.compare(mProgress, toState.verticalProgress) == 0) {
// Fail fast
onProgressAnimationEnd();
return;
}
Interpolator interpolator = outConfig.userControlled ? LINEAR : FAST_OUT_SLOW_IN;
ObjectAnimator anim = ObjectAnimator.ofFloat(this, PROGRESS, mProgress, progress);
anim.setDuration(outConfig.duration);
Interpolator interpolator = config.userControlled ? LINEAR : FAST_OUT_SLOW_IN;
ObjectAnimator anim = ObjectAnimator.ofFloat(
this, PROGRESS, mProgress, toState.verticalProgress);
anim.setDuration(config.duration);
anim.setInterpolator(interpolator);
anim.addListener(new AnimationSuccessListener() {
@Override

View File

@ -15,12 +15,14 @@
*/
package com.android.launcher3.uioverrides;
import static com.android.launcher3.WorkspaceStateTransitionAnimation.NO_ANIM_PROPERTY_SETTER;
import android.animation.AnimatorSet;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
@ -28,14 +30,20 @@ import android.widget.Toast;
import com.android.launcher3.Insettable;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherStateManager;
import com.android.launcher3.LauncherStateManager.AnimationConfig;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.WorkspaceStateTransitionAnimation.AnimatedPropertySetter;
import com.android.launcher3.WorkspaceStateTransitionAnimation.PropertySetter;
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
import com.android.launcher3.widget.WidgetsFullSheet;
public class OverviewPanel extends LinearLayout implements Insettable, View.OnClickListener,
View.OnLongClickListener {
View.OnLongClickListener, LauncherStateManager.StateHandler {
// Out of 100, the percent of space the overview bar should try and take vertically.
private static final float OVERVIEW_ICON_ZONE_RATIO = 0.22f;
@ -154,10 +162,30 @@ public class OverviewPanel extends LinearLayout implements Insettable, View.OnCl
getContext().startActivity(intent, mLauncher.getActivityLaunchOptions(v));
}
@Override
public void setState(LauncherState state) {
setState(state, NO_ANIM_PROPERTY_SETTER);
}
@Override
public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
AnimatorSet anim, AnimationConfig config) {
setState(toState, new AnimatedPropertySetter(config.duration, layerViews, anim));
}
private void setState(LauncherState state, PropertySetter setter) {
boolean isOverview = state == LauncherState.OVERVIEW;
float finalHotseatAlpha = isOverview ? 0 : 1;
setter.setViewAlpha(null, this, isOverview ? 1 : 0);
setter.setViewAlpha(
mLauncher.getWorkspace().createHotseatAlphaAnimator(finalHotseatAlpha),
mLauncher.getHotseat(), finalHotseatAlpha);
}
public static int getButtonBarHeight(Launcher launcher) {
int zoneHeight = (int) (OVERVIEW_ICON_ZONE_RATIO *
launcher.getDeviceProfile().availableWidthPx);
launcher.getDeviceProfile().availableHeightPx);
Resources res = launcher.getResources();
int overviewModeMinIconZoneHeightPx =
res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height);

View File

@ -36,7 +36,7 @@ public class OverviewState extends LauncherState {
// The percent to shrink the workspace during overview mode
public static final float SCALE_FACTOR = 0.7f;
private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_HIDE_HOTSEAT;
private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE;
public OverviewState(int id) {
super(id, ContainerType.WORKSPACE, OVERVIEW_TRANSITION_MS, 1f, STATE_FLAGS);

View File

@ -19,6 +19,7 @@ package com.android.launcher3.uioverrides;
import android.view.View.AccessibilityDelegate;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherStateManager.StateHandler;
import com.android.launcher3.VerticalSwipeController;
import com.android.launcher3.util.TouchController;
@ -32,4 +33,10 @@ public class UiFactory {
public static AccessibilityDelegate newPageIndicatorAccessibilityDelegate() {
return new OverviewAccessibilityDelegate();
}
public static StateHandler[] getStateHandler(Launcher launcher) {
return new StateHandler[] {
(OverviewPanel) launcher.getOverviewPanel(),
launcher.getAllAppsController(), launcher.getWorkspace() };
}
}