summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-05-11 19:26:51 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-05-11 19:26:51 +0000
commit7f71198dc833f4b7048409d0108af35dec8769ef (patch)
tree233afb82aadd899b30303a927533897ded1ba569 /src
parentdfb509c58039f8f7fd467d45e040198a5f1006e3 (diff)
parent6001ea2e2f1f22e08f229d07e41ff56230d0574d (diff)
downloadandroid_packages_apps_Trebuchet-7f71198dc833f4b7048409d0108af35dec8769ef.tar.gz
android_packages_apps_Trebuchet-7f71198dc833f4b7048409d0108af35dec8769ef.tar.bz2
android_packages_apps_Trebuchet-7f71198dc833f4b7048409d0108af35dec8769ef.zip
Merge "Separating the draglayer alpha into multiple dimensions so that different animaitons can run without affecting the other." into ub-launcher3-edmonton
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/Launcher.java22
-rw-r--r--src/com/android/launcher3/Workspace.java3
-rw-r--r--src/com/android/launcher3/dragndrop/DragLayer.java8
-rw-r--r--src/com/android/launcher3/util/MultiValueAlpha.java101
-rw-r--r--src/com/android/launcher3/views/BaseDragLayer.java11
5 files changed, 137 insertions, 8 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 521ad48a3..0a0e5834d 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -22,10 +22,13 @@ import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.NORMAL;
+import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_LAUNCHER_LOAD;
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.ActivityOptions;
@@ -103,6 +106,8 @@ import com.android.launcher3.util.ActivityResultInfo;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.MultiHashMap;
+import com.android.launcher3.util.MultiValueAlpha;
+import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.PendingRequestArgs;
@@ -308,7 +313,7 @@ public class Launcher extends BaseDraggingActivity
if (!internalStateHandled) {
// If we are not binding synchronously, show a fade in animation when
// the first page bind completes.
- mLauncherView.setAlpha(0);
+ mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0);
}
} else {
// Pages bound synchronously.
@@ -2086,9 +2091,18 @@ public class Launcher extends BaseDraggingActivity
@Override
public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
- if (mLauncherView.getAlpha() < 1) {
- mLauncherView.animate().alpha(1).withEndAction(
- executor == null ? null : executor::onLoadAnimationCompleted).start();
+ AlphaProperty property = mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD);
+ if (property.getValue() < 1) {
+ ObjectAnimator anim = ObjectAnimator.ofFloat(property, MultiValueAlpha.VALUE, 1);
+ if (executor != null) {
+ anim.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ executor.onLoadAnimationCompleted();
+ }
+ });
+ }
+ anim.start();
} else if (executor != null) {
executor.onLoadAnimationCompleted();
}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 223fa97cf..a03a7a8b2 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -22,6 +22,7 @@ import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_TRANSITION_M
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.SPRING_LOADED;
+import static com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_OVERLAY;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -1174,7 +1175,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
// different effects based on device performance. On at least one relatively high-end
// device I've tried, translating the launcher causes things to get quite laggy.
mLauncher.getDragLayer().setTranslationX(transX);
- mLauncher.getDragLayer().setAlpha(alpha);
+ mLauncher.getDragLayer().getAlphaProperty(ALPHA_INDEX_OVERLAY).setValue(alpha);
}
/**
diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java
index aad1e5a54..3a1837d31 100644
--- a/src/com/android/launcher3/dragndrop/DragLayer.java
+++ b/src/com/android/launcher3/dragndrop/DragLayer.java
@@ -62,6 +62,12 @@ import java.util.ArrayList;
*/
public class DragLayer extends BaseDragLayer<Launcher> {
+ public static final int ALPHA_INDEX_OVERLAY = 0;
+ public static final int ALPHA_INDEX_LAUNCHER_LOAD = 1;
+ public static final int ALPHA_INDEX_TRANSITIONS = 2;
+ public static final int ALPHA_INDEX_SWIPE_UP = 3;
+ private static final int ALPHA_CHANNEL_COUNT = 4;
+
public static final int ANIMATION_END_DISAPPEAR = 0;
public static final int ANIMATION_END_REMAIN_VISIBLE = 2;
@@ -90,7 +96,7 @@ public class DragLayer extends BaseDragLayer<Launcher> {
* @param attrs The attributes set containing the Workspace's customization values.
*/
public DragLayer(Context context, AttributeSet attrs) {
- super(context, attrs);
+ super(context, attrs, ALPHA_CHANNEL_COUNT);
// Disable multitouch across the workspace/all apps/customize tray
setMotionEventSplittingEnabled(false);
diff --git a/src/com/android/launcher3/util/MultiValueAlpha.java b/src/com/android/launcher3/util/MultiValueAlpha.java
new file mode 100644
index 000000000..f810f483d
--- /dev/null
+++ b/src/com/android/launcher3/util/MultiValueAlpha.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2018 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.util.Property;
+import android.view.View;
+
+/**
+ * Utility class to handle separating a single value as a factor of multiple values
+ */
+public class MultiValueAlpha {
+
+ public static final Property<AlphaProperty, Float> VALUE =
+ new Property<AlphaProperty, Float>(Float.TYPE, "value") {
+
+ @Override
+ public Float get(AlphaProperty alphaProperty) {
+ return alphaProperty.mValue;
+ }
+
+ @Override
+ public void set(AlphaProperty object, Float value) {
+ object.setValue(value);
+ }
+ };
+
+ private final View mView;
+ private final AlphaProperty[] mMyProperties;
+
+ private int mValidMask;
+
+ public MultiValueAlpha(View view, int size) {
+ mView = view;
+ mMyProperties = new AlphaProperty[size];
+
+ mValidMask = 0;
+ for (int i = 0; i < size; i++) {
+ int myMask = 1 << i;
+ mValidMask |= myMask;
+ mMyProperties[i] = new AlphaProperty(myMask);
+ }
+ }
+
+ public AlphaProperty getProperty(int index) {
+ return mMyProperties[index];
+ }
+
+ public class AlphaProperty {
+
+ private final int mMyMask;
+
+ private float mValue = 1;
+ // Factor of all other alpha channels, only valid if mMyMask is present in mValidMask.
+ private float mOthers = 1;
+
+ AlphaProperty(int myMask) {
+ mMyMask = myMask;
+ }
+
+ public void setValue(float value) {
+ if (mValue == value) {
+ return;
+ }
+
+ if ((mValidMask & mMyMask) == 0) {
+ // Our cache value is not correct, recompute it.
+ mOthers = 1;
+ for (AlphaProperty prop : mMyProperties) {
+ if (prop != this) {
+ mOthers *= prop.mValue;
+ }
+ }
+ }
+
+ // Since we have changed our value, all other caches except our own need to be
+ // recomputed. Change mValidMask to indicate the new valid caches (only our own).
+ mValidMask = mMyMask;
+ mValue = value;
+
+ mView.setAlpha(mOthers * mValue);
+ }
+
+ public float getValue() {
+ return mValue;
+ }
+ }
+}
diff --git a/src/com/android/launcher3/views/BaseDragLayer.java b/src/com/android/launcher3/views/BaseDragLayer.java
index 149b38b0f..66d9498a9 100644
--- a/src/com/android/launcher3/views/BaseDragLayer.java
+++ b/src/com/android/launcher3/views/BaseDragLayer.java
@@ -30,6 +30,8 @@ import com.android.launcher3.BaseActivity;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.InsettableFrameLayout;
import com.android.launcher3.Utilities;
+import com.android.launcher3.util.MultiValueAlpha;
+import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
import com.android.launcher3.util.TouchController;
import java.util.ArrayList;
@@ -45,17 +47,18 @@ public abstract class BaseDragLayer<T extends BaseDraggingActivity> extends Inse
protected final Rect mHitRect = new Rect();
protected final T mActivity;
+ private final MultiValueAlpha mMultiValueAlpha;
protected TouchController[] mControllers;
protected TouchController mActiveController;
private TouchCompleteListener mTouchCompleteListener;
- public BaseDragLayer(Context context, AttributeSet attrs) {
+ public BaseDragLayer(Context context, AttributeSet attrs, int alphaChannelCount) {
super(context, attrs);
mActivity = (T) BaseActivity.fromContext(context);
+ mMultiValueAlpha = new MultiValueAlpha(this, alphaChannelCount);
}
-
public boolean isEventOverView(View view, MotionEvent ev) {
getDescendantRectRelativeToSelf(view, mHitRect);
return mHitRect.contains((int) ev.getX(), (int) ev.getY());
@@ -276,6 +279,10 @@ public abstract class BaseDragLayer<T extends BaseDraggingActivity> extends Inse
return new LayoutParams(p);
}
+ public AlphaProperty getAlphaProperty(int index) {
+ return mMultiValueAlpha.getProperty(index);
+ }
+
public static class LayoutParams extends InsettableFrameLayout.LayoutParams {
public int x, y;
public boolean customPosition = false;