Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
| 17 | package com.android.launcher3; |
| 18 | |
| 19 | import android.animation.TimeInterpolator; |
| 20 | import android.content.Context; |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 21 | import android.view.animation.Interpolator; |
Sunny Goyal | 74a7e6a | 2018-06-27 13:05:55 -0700 | [diff] [blame] | 22 | import android.widget.Scroller; |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 23 | |
| 24 | /** |
Sunny Goyal | 74a7e6a | 2018-06-27 13:05:55 -0700 | [diff] [blame] | 25 | * Extension of {@link android.widget.Scroller} with the ability to modify the |
| 26 | * Interpolator post-construction. |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 27 | */ |
Sunny Goyal | 74a7e6a | 2018-06-27 13:05:55 -0700 | [diff] [blame] | 28 | public class LauncherScroller extends Scroller { |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 29 | |
Sunny Goyal | 74a7e6a | 2018-06-27 13:05:55 -0700 | [diff] [blame] | 30 | private final InterpolatorWrapper mInterpolatorWrapper; |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 31 | |
Sunny Goyal | 74a7e6a | 2018-06-27 13:05:55 -0700 | [diff] [blame] | 32 | public LauncherScroller(Context context) { |
| 33 | this(context, new InterpolatorWrapper()); |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Sunny Goyal | 74a7e6a | 2018-06-27 13:05:55 -0700 | [diff] [blame] | 36 | private LauncherScroller(Context context, InterpolatorWrapper interpolatorWrapper) { |
| 37 | super(context, interpolatorWrapper); |
| 38 | mInterpolatorWrapper = interpolatorWrapper; |
| 39 | } |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 40 | |
| 41 | public void setInterpolator(TimeInterpolator interpolator) { |
Sunny Goyal | 74a7e6a | 2018-06-27 13:05:55 -0700 | [diff] [blame] | 42 | mInterpolatorWrapper.interpolator = interpolator; |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Sunny Goyal | 74a7e6a | 2018-06-27 13:05:55 -0700 | [diff] [blame] | 45 | private static class InterpolatorWrapper implements Interpolator { |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 46 | |
Sunny Goyal | 74a7e6a | 2018-06-27 13:05:55 -0700 | [diff] [blame] | 47 | public TimeInterpolator interpolator; |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 48 | |
Sunny Goyal | 74a7e6a | 2018-06-27 13:05:55 -0700 | [diff] [blame] | 49 | @Override |
| 50 | public float getInterpolation(float v) { |
| 51 | return interpolator == null ? v : interpolator.getInterpolation(v); |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 52 | } |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 53 | } |
| 54 | } |