1 /*
2  * Copyright (C) 2021 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.util;
17 
18 import android.content.Context;
19 import android.view.MotionEvent;
20 import android.widget.EdgeEffect;
21 
22 import com.android.launcher3.Utilities;
23 
24 /**
25  * Extension of {@link EdgeEffect} to allow backwards compatibility
26  */
27 public class EdgeEffectCompat extends EdgeEffect {
28 
EdgeEffectCompat(Context context)29     public EdgeEffectCompat(Context context) {
30         super(context);
31     }
32 
33     @Override
getDistance()34     public float getDistance() {
35         return Utilities.ATLEAST_S ? super.getDistance() : 0;
36     }
37 
38     @Override
onPullDistance(float deltaDistance, float displacement)39     public float onPullDistance(float deltaDistance, float displacement) {
40         if (Utilities.ATLEAST_S) {
41             return super.onPullDistance(deltaDistance, displacement);
42         } else {
43             onPull(deltaDistance, displacement);
44             return deltaDistance;
45         }
46     }
47 
onPullDistance(float deltaDistance, float displacement, MotionEvent ev)48     public float onPullDistance(float deltaDistance, float displacement, MotionEvent ev) {
49         return onPullDistance(deltaDistance, displacement);
50     }
51 
onFlingVelocity(int velocity)52     public void onFlingVelocity(int velocity) { }
53 
onRelease(MotionEvent ev)54     public void onRelease(MotionEvent ev) {
55         onRelease();
56     }
57 }
58