Amrish-Sharma / FlipQuotes

1 stars 0 forks source link

remove deprecated apis #6

Open Amrish-Sharma opened 2 weeks ago

Amrish-Sharma commented 2 weeks ago

To replace deprecated APIs in code, we need to identify the deprecated methods and find their modern equivalents. Here are the replacements for the deprecated methods in code:

  1. setAlpha(float alpha) on View is deprecated. Use setAlpha(float alpha) from ViewCompat instead.
  2. setTranslationX(float translationX) on View is deprecated. Use setTranslationX(float translationX) from ViewCompat instead.
  3. setTranslationY(float translationY) on View is deprecated. Use setTranslationY(float translationY) from ViewCompat instead.
  4. setScaleX(float scaleX) on View is deprecated. Use setScaleX(float scaleX) from ViewCompat instead.
  5. setScaleY(float scaleY) on View is deprecated. Use setScaleY(float scaleY) from ViewCompat instead.

Here is the updated code:

import androidx.core.view.ViewCompat;

// Inside the VerticalViewPager.java file
@Override
public void transformPage(@NonNull View view, float position) {
    if (position < -1) { // [-Infinity,-1)
        // This page is way off-screen to the left.
        ViewCompat.setAlpha(view, 0);

    } else if (position <= 0) { // [-1,0]
        // Use the default slide transition when moving to the left page
        ViewCompat.setAlpha(view, 1);
        // Counteract the default slide transition
        ViewCompat.setTranslationX(view, view.getWidth() * -position);

        // Set Y position to swipe in from top
        float yPosition = position * view.getHeight();
        ViewCompat.setTranslationY(view, yPosition);
        ViewCompat.setScaleX(view, 1);
        ViewCompat.setScaleY(view, 1);

    } else if (position <= 1) { // [0,1]
        ViewCompat.setAlpha(view, 1);

        // Counteract the default slide transition
        ViewCompat.setTranslationX(view, view.getWidth() * -position);

        // Scale the page down (between MIN_SCALE and 1)
        float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
        ViewCompat.setScaleX(view, scaleFactor);
        ViewCompat.setScaleY(view, scaleFactor);

    } else { // (1,+Infinity]
        // This page is way off-screen to the right.
        ViewCompat.setAlpha(view, 0);
    }
}

This code uses ViewCompat to replace the deprecated methods, ensuring compatibility with newer Android versions.