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 | 5d2fc32 | 2015-07-06 22:52:49 -0700 | [diff] [blame] | 20 | import android.util.Property; |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 21 | import android.view.View; |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame] | 22 | import android.view.ViewGroup.LayoutParams; |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 23 | |
| 24 | public class LauncherAnimUtils { |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 25 | /** |
| 26 | * Durations for various state animations. These are not defined in resources to allow |
| 27 | * easier access from static classes and enums |
| 28 | */ |
| 29 | public static final int ALL_APPS_TRANSITION_MS = 320; |
| 30 | public static final int OVERVIEW_TRANSITION_MS = 250; |
| 31 | public static final int SPRING_LOADED_TRANSITION_MS = 150; |
Sunny Goyal | 4c7f215 | 2017-10-17 17:17:16 -0700 | [diff] [blame] | 32 | public static final int SPRING_LOADED_EXIT_DELAY = 500; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 33 | |
Tony Wickham | 0f640b6 | 2018-05-09 16:00:14 -0700 | [diff] [blame] | 34 | // The progress of an animation to all apps must be at least this far along to snap to all apps. |
| 35 | public static final float MIN_PROGRESS_TO_ALL_APPS = 0.5f; |
| 36 | |
Jon Miranda | 2d89ea8 | 2017-05-04 11:47:53 -0700 | [diff] [blame] | 37 | public static final Property<Drawable, Integer> DRAWABLE_ALPHA = |
| 38 | new Property<Drawable, Integer>(Integer.TYPE, "drawableAlpha") { |
| 39 | @Override |
| 40 | public Integer get(Drawable drawable) { |
| 41 | return drawable.getAlpha(); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public void set(Drawable drawable, Integer alpha) { |
| 46 | drawable.setAlpha(alpha); |
| 47 | } |
| 48 | }; |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 49 | |
| 50 | public static final Property<View, Float> SCALE_PROPERTY = |
| 51 | new Property<View, Float>(Float.class, "scale") { |
| 52 | @Override |
| 53 | public Float get(View view) { |
| 54 | return view.getScaleX(); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public void set(View view, Float scale) { |
| 59 | view.setScaleX(scale); |
| 60 | view.setScaleY(scale); |
| 61 | } |
| 62 | }; |
Sunny Goyal | ea52908 | 2017-10-31 13:33:03 -0700 | [diff] [blame] | 63 | |
Tony Wickham | 0f640b6 | 2018-05-09 16:00:14 -0700 | [diff] [blame] | 64 | /** Increase the duration if we prevented the fling, as we are going against a high velocity. */ |
| 65 | public static int blockedFlingDurationFactor(float velocity) { |
| 66 | return (int) Utilities.boundToRange(Math.abs(velocity) / 2, 2f, 6f); |
| 67 | } |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame] | 68 | |
| 69 | public static final Property<LayoutParams, Integer> LAYOUT_WIDTH = |
| 70 | new Property<LayoutParams, Integer>(Integer.TYPE, "width") { |
| 71 | @Override |
| 72 | public Integer get(LayoutParams lp) { |
| 73 | return lp.width; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void set(LayoutParams lp, Integer width) { |
| 78 | lp.width = width; |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | public static final Property<LayoutParams, Integer> LAYOUT_HEIGHT = |
| 83 | new Property<LayoutParams, Integer>(Integer.TYPE, "height") { |
| 84 | @Override |
| 85 | public Integer get(LayoutParams lp) { |
| 86 | return lp.height; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public void set(LayoutParams lp, Integer height) { |
| 91 | lp.height = height; |
| 92 | } |
| 93 | }; |
Jon Miranda | 86f6c44 | 2019-01-29 11:14:38 -0800 | [diff] [blame] | 94 | |
| 95 | public static class ViewProgressProperty implements ProgressInterface { |
| 96 | View mView; |
| 97 | Property<View, Float> mProperty; |
| 98 | |
| 99 | public ViewProgressProperty(View view, Property<View, Float> property) { |
| 100 | mView = view; |
| 101 | mProperty = property; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public void setProgress(float progress) { |
| 106 | mProperty.set(mView, progress); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public float getProgress() { |
| 111 | return mProperty.get(mView); |
| 112 | } |
| 113 | } |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 114 | } |