Java Code Examples for android.support.v4.view.ViewPager#setOnTouchListener()

The following examples show how to use android.support.v4.view.ViewPager#setOnTouchListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From banner with Apache License 2.0 6 votes vote down vote up
private void initView() {
    mIndicators = new ImageView[] {
            (ImageView)findViewById(R.id.indicator1),
            (ImageView)findViewById(R.id.indicator2),
            (ImageView)findViewById(R.id.indicator3),
            (ImageView)findViewById(R.id.indicator4),
            (ImageView)findViewById(R.id.indicator5)
    };
    mBanner = (ViewPager) findViewById(R.id.banner);
    mBannerAdapter = new BannerAdapter(this);
    mBanner.setAdapter(mBannerAdapter);
    mBanner.setOnPageChangeListener(mBannerAdapter);
    mBanner.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN
                    || action == MotionEvent.ACTION_MOVE) {
                mIsUserTouched = true;
            } else if (action == MotionEvent.ACTION_UP) {
                mIsUserTouched = false;
            }
            return false;
        }
    });
}
 
Example 2
Source File: ImageCycleView.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param context
 * @param attrs
 */
public ImageCycleView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;
    mScale = context.getResources().getDisplayMetrics().density;
    LayoutInflater.from(context).inflate(R.layout.social_view_ad_cycle,
            this);
    mAdvPager = (ViewPager) findViewById(R.id.adv_pager);
    mAdvPager.setOnPageChangeListener(new GuidePageChangeListener());
    mAdvPager.setOnTouchListener(new OnTouchListener() {
        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_UP:
                // 开始图片滚动
                // / startImageTimerTask();
                break;
            default:
                // 停止图片滚动
                // / stopImageTimerTask();
                break;
            }
            return false;
        }
    });
    // 滚动图片右下指示器视
    mGroup = (ViewGroup) findViewById(R.id.viewGroup);
  //  imageName = (TextView) findViewById(R.id.viewGroup2);
}
 
Example 3
Source File: AudioAlbumsSongsFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.audio_albums_songs, container, false);

    ListView albumsList = (ListView) v.findViewById(R.id.albums);
    ListView songsList = (ListView) v.findViewById(R.id.songs);

    List<View> lists = Arrays.asList((View)albumsList, songsList);
    String[] titles = new String[] {getString(R.string.albums), getString(R.string.songs)};
    mViewPager = (ViewPager) v.findViewById(R.id.pager);
    mViewPager.setOffscreenPageLimit(MODE_TOTAL - 1);
    mViewPager.setAdapter(new AudioPagerAdapter(lists, titles));

    mViewPager.setOnTouchListener(mSwipeFilter);
    TabLayout mTabLayout = (TabLayout) v.findViewById(R.id.sliding_tabs);
    mTabLayout.setupWithViewPager(mViewPager);

    songsList.setAdapter(mSongsAdapter);
    albumsList.setAdapter(mAlbumsAdapter);

    songsList.setOnItemClickListener(songsListener);
    albumsList.setOnItemClickListener(albumsListener);

    registerForContextMenu(albumsList);
    registerForContextMenu(songsList);

    mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipeLayout);

    mSwipeRefreshLayout.setColorSchemeResources(R.color.orange700);
    mSwipeRefreshLayout.setOnRefreshListener(this);

    songsList.setOnScrollListener(mScrollListener);
    albumsList.setOnScrollListener(mScrollListener);

    getActivity().setTitle(mTitle);
    return v;
}
 
Example 4
Source File: CycleViewPager.java    From CycleViewPager with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化控件
 *
 * @param context 上下文
 */
public void init(Context context) {
    View view = LayoutInflater.from(context).inflate(R.layout
            .cycleviewpager_content, this, true);
    mCycleViewPagerContainer = (RelativeLayout) view.findViewById(R.id
            .cycle_view_pager_container);

    mViewPager = (ViewPager) view.findViewById(R.id
            .cycle_view_pager);
    mViewPager.setOnTouchListener(this);
    mIndicatorContainer = (LinearLayout) view.findViewById(R.id.cycle_view_pager_indicator_container);

    mHandler = new CycleViewPageHandler(this) {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (mViewList.size() == 0 || mFinished) {
                return;
            }

            if (msg.what == WHEEL_SIGNAL) {
                int maxSize = mViewList.size();
                if (maxSize <= CYCLE_SIZE_THRESHOLD) {
                    return;
                }
                mCurrentPosition = (mCurrentPosition + 1) % maxSize;
                mViewPager.setCurrentItem(mCurrentPosition, true);
                mHandler.removeCallbacks(runnable);
                mHandler.postDelayed(runnable, mWheelTime);
            }
        }
    };
}
 
Example 5
Source File: PagedHeadListView.java    From PagedHeadListView with Apache License 2.0 5 votes vote down vote up
private void initializePagedHeader() {

        headerView = View.inflate(getContext(), R.layout.paged_header, null);

        AbsListView.LayoutParams headerViewParams = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) headerHeight);
        headerView.setLayoutParams(headerViewParams);

        mPager = (ViewPager) headerView.findViewById(R.id.headerViewPager);

        FragmentManager fragmentManager = ((FragmentActivity) getContext()).getSupportFragmentManager();
        headerViewPagerAdapter = new ViewPagerAdapter(fragmentManager);

        indicator = new PagedHeadIndicator(getContext());
        indicator.setBgColor(indicatorBgColor);
        indicator.setColor(indicatorColor);

        switch (indicatorType) {
            case 0:
                addHeaderView(headerView);
                break;
            case 1:
                addHeaderView(indicator);
                addHeaderView(headerView);
                break;
            case 2:
                addHeaderView(headerView);
                addHeaderView(indicator);
                break;
        }

        mPager.setAdapter(headerViewPagerAdapter);
        mPager.setOnPageChangeListener(indicator);

        if (disableVerticalTouchOnHeader)
            mPager.setOnTouchListener(touchListenerForHeaderIntercept);

        setHeaderPageTransformer(PageTransformerTypes.values()[pageTransformer]);
    }
 
