2019-12-19 11:50:55 -08:00
|
|
|
/*
|
|
|
|
|
* 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.touch;
|
|
|
|
|
|
2020-04-15 14:13:38 -07:00
|
|
|
import static android.widget.ListPopupWindow.WRAP_CONTENT;
|
2020-06-24 20:52:26 -07:00
|
|
|
|
2020-04-02 17:20:07 -07:00
|
|
|
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
|
|
|
|
|
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
|
|
|
|
|
import static com.android.launcher3.touch.SingleAxisSwipeDetector.HORIZONTAL;
|
2021-02-22 14:49:27 -08:00
|
|
|
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT;
|
|
|
|
|
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT;
|
|
|
|
|
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_TYPE_MAIN;
|
2020-04-02 17:20:07 -07:00
|
|
|
|
2019-12-19 11:50:55 -08:00
|
|
|
import android.content.res.Resources;
|
2020-02-14 10:45:55 -08:00
|
|
|
import android.graphics.PointF;
|
2019-12-19 11:50:55 -08:00
|
|
|
import android.graphics.Rect;
|
|
|
|
|
import android.graphics.RectF;
|
|
|
|
|
import android.util.FloatProperty;
|
|
|
|
|
import android.view.MotionEvent;
|
2020-02-14 10:45:55 -08:00
|
|
|
import android.view.Surface;
|
2019-12-19 11:50:55 -08:00
|
|
|
import android.view.VelocityTracker;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
2020-04-15 14:13:38 -07:00
|
|
|
import android.widget.LinearLayout;
|
2019-12-19 11:50:55 -08:00
|
|
|
|
2020-06-24 20:52:26 -07:00
|
|
|
import com.android.launcher3.DeviceProfile;
|
2019-12-19 11:50:55 -08:00
|
|
|
import com.android.launcher3.PagedView;
|
2021-02-22 14:49:27 -08:00
|
|
|
import com.android.launcher3.R;
|
2019-12-19 11:50:55 -08:00
|
|
|
import com.android.launcher3.Utilities;
|
|
|
|
|
import com.android.launcher3.util.OverScroller;
|
2021-02-22 14:49:27 -08:00
|
|
|
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
|
|
|
|
|
|
2021-04-05 12:41:06 -07:00
|
|
|
import java.util.Collections;
|
2021-02-22 14:49:27 -08:00
|
|
|
import java.util.List;
|
2019-12-19 11:50:55 -08:00
|
|
|
|
|
|
|
|
public class LandscapePagedViewHandler implements PagedOrientationHandler {
|
|
|
|
|
|
|
|
|
|
@Override
|
2020-10-23 22:37:51 -07:00
|
|
|
public <T> T getPrimaryValue(T x, T y) {
|
2020-10-28 22:34:23 -07:00
|
|
|
return y;
|
2019-12-19 11:50:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2020-10-23 22:37:51 -07:00
|
|
|
public <T> T getSecondaryValue(T x, T y) {
|
2020-10-28 22:34:23 -07:00
|
|
|
return x;
|
2019-12-19 11:50:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void delegateScrollTo(PagedView pagedView, int secondaryScroll, int minMaxScroll) {
|
|
|
|
|
pagedView.superScrollTo(secondaryScroll, minMaxScroll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void delegateScrollBy(PagedView pagedView, int unboundedScroll, int x, int y) {
|
|
|
|
|
pagedView.scrollTo(pagedView.getScrollX() + x, unboundedScroll + y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void scrollerStartScroll(OverScroller scroller, int newPosition) {
|
|
|
|
|
scroller.startScroll(scroller.getCurrPos(), newPosition - scroller.getCurrPos());
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 12:37:40 -07:00
|
|
|
@Override
|
|
|
|
|
public boolean isLayoutNaturalToLauncher() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 11:50:55 -08:00
|
|
|
@Override
|
2020-02-14 10:45:55 -08:00
|
|
|
public void adjustFloatingIconStartVelocity(PointF velocity) {
|
|
|
|
|
float oldX = velocity.x;
|
|
|
|
|
float oldY = velocity.y;
|
|
|
|
|
velocity.set(-oldY, oldX);
|
2019-12-19 11:50:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void delegateScrollTo(PagedView pagedView, int primaryScroll) {
|
|
|
|
|
pagedView.superScrollTo(pagedView.getScrollX(), primaryScroll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <T> void set(T target, Int2DAction<T> action, int param) {
|
|
|
|
|
action.call(target, 0, param);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <T> void set(T target, Float2DAction<T> action, float param) {
|
|
|
|
|
action.call(target, 0, param);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 17:25:28 -07:00
|
|
|
@Override
|
|
|
|
|
public <T> void setSecondary(T target, Float2DAction<T> action, float param) {
|
|
|
|
|
action.call(target, param, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 11:50:55 -08:00
|
|
|
@Override
|
|
|
|
|
public float getPrimaryDirection(MotionEvent event, int pointerIndex) {
|
|
|
|
|
return event.getY(pointerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getPrimaryVelocity(VelocityTracker velocityTracker, int pointerId) {
|
|
|
|
|
return velocityTracker.getYVelocity(pointerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getMeasuredSize(View view) {
|
|
|
|
|
return view.getMeasuredHeight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getPrimarySize(RectF rect) {
|
|
|
|
|
return rect.height();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-19 19:21:29 -07:00
|
|
|
@Override
|
2021-03-17 16:53:26 +00:00
|
|
|
public int getClearAllSidePadding(View view, boolean isRtl) {
|
2020-04-19 19:21:29 -07:00
|
|
|
return (isRtl ? view.getPaddingBottom() : - view.getPaddingTop()) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 11:50:55 -08:00
|
|
|
@Override
|
|
|
|
|
public int getSecondaryDimension(View view) {
|
|
|
|
|
return view.getWidth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FloatProperty<View> getPrimaryViewTranslate() {
|
|
|
|
|
return VIEW_TRANSLATE_Y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FloatProperty<View> getSecondaryViewTranslate() {
|
|
|
|
|
return VIEW_TRANSLATE_X;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getPrimaryScroll(View view) {
|
|
|
|
|
return view.getScrollY();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getPrimaryScale(View view) {
|
|
|
|
|
return view.getScaleY();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setMaxScroll(AccessibilityEvent event, int maxScroll) {
|
|
|
|
|
event.setMaxScrollY(maxScroll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean getRecentsRtlSetting(Resources resources) {
|
|
|
|
|
return !Utilities.isRtl(resources);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getDegreesRotated() {
|
|
|
|
|
return 90;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 21:39:06 -07:00
|
|
|
@Override
|
|
|
|
|
public int getRotation() {
|
|
|
|
|
return Surface.ROTATION_90;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 11:50:55 -08:00
|
|
|
@Override
|
|
|
|
|
public int getChildStart(View view) {
|
|
|
|
|
return view.getTop();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 17:37:19 -07:00
|
|
|
@Override
|
|
|
|
|
public float getChildStartWithTranslation(View view) {
|
|
|
|
|
return view.getTop() + view.getTranslationY();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 11:50:55 -08:00
|
|
|
@Override
|
|
|
|
|
public int getCenterForPage(View view, Rect insets) {
|
|
|
|
|
return (view.getPaddingLeft() + view.getMeasuredWidth() + insets.left
|
|
|
|
|
- insets.right - view.getPaddingRight()) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getScrollOffsetStart(View view, Rect insets) {
|
|
|
|
|
return insets.top + view.getPaddingTop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getScrollOffsetEnd(View view, Rect insets) {
|
|
|
|
|
return view.getHeight() - view.getPaddingBottom() - insets.bottom;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-06 15:04:51 -07:00
|
|
|
@Override
|
|
|
|
|
public int getPrimaryTranslationDirectionFactor() {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 17:25:28 -07:00
|
|
|
public int getSecondaryTranslationDirectionFactor() {
|
2020-05-12 12:31:44 -07:00
|
|
|
return 1;
|
2019-12-19 11:50:55 -08:00
|
|
|
}
|
|
|
|
|
|
2021-02-22 14:49:27 -08:00
|
|
|
@Override
|
|
|
|
|
public int getSplitTranslationDirectionFactor(int stagePosition) {
|
|
|
|
|
if (stagePosition == STAGE_POSITION_BOTTOM_OR_RIGHT) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getSplitAnimationTranslation(int translationOffset, DeviceProfile dp) {
|
|
|
|
|
return translationOffset;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 14:13:38 -07:00
|
|
|
@Override
|
|
|
|
|
public float getTaskMenuX(float x, View thumbnailView) {
|
|
|
|
|
return thumbnailView.getMeasuredWidth() + x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getTaskMenuY(float y, View thumbnailView) {
|
|
|
|
|
return y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getTaskMenuWidth(View view) {
|
|
|
|
|
return view.getMeasuredHeight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2020-07-10 11:55:06 -07:00
|
|
|
public int getTaskMenuLayoutOrientation(boolean canRecentsActivityRotate,
|
|
|
|
|
LinearLayout taskMenuLayout) {
|
2020-04-15 14:13:38 -07:00
|
|
|
return LinearLayout.HORIZONTAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp) {
|
|
|
|
|
lp.width = 0;
|
|
|
|
|
lp.height = WRAP_CONTENT;
|
|
|
|
|
lp.weight = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 15:18:33 -08:00
|
|
|
/* ---------- The following are only used by TaskViewTouchHandler. ---------- */
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SingleAxisSwipeDetector.Direction getUpDownSwipeDirection() {
|
|
|
|
|
return HORIZONTAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getUpDirection(boolean isRtl) {
|
|
|
|
|
return isRtl ? SingleAxisSwipeDetector.DIRECTION_NEGATIVE
|
|
|
|
|
: SingleAxisSwipeDetector.DIRECTION_POSITIVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isGoingUp(float displacement, boolean isRtl) {
|
|
|
|
|
return isRtl ? displacement < 0 : displacement > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getTaskDragDisplacementFactor(boolean isRtl) {
|
|
|
|
|
return isRtl ? 1 : -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------- */
|
|
|
|
|
|
2019-12-19 11:50:55 -08:00
|
|
|
@Override
|
|
|
|
|
public ChildBounds getChildBounds(View child, int childStart, int pageCenter,
|
|
|
|
|
boolean layoutChild) {
|
|
|
|
|
final int childHeight = child.getMeasuredHeight();
|
|
|
|
|
final int childBottom = childStart + childHeight;
|
|
|
|
|
final int childWidth = child.getMeasuredWidth();
|
|
|
|
|
final int childLeft = pageCenter - childWidth/ 2;
|
|
|
|
|
if (layoutChild) {
|
|
|
|
|
child.layout(childLeft, childStart, childLeft + childWidth, childBottom);
|
|
|
|
|
}
|
|
|
|
|
return new ChildBounds(childHeight, childWidth, childBottom, childLeft);
|
|
|
|
|
}
|
2020-06-24 20:52:26 -07:00
|
|
|
|
|
|
|
|
@SuppressWarnings("SuspiciousNameCombination")
|
|
|
|
|
@Override
|
|
|
|
|
public int getDistanceToBottomOfRect(DeviceProfile dp, Rect rect) {
|
|
|
|
|
return rect.left;
|
|
|
|
|
}
|
2021-02-22 14:49:27 -08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SplitPositionOption> getSplitPositionOptions(DeviceProfile dp) {
|
2021-04-05 12:41:06 -07:00
|
|
|
// Add "left" side of phone which is actually the top
|
|
|
|
|
return Collections.singletonList(new SplitPositionOption(
|
2021-02-22 14:49:27 -08:00
|
|
|
R.drawable.ic_split_screen, R.string.split_screen_position_left,
|
|
|
|
|
STAGE_POSITION_TOP_OR_LEFT, STAGE_TYPE_MAIN));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FloatProperty getSplitSelectTaskOffset(FloatProperty primary, FloatProperty secondary,
|
|
|
|
|
DeviceProfile deviceProfile) {
|
|
|
|
|
return primary;
|
|
|
|
|
}
|
2019-12-19 11:50:55 -08:00
|
|
|
}
|