Search in sources :

Example 1 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project actor-platform by actorapp.

the class TourActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tour_activity);
    final VerticalViewPager viewPager = (VerticalViewPager) findViewById(R.id.viewpager);
    final View backToTopText = findViewById(R.id.back_to_top);
    final View backToTopArrow = findViewById(R.id.back_to_top_arrow);
    final View paralax = findViewById(R.id.paralax);
    final View paralaxImage = findViewById(R.id.paralax_image);
    final View background = findViewById(R.id.background);
    final View loginHolder = findViewById(R.id.login_holder);
    final View welcomeImage = findViewById(R.id.welcome_logo);
    final View welcomeText = findViewById(R.id.welcome_text);
    background.findViewById(R.id.background_colored).setBackgroundColor(ActorSDK.sharedActor().style.getMainColor());
    TextView signupButtonText = (TextView) findViewById(R.id.signUpButtonText);
    StateListDrawable states = SelectorFactory.get(ActorSDK.sharedActor().style.getPrimaryAltColor(), this);
    signupButtonText.setBackgroundDrawable(states);
    signupButtonText.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    signupButtonText.setTypeface(Fonts.medium());
    TextView buttonSignUp = (TextView) findViewById(R.id.signIn);
    buttonSignUp.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    buttonSignUp.setTypeface(Fonts.medium());
    ((TextView) findViewById(R.id.app_name)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    ((TextView) findViewById(R.id.tour_welcome_subtitle)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    findViewById(R.id.signUpButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bundle authExtras = new Bundle();
            authExtras.putInt(AuthActivity.SIGN_TYPE_KEY, AuthActivity.SIGN_TYPE_UP);
            ActorSDK.sharedActor().startAuthActivity(TourActivity.this, authExtras);
            finish();
        }
    });
    findViewById(R.id.signIn).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bundle authExtras = new Bundle();
            authExtras.putInt(AuthActivity.SIGN_TYPE_KEY, AuthActivity.SIGN_TYPE_IN);
            ActorSDK.sharedActor().startAuthActivity(TourActivity.this, authExtras);
            finish();
        }
    });
    View.OnClickListener jumpToTopListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            backToTopArrow.animate().alpha(0).setDuration(0).start();
            backToTopText.animate().alpha(0).setDuration(0).start();
            viewPager.setCurrentItem(0, true);
        }
    };
    backToTopText.setOnClickListener(jumpToTopListener);
    backToTopArrow.setOnClickListener(jumpToTopListener);
    viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            if (position == 0 || position == lastPageIndex + 1)
                return new Fragment();
            return TourFragment.getInstance(position);
        }

        @Override
        public int getCount() {
            //6;
            return 4;
        }
    });
    //Necessary or the pager will only have one extra page to show
    // make this at least however many pages you can see
    viewPager.setOffscreenPageLimit(3);
    //A little space between pages
    viewPager.setPageMargin(-Screen.dp(165));
    //If hardware acceleration is enabled, you should also remove
    // clipping on the pager for its children.
    viewPager.setClipChildren(false);
    viewPager.setOnScrollListener(new ScrollListener() {

        public static final int LOGINHOLDER_STATUS_OUT = 1;

        public static final int LOGINHOLDER_STATUS_VISIBLE = 2;

        public int loginHolderStatus;

        public boolean welcomeShowed = false;

        public boolean mainContentHidden = false;

        public boolean loginHolderBackgroundVisible = false;

        @Override
        public void onScroll(int y, float page) {
            if (page < 1) {
                float alpha = 1 - page * 2;
                backToTopArrow.animate().alpha(alpha).setDuration(0).start();
                //status1.setText("alpha:" + alpha);
                if (loginHolder.getTop() != 0) {
                    float loginY = (float) loginHolder.getTop() * ((float) 1 - (page));
                    loginHolder.animate().y(loginY).setDuration(0).setStartDelay(0).start();
                    background.animate().y(loginY - background.getHeight() + loginHolder.getHeight() + Screen.dp(8)).setDuration(0).start();
                    /*if(loginHolderBackgroundVisible){
                            loginHolderBackgroundVisible = false;
                            loginHolderBackground.animate().alpha(0).setDuration(0).start();
                        } else {

                        }*/
                    //loginHolderBackground.animate().alpha(page).setDuration(0).start();
                    background.animate().alpha(page).setDuration(0).start();
                    loginHolderStatus = LOGINHOLDER_STATUS_VISIBLE;
                    float welcomeImageY = welcomeImage.getTop() - y / 2;
                    float welcomeTextY = welcomeText.getTop() - y / 2;
                    if (alpha > 0) {
                        welcomeImage.animate().alpha(alpha).y(welcomeImageY).setDuration(0).start();
                        welcomeText.animate().alpha(alpha).y(welcomeTextY).setDuration(0).start();
                    } else {
                        welcomeImage.animate().alpha(0).setDuration(0).start();
                        welcomeText.animate().alpha(0).setDuration(0).start();
                    }
                }
                mainContentHidden = false;
            } else {
                if (page >= 1 && page <= lastPageIndex) {
                    // todo freeze?
                    if (!mainContentHidden) {
                        mainContentHidden = true;
                        loginHolderBackgroundVisible = true;
                        //signinLastView.setEnabled(false);
                        //signinView.setEnabled(false);
                        //signupLastView.setEnabled(false);
                        //signupView.setEnabled(false);
                        loginHolder.animate().y(0).setDuration(0).start();
                        //loginHolderBackground.animate().alpha(1).setDuration(0).start();
                        background.animate().y(-loginHolder.getTop() + Screen.dp(8)).alpha(1).setDuration(0).start();
                        welcomeImage.animate().alpha(0).setDuration(0).start();
                        welcomeText.animate().alpha(0).setDuration(0).start();
                        backToTopArrow.animate().alpha(0).setDuration(0).start();
                        backToTopText.animate().alpha(0).setDuration(0).start();
                    }
                    if (page > lastPageIndex - 1) {
                        float alpha = (page - (lastPageIndex - 1)) * 3 - 2;
                        if (alpha > 0) {
                            backToTopText.animate().scaleX(alpha).scaleY(alpha).alpha(alpha).setDuration(0).start();
                        } else {
                            backToTopText.animate().scaleX(0).scaleY(0).alpha(0).setDuration(0).start();
                        }
                    }
                } else {
                    if (page > lastPageIndex) {
                        float progress = page - lastPageIndex;
                        if (progress > 0.5) {
                            if (loginHolderStatus == LOGINHOLDER_STATUS_VISIBLE) {
                                loginHolderStatus = LOGINHOLDER_STATUS_OUT;
                                loginHolder.animate().y(-loginHolder.getHeight()).setDuration(200).setInterpolator(new AccelerateDecelerateInterpolator()).setStartDelay(0).start();
                            }
                            mainContentHidden = false;
                        } else {
                            if (loginHolderStatus == LOGINHOLDER_STATUS_OUT) {
                                loginHolderStatus = LOGINHOLDER_STATUS_VISIBLE;
                                loginHolder.animate().y(0).setInterpolator(new AccelerateDecelerateInterpolator()).setDuration(200).setStartDelay(0).start();
                            }
                            if (!mainContentHidden) {
                                backToTopArrow.animate().alpha(0).setDuration(0).start();
                                backToTopText.animate().alpha(0).setDuration(0).start();
                            }
                        }
                    }
                }
            }
            int paralaxHolderHeight = paralax.getHeight();
            int paralaxImageHeight = paralaxImage.getHeight();
            float paralaxY = -(((float) paralaxImageHeight - paralaxHolderHeight) * ((float) page / (lastPageIndex)));
            paralaxImage.animate().y(paralaxY).setDuration(0).setStartDelay(0).start();
        }
    });
    if (Build.VERSION.SDK_INT >= 19) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        contentTopPadding = Screen.getStatusBarHeight();
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) findViewById(R.id.pager_container).getLayoutParams();
        params.topMargin = contentTopPadding;
        findViewById(R.id.pager_container).setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) backToTopArrow.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        backToTopArrow.setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) welcomeImage.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        welcomeImage.setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) welcomeText.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        welcomeText.setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) backToTopText.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        backToTopText.setLayoutParams(params);
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) Bundle(android.os.Bundle) StateListDrawable(android.graphics.drawable.StateListDrawable) TextView(android.widget.TextView) View(android.view.View) Fragment(android.support.v4.app.Fragment) RelativeLayout(android.widget.RelativeLayout) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) TextView(android.widget.TextView)