Example 6
Source File: FriendFragment.java    From yiim_v2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	mRootView = inflater.inflate(R.layout.main_frag_friend, null);

	View view1 = inflater.inflate(R.layout.frieng_frag_tab_contacts, null);
	View view2 = inflater.inflate(R.layout.frieng_frag_tab_groups, null);

	mViews = new ArrayList<View>();
	mViews.add(view1);
	mViews.add(view2);

	mViewPager = (ViewPager) mRootView.findViewById(R.id.friend_frag_pager);
	mFriendBtn = (TextView) mRootView
			.findViewById(R.id.friend_frag_friend_btn);
	mGroupBtn = (TextView) mRootView
			.findViewById(R.id.friend_frag_group_btn);

	// 禁止滑动
	mViewPager.setOnTouchListener(new OnTouchListener() {
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			// TODO Auto-generated method stub
			return true;
		}
	});

	mFriendBtn.setOnClickListener(this);
	mGroupBtn.setOnClickListener(this);

	mFriendManager = new FriendManager(this, view1);
	mFriendManager.onCreateView();

	mGroupManager = new GroupManager(this, view2);
	mGroupManager.onCreateView();

	return mRootView;
}
 
Example 7
Source File: CircularBarPager.java    From CircularBarPager with MIT License 4 votes vote down vote up
/**
 * Init the view by getting the {@link CircularBar},
 * the {@link android.support.v4.view.ViewPager} and the {@link com.viewpagerindicator.CirclePageIndicator}.
 * Init also some default values as PageTranformer etc...
 */
private void initializeView(AttributeSet attrs, int defStyleAttr) {
    if (attrs != null) {
        final TypedArray attributes = mContext.getTheme().obtainStyledAttributes(attrs, R.styleable.CircularViewPager,
                defStyleAttr, 0);

        boolean enableOnClick = attributes.getBoolean(R.styleable.CircularViewPager_progress_pager_on_click_enabled, false);
        isPaddingSet = false;

        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.circularbar_view_pager, this);

        mCircularBar = (CircularBar) view.findViewById(R.id.circular_bar);
        mViewPager = (ViewPager) view.findViewById(R.id.view_pager);
        mCirclePageIndicator = (CirclePageIndicator) view.findViewById(R.id.circle_page_indicator);

        //Default init
        if(mCircularBar != null){
            mCircularBar.loadStyledAttributes(attrs, defStyleAttr);
        }
        if(mViewPager != null){
            mViewPager.setPageTransformer(false, new FadeViewPagerTransformer());
        }


        //If we enable onClick, ie. we can switch between pages with both a swipe and a touch
        //Touch just goes to the next page % number of pages
        if (enableOnClick) {
            final GestureDetectorCompat tapGestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() {

                @Override
                public boolean onSingleTapConfirmed(MotionEvent e) {
                    mViewPager.setCurrentItem((mViewPager.getCurrentItem() + 1) % mViewPager.getAdapter().getCount());
                    return super.onSingleTapConfirmed(e);
                }
            });
            if(mViewPager != null){
                mViewPager.setOnTouchListener(new OnTouchListener() {
                    public boolean onTouch(View v, MotionEvent event) {
                        tapGestureDetector.onTouchEvent(event);
                        return false;
                    }
                });
            }

        }
    }
}
 
Example 8
Source File: HomeFragment.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
private void initLayout()
{

	mPhotoPager = (ViewPager) rootView.findViewById(R.id.pagerPhotos);
	mNoMedia = rootView.findViewById(R.id.media_display_no_media);

	mBtnPhoto = rootView.findViewById(R.id.btnPhoto);
	mBtnPhoto.setOnClickListener(this);
	mBtnPhotoIcon = (ImageView) mBtnPhoto.findViewById(R.id.ivPhoto);
	mBtnVideo = rootView.findViewById(R.id.btnVideo);
	mBtnVideo.setOnClickListener(this);
	mBtnVideoIcon = (ImageView) mBtnVideo.findViewById(R.id.ivVideo);
	setIsGeneratingKey(mIsGeneratingKey);
	mBtnGallery = rootView.findViewById(R.id.btnGallery);
	mBtnGallery.setOnClickListener(this);

	/*
	mBtnAudioNote = rootView.findViewById(R.id.btnAudioNote);
	mBtnAudioNote.setOnClickListener(this);
	mBtnStopRecording = rootView.findViewById(R.id.btnStopRecording);
	mBtnStopRecording.setOnClickListener(this);
	mBtnStopRecording.setVisibility(View.GONE);
	mTvRecordingTime = (TextView) rootView.findViewById(R.id.tvRecordingTime);
	mTvRecordingTime.setText("");
	mBtnShare = rootView.findViewById(R.id.btnShare);
	mBtnShare.setOnClickListener(this);
	**/

	mTapGestureDetector = new GestureDetector(a, new TapGestureListener(), h);
	mPhotoPager.setOnTouchListener(new OnTouchListener()
	{
		@Override
		public boolean onTouch(View v, MotionEvent event)
		{
			mTapGestureDetector.onTouchEvent(event);
			return false;
		}
	});
	
	initData();
	
	showSwipeHint();
}