Search in sources :

Example 1 with BadgeView

use of com.jauker.widget.BadgeView in project FishChatAndroid by oikomi.

the class ChatMainActivity method initView.

private void initView() {
    mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
    mChatTextView = (TextView) findViewById(R.id.id_tv_chat);
    mFriendTextView = (TextView) findViewById(R.id.id_tv_friend);
    mContactTextView = (TextView) findViewById(R.id.id_tv_contact);
    mMeTextView = (TextView) findViewById(R.id.id_tv_me);
    mChatLinearLayout = (LinearLayout) findViewById(R.id.id_ll_chat);
    mDatas = new ArrayList<Fragment>();
    mDatas.add(tab01);
    mDatas.add(tab02);
    mDatas.add(tab03);
    mDatas.add(tab04);
    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public int getCount() {
            return mDatas.size();
        }

        @Override
        public Fragment getItem(int arg0) {
            return mDatas.get(arg0);
        }
    };
    mViewPager.setAdapter(mAdapter);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            resetTextView();
            switch(position) {
                case 0:
                    if (mBadgeView != null) {
                        mChatLinearLayout.removeView(mBadgeView);
                    }
                    mBadgeView = new BadgeView(ChatMainActivity.this);
                    mBadgeView.setBadgeCount(7);
                    mChatLinearLayout.addView(mBadgeView);
                    mChatTextView.setTextColor(Color.parseColor("#008000"));
                    break;
                case 1:
                    mContactTextView.setTextColor(Color.parseColor("#008000"));
                    break;
                case 2:
                    mFriendTextView.setTextColor(Color.parseColor("#008000"));
                    break;
                case 3:
                    mMeTextView.setTextColor(Color.parseColor("#008000"));
                    break;
            }
            mCurrentPageIndex = position;
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPx) {
            Log.e("TAG", position + " , " + positionOffset + " , " + positionOffsetPx);
            LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) mTabline.getLayoutParams();
            if (// 0->1
            mCurrentPageIndex == 0 && position == 0) {
                lp.leftMargin = (int) (positionOffset * mScreen1_4 + mCurrentPageIndex * mScreen1_4);
            } else if (// 1->0
            mCurrentPageIndex == 1 && position == 0) {
                lp.leftMargin = (int) (mCurrentPageIndex * mScreen1_4 + (positionOffset - 1) * mScreen1_4);
            } else if (// 1->2
            mCurrentPageIndex == 1 && position == 1) {
                lp.leftMargin = (int) (mCurrentPageIndex * mScreen1_4 + positionOffset * mScreen1_4);
            } else if (// 2->1
            mCurrentPageIndex == 2 && position == 1) {
                lp.leftMargin = (int) (mCurrentPageIndex * mScreen1_4 + (positionOffset - 1) * mScreen1_4);
            } else if (// 2->3
            mCurrentPageIndex == 2 && position == 2) {
                lp.leftMargin = (int) (mCurrentPageIndex * mScreen1_4 + (positionOffset) * mScreen1_4);
            } else if (// 3->2
            mCurrentPageIndex == 3 && position == 1) {
                lp.leftMargin = (int) (mCurrentPageIndex * mScreen1_4 + (positionOffset - 1) * mScreen1_4);
            }
            mTabline.setLayoutParams(lp);
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) OnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener) BadgeView(com.jauker.widget.BadgeView) Fragment(android.support.v4.app.Fragment) LinearLayout(android.widget.LinearLayout)

Aggregations

Fragment (android.support.v4.app.Fragment)1 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)1 OnPageChangeListener (android.support.v4.view.ViewPager.OnPageChangeListener)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 LinearLayout (android.widget.LinearLayout)1 BadgeView (com.jauker.widget.BadgeView)1