blob: e5042c4e2e0f178d7b0124f8647a8b1d35eec083 [file] [log] [blame]
Adam Cohenf9618852013-11-08 06:45:03 -08001/*
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
17package com.android.launcher3;
18
19import android.animation.TimeInterpolator;
20import android.content.Context;
Adam Cohenf9618852013-11-08 06:45:03 -080021import android.view.animation.Interpolator;
Sunny Goyal74a7e6a2018-06-27 13:05:55 -070022import android.widget.Scroller;
Adam Cohenf9618852013-11-08 06:45:03 -080023
24/**
Sunny Goyal74a7e6a2018-06-27 13:05:55 -070025 * Extension of {@link android.widget.Scroller} with the ability to modify the
26 * Interpolator post-construction.
Adam Cohenf9618852013-11-08 06:45:03 -080027 */
Sunny Goyal74a7e6a2018-06-27 13:05:55 -070028public class LauncherScroller extends Scroller {
Adam Cohenf9618852013-11-08 06:45:03 -080029
Sunny Goyal74a7e6a2018-06-27 13:05:55 -070030 private final InterpolatorWrapper mInterpolatorWrapper;
Adam Cohenf9618852013-11-08 06:45:03 -080031
Sunny Goyal74a7e6a2018-06-27 13:05:55 -070032 public LauncherScroller(Context context) {
33 this(context, new InterpolatorWrapper());
Adam Cohenf9618852013-11-08 06:45:03 -080034 }
35
Sunny Goyal74a7e6a2018-06-27 13:05:55 -070036 private LauncherScroller(Context context, InterpolatorWrapper interpolatorWrapper) {
37 super(context, interpolatorWrapper);
38 mInterpolatorWrapper = interpolatorWrapper;
39 }
Adam Cohenf9618852013-11-08 06:45:03 -080040
41 public void setInterpolator(TimeInterpolator interpolator) {
Sunny Goyal74a7e6a2018-06-27 13:05:55 -070042 mInterpolatorWrapper.interpolator = interpolator;
Adam Cohenf9618852013-11-08 06:45:03 -080043 }
44
Sunny Goyal74a7e6a2018-06-27 13:05:55 -070045 private static class InterpolatorWrapper implements Interpolator {
Adam Cohenf9618852013-11-08 06:45:03 -080046
Sunny Goyal74a7e6a2018-06-27 13:05:55 -070047 public TimeInterpolator interpolator;
Adam Cohenf9618852013-11-08 06:45:03 -080048
Sunny Goyal74a7e6a2018-06-27 13:05:55 -070049 @Override
50 public float getInterpolation(float v) {
51 return interpolator == null ? v : interpolator.getInterpolation(v);
Adam Cohenf9618852013-11-08 06:45:03 -080052 }
Adam Cohenf9618852013-11-08 06:45:03 -080053 }
54}