package com.nozomi.autohidescrollview.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.ListView;

public class BounceListView extends ListView {
	private static final int MAX_Y_OVERSCROLL_DISTANCE = 200;

	private Context mContext;
	private int mMaxYOverscrollDistance;

	public BounceListView(Context context) {
		super(context);
		mContext = context;
		initBounceListView();
	}

	public BounceListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		initBounceListView();
	}

	public BounceListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		initBounceListView();
	}

	private void initBounceListView() {
		// get the density of the screen and do some maths with it on the max
		// overscroll distance
		// variable so that you get similar behaviors no matter what the screen
		// size

		final DisplayMetrics metrics = mContext.getResources()
				.getDisplayMetrics();
		final float density = metrics.density;

		mMaxYOverscrollDistance = (int) (density * MAX_Y_OVERSCROLL_DISTANCE);
	}

	@Override
	protected boolean overScrollBy(int deltaX, int deltaY, int scrollX,
			int scrollY, int scrollRangeX, int scrollRangeY,
			int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
		// This is where the magic happens, we have replaced the incoming
		// maxOverScrollY with our own custom variable mMaxYOverscrollDistance;
		return super.overScrollBy(deltaX, deltaY, scrollX, scrollY,
				scrollRangeX, scrollRangeY, maxOverScrollX,
				mMaxYOverscrollDistance, isTouchEvent);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
		int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
				MeasureSpec.AT_MOST);

		super.onMeasure(widthMeasureSpec, expandSpec);
	}

}
@@ -1223,518 +1223,8 @@
 %0D%0A%0D%0A
-%09@Override%0D%0A%09protected boolean overScrollBy(int deltaX, int deltaY, int scrollX,%0D%0A%09%09%09int scrollY, int scrollRangeX, int scrollRangeY,%0D%0A%09%09%09int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) %7B%0D%0A%09%09// This is where the magic happens, we have replaced the incoming%0D%0A%09%09// maxOverScrollY with our own custom variable mMaxYOverscrollDistance;%0D%0A%09%09return super.overScrollBy(deltaX, deltaY, scrollX, scrollY,%0D%0A%09%09%09%09scrollRangeX, scrollRangeY, maxOverScrollX,%0D%0A%09%09%09%09mMaxYOverscrollDistance, isTouchEvent);%0D%0A%09%7D%0D%0A%0D%0A
 %09@Ov

remove overScrollBy