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.graphics.Canvas; 20 import android.widget.EdgeEffect; 21 22 import com.android.launcher3.Utilities; 23 import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay; 24 25 /** 26 * Extension of {@link EdgeEffect} which shows the Launcher overlay 27 */ 28 public class OverlayEdgeEffect extends EdgeEffectCompat { 29 30 protected float mDistance; 31 protected final LauncherOverlay mOverlay; 32 protected boolean mIsScrolling; 33 protected final boolean mIsRtl; 34 OverlayEdgeEffect(Context context, LauncherOverlay overlay)35 public OverlayEdgeEffect(Context context, LauncherOverlay overlay) { 36 super(context); 37 mOverlay = overlay; 38 mIsRtl = Utilities.isRtl(context.getResources()); 39 } 40 41 @Override getDistance()42 public float getDistance() { 43 return mDistance; 44 } 45 onPullDistance(float deltaDistance, float displacement)46 public float onPullDistance(float deltaDistance, float displacement) { 47 mDistance = Math.max(0f, deltaDistance + mDistance); 48 if (!mIsScrolling) { 49 mOverlay.onScrollInteractionBegin(); 50 mIsScrolling = true; 51 } 52 mOverlay.onScrollChange(mDistance, mIsRtl); 53 return mDistance > 0 ? deltaDistance : 0; 54 } 55 56 @Override onAbsorb(int velocity)57 public void onAbsorb(int velocity) { } 58 59 @Override isFinished()60 public boolean isFinished() { 61 return mDistance <= 0; 62 } 63 64 @Override onRelease()65 public void onRelease() { 66 if (mIsScrolling) { 67 mDistance = 0; 68 mOverlay.onScrollInteractionEnd(); 69 mIsScrolling = false; 70 } 71 } 72 73 @Override draw(Canvas canvas)74 public boolean draw(Canvas canvas) { 75 return false; 76 } 77 finish()78 public void finish() { 79 mDistance = 0; 80 } 81 } 82