• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 static android.widget.ListPopupWindow.WRAP_CONTENT;
20 
21 import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
22 import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
23 import static com.android.launcher3.touch.SingleAxisSwipeDetector.HORIZONTAL;
24 
25 import android.content.res.Resources;
26 import android.graphics.PointF;
27 import android.graphics.Rect;
28 import android.graphics.RectF;
29 import android.util.FloatProperty;
30 import android.view.MotionEvent;
31 import android.view.Surface;
32 import android.view.VelocityTracker;
33 import android.view.View;
34 import android.view.accessibility.AccessibilityEvent;
35 import android.widget.LinearLayout;
36 
37 import com.android.launcher3.DeviceProfile;
38 import com.android.launcher3.PagedView;
39 import com.android.launcher3.Utilities;
40 import com.android.launcher3.util.OverScroller;
41 
42 public class LandscapePagedViewHandler implements PagedOrientationHandler {
43 
44     @Override
getPrimaryValue(T x, T y)45     public <T> T getPrimaryValue(T x, T y) {
46         return y;
47     }
48 
49     @Override
getSecondaryValue(T x, T y)50     public <T> T getSecondaryValue(T x, T y) {
51         return x;
52     }
53 
54     @Override
delegateScrollTo(PagedView pagedView, int secondaryScroll, int minMaxScroll)55     public void delegateScrollTo(PagedView pagedView, int secondaryScroll, int minMaxScroll) {
56         pagedView.superScrollTo(secondaryScroll, minMaxScroll);
57     }
58 
59     @Override
delegateScrollBy(PagedView pagedView, int unboundedScroll, int x, int y)60     public void delegateScrollBy(PagedView pagedView, int unboundedScroll, int x, int y) {
61         pagedView.scrollTo(pagedView.getScrollX() + x, unboundedScroll + y);
62     }
63 
64     @Override
scrollerStartScroll(OverScroller scroller, int newPosition)65     public void scrollerStartScroll(OverScroller scroller, int newPosition) {
66         scroller.startScroll(scroller.getCurrPos(), newPosition - scroller.getCurrPos());
67     }
68 
69     @Override
getCurveProperties(PagedView view, Rect insets, CurveProperties out)70     public void getCurveProperties(PagedView view, Rect insets, CurveProperties out) {
71         out.scroll = view.getScrollY();
72         out.halfPageSize = view.getNormalChildHeight() / 2;
73         out.halfScreenSize = view.getMeasuredHeight() / 2;
74         out.screenCenter = insets.top + view.getPaddingTop() + out.scroll + out.halfPageSize;
75     }
76 
77     @Override
isGoingUp(float displacement, boolean isRtl)78     public boolean isGoingUp(float displacement, boolean isRtl) {
79         return isRtl ? displacement < 0 : displacement > 0;
80     }
81 
82     @Override
isLayoutNaturalToLauncher()83     public boolean isLayoutNaturalToLauncher() {
84         return false;
85     }
86 
87     @Override
adjustFloatingIconStartVelocity(PointF velocity)88     public void adjustFloatingIconStartVelocity(PointF velocity) {
89         float oldX = velocity.x;
90         float oldY = velocity.y;
91         velocity.set(-oldY, oldX);
92     }
93 
94     @Override
delegateScrollTo(PagedView pagedView, int primaryScroll)95     public void delegateScrollTo(PagedView pagedView, int primaryScroll) {
96         pagedView.superScrollTo(pagedView.getScrollX(), primaryScroll);
97     }
98 
99     @Override
set(T target, Int2DAction<T> action, int param)100     public <T> void set(T target, Int2DAction<T> action, int param) {
101         action.call(target, 0, param);
102     }
103 
104     @Override
set(T target, Float2DAction<T> action, float param)105     public <T> void set(T target, Float2DAction<T> action, float param) {
106         action.call(target, 0, param);
107     }
108 
109     @Override
setSecondary(T target, Float2DAction<T> action, float param)110     public <T> void setSecondary(T target, Float2DAction<T> action, float param) {
111         action.call(target, param, 0);
112     }
113 
114     @Override
getPrimaryDirection(MotionEvent event, int pointerIndex)115     public float getPrimaryDirection(MotionEvent event, int pointerIndex) {
116         return event.getY(pointerIndex);
117     }
118 
119     @Override
getPrimaryVelocity(VelocityTracker velocityTracker, int pointerId)120     public float getPrimaryVelocity(VelocityTracker velocityTracker, int pointerId) {
121         return velocityTracker.getYVelocity(pointerId);
122     }
123 
124     @Override
getMeasuredSize(View view)125     public int getMeasuredSize(View view) {
126         return view.getMeasuredHeight();
127     }
128 
129     @Override
getPrimarySize(RectF rect)130     public float getPrimarySize(RectF rect) {
131         return rect.height();
132     }
133 
134     @Override
getClearAllScrollOffset(View view, boolean isRtl)135     public int getClearAllScrollOffset(View view, boolean isRtl) {
136         return (isRtl ? view.getPaddingBottom() : - view.getPaddingTop()) / 2;
137     }
138 
139     @Override
getSecondaryDimension(View view)140     public int getSecondaryDimension(View view) {
141         return view.getWidth();
142     }
143 
144     @Override
getPrimaryViewTranslate()145     public FloatProperty<View> getPrimaryViewTranslate() {
146         return VIEW_TRANSLATE_Y;
147     }
148 
149     @Override
getSecondaryViewTranslate()150     public FloatProperty<View> getSecondaryViewTranslate() {
151         return VIEW_TRANSLATE_X;
152     }
153 
154     @Override
setPrimaryAndResetSecondaryTranslate(View view, float translation)155     public void setPrimaryAndResetSecondaryTranslate(View view, float translation) {
156         view.setTranslationX(0);
157         view.setTranslationY(translation);
158     }
159 
160     @Override
getPrimaryScroll(View view)161     public int getPrimaryScroll(View view) {
162         return view.getScrollY();
163     }
164 
165     @Override
getPrimaryScale(View view)166     public float getPrimaryScale(View view) {
167         return view.getScaleY();
168     }
169 
170     @Override
setMaxScroll(AccessibilityEvent event, int maxScroll)171     public void setMaxScroll(AccessibilityEvent event, int maxScroll) {
172         event.setMaxScrollY(maxScroll);
173     }
174 
175     @Override
getRecentsRtlSetting(Resources resources)176     public boolean getRecentsRtlSetting(Resources resources) {
177         return !Utilities.isRtl(resources);
178     }
179 
180     @Override
getDegreesRotated()181     public float getDegreesRotated() {
182         return 90;
183     }
184 
185     @Override
getRotation()186     public int getRotation() {
187         return Surface.ROTATION_90;
188     }
189 
190     @Override
getChildStart(View view)191     public int getChildStart(View view) {
192         return view.getTop();
193     }
194 
195     @Override
getChildStartWithTranslation(View view)196     public float getChildStartWithTranslation(View view) {
197         return view.getTop() + view.getTranslationY();
198     }
199 
200     @Override
getCenterForPage(View view, Rect insets)201     public int getCenterForPage(View view, Rect insets) {
202         return (view.getPaddingLeft() + view.getMeasuredWidth() + insets.left
203             - insets.right - view.getPaddingRight()) / 2;
204     }
205 
206     @Override
getScrollOffsetStart(View view, Rect insets)207     public int getScrollOffsetStart(View view, Rect insets) {
208         return insets.top + view.getPaddingTop();
209     }
210 
211     @Override
getScrollOffsetEnd(View view, Rect insets)212     public int getScrollOffsetEnd(View view, Rect insets) {
213         return view.getHeight() - view.getPaddingBottom() - insets.bottom;
214     }
215 
216     @Override
getOppositeSwipeDirection()217     public SingleAxisSwipeDetector.Direction getOppositeSwipeDirection() {
218         return HORIZONTAL;
219     }
220 
221     @Override
getPrimaryTranslationDirectionFactor()222     public int getPrimaryTranslationDirectionFactor() {
223         return -1;
224     }
225 
getSecondaryTranslationDirectionFactor()226     public int getSecondaryTranslationDirectionFactor() {
227         return 1;
228     }
229 
230     @Override
getTaskDragDisplacementFactor(boolean isRtl)231     public int getTaskDragDisplacementFactor(boolean isRtl) {
232         return isRtl ? 1 : -1;
233     }
234 
235     @Override
getTaskMenuX(float x, View thumbnailView)236     public float getTaskMenuX(float x, View thumbnailView) {
237         return thumbnailView.getMeasuredWidth() + x;
238     }
239 
240     @Override
getTaskMenuY(float y, View thumbnailView)241     public float getTaskMenuY(float y, View thumbnailView) {
242         return y;
243     }
244 
245     @Override
getTaskMenuWidth(View view)246     public int getTaskMenuWidth(View view) {
247         return view.getMeasuredHeight();
248     }
249 
250     @Override
getTaskMenuLayoutOrientation(boolean canRecentsActivityRotate, LinearLayout taskMenuLayout)251     public int getTaskMenuLayoutOrientation(boolean canRecentsActivityRotate,
252         LinearLayout taskMenuLayout) {
253         return LinearLayout.HORIZONTAL;
254     }
255 
256     @Override
setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp)257     public void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp) {
258         lp.width = 0;
259         lp.height = WRAP_CONTENT;
260         lp.weight = 1;
261     }
262 
263     @Override
getChildBounds(View child, int childStart, int pageCenter, boolean layoutChild)264     public ChildBounds getChildBounds(View child, int childStart, int pageCenter,
265         boolean layoutChild) {
266         final int childHeight = child.getMeasuredHeight();
267         final int childBottom = childStart + childHeight;
268         final int childWidth = child.getMeasuredWidth();
269         final int childLeft = pageCenter - childWidth/ 2;
270         if (layoutChild) {
271             child.layout(childLeft, childStart, childLeft + childWidth, childBottom);
272         }
273         return new ChildBounds(childHeight, childWidth, childBottom, childLeft);
274     }
275 
276     @SuppressWarnings("SuspiciousNameCombination")
277     @Override
getDistanceToBottomOfRect(DeviceProfile dp, Rect rect)278     public int getDistanceToBottomOfRect(DeviceProfile dp, Rect rect) {
279         return rect.left;
280     }
281 }
282