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