1b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell/* 2b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * Copyright (C) 2013 The Android Open Source Project 3b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * 4b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 5b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * you may not use this file except in compliance with the License. 6b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * You may obtain a copy of the License at 7b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * 8b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * http://www.apache.org/licenses/LICENSE-2.0 9b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * 10b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * Unless required by applicable law or agreed to in writing, software 11b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * distributed under the License is distributed on an "AS IS" BASIS, 12b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * See the License for the specific language governing permissions and 14b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell * limitations under the License. 15b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell */ 16b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 17b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 18b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powellpackage android.support.v4.widget; 19b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 20b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powellimport android.content.Context; 21b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powellimport android.view.animation.Interpolator; 22b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powellimport android.widget.OverScroller; 23b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 24b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powellclass ScrollerCompatGingerbread { 25b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static Object createScroller(Context context, Interpolator interpolator) { 26b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell return interpolator != null ? 27b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell new OverScroller(context, interpolator) : new OverScroller(context); 28b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 29b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 30b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static boolean isFinished(Object scroller) { 31b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell return ((OverScroller) scroller).isFinished(); 32b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 33b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 34b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static int getCurrX(Object scroller) { 35b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell return ((OverScroller) scroller).getCurrX(); 36b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 37b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 38b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static int getCurrY(Object scroller) { 39b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell return ((OverScroller) scroller).getCurrY(); 40b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 41b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 42b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static boolean computeScrollOffset(Object scroller) { 43b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell return ((OverScroller) scroller).computeScrollOffset(); 44b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 45b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 46b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static void startScroll(Object scroller, int startX, int startY, int dx, int dy) { 47b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell ((OverScroller) scroller).startScroll(startX, startY, dx, dy); 48b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 49b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 50b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static void startScroll(Object scroller, int startX, int startY, int dx, int dy, 51b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell int duration) { 52b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell ((OverScroller) scroller).startScroll(startX, startY, dx, dy, duration); 53b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 54b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 55b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static void fling(Object scroller, int startX, int startY, int velX, int velY, 56b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell int minX, int maxX, int minY, int maxY) { 57b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell ((OverScroller) scroller).fling(startX, startY, velX, velY, minX, maxX, minY, maxY); 58b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 59b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 60b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static void fling(Object scroller, int startX, int startY, int velX, int velY, 61b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell int minX, int maxX, int minY, int maxY, int overX, int overY) { 62b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell ((OverScroller) scroller).fling(startX, startY, velX, velY, 63b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell minX, maxX, minY, maxY, overX, overY); 64b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 65b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 66b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static void abortAnimation(Object scroller) { 67b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell ((OverScroller) scroller).abortAnimation(); 68b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 69b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 70b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static void notifyHorizontalEdgeReached(Object scroller, int startX, int finalX, 71b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell int overX) { 72b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell ((OverScroller) scroller).notifyHorizontalEdgeReached(startX, finalX, overX); 73b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 74b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 75b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static void notifyVerticalEdgeReached(Object scroller, int startY, int finalY, int overY) { 76b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell ((OverScroller) scroller).notifyVerticalEdgeReached(startY, finalY, overY); 77b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 78b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell 79b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell public static boolean isOverScrolled(Object scroller) { 80b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell return ((OverScroller) scroller).isOverScrolled(); 81b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell } 826580cf4b7e74a2a017ed95b0dc50155b9995edebAdam Powell 836580cf4b7e74a2a017ed95b0dc50155b9995edebAdam Powell public static int getFinalX(Object scroller) { 846580cf4b7e74a2a017ed95b0dc50155b9995edebAdam Powell return ((OverScroller) scroller).getFinalX(); 856580cf4b7e74a2a017ed95b0dc50155b9995edebAdam Powell } 866580cf4b7e74a2a017ed95b0dc50155b9995edebAdam Powell 876580cf4b7e74a2a017ed95b0dc50155b9995edebAdam Powell public static int getFinalY(Object scroller) { 886580cf4b7e74a2a017ed95b0dc50155b9995edebAdam Powell return ((OverScroller) scroller).getFinalY(); 896580cf4b7e74a2a017ed95b0dc50155b9995edebAdam Powell } 9000db92e217c3bc08acd09143cac8e3d3b0d0e813Chris Banes 9100db92e217c3bc08acd09143cac8e3d3b0d0e813Chris Banes public static boolean springBack(Object scroller, int startX, int startY, int minX, int maxX, 9200db92e217c3bc08acd09143cac8e3d3b0d0e813Chris Banes int minY, int maxY) { 9300db92e217c3bc08acd09143cac8e3d3b0d0e813Chris Banes return ((OverScroller) scroller).springBack(startX, startY, minX, maxX, minY, maxY); 9400db92e217c3bc08acd09143cac8e3d3b0d0e813Chris Banes } 95b9e34c7d443082d5ee2b90a0e6788523d8df0df1Adam Powell} 96