0

I am working o na Android app. This app has tutorial screens. In this tutorial user has to slide right and left to complete the tutorial. When it launches the app it shows first fragment called SwipeLeftFragment. When user swipes left it shows second fragment called SwipeRightFragment. When user swipes right it shows third fragment called CompletedTutorialFragment. Currently It works fine but animation doesn't work. Following is my code:

public class TutorialActivity extends FragmentActivity {
@Override
protected void onStart() {
    super.onStart();
    final swipeLeftFragment swipeLeftFragment = new SwipeLeftFragment();
    addFragmentToBottom(swipeLeftFragment);


    swipeLeftFragment.getView().setOnTouchListener(new OnSwipeListener(TutorialActivity.this) {
        @Override
        public void onSwipeRight() {

        }

        @Override
        public void onSwipeLeft() {
            TranslateAnimation animation = new TranslateAnimation(0, -swipeLeftFragment.getView().getWidth(), 0, 0);
            animation.setDuration(5000);
            swipeLeftFragment.getView().startAnimation(animation);
            swipeLeftFragment.getView().setVisibility(View.GONE);
            final SwipeRightFragment swipeRightFragment = new SwipeRightFragment();
            addFragmentToBottom(swipeRightFragment);
            swipeRightFragment.getView().setOnTouchListener(new OnSwipeListener(TutorialActivity.this) {
                @Override
                public void onSwipeRight() {
                    TranslateAnimation animation = new TranslateAnimation(0, +swipeRightFragment.getView().getWidth(), 0, 0);
                    animation.setDuration(5000);
                    swipeRightFragment.getView().startAnimation(animation);
                    swipeRightFragment.getView().setVisibility(View.GONE);
                    final CompletedTutorialFragment completedTutorialFragment = new CompletedTutorialFragment();
                    addFragmentToBottom(completedTutorialFragment);
                    startSignupActivity();
                }

                @Override
                public void onSwipeLeft() {

                }
            });
        }
    });
}

private void startSignupActivity() {
    Handler mHandler = new Handler();
    mHandler.postDelayed(new Runnable() {

        @Override
        public void run() {
            startActivity(new Intent(TutorialActivity.this, SignUpActivity.class));
        }

    }, 2000L);
}
}

Can someone tell me whats wrong with my code?

this is the OnTouchListener I am using

Community
  • 1
  • 1
Akshay
  • 833
  • 2
  • 16
  • 34
  • Why not use a ViewPager? Check this: http://developer.android.com/training/animation/screen-slide.html – Hussein El Feky Aug 21 '15 at 00:05
  • ViewPager works in only one direction. In my case user first slides left then slides right – Akshay Aug 21 '15 at 00:09
  • You can create three fragments and use this code: viewPager.setCurrentItem(1); where 1 will be your current default page. (0, 1, 2 will be your pages) – Hussein El Feky Aug 21 '15 at 00:12
  • lets say page 0 : says swipe left, page 1: says swipe right and page 2: says completed tutorial. as per your suggestion. If i am on page 1, which says swipe right then it will go to page 2 as i am on page 1, then what about page 0 ? Other scenario. If I am on page 0, which says swipe left. But as there is no page on left, so it will not do anything. One more thing user has to actually slide right or left not just to show it on UI. – Akshay Aug 21 '15 at 00:23
  • You should use a ViewPager. Demo with details: http://developer.android.com/training/animation/screen-slide.html – Malwinder Singh Aug 21 '15 at 01:21

0 Answers0