示例#1
0
  @Override
  public Fragment onGetFragmentItem(int position) {
    String title = NavigationHelper.getTitle(position);
    Fragment fragment = NavigationHelper.getFragment(title);

    Bundle args = new Bundle();
    args.putInt(ARG_SECTION_POSITION, position);
    fragment.setArguments(args);
    return fragment;
  }
示例#2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set up the action bar to show a dropdown list.
    actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    // Set up the dropdown list navigation in the action bar.
    String[] titles = NavigationHelper.getTitles();
    actionBar.setListNavigationCallbacks(
        // Specify a SpinnerAdapter to populate the dropdown list.
        new ArrayAdapter<String>(
            actionBar.getThemedContext(),
            R.layout.navigation_list_item,
            android.R.id.text1,
            titles),
        this);

    mPagerTitle = getPagerTitle();
    initFlickerAnimations();

    mPagerTitleHander =
        new Handler() {
          @Override
          public void handleMessage(Message msg) {

            switch (msg.what) {
              case 1: // init show
                sendEmptyMessage(3);
                sendEmptyMessageDelayed(2, 2000);
                break;
              case 2: // hide page title
                if (isShowTitle && autoHide) {
                  mPagerTitle.startAnimation(hideAnim);
                }
                break;
              case 3: // show page title
                if (!isShowTitle) {
                  isShowTitle = true;
                  ViewParent parent = mPagerTitle.getParent();
                  if (parent == null) {
                    // mViewPager.addView( mPagerTitle,
                    // LayoutParams.MATCH_PARENT,
                    // LayoutParams.WRAP_CONTENT);
                    mViewPager.addView(mPagerTitle);
                    mPagerTitle.startAnimation(showAnim);
                  }
                }
                break;
            }
          };
        };

    mPagerTitleHander.sendEmptyMessageDelayed(1, 100);
    mViewPager.setOnPageChangeListener(
        new OnPageChangeListener() {
          @Override
          public void onPageSelected(int pos) {
            actionBar.setSelectedNavigationItem(pos);
            onPageChanged(pos);
          }

          @Override
          public void onPageScrolled(int arg0, float arg1, int arg2) {}

          @Override
          public void onPageScrollStateChanged(int state) {
            Log.d("TestData", "onPageScrollStateChanged state:" + state);
            if (state == ViewPager.SCROLL_STATE_DRAGGING) {
              mPagerTitleHander.removeMessages(2);
              if (autoHide) mPagerTitleHander.sendEmptyMessage(3);
            } else if (state == ViewPager.SCROLL_STATE_IDLE) {
              mPagerTitleHander.sendEmptyMessageDelayed(2, 2000);
            }
          }
        });
  }