• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.graphics.RenderNode;
21 import android.widget.EdgeEffect;
22 
23 /**
24  * Extension of {@link EdgeEffect} which translates the content instead of the default
25  * platform implementation
26  */
27 @SuppressWarnings("NewApi")
28 public class TranslateEdgeEffect extends EdgeEffectCompat {
29 
30     private final RenderNode mNode;
31 
TranslateEdgeEffect(Context context)32     public TranslateEdgeEffect(Context context) {
33         super(context);
34         mNode = new RenderNode("TranslateEdgeEffect");
35     }
36 
37     @Override
draw(Canvas canvas)38     public boolean draw(Canvas canvas) {
39         return false;
40     }
41 
getTranslationShift(float[] out)42     public boolean getTranslationShift(float[] out) {
43         Canvas c = mNode.beginRecording(1, 1);
44         boolean result = super.draw(c);
45         mNode.endRecording();
46 
47         out[0] = getDistance();
48         return result;
49     }
50 }
51