Example usage for android.support.v4.view ViewPager getVisibility

List of usage examples for android.support.v4.view ViewPager getVisibility

Introduction

In this page you can find the example usage for android.support.v4.view ViewPager getVisibility.

Prototype

@ViewDebug.ExportedProperty(mapping = { @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"),
        @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"),
        @ViewDebug.IntToString(from = GONE, to = "GONE") })
@Visibility
public int getVisibility() 

Source Link

Document

Returns the visibility status for this view.

Usage

From source file:org.glucosio.android.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    GlucosioApplication application = (GlucosioApplication) getApplication();

    initPresenters(application);/*  ww w. j  av  a2s  .com*/
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
    tabLayout = (TabLayout) findViewById(R.id.activity_main_tab_layout);
    viewPager = (ViewPager) findViewById(R.id.activity_main_pager);

    if (toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        getSupportActionBar().setElevation(0);
        getSupportActionBar().setTitle("");
        getSupportActionBar().setLogo(R.drawable.ic_logo);
    }

    homePagerAdapter = new HomePagerAdapter(getSupportFragmentManager(), getApplicationContext());

    viewPager.setAdapter(homePagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            super.onTabSelected(tab);
        }
    });

    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            if (position == 2) {
                hideFabAnimation();
                LinearLayout emptyLayout = (LinearLayout) findViewById(R.id.activity_main_empty_layout);
                ViewPager pager = (ViewPager) findViewById(R.id.activity_main_pager);
                if (pager.getVisibility() == View.GONE) {
                    pager.setVisibility(View.VISIBLE);
                    emptyLayout.setVisibility(View.INVISIBLE);
                }
            } else {
                showFabAnimation();
                checkIfEmptyLayout();
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    FloatingActionButton fabAddReading = (FloatingActionButton) findViewById(
            R.id.activity_main_fab_add_reading);
    fabAddReading.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            bottomSheetAddDialog.show();
            bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        }
    });

    bottomSheetAddDialog = new BottomSheetDialog(this);

    // Add Nav Drawer
    final PrimaryDrawerItem itemSettings = new PrimaryDrawerItem().withName(R.string.action_settings)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_settings_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemExport = new PrimaryDrawerItem().withName(R.string.sidebar_backup_export)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_backup_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemFeedback = new PrimaryDrawerItem().withName(R.string.menu_support)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_announcement_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemAbout = new PrimaryDrawerItem().withName(R.string.preferences_about_glucosio)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_info_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemInvite = new PrimaryDrawerItem().withName(R.string.action_invite)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_face_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemDonate = new PrimaryDrawerItem().withName(R.string.about_donate)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_favorite_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemA1C = new PrimaryDrawerItem().withName(R.string.activity_converter_title)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_calculator_a1c_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemReminders = new PrimaryDrawerItem().withName(R.string.activity_reminders_title)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_alarm_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);

    DrawerBuilder drawerBuilder = new DrawerBuilder().withActivity(this).withTranslucentStatusBar(false)
            .withToolbar(toolbar).withActionBarDrawerToggle(true)
            .withAccountHeader(new AccountHeaderBuilder().withActivity(this)
                    .withHeaderBackground(R.drawable.drawer_header).build())
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    if (drawerItem.equals(itemSettings)) {
                        // Settings
                        openPreferences();
                    } else if (drawerItem.equals(itemAbout)) {
                        // About
                        startAboutActivity();
                    } else if (drawerItem.equals(itemFeedback)) {
                        // Feedback
                        openSupportDialog();
                    } else if (drawerItem.equals(itemInvite)) {
                        // Invite
                        showInviteDialog();
                    } else if (drawerItem.equals(itemExport)) {
                        // Export
                        startExportActivity();
                    } else if (drawerItem.equals(itemDonate)) {
                        // Donate
                        openDonateIntent();
                    } else if (drawerItem.equals(itemA1C)) {
                        openA1CCalculator();
                    } else if (drawerItem.equals(itemReminders)) {
                        openRemindersActivity();
                    }
                    return false;
                }
            });

    if (isPlayServicesAvailable()) {
        drawerBuilder.addDrawerItems(itemA1C, itemReminders, itemExport, itemSettings, itemFeedback, itemAbout,
                itemDonate, itemInvite).withSelectedItem(-1).build();
    } else {
        drawerBuilder.addDrawerItems(itemA1C, itemReminders, itemExport, itemSettings, itemFeedback, itemAbout,
                itemDonate).withSelectedItem(-1).build();
    }

    // Restore pager position
    Bundle b = getIntent().getExtras();
    if (b != null) {
        viewPager.setCurrentItem(b.getInt("pager"));
    }

    checkIfEmptyLayout();
    bottomSheetAddDialog.setContentView(bottomSheetAddDialogView);
    bottomSheetBehavior = BottomSheetBehavior.from((View) bottomSheetAddDialogView.getParent());
    bottomSheetBehavior.setHideable(false);

    Analytics analytics = application.getAnalytics();
    Log.i("MainActivity", "Setting screen name: " + "main");
    analytics.reportScreen("Main Activity");
}

