diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2019-04-30 12:04:37 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2019-05-02 10:59:28 -0700 |
commit | ae6e318711239601fdd11a14c3cf8c542b808f19 (patch) | |
tree | cc648803791d551f80202267b1c05ca6f1084517 /src/com/android/launcher3/views | |
parent | c2803ec5b272c902b6ab314d782afe852163b4ff (diff) | |
download | android_packages_apps_Trebuchet-ae6e318711239601fdd11a14c3cf8c542b808f19.tar.gz android_packages_apps_Trebuchet-ae6e318711239601fdd11a14c3cf8c542b808f19.tar.bz2 android_packages_apps_Trebuchet-ae6e318711239601fdd11a14c3cf8c542b808f19.zip |
Initial changes to creating a fake landscape Launcher UI
Workspace and hotseat are drawn in rotated UI giving the impression that the
device is in Portrait, even though it is in landscape
Bug: 131360075
Change-Id: I29c4068af25fd4dcf7039b9a45886e864a137977
Diffstat (limited to 'src/com/android/launcher3/views')
-rw-r--r-- | src/com/android/launcher3/views/ActivityContext.java | 14 | ||||
-rw-r--r-- | src/com/android/launcher3/views/BaseDragLayer.java | 43 | ||||
-rw-r--r-- | src/com/android/launcher3/views/FloatingIconView.java | 73 | ||||
-rw-r--r-- | src/com/android/launcher3/views/Transposable.java | 26 |
4 files changed, 136 insertions, 20 deletions
diff --git a/src/com/android/launcher3/views/ActivityContext.java b/src/com/android/launcher3/views/ActivityContext.java index c9cdeffb9..0331a86cd 100644 --- a/src/com/android/launcher3/views/ActivityContext.java +++ b/src/com/android/launcher3/views/ActivityContext.java @@ -22,6 +22,7 @@ import android.view.View.AccessibilityDelegate; import com.android.launcher3.DeviceProfile; import com.android.launcher3.ItemInfo; +import com.android.launcher3.graphics.RotationMode; import com.android.launcher3.dot.DotInfo; /** @@ -56,6 +57,19 @@ public interface ActivityContext { DeviceProfile getDeviceProfile(); + /** + * Device profile to be used by UI elements which are shown directly on top of the wallpaper + * and whose presentation is tied to the wallpaper (and physical device) and not the activity + * configuration. + */ + default DeviceProfile getWallpaperDeviceProfile() { + return getDeviceProfile(); + } + + default RotationMode getRotationMode() { + return RotationMode.NORMAL; + } + static ActivityContext lookupContext(Context context) { if (context instanceof ActivityContext) { return (ActivityContext) context; diff --git a/src/com/android/launcher3/views/BaseDragLayer.java b/src/com/android/launcher3/views/BaseDragLayer.java index 86e1e32a3..3c81bcf39 100644 --- a/src/com/android/launcher3/views/BaseDragLayer.java +++ b/src/com/android/launcher3/views/BaseDragLayer.java @@ -88,7 +88,8 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext> // Touch is being dispatched through a proxy from InputMonitor private static final int TOUCH_DISPATCHING_PROXY = 1 << 2; - protected final int[] mTmpXY = new int[2]; + protected final float[] mTmpXY = new float[2]; + protected final float[] mTmpRectPoints = new float[4]; protected final Rect mHitRect = new Rect(); @ViewDebug.ExportedProperty(category = "launcher") @@ -306,14 +307,16 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext> * @return The factor by which this descendant is scaled relative to this DragLayer. */ public float getDescendantRectRelativeToSelf(View descendant, Rect r) { - mTmpXY[0] = 0; - mTmpXY[1] = 0; - float scale = getDescendantCoordRelativeToSelf(descendant, mTmpXY); - - r.set(mTmpXY[0], mTmpXY[1], - (int) (mTmpXY[0] + scale * descendant.getMeasuredWidth()), - (int) (mTmpXY[1] + scale * descendant.getMeasuredHeight())); - return scale; + mTmpRectPoints[0] = 0; + mTmpRectPoints[1] = 0; + mTmpRectPoints[2] = descendant.getWidth(); + mTmpRectPoints[3] = descendant.getHeight(); + float s = getDescendantCoordRelativeToSelf(descendant, mTmpRectPoints); + r.left = Math.round(Math.min(mTmpRectPoints[0], mTmpRectPoints[2])); + r.top = Math.round(Math.min(mTmpRectPoints[1], mTmpRectPoints[3])); + r.right = Math.round(Math.max(mTmpRectPoints[0], mTmpRectPoints[2])); + r.bottom = Math.round(Math.max(mTmpRectPoints[1], mTmpRectPoints[3])); + return s; } public float getLocationInDragLayer(View child, int[] loc) { @@ -323,6 +326,14 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext> } public float getDescendantCoordRelativeToSelf(View descendant, int[] coord) { + mTmpXY[0] = coord[0]; + mTmpXY[1] = coord[1]; + float scale = getDescendantCoordRelativeToSelf(descendant, mTmpXY); + Utilities.roundArray(mTmpXY, coord); + return scale; + } + + public float getDescendantCoordRelativeToSelf(View descendant, float[] coord) { return getDescendantCoordRelativeToSelf(descendant, coord, false); } @@ -338,17 +349,27 @@ public abstract class BaseDragLayer<T extends Context & ActivityContext> * this scale factor is assumed to be equal in X and Y, and so if at any point this * assumption fails, we will need to return a pair of scale factors. */ - public float getDescendantCoordRelativeToSelf(View descendant, int[] coord, + public float getDescendantCoordRelativeToSelf(View descendant, float[] coord, boolean includeRootScroll) { return Utilities.getDescendantCoordRelativeToAncestor(descendant, this, coord, includeRootScroll); } /** + * Inverse of {@link #getDescendantCoordRelativeToSelf(View, float[])}. + */ + public void mapCoordInSelfToDescendant(View descendant, float[] coord) { + Utilities.mapCoordInSelfToDescendant(descendant, this, coord); + } + + /** * Inverse of {@link #getDescendantCoordRelativeToSelf(View, int[])}. */ public void mapCoordInSelfToDescendant(View descendant, int[] coord) { - Utilities.mapCoordInSelfToDescendant(descendant, this, coord); + mTmpXY[0] = coord[0]; + mTmpXY[1] = coord[1]; + Utilities.mapCoordInSelfToDescendant(descendant, this, mTmpXY); + Utilities.roundArray(mTmpXY, coord); } public void getViewRectRelativeToSelf(View v, Rect r) { diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java index 77f278a19..257466539 100644 --- a/src/com/android/launcher3/views/FloatingIconView.java +++ b/src/com/android/launcher3/views/FloatingIconView.java @@ -15,6 +15,9 @@ */ package com.android.launcher3.views; +import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP; +import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT; +import static com.android.launcher3.Utilities.mapToRange; import static com.android.launcher3.anim.Interpolators.LINEAR; import static com.android.launcher3.config.FeatureFlags.ADAPTIVE_ICON_WINDOW_ANIM; @@ -23,6 +26,7 @@ import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; +import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; @@ -61,12 +65,10 @@ import com.android.launcher3.shortcuts.DeepShortcutView; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; -import static com.android.launcher3.Utilities.mapToRange; - /** * A view that is created to look like another view with the purpose of creating fluid animations. */ - +@TargetApi(Build.VERSION_CODES.Q) public class FloatingIconView extends View implements Animator.AnimatorListener, ClipPathView { public static final float SHAPE_PROGRESS_DURATION = 0.15f; @@ -186,14 +188,16 @@ public class FloatingIconView extends View implements Animator.AnimatorListener, * @param v The view to copy * @param positionOut Rect that will hold the size and position of v. */ - private void matchPositionOf(Launcher launcher, View v, Rect positionOut) { - Utilities.getLocationBoundsForView(launcher, v, positionOut); - final LayoutParams lp = new LayoutParams(positionOut.width(), positionOut.height()); + private void matchPositionOf(Launcher launcher, View v, RectF positionOut) { + getLocationBoundsForView(launcher, v, positionOut); + final LayoutParams lp = new LayoutParams( + Math.round(positionOut.width()), + Math.round(positionOut.height())); lp.ignoreInsets = true; // Position the floating view exactly on top of the original - lp.leftMargin = positionOut.left; - lp.topMargin = positionOut.top; + lp.leftMargin = Math.round(positionOut.left); + lp.topMargin = Math.round(positionOut.top); setLayoutParams(lp); // Set the properties here already to make sure they are available when running the first // animation frame. @@ -201,6 +205,57 @@ public class FloatingIconView extends View implements Animator.AnimatorListener, + lp.height); } + /** + * Returns the location bounds of a view. + * - For DeepShortcutView, we return the bounds of the icon view. + * - For BubbleTextView, we return the icon bounds. + */ + private void getLocationBoundsForView(Launcher launcher, View v, RectF outRect) { + final boolean isBubbleTextView = v instanceof BubbleTextView; + final boolean isFolderIcon = v instanceof FolderIcon; + + // Deep shortcut views have their icon drawn in a separate view. + final boolean fromDeepShortcutView = v.getParent() instanceof DeepShortcutView; + + final View targetView; + boolean ignoreTransform = false; + + if (v instanceof DeepShortcutView) { + targetView = ((DeepShortcutView) v).getIconView(); + } else if (fromDeepShortcutView) { + DeepShortcutView view = (DeepShortcutView) v.getParent(); + targetView = view.getIconView(); + } else if ((isBubbleTextView || isFolderIcon) && v.getTag() instanceof ItemInfo + && (((ItemInfo) v.getTag()).container == CONTAINER_DESKTOP + || ((ItemInfo) v.getTag()).container == CONTAINER_HOTSEAT)) { + targetView = v; + ignoreTransform = true; + } else { + targetView = v; + } + + float[] points = new float[] {0, 0, targetView.getWidth(), targetView.getHeight()}; + Utilities.getDescendantCoordRelativeToAncestor(targetView, launcher.getDragLayer(), points, + false, ignoreTransform); + + float viewLocationLeft = Math.min(points[0], points[2]); + float viewLocationTop = Math.min(points[1], points[3]); + + final Rect iconRect = new Rect(); + if (isBubbleTextView && !fromDeepShortcutView) { + ((BubbleTextView) v).getIconBounds(iconRect); + } else if (isFolderIcon) { + ((FolderIcon) v).getPreviewBounds(iconRect); + } else { + iconRect.set(0, 0, Math.abs(Math.round(points[2] - points[0])), + Math.abs(Math.round(points[3] - points[1]))); + } + viewLocationLeft += iconRect.left; + viewLocationTop += iconRect.top; + outRect.set(viewLocationLeft, viewLocationTop, viewLocationLeft + iconRect.width(), + viewLocationTop + iconRect.height()); + } + @WorkerThread private void getIcon(Launcher launcher, View v, ItemInfo info, boolean isOpening, Runnable onIconLoadedRunnable, CancellationSignal loadIconSignal) { @@ -411,7 +466,7 @@ public class FloatingIconView extends View implements Animator.AnimatorListener, * @param isOpening True if this view replaces the icon for app open animation. */ public static FloatingIconView getFloatingIconView(Launcher launcher, View originalView, - boolean hideOriginal, Rect positionOut, boolean isOpening, FloatingIconView recycle) { + boolean hideOriginal, RectF positionOut, boolean isOpening, FloatingIconView recycle) { if (recycle != null) { recycle.recycle(); } diff --git a/src/com/android/launcher3/views/Transposable.java b/src/com/android/launcher3/views/Transposable.java new file mode 100644 index 000000000..929c1aa9b --- /dev/null +++ b/src/com/android/launcher3/views/Transposable.java @@ -0,0 +1,26 @@ +/** + * Copyright (C) 2019 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.views; + +import com.android.launcher3.graphics.RotationMode; + +/** + * Indicates that a view can be transposed. + */ +public interface Transposable { + + RotationMode getRotationMode(); +} |