/* * This program is part of the OpenLMIS logistics management information * system platform software. * * Copyright © 2015 ThoughtWorks, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero 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 Affero General Public License for more details. You should * have received a copy of the GNU Affero General Public License along with * this program. If not, see http://www.gnu.org/licenses. For additional * information contact info@OpenLMIS.org */ package org.openlmis.core.view.widget; import android.content.Context; import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.ViewConfiguration; import android.widget.HorizontalScrollView; public class CustomHorizontalScrollView extends HorizontalScrollView { private int mTouchSlop; private float mPrevY; public CustomHorizontalScrollView(Context context, AttributeSet attrs) { super(context, attrs); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } @Override public boolean onInterceptTouchEvent(@NonNull MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mPrevY = MotionEvent.obtain(event).getY(); break; case MotionEvent.ACTION_MOVE: final float eventY = event.getY(); float yDiff = Math.abs(eventY - mPrevY); if (yDiff > mTouchSlop) { return false; } } return super.onInterceptTouchEvent(event); } }