/*
 * Copyright (c) 2014 Intellibins authors
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *   * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *   * Neither the name of The Intern nor the names of its contributors may
 * be used to endorse or promote products derived from this software
 * without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE LISTED COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.intellibins.recycle.activity;

import com.intellibins.recycle.R;
import com.intellibins.recycle.view.CirclePageIndicator;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;

public class OnboardingActivity extends ActionBarActivity {

    private static final int NUM_PAGES = 3;

    private ViewPager mPager;

    private Button mSkipButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_onboarding);

        mPager = (ViewPager) findViewById(R.id.onboardingViewPager);
        PagerAdapter pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
        mPager.setAdapter(pagerAdapter);

        CirclePageIndicator circlePageIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
        circlePageIndicator.setViewPager(mPager);

        mSkipButton = (Button) findViewById(R.id.skipButton);
        mSkipButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(OnboardingActivity.this, MapActivity.class);
                OnboardingActivity.this.startActivity(intent);
            }
        });

    }

    @Override
    public void onBackPressed() {
        if (mPager.getCurrentItem() == 0) {
            super.onBackPressed();
        } else {
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        }
    }

    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {

        public ScreenSlidePagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return OnboardingFragment.newInstance(position);
        }

        @Override
        public int getCount() {
            return NUM_PAGES;
        }
    }
}

@@ -2101,16 +2101,66 @@
 Activity
+%0A        implements ViewPager.OnPageChangeListener
  %7B%0A%0A    
@@ -2264,16 +2264,49 @@
 utton;%0A%0A
+    private Button mNextButton;%0A%0A
     @Ove
@@ -2721,16 +2721,32 @@
 icator =
+%0A               
  (Circle
@@ -2835,24 +2835,83 @@
 ger(mPager);
+%0A        circlePageIndicator.setOnPageChangeListener(this);
 %0A%0A        mS
@@ -3001,16 +3001,234 @@
 istener(
+skipButtonOnClickListener);%0A%0A        mNextButton = (Button) findViewById(R.id.nextButton);%0A        mNextButton.setOnClickListener(nextButtonOnClickListener);%0A    %7D%0A%0A    View.OnClickListener skipButtonOnClickListener = 
 new View
@@ -3244,28 +3244,24 @@
 istener() %7B%0A
-    
         @Ove
@@ -3262,28 +3262,24 @@
   @Override%0A
-    
         publ
@@ -3300,28 +3300,24 @@
 k(View v) %7B%0A
-    
             
@@ -3400,20 +3400,16 @@
         
-    
 Onboardi
@@ -3455,24 +3455,404 @@
             
+OnboardingActivity.this.finish();%0A        %7D%0A    %7D;%0A%0A    View.OnClickListener nextButtonOnClickListener = new View.OnClickListener() %7B%0A        @Override%0A        public void onClick(View v) %7B%0A            if (mPager.getCurrentItem() + 1 %3C NUM_PAGES) %7B%0A                mPager.setCurrentItem(mPager.getCurrentItem() + 1, true);%0A                // smoothScroll doesn't work%0A            
 %7D%0A        %7D)
@@ -3854,17 +3854,15 @@
    %7D
-);%0A
 %0A    %7D
+;
 %0A%0A  
@@ -4080,24 +4080,713 @@
    %7D%0A    %7D%0A%0A
+    @Override%0A    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) %7B%0A        onPageSelected(position);%0A    %7D%0A%0A    @Override%0A    public void onPageSelected(int position) %7B%0A        if (position %3E= NUM_PAGES - 1) %7B%0A            mSkipButton.setVisibility(View.GONE);%0A            mNextButton.setText(%22DONE%22);%0A            mNextButton.setOnClickListener(skipButtonOnClickListener);%0A        %7D else %7B%0A            mSkipButton.setVisibility(View.VISIBLE);%0A            mNextButton.setText(%22NEXT%22);%0A            mNextButton.setOnClickListener(nextButtonOnClickListener);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void onPageScrollStateChanged(int state) %7B%0A%0A    %7D%0A%0A
     private 

Add NEXT and SKIP buttons