From source file:org.medcada.android.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    GlucosioApplication application = (GlucosioApplication) getApplication();
    //startActivity(new Intent(this,PinCodeActivity.class));
    initPresenters(application);/*from   w w  w.  j  a va 2  s.  co  m*/
    setContentView(R.layout.activity_main);
    showDebugDBAddressLogToast();
    Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
    tabLayout = (TabLayout) findViewById(R.id.activity_main_tab_layout);
    viewPager = (ViewPager) findViewById(R.id.activity_main_pager);

    if (toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        getSupportActionBar().setElevation(0);
        getSupportActionBar().setTitle("assistBUD");
        getSupportActionBar().setLogo(R.drawable.ic_logo);
    }

    homePagerAdapter = new HomePagerAdapter(getSupportFragmentManager(), getApplicationContext());

    viewPager.setAdapter(homePagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            super.onTabSelected(tab);
        }
    });

    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            if (position == 2) {
                hideFabAnimation();
                LinearLayout emptyLayout = (LinearLayout) findViewById(R.id.activity_main_empty_layout);
                ViewPager pager = (ViewPager) findViewById(R.id.activity_main_pager);
                if (pager.getVisibility() == View.GONE) {
                    pager.setVisibility(View.VISIBLE);
                    emptyLayout.setVisibility(View.INVISIBLE);
                }
            } else {
                showFabAnimation();
                checkIfEmptyLayout();
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    FloatingActionButton fabAddReading = (FloatingActionButton) findViewById(
            R.id.activity_main_fab_add_reading);
    fabAddReading.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            bottomSheetAddDialog.show();
            bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        }
    });

    bottomSheetAddDialog = new BottomSheetDialog(this);

    // Add Nav Drawer
    final PrimaryDrawerItem itemSettings = new PrimaryDrawerItem().withName(R.string.action_settings)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_settings_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemExport = new PrimaryDrawerItem().withName(R.string.sidebar_backup_export)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_backup_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemFeedback = new PrimaryDrawerItem().withName(R.string.menu_support)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_announcement_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemAbout = new PrimaryDrawerItem().withName(R.string.preferences_about_glucosio)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_info_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemInvite = new PrimaryDrawerItem().withName(R.string.action_invite)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_face_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    //final PrimaryDrawerItem itemDonate = new PrimaryDrawerItem().withName(R.string.about_donate).withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_favorite_grey_24dp, null)).withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemA1C = new PrimaryDrawerItem().withName("Profile")
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_person_black_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itememergency = new PrimaryDrawerItem().withName("Emergency")
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_add_alert_black_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemmedications = new PrimaryDrawerItem().withName("Medications")
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_calculator_a1c_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);
    final PrimaryDrawerItem itemReminders = new PrimaryDrawerItem().withName(R.string.activity_reminders_title)
            .withIcon(VectorDrawableCompat.create(getResources(), R.drawable.ic_alarm_grey_24dp, null))
            .withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD);

    DrawerBuilder drawerBuilder = new DrawerBuilder().withActivity(this).withTranslucentStatusBar(false)
            .withToolbar(toolbar).withActionBarDrawerToggle(true)
            .withAccountHeader(new AccountHeaderBuilder().withActivity(this)

                    .withHeaderBackground(R.drawable.drawer_header).build())
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    if (drawerItem.equals(itemSettings)) {
                        // Settings
                        openPreferences();
                    } else if (drawerItem.equals(itemAbout)) {
                        // About
                        startAboutActivity();
                    } else if (drawerItem.equals(itemFeedback)) {
                        // Feedback
                        openSupportDialog();
                    } else if (drawerItem.equals(itemInvite)) {
                        // Invite
                        showInviteDialog();
                    } else if (drawerItem.equals(itemExport)) {
                        // Export
                        startExportActivity();
                    }
                    //                        else if (drawerItem.equals(itemDonate)) {
                    //                            // Donate
                    //                            openDonateIntent();
                    //                        }

                    else if (drawerItem.equals(itemA1C)) {
                        startProfileActivity();
                    }

            else if (drawerItem.equals(itemmedications)) {
                        startMedicationActivity();
                    } else if (drawerItem.equals(itemReminders)) {
                        openRemindersActivity();
                    }
                    return false;
                }
            });

    if (isPlayServicesAvailable()) {
        drawerBuilder.addDrawerItems(itemA1C, itememergency, itemmedications, itemReminders, itemExport,
                itemSettings, itemFeedback, itemAbout,
                //itemDonate,
                itemInvite).withSelectedItem(-1).build();
    } else {
        drawerBuilder.addDrawerItems(itemA1C, itememergency, itemmedications, itemReminders, itemExport,
                itemSettings, itemFeedback, itemAbout
        // itemDonate
        ).withSelectedItem(-1).build();
    }

    // Restore pager position
    Bundle b = getIntent().getExtras();
    if (b != null) {
        viewPager.setCurrentItem(b.getInt("pager"));
    }

    checkIfEmptyLayout();
    bottomSheetAddDialog.setContentView(bottomSheetAddDialogView);
    bottomSheetBehavior = BottomSheetBehavior.from((View) bottomSheetAddDialogView.getParent());
    bottomSheetBehavior.setHideable(false);

    Analytics analytics = application.getAnalytics();
    Log.i("MainActivity", "Setting screen name: " + "main");
    analytics.reportScreen("Main Activity");
}

