Alan Viverette | 4cda5b7 | 2013-08-28 17:53:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Bjorn Bringert | b66773c | 2013-09-25 16:12:24 +0100 | [diff] [blame] | 19 | import android.support.v4.widget.AutoScrollHelper; |
Alan Viverette | 4cda5b7 | 2013-08-28 17:53:41 -0700 | [diff] [blame] | 20 | import android.widget.ScrollView; |
| 21 | |
| 22 | /** |
| 23 | * An implementation of {@link AutoScrollHelper} that knows how to scroll |
| 24 | * through a {@link Folder}. |
| 25 | */ |
| 26 | public class FolderAutoScrollHelper extends AutoScrollHelper { |
| 27 | private static final float MAX_SCROLL_VELOCITY = 1500f; |
| 28 | |
| 29 | private final ScrollView mTarget; |
| 30 | |
| 31 | public FolderAutoScrollHelper(ScrollView target) { |
| 32 | super(target); |
| 33 | |
| 34 | mTarget = target; |
| 35 | |
| 36 | setActivationDelay(0); |
Mindy Pereira | e886ee1 | 2013-09-04 14:32:02 -0700 | [diff] [blame] | 37 | setEdgeType(EDGE_TYPE_INSIDE_EXTEND); |
Alan Viverette | 4cda5b7 | 2013-08-28 17:53:41 -0700 | [diff] [blame] | 38 | setExclusive(true); |
| 39 | setMaximumVelocity(MAX_SCROLL_VELOCITY, MAX_SCROLL_VELOCITY); |
Mindy Pereira | 33d143a | 2013-09-06 14:03:41 -0700 | [diff] [blame] | 40 | setRampDownDuration(0); |
| 41 | setRampUpDuration(0); |
Alan Viverette | 4cda5b7 | 2013-08-28 17:53:41 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public void scrollTargetBy(int deltaX, int deltaY) { |
| 46 | mTarget.scrollBy(deltaX, deltaY); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public boolean canTargetScrollHorizontally(int direction) { |
| 51 | // List do not scroll horizontally. |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public boolean canTargetScrollVertically(int direction) { |
| 57 | return mTarget.canScrollVertically(direction); |
| 58 | } |
| 59 | } |