Example 2 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project Timber by naman14.

the class PlaylistFragment method initPager.

private void initPager() {
    pager.setVisibility(View.VISIBLE);
    recyclerView.setVisibility(View.GONE);
    recyclerView.setAdapter(null);
    adapter = new FragmentStatePagerAdapter(getChildFragmentManager()) {

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

        @Override
        public Fragment getItem(int position) {
            return PlaylistPagerFragment.newInstance(position);
        }
    };
    pager.setAdapter(adapter);
    pager.setOffscreenPageLimit(3);
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) Fragment(android.support.v4.app.Fragment) PlaylistPagerFragment(com.naman14.timber.subfragments.PlaylistPagerFragment)

Example 3 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project making-apps-beautiful by ankurkotwal.

the class ArticleDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_article_detail);
    // Show the Up button in the action bar.
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int i) {
            Bundle arguments = new Bundle();
            arguments.putString(ArticleDetailFragment.ARG_ITEM_ID, DummyContent.ITEMS.get(i).id);
            ArticleDetailFragment fragment = new ArticleDetailFragment();
            fragment.setArguments(arguments);
            return fragment;
        }

        @Override
        public int getCount() {
            return DummyContent.ITEMS.size();
        }
    });
    pager.setPageMarginDrawable(getResources().getDrawable(R.drawable.list_divider_holo_light));
    pager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    String startId = getIntent().getStringExtra(ArticleDetailFragment.ARG_ITEM_ID);
    for (int i = 0; i < DummyContent.ITEMS.size(); i++) {
        if (DummyContent.ITEMS.get(i).id.equals(startId)) {
            pager.setCurrentItem(i);
            return;
        }
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) Bundle(android.os.Bundle) ViewPager(android.support.v4.view.ViewPager) Fragment(android.support.v4.app.Fragment)

