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 public static final int INDEX_TASKBAR_PINNING_ANIM = 5; 40 41 // Affect all items inside of a MultipageCellLayout 42 public static final int INDEX_CELLAYOUT_MULTIPAGE_SPACING = 3; 43 44 // Specific for widgets 45 public static final int INDEX_WIDGET_CENTERING = 4; 46 47 // Specific for hotseat items when adjusting for bubbles 48 public static final int INDEX_BUBBLE_ADJUSTMENT_ANIM = 3; 49 50 public static final int COUNT = 6; 51 52 private final MultiPropertyFactory<View> mTranslationX; 53 private final MultiPropertyFactory<View> mTranslationY; 54 MultiTranslateDelegate(View target)55 public MultiTranslateDelegate(View target) { 56 this(target, COUNT, COUNT); 57 } 58 MultiTranslateDelegate(View target, int countX, int countY)59 public MultiTranslateDelegate(View target, int countX, int countY) { 60 mTranslationX = new MultiPropertyFactory<>(target, VIEW_TRANSLATE_X, countX, Float::sum); 61 mTranslationY = new MultiPropertyFactory<>(target, VIEW_TRANSLATE_Y, countY, Float::sum); 62 } 63 64 /** 65 * Helper method to set both translations, x and y at a given index 66 */ setTranslation(int index, float x, float y)67 public void setTranslation(int index, float x, float y) { 68 getTranslationX(index).setValue(x); 69 getTranslationY(index).setValue(y); 70 } 71 72 /** 73 * Returns the translation x for the provided index 74 */ getTranslationX(int index)75 public MultiProperty getTranslationX(int index) { 76 return mTranslationX.get(index); 77 } 78 79 /** 80 * Returns the translation y for the provided index 81 */ getTranslationY(int index)82 public MultiProperty getTranslationY(int index) { 83 return mTranslationY.get(index); 84 } 85 } 86