blob: d9cf7f19b3f114f5251bbc64fd6abdfb893d0ecf [file] [log] [blame]
Michael Jurka2ecf9952012-06-18 12:52:28 -07001/*
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 Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Michael Jurka2ecf9952012-06-18 12:52:28 -070018
Jon Miranda2d89ea82017-05-04 11:47:53 -070019import android.graphics.drawable.Drawable;
Sunny Goyalb80941b2019-06-19 21:30:40 -070020import android.util.FloatProperty;
Sunny Goyaldbcc63e2020-03-06 15:35:55 -080021import android.util.IntProperty;
Michael Jurkaf1ad6082013-03-13 12:55:46 +010022import android.view.View;
Sunny Goyal55bdeed2018-09-18 16:17:22 -070023import android.view.ViewGroup.LayoutParams;
Michael Jurka2ecf9952012-06-18 12:52:28 -070024
25public class LauncherAnimUtils {
Sunny Goyalaeb16432017-10-16 11:46:41 -070026 /**
27 * Durations for various state animations. These are not defined in resources to allow
28 * easier access from static classes and enums
29 */
Sunny Goyal4c7f2152017-10-17 17:17:16 -070030 public static final int SPRING_LOADED_EXIT_DELAY = 500;
Sunny Goyalaeb16432017-10-16 11:46:41 -070031
Tony Wickham0f640b62018-05-09 16:00:14 -070032 // 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 Goyaldbcc63e2020-03-06 15:35:55 -080035 public static final IntProperty<Drawable> DRAWABLE_ALPHA =
36 new IntProperty<Drawable>("drawableAlpha") {
Jon Miranda2d89ea82017-05-04 11:47:53 -070037 @Override
38 public Integer get(Drawable drawable) {
39 return drawable.getAlpha();
40 }
41
42 @Override
Sunny Goyaldbcc63e2020-03-06 15:35:55 -080043 public void setValue(Drawable drawable, int alpha) {
Jon Miranda2d89ea82017-05-04 11:47:53 -070044 drawable.setAlpha(alpha);
45 }
46 };
Sunny Goyalaeb16432017-10-16 11:46:41 -070047
Sunny Goyalb80941b2019-06-19 21:30:40 -070048 public static final FloatProperty<View> SCALE_PROPERTY =
49 new FloatProperty<View>("scale") {
Sunny Goyalaeb16432017-10-16 11:46:41 -070050 @Override
51 public Float get(View view) {
52 return view.getScaleX();
53 }
54
55 @Override
Sunny Goyalb80941b2019-06-19 21:30:40 -070056 public void setValue(View view, float scale) {
Sunny Goyalaeb16432017-10-16 11:46:41 -070057 view.setScaleX(scale);
58 view.setScaleY(scale);
59 }
60 };
Sunny Goyalea529082017-10-31 13:33:03 -070061
Tony Wickham0f640b62018-05-09 16:00:14 -070062 /** 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 Goyal55bdeed2018-09-18 16:17:22 -070066
Sunny Goyaldbcc63e2020-03-06 15:35:55 -080067 public static final IntProperty<LayoutParams> LAYOUT_WIDTH =
68 new IntProperty<LayoutParams>("width") {
Sunny Goyal55bdeed2018-09-18 16:17:22 -070069 @Override
70 public Integer get(LayoutParams lp) {
71 return lp.width;
72 }
73
74 @Override
Sunny Goyaldbcc63e2020-03-06 15:35:55 -080075 public void setValue(LayoutParams lp, int width) {
Sunny Goyal55bdeed2018-09-18 16:17:22 -070076 lp.width = width;
77 }
78 };
79
Sunny Goyaldbcc63e2020-03-06 15:35:55 -080080 public static final IntProperty<LayoutParams> LAYOUT_HEIGHT =
81 new IntProperty<LayoutParams>("height") {
Sunny Goyal55bdeed2018-09-18 16:17:22 -070082 @Override
83 public Integer get(LayoutParams lp) {
84 return lp.height;
85 }
86
87 @Override
Sunny Goyaldbcc63e2020-03-06 15:35:55 -080088 public void setValue(LayoutParams lp, int height) {
Sunny Goyal55bdeed2018-09-18 16:17:22 -070089 lp.height = height;
90 }
91 };
Jon Miranda86f6c442019-01-29 11:14:38 -080092
Sunny Goyalb80941b2019-06-19 21:30:40 -070093 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 Miranda86f6c442019-01-29 11:14:38 -0800100
Sunny Goyalb80941b2019-06-19 21:30:40 -0700101 @Override
102 public Float get(View view) {
103 return view.getTranslationX();
104 }
105 };
Jon Miranda86f6c442019-01-29 11:14:38 -0800106
Sunny Goyalb80941b2019-06-19 21:30:40 -0700107 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 Miranda86f6c442019-01-29 11:14:38 -0800114
Sunny Goyalb80941b2019-06-19 21:30:40 -0700115 @Override
116 public Float get(View view) {
117 return view.getTranslationY();
118 }
119 };
Sunny Goyaldbcc63e2020-03-06 15:35:55 -0800120
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 Jurka2ecf9952012-06-18 12:52:28 -0700134}