Example 4 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project making-apps-beautiful by ankurkotwal.

the class ArticleDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_article_detail);
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int i) {
            Bundle arguments = new Bundle();
            arguments.putString(ArticleDetailFragment.ARG_ITEM_ID, DummyContent.ITEMS.get(i).id);
            ArticleDetailFragment fragment = new ArticleDetailFragment();
            fragment.setArguments(arguments);
            return fragment;
        }

        @Override
        public int getCount() {
            return DummyContent.ITEMS.size();
        }
    });
    pager.setPageMarginDrawable(getResources().getDrawable(R.drawable.list_divider_holo_light));
    pager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    String startId = getIntent().getStringExtra(ArticleDetailFragment.ARG_ITEM_ID);
    for (int i = 0; i < DummyContent.ITEMS.size(); i++) {
        if (DummyContent.ITEMS.get(i).id.equals(startId)) {
            pager.setCurrentItem(i);
            return;
        }
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) Bundle(android.os.Bundle) ViewPager(android.support.v4.view.ViewPager) Fragment(android.support.v4.app.Fragment)

Example 5 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project making-apps-beautiful by ankurkotwal.

the class ArticleDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_article_detail);
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int i) {
            Bundle arguments = new Bundle();
            arguments.putString(ArticleDetailFragment.ARG_ITEM_ID, DummyContent.ITEMS.get(i).id);
            ArticleDetailFragment fragment = new ArticleDetailFragment();
            fragment.setArguments(arguments);
            return fragment;
        }

        @Override
        public int getCount() {
            return DummyContent.ITEMS.size();
        }
    });
    pager.setPageMarginDrawable(getResources().getDrawable(R.drawable.list_divider_holo_light));
    pager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    String startId = getIntent().getStringExtra(ArticleDetailFragment.ARG_ITEM_ID);
    for (int i = 0; i < DummyContent.ITEMS.size(); i++) {
        if (DummyContent.ITEMS.get(i).id.equals(startId)) {
            pager.setCurrentItem(i);
            return;
        }
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) Bundle(android.os.Bundle) ViewPager(android.support.v4.view.ViewPager) Fragment(android.support.v4.app.Fragment)

Aggregations

FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)21 Fragment (android.support.v4.app.Fragment)20 ViewPager (android.support.v4.view.ViewPager)13 Bundle (android.os.Bundle)11 View (android.view.View)6 Toolbar (android.support.v7.widget.Toolbar)3 BindView (butterknife.BindView)3 MaterialViewPager (com.github.florent37.materialviewpager.MaterialViewPager)3 HeaderDesign (com.github.florent37.materialviewpager.header.HeaderDesign)3 PagerAdapter (android.support.v4.view.PagerAdapter)2 TextView (android.widget.TextView)2 RecyclerViewFragment (com.github.florent37.materialviewpager.sample.fragment.RecyclerViewFragment)2 Intent (android.content.Intent)1 StateListDrawable (android.graphics.drawable.StateListDrawable)1 FragmentManager (android.support.v4.app.FragmentManager)1 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)1 RecyclerView (android.support.v7.widget.RecyclerView)1 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)1 WebView (android.webkit.WebView)1 AbsListView (android.widget.AbsListView)1