Merge "Removing QsbBlockerView" into ub-launcher3-dorval-polish

This commit is contained in:
TreeHugger Robot 2017-06-07 00:47:55 +00:00 committed by Android (Google) Code Review
commit da84e97947
12 changed files with 8 additions and 378 deletions

View File

@ -67,12 +67,6 @@
android:layout_height="@dimen/dynamic_grid_page_indicator_height"
android:layout_gravity="bottom|left"/>
<!-- A place holder view instead of the QSB in transposed layout -->
<View
android:layout_width="0dp"
android:layout_height="10dp"
android:id="@+id/workspace_blocked_row" />
<include layout="@layout/widgets_view"
android:id="@+id/widgets_view"
android:layout_width="match_parent"

View File

@ -66,10 +66,6 @@
android:id="@+id/drop_target_bar"
layout="@layout/drop_target_bar_horz" />
<include
layout="@layout/qsb_container"
android:id="@+id/qsb_container" />
<include layout="@layout/widgets_view"
android:id="@+id/widgets_view"
android:layout_width="match_parent"

View File

@ -65,10 +65,6 @@
<include layout="@layout/page_indicator"
android:id="@+id/page_indicator" />
<include
layout="@layout/qsb_container"
android:id="@+id/qsb_container" />
<include layout="@layout/widgets_view"
android:id="@+id/widgets_view"
android:layout_width="match_parent"

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.
-->
<com.android.launcher3.qsb.QsbBlockerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -114,9 +114,6 @@
<!-- View ID to use for QSB widget -->
<item type="id" name="qsb_widget" />
<!-- View ID to use for blocked area on the first screen -->
<item type="id" name="workspace_blocked_row" />
<!-- View ID used by cell layout to jail its content -->
<item type="id" name="cell_layout_jail_id" />

View File

@ -532,14 +532,6 @@ public class DeviceProfile {
workspacePadding.bottom);
workspace.setPageSpacing(getWorkspacePageSpacing());
// Only display when enabled
if (FeatureFlags.QSB_ON_FIRST_SCREEN) {
View qsbContainer = launcher.getQsbContainer();
lp = (FrameLayout.LayoutParams) qsbContainer.getLayoutParams();
lp.topMargin = mInsets.top + workspacePadding.top;
qsbContainer.setLayoutParams(lp);
}
// Layout the hotseat
Hotseat hotseat = (Hotseat) launcher.findViewById(R.id.hotseat);
lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();

View File

@ -224,7 +224,6 @@ public class Launcher extends BaseActivity
private View mLauncherView;
@Thunk DragLayer mDragLayer;
private DragController mDragController;
private View mQsbContainer;
public View mWeightWatcher;
@ -1278,9 +1277,7 @@ public class Launcher extends BaseActivity
private void setupViews() {
mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
mFocusHandler = mDragLayer.getFocusIndicatorHelper();
mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
mQsbContainer = mDragLayer.findViewById(mDeviceProfile.isVerticalBarLayout()
? R.id.workspace_blocked_row : R.id.qsb_container);
mWorkspace = mDragLayer.findViewById(R.id.workspace);
mWorkspace.initParentViews(mDragLayer);
mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
@ -1667,10 +1664,6 @@ public class Launcher extends BaseActivity
return mWorkspace;
}
public View getQsbContainer() {
return mQsbContainer;
}
public Hotseat getHotseat() {
return mHotseat;
}

View File

