/* * Copyright (C) 2014 Fastboot Mobile, LLC. * * This program is free software; you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation; either version 3 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; * if not, see <http://www.gnu.org/licenses>. */ package com.fastbootmobile.encore.app.ui; import android.content.Context; import android.util.AttributeSet; import android.widget.ScrollView; /** * ScrollView that can be observed (ie. get a callback on scroll event) */ public class ObservableScrollView extends ScrollView { public interface ScrollViewListener { void onScroll(ObservableScrollView scrollView, int x, int y, int oldx, int oldy); } private ScrollViewListener mScrollListener = null; public ObservableScrollView(Context context) { super(context); } public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public ObservableScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public void setOnScrollListener(ScrollViewListener scrollViewListener) { mScrollListener = scrollViewListener; } @Override public int computeVerticalScrollRange() { return super.computeVerticalScrollRange(); } @Override protected void onScrollChanged(int x, int y, int oldx, int oldy) { super.onScrollChanged(x, y, oldx, oldy); if (mScrollListener != null) { mScrollListener.onScroll(this, x, y, oldx, oldy); } } }