// Copied from https://github.com/ToxicBakery/ViewPagerTransforms @SuppressWarnings("WeakerAccess") public abstract class BaseTransformer implements PageTransformer { public static final float DAMPING_RATIO_NO_BOUNCY = 1f; /** * Called each {@link #transformPage(View, float)}. * * @param view the view * @param position the position */ protected abstract void onTransform(View view, float position); @Override public void transformPage(@NonNull View view, float position) { onPreTransform(view, position); onTransform(view, position); onPostTransform(view, position); } /** * If the position offset of a fragment is less than negative one or greater than one, returning true will set the * visibility of the fragment to {@link View#GONE}. Returning false will force the fragment to {@link View#VISIBLE}. * * @return hideOffscreenPages */ protected boolean hideOffscreenPages() { return true; } /** * Indicates if the default animations of the view pager should be used. * * @return isPagingEnabled */ protected boolean isPagingEnabled() { return false; } /** * Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)} is called. * * @param view the view * @param position the position */ protected void onPreTransform(@NonNull View view, float position) { float alpha = 0.0f; float width = (float) view.getWidth(); view.setRotationX(0.0f); view.setRotationY(0.0f); view.setRotation(0.0f); view.setScaleX(DAMPING_RATIO_NO_BOUNCY); view.setScaleY(DAMPING_RATIO_NO_BOUNCY); view.setPivotX(0.0f); view.setPivotY(0.0f); view.setTranslationY(0.0f); view.setTranslationX(isPagingEnabled() ? 0.0f : (-width) * position); if (hideOffscreenPages()) { if (position > -1.0f && position < DAMPING_RATIO_NO_BOUNCY) { alpha = DAMPING_RATIO_NO_BOUNCY; } view.setAlpha(alpha); view.setEnabled(false); return; } view.setEnabled(true); view.setAlpha(DAMPING_RATIO_NO_BOUNCY); } /** * Called each {@link #transformPage(View, float)} call after {@link #onTransform(View, float)} is finished. * * @param view the view * @param position the position */ protected void onPostTransform(@NonNull View view, float position) {} }