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

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

Introduction

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

Prototype

public void setOverScrollMode(int overScrollMode) 

Source Link

Document

Set the over-scroll mode for this view.

Usage

From source file:com.woodblockwithoutco.quickcontroldock.ui.factory.ServiceViewFactory.java

@SuppressWarnings("deprecation")
public View getServiceView() {

    boolean sameLayout = GeneralResolver.isSameLayoutForLandscape(mContext);
    int inflateId = 0;
    if (ScreenUtils.getScreenOrientation(mContext) == Configuration.ORIENTATION_PORTRAIT || sameLayout) {
        inflateId = R.layout.panel_layout;
    } else {//from ww w .  jav  a  2s .  co  m
        inflateId = R.layout.panel_layout_land;
    }

    View view = LayoutInflater.from(mContext).inflate(inflateId, null, false);

    final DragViewGroup dragView = (DragViewGroup) view.findViewById(R.id.panel_drag_handler);
    dragView.setBackgroundDrawable(ColorsResolver.getBackgroundDrawable(mContext));

    if (ConstantHolder.getIsDebug()) {
        initTestVersionText(dragView);
    }

    ViewGroup viewToHide;
    if (ScreenUtils.getScreenOrientation(mContext) == Configuration.ORIENTATION_PORTRAIT || sameLayout) {
        LinearLayout panelsContainer = (LinearLayout) dragView.findViewById(R.id.panels_container);
        viewToHide = panelsContainer;
        if (ScreenUtils.getScreenOrientation(mContext) == Configuration.ORIENTATION_PORTRAIT) {
            panelsContainer.setTranslationY(GeneralResolver.getPanelsOffset(mContext));
        }

        List<String> panelsOrder = PanelsOrderResolver.getPanelsOrder(mContext);
        if (ShortcutsResolver.isShortcutsEnabled(mContext)) {
            ShortcutsViewFactory svFactory = new ShortcutsViewFactory(mContext);
            int id = getContainerIdForPanelType(panelsOrder, PanelType.SHORTCUTS.name());
            FrameLayout section = (FrameLayout) view.findViewById(id);
            adjustPanelMargins(section);
            section.addView(svFactory.getShortcutsSectionView());
        }

        if (MusicResolver.isMusicPanelEnabled(mContext)) {
            MusicViewFactory mvFactory = new MusicViewFactory(mContext);
            int id = getContainerIdForPanelType(panelsOrder, PanelType.MUSIC.name());
            FrameLayout section = (FrameLayout) view.findViewById(id);
            adjustPanelMargins(section);
            section.addView(mvFactory.getMusicView());
        }

        if (TogglesResolver.isTogglesEnabled(mContext)) {
            TogglesViewFactory tvFactory = new TogglesViewFactory(mContext);
            int id = getContainerIdForPanelType(panelsOrder, PanelType.TOGGLES.name());
            FrameLayout section = (FrameLayout) view.findViewById(id);
            adjustPanelMargins(section);
            section.addView(tvFactory.getTogglesSectionView());
        }

        if (InfoResolver.isInfoPanelEnabled(mContext)) {
            InfoViewFactory ivFactory = new InfoViewFactory(mContext);
            int id = getContainerIdForPanelType(panelsOrder, PanelType.INFO.name());
            FrameLayout section = (FrameLayout) view.findViewById(id);
            adjustPanelMargins(section);
            section.addView(ivFactory.getInfoView());
        }

        if (NotificationsResolver.isNotificationsEnabled(mContext)) {
            final ImageView fakeNotificationsButton = (ImageView) dragView
                    .findViewById(R.id.notifications_button_fake);
            PressImageView notificationsButton = (PressImageView) dragView
                    .findViewById(R.id.notifications_button);
            fakeNotificationsButton.setVisibility(View.VISIBLE);
            notificationsButton.setVisibility(View.VISIBLE);
            fakeNotificationsButton.setImageResource(R.drawable.ic_notification_switch);
            fakeNotificationsButton.setColorFilter(ColorsResolver.getActiveColor(mContext));
            final float SCALE = 1.5f;
            fakeNotificationsButton.setScaleX(SCALE);
            fakeNotificationsButton.setScaleY(SCALE);
            notificationsButton.setOnPressedStateChangeListener(new OnPressedStateChangeListener() {
                private final int BG_COLOR = ColorsResolver.getPressedColor(mContext);

                @Override
                public void onPressedStateChange(ImageView v, boolean pressed) {
                    if (pressed) {
                        fakeNotificationsButton.setBackgroundColor(BG_COLOR);
                    } else {
                        fakeNotificationsButton.setBackgroundColor(0x00000000);
                    }
                }
            });

            NotificationViewFactory nvFactory = new NotificationViewFactory(mContext);
            ViewGroup notificationsView = nvFactory.getNotificationsView();
            notificationsView.setAlpha(0.0f);
            notificationsView.setVisibility(View.INVISIBLE);
            FrameLayout notificationsContainer = (FrameLayout) dragView
                    .findViewById(R.id.notifications_section);
            notificationsContainer.addView(notificationsView);
            notificationsButton
                    .setOnClickListener(new NotificationButtonClickListener(viewToHide, notificationsView));
        }

    } else {

        ViewPager pager = (ViewPager) view.findViewById(R.id.landscape_pager);
        viewToHide = pager;
        List<View> views = new ArrayList<View>();

        if (NotificationsResolver.isNotificationsEnabled(mContext)) {
            NotificationViewFactory nvFactory = new NotificationViewFactory(mContext);
            ViewGroup notificationsView = nvFactory.getNotificationsView();
            views.add(notificationsView);
        }

        List<String> panelsOrder = PanelsOrderResolver.getPanelsOrder(mContext);
        for (String t : panelsOrder) {
            PanelType type = PanelType.valueOf(t);
            View v = null;
            FrameLayout container = (FrameLayout) LayoutInflater.from(mContext)
                    .inflate(R.layout.panel_section_land, null, false);
            switch (type) {
            case INFO:
                //     
                if (InfoResolver.isInfoPanelEnabled(mContext)) {
                    InfoViewFactory ivFactory = new InfoViewFactory(mContext);
                    FrameLayout fourthSection = (FrameLayout) view.findViewById(R.id.fourth_section);
                    fourthSection.addView(ivFactory.getInfoView());
                }
                break;
            case MUSIC:
                if (MusicResolver.isMusicPanelEnabled(mContext)) {
                    MusicViewFactory mvFactory = new MusicViewFactory(mContext);
                    v = mvFactory.getMusicView();
                }
                break;
            case SHORTCUTS:
                if (ShortcutsResolver.isShortcutsEnabled(mContext)) {
                    ShortcutsViewFactory svFactory = new ShortcutsViewFactory(mContext);
                    v = svFactory.getShortcutsSectionView();
                }
                break;
            case TOGGLES:
                if (TogglesResolver.isTogglesEnabled(mContext)) {
                    TogglesViewFactory tvFactory = new TogglesViewFactory(mContext);
                    v = tvFactory.getTogglesSectionView();
                }
                break;
            }

            if (v != null) {
                views.add(v);
                container.addView(v);
            }
        }

        LandscapePanelsAdapter adapter = new LandscapePanelsAdapter(views);
        pager.setAdapter(adapter);
        pager.setOverScrollMode(View.OVER_SCROLL_NEVER);
        pager.setOffscreenPageLimit(VIEW_PAGER_OFFSCREEN_PAGES_COUNT);
        pager.setPageMargin(mContext.getResources().getDimensionPixelSize(R.dimen.pager_margin));
    }

    return view;
}