Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 18 | |
Jon Miranda | 2d89ea8 | 2017-05-04 11:47:53 -0700 | [diff] [blame] | 19 | import android.graphics.drawable.Drawable; |
Sunny Goyal | b80941b | 2019-06-19 21:30:40 -0700 | [diff] [blame] | 20 | import android.util.FloatProperty; |
Sunny Goyal | dbcc63e | 2020-03-06 15:35:55 -0800 | [diff] [blame^] | 21 | import android.util.IntProperty; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 22 | import android.view.View; |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame] | 23 | import android.view.ViewGroup.LayoutParams; |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 24 | |
| 25 | public class LauncherAnimUtils { |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Durations for various state animations. These are not defined in resources to allow |
| 28 | * easier access from static classes and enums |
| 29 | */ |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 30 | public static final int SPRING_LOADED_EXIT_DELAY = 500; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 31 | |
Tony Wickham | 0f640b6 | 2018-05-09 16:00:14 -0700 | [diff] [blame] | 32 | // The progress of an animation to all apps must be at least this far along to snap to all apps. |
| 33 | public static final float MIN_PROGRESS_TO_ALL_APPS = 0.5f; |
| 34 | |
Sunny Goyal | dbcc63e | 2020-03-06 15:35:55 -0800 | [diff] [blame^] | 35 | public static final IntProperty<Drawable> DRAWABLE_ALPHA = |
| 36 | new IntProperty<Drawable>("drawableAlpha") { |
Jon Miranda | 2d89ea8 | 2017-05-04 11:47:53 -0700 | [diff] [blame] | 37 | @Override |
| 38 | public Integer get(Drawable drawable) { |
| 39 | return drawable.getAlpha(); |
| 40 | } |
| 41 | |
| 42 | @Override |
Sunny Goyal | dbcc63e | 2020-03-06 15:35:55 -0800 | [diff] [blame^] | 43 | public void setValue(Drawable drawable, int alpha) { |
Jon Miranda | 2d89ea8 | 2017-05-04 11:47:53 -0700 | [diff] [blame] | 44 | drawable.setAlpha(alpha); |
| 45 | } |
| 46 | }; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 47 | |
Sunny Goyal | b80941b | 2019-06-19 21:30:40 -0700 | [diff] [blame] | 48 | public static final FloatProperty<View> SCALE_PROPERTY = |
| 49 | new FloatProperty<View>("scale") { |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 50 | @Override |
| 51 | public Float get(View view) { |
| 52 | return view.getScaleX(); |
| 53 | } |
| 54 | |
| 55 | @Override |
Sunny Goyal | b80941b | 2019-06-19 21:30:40 -0700 | [diff] [blame] | 56 | public void setValue(View view, float scale) { |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 57 | view.setScaleX(scale); |
| 58 | view.setScaleY(scale); |
| 59 | } |
| 60 | }; |
Sunny Goyal | ea52908 | 2017-10-31 13:33:03 -0700 | [diff] [blame] | 61 | |
Tony Wickham | 0f640b6 | 2018-05-09 16:00:14 -0700 | [diff] [blame] | 62 | /** Increase the duration if we prevented the fling, as we are going against a high velocity. */ |
| 63 | public static int blockedFlingDurationFactor(float velocity) { |
| 64 | return (int) Utilities.boundToRange(Math.abs(velocity) / 2, 2f, 6f); |
| 65 | } |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame] | 66 | |
Sunny Goyal | dbcc63e | 2020-03-06 15:35:55 -0800 | [diff] [blame^] | 67 | public static final IntProperty<LayoutParams> LAYOUT_WIDTH = |
| 68 | new IntProperty<LayoutParams>("width") { |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame] | 69 | @Override |
| 70 | public Integer get(LayoutParams lp) { |
| 71 | return lp.width; |
| 72 | } |
| 73 | |
| 74 | @Override |
Sunny Goyal | dbcc63e | 2020-03-06 15:35:55 -0800 | [diff] [blame^] | 75 | public void setValue(LayoutParams lp, int width) { |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame] | 76 | lp.width = width; |
| 77 | } |
| 78 | }; |
| 79 | |
Sunny Goyal | dbcc63e | 2020-03-06 15:35:55 -0800 | [diff] [blame^] | 80 | public static final IntProperty<LayoutParams> LAYOUT_HEIGHT = |
| 81 | new IntProperty<LayoutParams>("height") { |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame] | 82 | @Override |
| 83 | public Integer get(LayoutParams lp) { |
| 84 | return lp.height; |
| 85 | } |
| 86 | |
| 87 | @Override |
Sunny Goyal | dbcc63e | 2020-03-06 15:35:55 -0800 | [diff] [blame^] | 88 | public void setValue(LayoutParams lp, int height) { |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame] | 89 | lp.height = height; |
| 90 | } |
| 91 | }; |
Jon Miranda | 86f6c44 | 2019-01-29 11:14:38 -0800 | [diff] [blame] | 92 | |
Sunny Goyal | b80941b | 2019-06-19 21:30:40 -0700 | [diff] [blame] | 93 | public static final FloatProperty<View> VIEW_TRANSLATE_X = |
| 94 | View.TRANSLATION_X instanceof FloatProperty ? (FloatProperty) View.TRANSLATION_X |
| 95 | : new FloatProperty<View>("translateX") { |
| 96 | @Override |
| 97 | public void setValue(View view, float v) { |
| 98 | view.setTranslationX(v); |
| 99 | } |
Jon Miranda | 86f6c44 | 2019-01-29 11:14:38 -0800 | [diff] [blame] | 100 | |
Sunny Goyal | b80941b | 2019-06-19 21:30:40 -0700 | [diff] [blame] | 101 | @Override |
| 102 | public Float get(View view) { |
| 103 | return view.getTranslationX(); |
| 104 | } |
| 105 | }; |
Jon Miranda | 86f6c44 | 2019-01-29 11:14:38 -0800 | [diff] [blame] | 106 | |
Sunny Goyal | b80941b | 2019-06-19 21:30:40 -0700 | [diff] [blame] | 107 | public static final FloatProperty<View> VIEW_TRANSLATE_Y = |
| 108 | View.TRANSLATION_Y instanceof FloatProperty ? (FloatProperty) View.TRANSLATION_Y |
| 109 | : new FloatProperty<View>("translateY") { |
| 110 | @Override |
| 111 | public void setValue(View view, float v) { |
| 112 | view.setTranslationY(v); |
| 113 | } |
Jon Miranda | 86f6c44 | 2019-01-29 11:14:38 -0800 | [diff] [blame] | 114 | |
Sunny Goyal | b80941b | 2019-06-19 21:30:40 -0700 | [diff] [blame] | 115 | @Override |
| 116 | public Float get(View view) { |
| 117 | return view.getTranslationY(); |
| 118 | } |
| 119 | }; |
Sunny Goyal | dbcc63e | 2020-03-06 15:35:55 -0800 | [diff] [blame^] | 120 | |
| 121 | public static final FloatProperty<View> VIEW_ALPHA = |
| 122 | View.ALPHA instanceof FloatProperty ? (FloatProperty) View.ALPHA |
| 123 | : new FloatProperty<View>("alpha") { |
| 124 | @Override |
| 125 | public void setValue(View view, float v) { |
| 126 | view.setAlpha(v); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public Float get(View view) { |
| 131 | return view.getAlpha(); |
| 132 | } |
| 133 | }; |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 134 | } |