Home | History | Annotate | Download | only in launcher3
      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 
     19 import android.support.v4.widget.AutoScrollHelper;
     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);
     37         setEdgeType(EDGE_TYPE_INSIDE_EXTEND);
     38         setExclusive(true);
     39         setMaximumVelocity(MAX_SCROLL_VELOCITY, MAX_SCROLL_VELOCITY);
     40         setRampDownDuration(0);
     41         setRampUpDuration(0);
     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 }