/** * Wire * Copyright (C) 2016 Wire Swiss GmbH * * 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.waz.zclient.pages.main.conversationpager; import android.content.Context; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.view.MotionEvent; import com.waz.zclient.ui.animation.interpolators.penner.Expo; import java.lang.reflect.Field; public class ConversationViewPager extends ViewPager { public ConversationViewPager(Context context) { super(context); postInitViewPager(); } public ConversationViewPager(Context context, AttributeSet attrs) { super(context, attrs); postInitViewPager(); } private ViewPagerScroller viewPagerScroller = null; /** * Override the Scroller instance with our own class so we can change the * duration */ private void postInitViewPager() { try { Field scroller = ViewPager.class.getDeclaredField("mScroller"); scroller.setAccessible(true); Field interpolator = ViewPager.class.getDeclaredField("sInterpolator"); interpolator.setAccessible(true); viewPagerScroller = new ViewPagerScroller(getContext(), new Expo.EaseOut()); scroller.set(this, viewPagerScroller); } catch (Exception ignored) { } } /** * Set the factor by which the duration will change */ public void setScrollDurationFactor(double scrollFactor) { viewPagerScroller.setScrollDurationFactor(scrollFactor); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!isEnabled()) { return false; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { if (!isEnabled()) { return false; } return super.onTouchEvent(ev); } }