1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.launcher3.touch;
18 
19 import android.content.res.Resources;
20 import android.graphics.Canvas;
21 import android.graphics.Matrix;
22 import android.graphics.PointF;
23 import android.graphics.Rect;
24 import android.graphics.RectF;
25 import android.util.FloatProperty;
26 import android.view.MotionEvent;
27 import android.view.VelocityTracker;
28 import android.view.View;
29 import android.view.accessibility.AccessibilityEvent;
30 import android.widget.LinearLayout;
31 
32 import com.android.launcher3.DeviceProfile;
33 import com.android.launcher3.PagedView;
34 import com.android.launcher3.util.OverScroller;
35 
36 /**
37  * Abstraction layer to separate horizontal and vertical specific implementations
38  * for {@link com.android.launcher3.PagedView}. Majority of these implementations are (should be) as
39  * simple as choosing the correct X and Y analogous methods.
40  */
41 public interface PagedOrientationHandler {
42 
43     PagedOrientationHandler PORTRAIT = new PortraitPagedViewHandler();
44     PagedOrientationHandler LANDSCAPE = new LandscapePagedViewHandler();
45     PagedOrientationHandler SEASCAPE = new SeascapePagedViewHandler();
46 
47     interface Int2DAction<T> {
call(T target, int x, int y)48         void call(T target, int x, int y);
49     }
50     interface Float2DAction<T> {
call(T target, float x, float y)51         void call(T target, float x, float y);
52     }
53     Int2DAction<View> VIEW_SCROLL_BY = View::scrollBy;
54     Int2DAction<View> VIEW_SCROLL_TO = View::scrollTo;
55     Float2DAction<Canvas> CANVAS_TRANSLATE = Canvas::translate;
56     Float2DAction<Matrix> MATRIX_POST_TRANSLATE = Matrix::postTranslate;
57 
set(T target, Int2DAction<T> action, int param)58     <T> void set(T target, Int2DAction<T> action, int param);
set(T target, Float2DAction<T> action, float param)59     <T> void set(T target, Float2DAction<T> action, float param);
getPrimaryDirection(MotionEvent event, int pointerIndex)60     float getPrimaryDirection(MotionEvent event, int pointerIndex);
getPrimaryVelocity(VelocityTracker velocityTracker, int pointerId)61     float getPrimaryVelocity(VelocityTracker velocityTracker, int pointerId);
getMeasuredSize(View view)62     int getMeasuredSize(View view);
getPrimarySize(RectF rect)63     float getPrimarySize(RectF rect);
getClearAllScrollOffset(View view, boolean isRtl)64     int getClearAllScrollOffset(View view, boolean isRtl);
getSecondaryDimension(View view)65     int getSecondaryDimension(View view);
getPrimaryViewTranslate()66     FloatProperty<View> getPrimaryViewTranslate();
getSecondaryViewTranslate()67     FloatProperty<View> getSecondaryViewTranslate();
setPrimaryAndResetSecondaryTranslate(View view, float translation)68     void setPrimaryAndResetSecondaryTranslate(View view, float translation);
getPrimaryScroll(View view)69     int getPrimaryScroll(View view);
getPrimaryScale(View view)70     float getPrimaryScale(View view);
getChildStart(View view)71     int getChildStart(View view);
getChildStartWithTranslation(View view)72     float getChildStartWithTranslation(View view);
getCenterForPage(View view, Rect insets)73     int getCenterForPage(View view, Rect insets);
getScrollOffsetStart(View view, Rect insets)74     int getScrollOffsetStart(View view, Rect insets);
getScrollOffsetEnd(View view, Rect insets)75     int getScrollOffsetEnd(View view, Rect insets);
getOppositeSwipeDirection()76     SingleAxisSwipeDetector.Direction getOppositeSwipeDirection();
getTaskDismissDirectionFactor()77     int getTaskDismissDirectionFactor();
getTaskDragDisplacementFactor(boolean isRtl)78     int getTaskDragDisplacementFactor(boolean isRtl);
getChildBounds(View child, int childStart, int pageCenter, boolean layoutChild)79     ChildBounds getChildBounds(View child, int childStart, int pageCenter, boolean layoutChild);
setMaxScroll(AccessibilityEvent event, int maxScroll)80     void setMaxScroll(AccessibilityEvent event, int maxScroll);
getRecentsRtlSetting(Resources resources)81     boolean getRecentsRtlSetting(Resources resources);
getDegreesRotated()82     float getDegreesRotated();
getRotation()83     int getRotation();
getPrimaryValue(int x, int y)84     int getPrimaryValue(int x, int y);
getSecondaryValue(int x, int y)85     int getSecondaryValue(int x, int y);
delegateScrollTo(PagedView pagedView, int secondaryScroll, int primaryScroll)86     void delegateScrollTo(PagedView pagedView, int secondaryScroll, int primaryScroll);
87     /** Uses {@params pagedView}.getScroll[X|Y]() method for the secondary amount*/
delegateScrollTo(PagedView pagedView, int primaryScroll)88     void delegateScrollTo(PagedView pagedView, int primaryScroll);
delegateScrollBy(PagedView pagedView, int unboundedScroll, int x, int y)89     void delegateScrollBy(PagedView pagedView, int unboundedScroll, int x, int y);
scrollerStartScroll(OverScroller scroller, int newPosition)90     void scrollerStartScroll(OverScroller scroller, int newPosition);
getCurveProperties(PagedView view, Rect insets, CurveProperties out)91     void getCurveProperties(PagedView view, Rect insets, CurveProperties out);
isGoingUp(float displacement, boolean isRtl)92     boolean isGoingUp(float displacement, boolean isRtl);
isLayoutNaturalToLauncher()93     boolean isLayoutNaturalToLauncher();
getTaskMenuX(float x, View thumbnailView)94     float getTaskMenuX(float x, View thumbnailView);
getTaskMenuY(float y, View thumbnailView)95     float getTaskMenuY(float y, View thumbnailView);
getTaskMenuWidth(View view)96     int getTaskMenuWidth(View view);
getTaskMenuLayoutOrientation(LinearLayout taskMenuLayout)97     int getTaskMenuLayoutOrientation(LinearLayout taskMenuLayout);
setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp)98     void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp);
99 
100     /**
101      * Maps the velocity from the coordinate plane of the foreground app to that
102      * of Launcher's (which now will always be portrait)
103      */
adjustFloatingIconStartVelocity(PointF velocity)104     void adjustFloatingIconStartVelocity(PointF velocity);
105 
106     class CurveProperties {
107         public int scroll;
108         public int halfPageSize;
109         public int screenCenter;
110         public int halfScreenSize;
111     }
112 
113     class ChildBounds {
114 
115         public final int primaryDimension;
116         public final int secondaryDimension;
117         public final int childPrimaryEnd;
118         public final int childSecondaryEnd;
119 
ChildBounds(int primaryDimension, int secondaryDimension, int childPrimaryEnd, int childSecondaryEnd)120         ChildBounds(int primaryDimension, int secondaryDimension, int childPrimaryEnd,
121             int childSecondaryEnd) {
122             this.primaryDimension = primaryDimension;
123             this.secondaryDimension = secondaryDimension;
124             this.childPrimaryEnd = childPrimaryEnd;
125             this.childSecondaryEnd = childSecondaryEnd;
126         }
127     }
128 }
129