• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 package com.android.launcher3.allapps;
17 
18 import android.content.Context;
19 import android.util.AttributeSet;
20 import android.view.MotionEvent;
21 
22 import com.android.launcher3.PagedView;
23 
24 public class AllAppsPagedView extends PagedView<PersonalWorkSlidingTabStrip> {
25 
26   final static float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6;
27   final static float MAX_SWIPE_ANGLE = (float) Math.PI / 3;
28   final static float TOUCH_SLOP_DAMPING_FACTOR = 4;
29 
AllAppsPagedView(Context context)30   public AllAppsPagedView(Context context) {
31         this(context, null);
32     }
33 
AllAppsPagedView(Context context, AttributeSet attrs)34     public AllAppsPagedView(Context context, AttributeSet attrs) {
35         this(context, attrs, 0);
36     }
37 
AllAppsPagedView(Context context, AttributeSet attrs, int defStyle)38     public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) {
39         super(context, attrs, defStyle);
40     }
41 
42     @Override
getCurrentPageDescription()43     protected String getCurrentPageDescription() {
44         // Not necessary, tab-bar already has two tabs with their own descriptions.
45         return "";
46     }
47 
48     @Override
onScrollChanged(int l, int t, int oldl, int oldt)49     protected void onScrollChanged(int l, int t, int oldl, int oldt) {
50         super.onScrollChanged(l, t, oldl, oldt);
51         mPageIndicator.setScroll(l, mMaxScrollX);
52     }
53 
54     @Override
determineScrollingStart(MotionEvent ev)55     protected void determineScrollingStart(MotionEvent ev) {
56         float absDeltaX = Math.abs(ev.getX() - getDownMotionX());
57         float absDeltaY = Math.abs(ev.getY() - getDownMotionY());
58 
59         if (Float.compare(absDeltaX, 0f) == 0) return;
60 
61         float slope = absDeltaY / absDeltaX;
62         float theta = (float) Math.atan(slope);
63 
64         if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) {
65             cancelCurrentPageLongPress();
66         }
67 
68         if (theta > MAX_SWIPE_ANGLE) {
69             return;
70         } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) {
71             theta -= START_DAMPING_TOUCH_SLOP_ANGLE;
72             float extraRatio = (float)
73                     Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE)));
74             super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio);
75         } else {
76             super.determineScrollingStart(ev);
77         }
78     }
79 
80     @Override
hasOverlappingRendering()81     public boolean hasOverlappingRendering() {
82         return false;
83     }
84 }
85