2019-12-19 11:50:55 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 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;
|
|
|
|
|
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.graphics.Canvas;
|
2020-04-01 20:13:12 -07:00
|
|
|
import android.graphics.Matrix;
|
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;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
import com.android.launcher3.DeviceProfile;
|
|
|
|
|
import com.android.launcher3.PagedView;
|
|
|
|
|
import com.android.launcher3.util.OverScroller;
|
2021-02-22 14:49:27 -08:00
|
|
|
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
|
|
|
|
|
import com.android.launcher3.util.SplitConfigurationOptions.StagePosition;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
2019-12-19 11:50:55 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Abstraction layer to separate horizontal and vertical specific implementations
|
|
|
|
|
* for {@link com.android.launcher3.PagedView}. Majority of these implementations are (should be) as
|
|
|
|
|
* simple as choosing the correct X and Y analogous methods.
|
|
|
|
|
*/
|
|
|
|
|
public interface PagedOrientationHandler {
|
|
|
|
|
|
2020-04-03 15:58:45 -07:00
|
|
|
PagedOrientationHandler PORTRAIT = new PortraitPagedViewHandler();
|
|
|
|
|
PagedOrientationHandler LANDSCAPE = new LandscapePagedViewHandler();
|
|
|
|
|
PagedOrientationHandler SEASCAPE = new SeascapePagedViewHandler();
|
|
|
|
|
|
2019-12-19 11:50:55 -08:00
|
|
|
interface Int2DAction<T> {
|
|
|
|
|
void call(T target, int x, int y);
|
|
|
|
|
}
|
|
|
|
|
interface Float2DAction<T> {
|
|
|
|
|
void call(T target, float x, float y);
|
|
|
|
|
}
|
|
|
|
|
Int2DAction<View> VIEW_SCROLL_BY = View::scrollBy;
|
|
|
|
|
Int2DAction<View> VIEW_SCROLL_TO = View::scrollTo;
|
|
|
|
|
Float2DAction<Canvas> CANVAS_TRANSLATE = Canvas::translate;
|
2020-04-01 20:13:12 -07:00
|
|
|
Float2DAction<Matrix> MATRIX_POST_TRANSLATE = Matrix::postTranslate;
|
|
|
|
|
|
2019-12-19 11:50:55 -08:00
|
|
|
<T> void set(T target, Int2DAction<T> action, int param);
|
|
|
|
|
<T> void set(T target, Float2DAction<T> action, float param);
|
2020-07-01 17:25:28 -07:00
|
|
|
<T> void setSecondary(T target, Float2DAction<T> action, float param);
|
2019-12-19 11:50:55 -08:00
|
|
|
float getPrimaryDirection(MotionEvent event, int pointerIndex);
|
|
|
|
|
float getPrimaryVelocity(VelocityTracker velocityTracker, int pointerId);
|
|
|
|
|
int getMeasuredSize(View view);
|
|
|
|
|
float getPrimarySize(RectF rect);
|
2021-03-17 16:53:26 +00:00
|
|
|
int getClearAllSidePadding(View view, boolean isRtl);
|
2019-12-19 11:50:55 -08:00
|
|
|
int getSecondaryDimension(View view);
|
|
|
|
|
FloatProperty<View> getPrimaryViewTranslate();
|
|
|
|
|
FloatProperty<View> getSecondaryViewTranslate();
|
|
|
|
|
int getPrimaryScroll(View view);
|
|
|
|
|
float getPrimaryScale(View view);
|
|
|
|
|
int getChildStart(View view);
|
2020-04-09 17:37:19 -07:00
|
|
|
float getChildStartWithTranslation(View view);
|
2019-12-19 11:50:55 -08:00
|
|
|
int getCenterForPage(View view, Rect insets);
|
|
|
|
|
int getScrollOffsetStart(View view, Rect insets);
|
|
|
|
|
int getScrollOffsetEnd(View view, Rect insets);
|
2020-08-06 15:04:51 -07:00
|
|
|
int getPrimaryTranslationDirectionFactor();
|
2020-07-01 17:25:28 -07:00
|
|
|
int getSecondaryTranslationDirectionFactor();
|
2021-02-22 14:49:27 -08:00
|
|
|
int getSplitTranslationDirectionFactor(@StagePosition int stagePosition);
|
|
|
|
|
int getSplitAnimationTranslation(int translationOffset, DeviceProfile dp);
|
2019-12-19 11:50:55 -08:00
|
|
|
ChildBounds getChildBounds(View child, int childStart, int pageCenter, boolean layoutChild);
|
|
|
|
|
void setMaxScroll(AccessibilityEvent event, int maxScroll);
|
|
|
|
|
boolean getRecentsRtlSetting(Resources resources);
|
|
|
|
|
float getDegreesRotated();
|
2020-05-03 21:39:06 -07:00
|
|
|
int getRotation();
|
2020-10-23 22:37:51 -07:00
|
|
|
<T> T getPrimaryValue(T x, T y);
|
|
|
|
|
<T> T getSecondaryValue(T x, T y);
|
2019-12-19 11:50:55 -08:00
|
|
|
void delegateScrollTo(PagedView pagedView, int secondaryScroll, int primaryScroll);
|
|
|
|
|
/** Uses {@params pagedView}.getScroll[X|Y]() method for the secondary amount*/
|
|
|
|
|
void delegateScrollTo(PagedView pagedView, int primaryScroll);
|
|
|
|
|
void delegateScrollBy(PagedView pagedView, int unboundedScroll, int x, int y);
|
|
|
|
|
void scrollerStartScroll(OverScroller scroller, int newPosition);
|
2020-04-09 17:37:19 -07:00
|
|
|
void getCurveProperties(PagedView view, Rect insets, CurveProperties out);
|
2020-04-01 12:37:40 -07:00
|
|
|
boolean isLayoutNaturalToLauncher();
|
2020-04-15 14:13:38 -07:00
|
|
|
float getTaskMenuX(float x, View thumbnailView);
|
|
|
|
|
float getTaskMenuY(float y, View thumbnailView);
|
|
|
|
|
int getTaskMenuWidth(View view);
|
2020-07-10 11:55:06 -07:00
|
|
|
int getTaskMenuLayoutOrientation(boolean canRecentsActivityRotate, LinearLayout taskMenuLayout);
|
2020-04-15 14:13:38 -07:00
|
|
|
void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp);
|
2020-06-24 20:52:26 -07:00
|
|
|
int getDistanceToBottomOfRect(DeviceProfile dp, Rect rect);
|
2021-02-22 14:49:27 -08:00
|
|
|
List<SplitPositionOption> getSplitPositionOptions(DeviceProfile dp);
|
|
|
|
|
FloatProperty getSplitSelectTaskOffset(FloatProperty primary, FloatProperty secondary,
|
|
|
|
|
DeviceProfile deviceProfile);
|
2019-12-19 11:50:55 -08:00
|
|
|
|
2020-12-11 15:18:33 -08:00
|
|
|
// The following are only used by TaskViewTouchHandler.
|
|
|
|
|
/** @return Either VERTICAL or HORIZONTAL. */
|
|
|
|
|
SingleAxisSwipeDetector.Direction getUpDownSwipeDirection();
|
|
|
|
|
/** @return Given {@link #getUpDownSwipeDirection()}, whether POSITIVE or NEGATIVE is up. */
|
|
|
|
|
int getUpDirection(boolean isRtl);
|
|
|
|
|
/** @return Whether the displacement is going towards the top of the screen. */
|
|
|
|
|
boolean isGoingUp(float displacement, boolean isRtl);
|
|
|
|
|
/** @return Either 1 or -1, a factor to multiply by so the animation goes the correct way. */
|
|
|
|
|
int getTaskDragDisplacementFactor(boolean isRtl);
|
|
|
|
|
|
2020-02-14 10:45:55 -08:00
|
|
|
/**
|
|
|
|
|
* Maps the velocity from the coordinate plane of the foreground app to that
|
|
|
|
|
* of Launcher's (which now will always be portrait)
|
|
|
|
|
*/
|
|
|
|
|
void adjustFloatingIconStartVelocity(PointF velocity);
|
|
|
|
|
|
2020-04-02 17:20:07 -07:00
|
|
|
class CurveProperties {
|
|
|
|
|
public int scroll;
|
|
|
|
|
public int halfPageSize;
|
|
|
|
|
public int screenCenter;
|
|
|
|
|
public int halfScreenSize;
|
2019-12-19 11:50:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ChildBounds {
|
|
|
|
|
|
|
|
|
|
public final int primaryDimension;
|
|
|
|
|
public final int secondaryDimension;
|
|
|
|
|
public final int childPrimaryEnd;
|
|
|
|
|
public final int childSecondaryEnd;
|
|
|
|
|
|
|
|
|
|
ChildBounds(int primaryDimension, int secondaryDimension, int childPrimaryEnd,
|
|
|
|
|
int childSecondaryEnd) {
|
|
|
|
|
this.primaryDimension = primaryDimension;
|
|
|
|
|
this.secondaryDimension = secondaryDimension;
|
|
|
|
|
this.childPrimaryEnd = childPrimaryEnd;
|
|
|
|
|
this.childSecondaryEnd = childSecondaryEnd;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|