• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
19 import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
20 
21 import android.view.View;
22 
23 import com.android.launcher3.util.MultiPropertyFactory.MultiProperty;
24 
25 /**
26  * A utility class to split translation components for various workspace items
27  */
28 public class MultiTranslateDelegate {
29 
30     // offset related to reorder hint and bounce animations
31     public static final int INDEX_REORDER_BOUNCE_OFFSET = 0;
32     // offset related to previewing the new reordered position
33     public static final int INDEX_REORDER_PREVIEW_OFFSET = 1;
34     public static final int INDEX_MOVE_FROM_CENTER_ANIM = 2;
35 
36     // Specific for items in taskbar (icons, folders, qsb)
37     public static final int INDEX_TASKBAR_ALIGNMENT_ANIM = 3;
38     public static final int INDEX_TASKBAR_REVEAL_ANIM = 4;
39 
40     // Specific for widgets
41     public static final int INDEX_WIDGET_CENTERING = 3;
42 
43     public static final int COUNT = 5;
44 
45     private final MultiPropertyFactory<View> mTranslationX;
46     private final MultiPropertyFactory<View> mTranslationY;
47 
MultiTranslateDelegate(View target)48     public MultiTranslateDelegate(View target) {
49         this(target, COUNT, COUNT);
50     }
51 
MultiTranslateDelegate(View target, int countX, int countY)52     public MultiTranslateDelegate(View target, int countX, int countY) {
53         mTranslationX = new MultiPropertyFactory<>(target, VIEW_TRANSLATE_X, countX, Float::sum);
54         mTranslationY = new MultiPropertyFactory<>(target, VIEW_TRANSLATE_Y, countY, Float::sum);
55     }
56 
57     /**
58      * Helper method to set both translations, x and y at a given index
59      */
setTranslation(int index, float x, float y)60     public void setTranslation(int index, float x, float y) {
61         getTranslationX(index).setValue(x);
62         getTranslationY(index).setValue(y);
63     }
64 
65     /**
66      * Returns the translation x for the provided index
67      */
getTranslationX(int index)68     public MultiProperty getTranslationX(int index) {
69         return mTranslationX.get(index);
70     }
71 
72     /**
73      * Returns the translation y for the provided index
74      */
getTranslationY(int index)75     public MultiProperty getTranslationY(int index) {
76         return mTranslationY.get(index);
77     }
78 }
79