@ -56,11 +56,10 @@ public class PinchAnimationManager {
private static final LinearInterpolator INTERPOLATOR = new LinearInterpolator();
private static final int INDEX_HOTSEAT = 0;
private static final int INDEX_QSB = 1;
private static final int INDEX_OVERVIEW_PANEL_BUTTONS = 2;
private static final int INDEX_SCRIM = 3;
private static final int INDEX_OVERVIEW_PANEL_BUTTONS = 1;
private static final int INDEX_SCRIM = 2;
private final Animator[] mAnimators = new Animator[4];
private final Animator[] mAnimators = new Animator[3];
private Launcher mLauncher;
private Workspace mWorkspace;
@ -196,8 +195,6 @@ public class PinchAnimationManager {
private void animateHotseatAndQsb(boolean show) {
startAnimator(INDEX_HOTSEAT,
mWorkspace.createHotseatAlphaAnimator(show ? 1 : 0), THRESHOLD_ANIM_DURATION);
startAnimator(INDEX_QSB, mWorkspace.mQsbAlphaController.animateAlphaAtIndex(
show ? 1 : 0, Workspace.QSB_ALPHA_INDEX_STATE_CHANGE), THRESHOLD_ANIM_DURATION);
}
private void animateOverviewPanelButtons(boolean show) {

View File

@ -80,7 +80,6 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.MultiStateAlphaController;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.VerticalFlingDetector;
@ -234,14 +233,6 @@ public class Workspace extends PagedView
*/
private float[] mHotseatAlpha = new float[] {1, 1, 1};
public static final int QSB_ALPHA_INDEX_STATE_CHANGE = 0;
public static final int QSB_ALPHA_INDEX_Y_TRANSLATION = 1;
public static final int QSB_ALPHA_INDEX_PAGE_SCROLL = 2;
public static final int QSB_ALPHA_INDEX_OVERLAY_SCROLL = 3;
MultiStateAlphaController mQsbAlphaController;
@ViewDebug.ExportedProperty(category = "launcher")
private State mState = State.NORMAL;
private boolean mIsSwitchingState = false;
@ -323,7 +314,6 @@ public class Workspace extends PagedView
private WorkspaceStateTransitionAnimation mStateTransitionAnimation;
private AccessibilityDelegate mPagesAccessibilityDelegate;
private OnStateChangeListener mOnStateChangeListener;
/**
* Used to inflate the Workspace from XML.
@ -378,10 +368,6 @@ public class Workspace extends PagedView
}
}
public void setOnStateChangeListener(OnStateChangeListener listener) {
mOnStateChangeListener = listener;
}
/**
* Estimates the size of an item using spans: hSpan, vSpan.
*
@ -536,7 +522,6 @@ public class Workspace extends PagedView
public void initParentViews(View parent) {
super.initParentViews(parent);
mPageIndicator.setAccessibilityDelegate(new OverviewAccessibilityDelegate());
mQsbAlphaController = new MultiStateAlphaController(mLauncher.getQsbContainer(), 4);
}
private int getDefaultPage() {
@ -576,11 +561,6 @@ public class Workspace extends PagedView
return mTouchState != TOUCH_STATE_REST;
}
private int getEmbeddedQsbId() {
return mLauncher.getDeviceProfile().isVerticalBarLayout()
? R.id.qsb_container : R.id.workspace_blocked_row;
}
/**
* Initializes and binds the first page
* @param qsb an existing qsb to recycle or null.
@ -622,41 +602,17 @@ public class Workspace extends PagedView
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(
mLauncher.getDeviceProfile().isVerticalBarLayout()
? R.layout.qsb_container : R.layout.qsb_blocker_view,
firstPage, false);
qsb = LayoutInflater.from(getContext())
.inflate(R.layout.qsb_container,firstPage, false);
}
CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(), 1);
lp.canReorder = false;
if (!firstPage.addViewToCellLayout(qsb, 0, getEmbeddedQsbId(), lp, true)) {
if (!firstPage.addViewToCellLayout(qsb, 0, R.id.qsb_container, lp, true)) {
Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout");
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// Update the QSB to match the cell height. This is treating the QSB essentially as a child
// of workspace despite that it's not a true child.
// Note that it relies on the strict ordering of measuring the workspace before the QSB
// at the dragLayer level.
// Only measure the QSB when the view is enabled
if (FeatureFlags.QSB_ON_FIRST_SCREEN && getChildCount() > 0) {
CellLayout firstPage = (CellLayout) getChildAt(0);
int cellHeight = firstPage.getCellHeight();
View qsbContainer = mLauncher.getQsbContainer();
ViewGroup.LayoutParams lp = qsbContainer.getLayoutParams();
if (cellHeight > 0 && lp.height != cellHeight) {
lp.height = cellHeight;
qsbContainer.setLayoutParams(lp);
}
}
}
public void removeAllWorkspaceScreens() {
// Disable all layout transitions before removing all pages to ensure that we don't get the
// transition animations competing with us changing the scroll when we add pages or the
@ -670,7 +626,7 @@ public class Workspace extends PagedView
}
// Recycle the QSB widget
View qsb = findViewById(getEmbeddedQsbId());
View qsb = findViewById(R.id.qsb_container);
if (qsb != null) {
((ViewGroup) qsb.getParent()).removeView(qsb);
}
@ -1406,17 +1362,9 @@ public class Workspace extends PagedView
super.scrollTo(x, y);
}
private void onWorkspaceOverallScrollChanged() {
if (!mIgnoreQsbScroll) {
mLauncher.getQsbContainer().setTranslationX(
mOverlayTranslation + mFirstPageScrollX - getScrollX());
}
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
onWorkspaceOverallScrollChanged();
// Update the page indicator progress.
boolean isTransitioning = mIsSwitchingState
@ -1497,9 +1445,6 @@ public class Workspace extends PagedView
// device I've tried, translating the launcher causes things to get quite laggy.
setWorkspaceTranslationAndAlpha(Direction.X, transX, alpha);
setHotseatTranslationAndAlpha(Direction.X, transX, alpha);
onWorkspaceOverallScrollChanged();
mQsbAlphaController.setAlphaAtIndex(alpha, QSB_ALPHA_INDEX_OVERLAY_SCROLL);
}
/**
@ -1509,9 +1454,6 @@ public class Workspace extends PagedView
*/
public void setWorkspaceYTranslationAndAlpha(float translation, float alpha) {
setWorkspaceTranslationAndAlpha(Direction.Y, translation, alpha);
mLauncher.getQsbContainer().setTranslationY(translation);
mQsbAlphaController.setAlphaAtIndex(alpha, QSB_ALPHA_INDEX_Y_TRANSLATION);
}
/**
@ -1707,10 +1649,6 @@ public class Workspace extends PagedView
float scrollProgress = getScrollProgress(screenCenter, child, i);
float alpha = 1 - Math.abs(scrollProgress);
child.getShortcutsAndWidgets().setAlpha(alpha);
if (isQsbContainerPage(i)) {
mQsbAlphaController.setAlphaAtIndex(alpha, QSB_ALPHA_INDEX_PAGE_SCROLL);
}
}
}
}
@ -1805,7 +1743,6 @@ public class Workspace extends PagedView
}
super.onLayout(changed, left, top, right, bottom);
mFirstPageScrollX = getScrollForPage(0);
onWorkspaceOverallScrollChanged();
final LayoutTransition transition = getLayoutTransition();
// If the transition is running defer updating max scroll, as some empty pages could
@ -1827,7 +1764,6 @@ public class Workspace extends PagedView
mIgnoreQsbScroll = false;
transition.removeTransitionListener(this);
mFirstPageScrollX = getScrollForPage(0);
onWorkspaceOverallScrollChanged();
}
}
});
@ -2070,10 +2006,6 @@ public class Workspace extends PagedView
mLauncher.notifyWidgetProvidersChanged();
}
if (mOnStateChangeListener != null) {
mOnStateChangeListener.prepareStateChange(toState, animated ? workspaceAnim : null);
}
onPrepareStateTransition(mState.hasMultipleVisiblePages);
StateTransitionListener listener = new StateTransitionListener();
@ -4230,20 +4162,6 @@ public class Workspace extends PagedView
}
}
public interface OnStateChangeListener {
/**
* Called when the workspace state is changing.
* @param toState final state
* @param targetAnim animation which will be played during the transition or null.
*/
void prepareStateChange(State toState, AnimatorSet targetAnim);
}
public static final boolean isQsbContainerPage(int pageNo) {
return pageNo == 0;
}
private class StateTransitionListener extends AnimatorListenerAdapter
implements AnimatorUpdateListener {
@Override

View File

@ -355,27 +355,10 @@ public class WorkspaceStateTransitionAnimation {
cl.setBackgroundAlpha(finalBackgroundAlpha);
cl.setShortcutAndWidgetAlpha(finalAlpha);
}
if (Workspace.isQsbContainerPage(i) &&
states.stateIsNormal && mWorkspaceFadeInAdjacentScreens) {
if (animated) {
Animator anim = mWorkspace.mQsbAlphaController
.animateAlphaAtIndex(finalAlpha, Workspace.QSB_ALPHA_INDEX_PAGE_SCROLL);
anim.setDuration(duration);
anim.setInterpolator(mZoomInInterpolator);
mStateAnimator.play(anim);
} else {
mWorkspace.mQsbAlphaController.setAlphaAtIndex(
finalAlpha, Workspace.QSB_ALPHA_INDEX_PAGE_SCROLL);
}
}
}
final ViewGroup overviewPanel = mLauncher.getOverviewPanel();
Animator qsbAlphaAnimation = mWorkspace.mQsbAlphaController
.animateAlphaAtIndex(finalQsbAlpha, Workspace.QSB_ALPHA_INDEX_STATE_CHANGE);
if (animated) {
Animator scale = LauncherAnimUtils.ofPropertyValuesHolder(mWorkspace,
new PropertyListBuilder().scale(mNewScale)
@ -393,7 +376,6 @@ public class WorkspaceStateTransitionAnimation {
// For animation optimization, we may need to provide the Launcher transition
// with a set of views on which to force build and manage layers in certain scenarios.
layerViews.addView(overviewPanel);
layerViews.addView(mLauncher.getQsbContainer());
layerViews.addView(mLauncher.getHotseat());
layerViews.addView(mWorkspace.getPageIndicator());
@ -407,11 +389,9 @@ public class WorkspaceStateTransitionAnimation {
overviewPanelAlpha.setDuration(duration);
hotseatAlpha.setDuration(duration);
qsbAlphaAnimation.setDuration(duration);
mStateAnimator.play(overviewPanelAlpha);
mStateAnimator.play(hotseatAlpha);
mStateAnimator.play(qsbAlphaAnimation);
mStateAnimator.addListener(new AnimatorListenerAdapter() {
boolean canceled = false;
@Override
@ -439,7 +419,6 @@ public class WorkspaceStateTransitionAnimation {
AlphaUpdateListener.updateVisibility(overviewPanel, accessibilityEnabled);
mWorkspace.getPageIndicator().setShouldAutoHide(!states.stateIsSpringLoaded);
qsbAlphaAnimation.end();
mWorkspace.createHotseatAlphaAnimator(finalHotseatAlpha).end();
mWorkspace.updateCustomContentVisibility();
mWorkspace.setScaleX(mNewScale);

View File

@ -1,93 +0,0 @@
/*
* Copyright (C) 2016 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.qsb;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import com.android.launcher3.Launcher;
import com.android.launcher3.Workspace;
import com.android.launcher3.Workspace.OnStateChangeListener;
import com.android.launcher3.Workspace.State;
/**
* A simple view used to show the region blocked by QSB during drag and drop.
*/
public class QsbBlockerView extends View implements OnStateChangeListener {
private static final int VISIBLE_ALPHA = 100;
private final Paint mBgPaint;
public QsbBlockerView(Context context, AttributeSet attrs) {
super(context, attrs);
mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBgPaint.setColor(Color.WHITE);
mBgPaint.setAlpha(0);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
Workspace w = Launcher.getLauncher(getContext()).getWorkspace();
w.setOnStateChangeListener(this);
prepareStateChange(w.getState(), null);
}
@Override
public void prepareStateChange(State toState, AnimatorSet targetAnim) {
int finalAlpha = getAlphaForState(toState);
if (targetAnim == null) {
mBgPaint.setAlpha(finalAlpha);
invalidate();
} else {
ObjectAnimator anim = ObjectAnimator.ofArgb(mBgPaint, "alpha", finalAlpha);
anim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
invalidate();
}
});
targetAnim.play(anim);
}
}
private static int getAlphaForState(State state) {
switch (state) {
case SPRING_LOADED:
case OVERVIEW:
case OVERVIEW_HIDDEN:
return VISIBLE_ALPHA;
}
return 0;
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawPaint(mBgPaint);
}
}

View File

@ -1,119 +0,0 @@
/*
* Copyright (C) 2016 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.util;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import java.util.Arrays;
/**
* A utility class which divides the alpha for a view across multiple states.
*/
public class MultiStateAlphaController {
private final View mTargetView;
private final float[] mAlphas;
private final AccessibilityManager mAm;
private int mZeroAlphaListenerCount = 0;
public MultiStateAlphaController(View view, int stateCount) {
mTargetView = view;
mAlphas = new float[stateCount];
Arrays.fill(mAlphas, 1);
mAm = (AccessibilityManager) view.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
}
public void setAlphaAtIndex(float alpha, int index) {
mAlphas[index] = alpha;
updateAlpha();
}
private void updateAlpha() {
// Only update the alpha if no zero-alpha animation is running.
if (mZeroAlphaListenerCount > 0) {
return;
}
float finalAlpha = 1;
for (float a : mAlphas) {
finalAlpha = finalAlpha * a;
}
mTargetView.setAlpha(finalAlpha);
mTargetView.setVisibility(finalAlpha > 0 ? View.VISIBLE
: (mAm.isEnabled() ? View.GONE : View.INVISIBLE));
}
/**
* Returns an animator which changes the alpha at the index {@param index}
* to {@param finalAlpha}. Alphas at other index are not affected.
*/
public Animator animateAlphaAtIndex(float finalAlpha, final int index) {
final ValueAnimator anim;
if (Float.compare(finalAlpha, mAlphas[index]) == 0) {
// Return a dummy animator to avoid null checks.
anim = ValueAnimator.ofFloat(0, 0);
} else {
ValueAnimator animator = ValueAnimator.ofFloat(mAlphas[index], finalAlpha);
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float value = (Float) valueAnimator.getAnimatedValue();
setAlphaAtIndex(value, index);
}
});
anim = animator;
}
if (Float.compare(finalAlpha, 0f) == 0) {
// In case when any channel is animating to 0, and the current alpha is also 0, do not
// update alpha of the target view while the animation is running.
// We special case '0' because if any channel is set to 0, values of other
// channels do not matter.
anim.addListener(new ZeroAlphaAnimatorListener());
}
return anim;
}
private class ZeroAlphaAnimatorListener extends AnimatorListenerAdapter {
private boolean mStartedAtZero = false;
@Override
public void onAnimationStart(Animator animation) {
mStartedAtZero = Float.compare(mTargetView.getAlpha(), 0f) == 0;
if (mStartedAtZero) {
mZeroAlphaListenerCount++;
mTargetView.setAlpha(0);
}
}
@Override
public void onAnimationEnd(Animator animation) {
if (mStartedAtZero) {
mZeroAlphaListenerCount--;
updateAlpha();
}
}
}
}