Esempio n. 1
0
  @Override
  public void setCurrentItem(int item, boolean smoothScroll) {
    super.setCurrentItem(item, smoothScroll);

    if (mDecor != null) {
      mDecor.onPageSelected(item);
    }
  }
Esempio n. 2
0
  private void updateUiFromPanelConfigs(List<PanelConfig> panelConfigs) {
    // We only care about the adapter if HomePager is currently
    // loaded, which means it's visible in the activity.
    if (!mLoaded) {
      return;
    }

    if (mDecor != null) {
      mDecor.removeAllPagerViews();
    }

    final HomeAdapter adapter = (HomeAdapter) getAdapter();

    // Destroy any existing panels currently loaded
    // in the pager.
    setAdapter(null);

    // Only keep enabled panels.
    final List<PanelConfig> enabledPanels = new ArrayList<PanelConfig>();

    for (PanelConfig panelConfig : panelConfigs) {
      if (!panelConfig.isDisabled()) {
        enabledPanels.add(panelConfig);
      }
    }

    // Update the adapter with the new panel configs
    adapter.update(enabledPanels);

    // Hide the tab strip if the new configuration contains no panels.
    final int count = enabledPanels.size();
    mTabStrip.setVisibility(count > 0 ? View.VISIBLE : View.INVISIBLE);
    // Re-install the adapter with the final state
    // in the pager.
    setAdapter(adapter);

    // Use the default panel as defined in the HomePager's configuration
    // if the initial panel wasn't explicitly set by the show() caller.
    if (mInitialPanelId != null) {
      // XXX: Handle the case where the desired panel isn't currently in the adapter (bug 949178)
      setCurrentItem(adapter.getItemPosition(mInitialPanelId), false);
      mInitialPanelId = null;
    } else {
      for (int i = 0; i < count; i++) {
        final PanelConfig panelConfig = enabledPanels.get(i);
        if (panelConfig.isDefault()) {
          setCurrentItem(i, false);
          break;
        }
      }
    }
  }
Esempio n. 3
0
  @Override
  public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child instanceof Decor) {
      ((ViewPager.LayoutParams) params).isDecor = true;
      mDecor = (Decor) child;
      mTabStrip = child;

      mDecor.setOnTitleClickListener(
          new OnTitleClickListener() {
            @Override
            public void onTitleClicked(int index) {
              setCurrentItem(index, true);
            }
          });

      setOnPageChangeListener(
          new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
              mDecor.onPageSelected(position);
            }

            @Override
            public void onPageScrolled(
                int position, float positionOffset, int positionOffsetPixels) {
              mDecor.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }

            @Override
            public void onPageScrollStateChanged(int state) {}
          });
    } else if (child instanceof HomePagerTabStrip) {
      mTabStrip = child;
    }

    super.addView(child, index, params);
  }