From source file:com.poloure.simplerss.AsyncNewTagAdapters.java

@Override
protected void onPostExecute(TreeMap<Long, FeedItem>[] result) {
    ViewPager pager = (ViewPager) m_activity.findViewById(R.id.viewpager);
    PagerAdapter pagerAdapter = pager.getAdapter();
    int pageCount = pagerAdapter.getCount();

    for (int i = 0; pageCount > i; i++) {
        // Get the tag page and skip ListViews that are null.
        ListFragmentTag fragment = FragmentFeeds.getViewPagerFragment(i);
        LinkedMapAdapter<Long, FeedItem> adapterTag = fragment.getListAdapter();
        ListViewFeeds listView = fragment.getListView();

        if (null == adapterTag) {
            fragment.setListAdapter(new AdapterFeedItems(m_activity, result[i]));
            listView.setSelectionOldestUnread(m_activity.getReadItemTimes());
        } else {/*from  w  w w. ja va2 s  .c o  m*/
            long topKeyBefore = 0L;
            int top = 0;

            // If there are items in the currently viewed page, save the position.
            boolean firstLoad = null == listView || 0 == listView.getCount();
            if (!firstLoad) {
                // Get the time of the top item.
                int topVisibleItem = listView.getFirstVisiblePosition();
                topKeyBefore = adapterTag.getKey(topVisibleItem);

                View v = listView.getChildAt(0);
                top = null == v ? 0 : v.getTop();
            }

            // Update the feedItems in the adapter.
            adapterTag.replaceAll(result[i]);

            // Now find the position of the item with the time timeBefore.
            if (firstLoad) {
                listView.setSelectionOldestUnread(m_activity.getReadItemTimes());
            } else {
                int newPos = adapterTag.indexOf(topKeyBefore);
                listView.setSelectionFromTop(newPos, top - listView.getPaddingTop());
            }
        }
    }

    // If the pager is invisible, use a fade in animation.
    if (View.VISIBLE != pager.getVisibility()) {
        pager.setVisibility(View.VISIBLE);
        AlphaAnimation animation = new AlphaAnimation(0.0F, 1.0F);
        animation.setDuration(300);
        pager.startAnimation(animation);
    }
}