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.Rect; 23 import android.view.MotionEvent; 24 import android.view.VelocityTracker; 25 import android.view.View; 26 import android.view.accessibility.AccessibilityEvent; 27 28 /** 29 * Abstraction layer to separate horizontal and vertical specific implementations 30 * for {@link com.android.launcher3.PagedView}. Majority of these implementations are (should be) as 31 * simple as choosing the correct X and Y analogous methods. 32 */ 33 public interface PagedOrientationHandler { 34 35 PagedOrientationHandler DEFAULT = new DefaultPagedViewHandler(); 36 37 interface Int2DAction<T> { call(T target, int x, int y)38 void call(T target, int x, int y); 39 } 40 interface Float2DAction<T> { call(T target, float x, float y)41 void call(T target, float x, float y); 42 } 43 Int2DAction<View> VIEW_SCROLL_BY = View::scrollBy; 44 Int2DAction<View> VIEW_SCROLL_TO = View::scrollTo; 45 Float2DAction<Canvas> CANVAS_TRANSLATE = Canvas::translate; 46 Float2DAction<Matrix> MATRIX_POST_TRANSLATE = Matrix::postTranslate; 47 setPrimary(T target, Int2DAction<T> action, int param)48 <T> void setPrimary(T target, Int2DAction<T> action, int param); setPrimary(T target, Float2DAction<T> action, float param)49 <T> void setPrimary(T target, Float2DAction<T> action, float param); getPrimaryDirection(MotionEvent event, int pointerIndex)50 float getPrimaryDirection(MotionEvent event, int pointerIndex); getPrimaryVelocity(VelocityTracker velocityTracker, int pointerId)51 float getPrimaryVelocity(VelocityTracker velocityTracker, int pointerId); getMeasuredSize(View view)52 int getMeasuredSize(View view); getPrimaryScroll(View view)53 int getPrimaryScroll(View view); getPrimaryScale(View view)54 float getPrimaryScale(View view); getChildStart(View view)55 int getChildStart(View view); getCenterForPage(View view, Rect insets)56 int getCenterForPage(View view, Rect insets); getScrollOffsetStart(View view, Rect insets)57 int getScrollOffsetStart(View view, Rect insets); getScrollOffsetEnd(View view, Rect insets)58 int getScrollOffsetEnd(View view, Rect insets); getChildBounds(View child, int childStart, int pageCenter, boolean layoutChild)59 ChildBounds getChildBounds(View child, int childStart, int pageCenter, boolean layoutChild); setMaxScroll(AccessibilityEvent event, int maxScroll)60 void setMaxScroll(AccessibilityEvent event, int maxScroll); getRecentsRtlSetting(Resources resources)61 boolean getRecentsRtlSetting(Resources resources); 62 getPrimaryValue(int x, int y)63 int getPrimaryValue(int x, int y); getSecondaryValue(int x, int y)64 int getSecondaryValue(int x, int y); 65 getPrimaryValue(float x, float y)66 float getPrimaryValue(float x, float y); getSecondaryValue(float x, float y)67 float getSecondaryValue(float x, float y); 68 69 class ChildBounds { 70 71 public final int primaryDimension; 72 public final int secondaryDimension; 73 public final int childPrimaryEnd; 74 public final int childSecondaryEnd; 75 ChildBounds(int primaryDimension, int secondaryDimension, int childPrimaryEnd, int childSecondaryEnd)76 public ChildBounds(int primaryDimension, int secondaryDimension, int childPrimaryEnd, 77 int childSecondaryEnd) { 78 this.primaryDimension = primaryDimension; 79 this.secondaryDimension = secondaryDimension; 80 this.childPrimaryEnd = childPrimaryEnd; 81 this.childSecondaryEnd = childSecondaryEnd; 82 } 83 } 84 } 85