public void updatePageNumView() {
    Log.i("StoreMainActivity - updatePageNumView", "Start");
    TextView tvPage = (TextView) findViewById(R.id.tvStoreDetailPage);
    if (this.listProduct.size() > 0) {
      String pageDisplay = mPager.getCurrentItem() + 1 + "/" + mPagerAdapter.getCount();
      tvPage.setText(pageDisplay);
    }

    ImageView btnPagePrevious = (ImageView) findViewById(R.id.btnStoreDetailPagePrevious);
    ImageView btnPageNext = (ImageView) findViewById(R.id.btnStoreDetailPageNext);

    if (mPagerAdapter.getCount() > 1) {
      if (mPager.getCurrentItem() == 0) {
        btnPagePrevious.setImageAlpha(70);
        btnPageNext.setImageAlpha(255);
      } else if (mPager.getCurrentItem() == (mPagerAdapter.getCount() - 1)) {
        btnPageNext.setImageAlpha(70);
        btnPagePrevious.setImageAlpha(255);
      } else {
        btnPagePrevious.setImageAlpha(255);
      }
    } else {
      btnPageNext.setImageAlpha(70);
      btnPagePrevious.setImageAlpha(70);
    }

    StoreMainActivity.productTransactionDetailInfo = new TransactionDetailInfo();
  }
 @Override
 public Object instantiateItem(ViewGroup container, int position) {
   if (position == 0) {
     return wrappedAdapter.instantiateItem(container, wrappedAdapter.getCount() - 1);
   } else if (position == wrappedAdapter.getCount() + 1) {
     return wrappedAdapter.instantiateItem(container, 0);
   } else {
     return wrappedAdapter.instantiateItem(container, position - 1);
   }
 }
 @Override
 public int getCount() {
   if (wrappedAdapter == null) {
     return 0;
   } else if (wrappedAdapter.getCount() > 1) {
     return wrappedAdapter.getCount() + 2;
   } else {
     return wrappedAdapter.getCount();
   }
 }
示例#4
0
  private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
      View tabView = null;
      TextView tabTitleView = null;

      if (mTabViewLayoutId != 0) {
        // If there is a custom tab view layout id set, try and inflate it
        tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
        tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
      }

      if (tabView == null) {
        tabView = createDefaultTabView(getContext());
      }

      if (tabTitleView == null && TextView.class.isInstance(tabView)) {
        tabTitleView = (TextView) tabView;
      }

      tabTitleView.setText(adapter.getPageTitle(i));
      tabView.setOnClickListener(tabClickListener);

      mTabStrip.addView(tabView);
    }
  }
 @Override
 public void onChanged() {
   PagerAdapter adapter = mPager.getAdapter();
   int count = 0;
   if (adapter instanceof InfinitePagerAdapter) {
     count = ((InfinitePagerAdapter) adapter).getRealCount();
   } else {
     count = adapter.getCount();
   }
   if (count > mItemCount) {
     for (int i = 0; i < count - mItemCount; i++) {
       ImageView indicator = new ImageView(mContext);
       indicator.setImageDrawable(mUnselectedDrawable);
       indicator.setPadding(
           (int) mUnSelectedPadding_Left,
           (int) mUnSelectedPadding_Top,
           (int) mUnSelectedPadding_Right,
           (int) mUnSelectedPadding_Bottom);
       addView(indicator);
       mIndicators.add(indicator);
     }
   } else if (count < mItemCount) {
     for (int i = 0; i < mItemCount - count; i++) {
       removeView(mIndicators.get(0));
       mIndicators.remove(0);
     }
   }
   mItemCount = count;
   mPager.setCurrentItem(mItemCount * 20 + mPager.getCurrentItem());
 }
示例#6
0
  /** 开始播放 仅当view正在显示 且 触摸等待时间过后 播放 */
  private void startPlay() {
    if (delay <= 0 || mAdapter.getCount() <= 1) {
      return;
    }
    if (timer != null) {
      timer.cancel();
    }
    timer = new Timer();
    // 用一个timer定时设置当前项为下一项
    timer.schedule(
        new TimerTask() {

          @Override
          public void run() {
            if (isShown() && System.currentTimeMillis() - mRecentTouchTime > delay)
              new Handler(Looper.getMainLooper())
                  .post(
                      new Runnable() {

                        @Override
                        public void run() {
                          int cur = mViewPager.getCurrentItem() + 1;
                          if (cur >= mAdapter.getCount()) {
                            cur = 0;
                          }
                          mViewPager.setCurrentItem(cur);
                          if (mHintView != null) ((HintView) mHintView).setCurrent(cur);
                        }
                      });
          }
        },
        delay,
        delay);
  }
 public void notifyDataSetChanged() {
   mTabLayout.removeAllViews();
   PagerAdapter adapter = mViewPager.getAdapter();
   IconPagerAdapter iconAdapter = null;
   if (adapter instanceof IconPagerAdapter) {
     iconAdapter = (IconPagerAdapter) adapter;
   }
   final int count = adapter.getCount();
   for (int i = 0; i < count; i++) {
     CharSequence title = adapter.getPageTitle(i);
     if (title == null) {
       title = EMPTY_TITLE;
     }
     int iconResId = 0;
     if (iconAdapter != null) {
       iconResId = iconAdapter.getIconResId(i);
     }
     addTab(i, title, iconResId);
   }
   if (mSelectedTabIndex > count) {
     mSelectedTabIndex = count - 1;
   }
   setCurrentItem(mSelectedTabIndex);
   requestLayout();
 }
  private void populateTabStrip() {
    final PagerAdapter adapter = viewPager.getAdapter();

    for (int i = 0; i < adapter.getCount(); i++) {

      final View tabView =
          (tabProvider == null)
              ? createDefaultTabView(adapter.getPageTitle(i))
              : tabProvider.createTabView(tabStrip, i, adapter);

      if (tabView == null) {
        throw new IllegalStateException("tabView is null.");
      }

      if (distributeEvenly) {
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
        lp.width = 0;
        lp.weight = 1;
      }

      if (internalTabClickListener != null) {
        tabView.setOnClickListener(internalTabClickListener);
      }

      tabStrip.addView(tabView);

      if (i == viewPager.getCurrentItem()) {
        tabView.setSelected(true);
      }
    }
  }
示例#9
0
 private void populateTabStrip() {
   final PagerAdapter adapter = mViewPager.getAdapter();
   final View.OnClickListener tabClickListener = new TabClickListener();
   for (int i = 0; i < adapter.getCount(); i++) {
     View tabView = null;
     TextView tabTitleView = null;
     if (mTabViewLayoutId != 0) {
       // If there is a custom tab view layout id set, try and inflate it
       tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
       tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
     }
     if (tabView == null) {
       tabView = createDefaultTabView(getContext());
     }
     if (tabTitleView == null && TextView.class.isInstance(tabView)) {
       tabTitleView = (TextView) tabView;
     }
     if (mDistributeEvenly) {
       LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
       lp.width = 0;
       lp.weight = 1;
     }
     tabTitleView.setText(adapter.getPageTitle(i));
     tabView.setOnClickListener(tabClickListener);
     String desc = mContentDescriptions.get(i, null);
     if (desc != null) {
       tabView.setContentDescription(desc);
     }
     mTabStrip.addView(tabView);
     if (i == mViewPager.getCurrentItem()) {
       tabView.setSelected(true);
     }
   }
 }
示例#10
0
  public void scrollOnce() {
    try {
      PagerAdapter adapter = getAdapter();
      int currentItem = getCurrentItem();
      int totalCount;
      if (adapter == null || (totalCount = adapter.getCount()) <= 1) {
        return;
      }

      int nextItem = (direction == LEFT) ? --currentItem : ++currentItem;
      if (nextItem < 0) {
        if (isCycle) {
          setCurrentItem(totalCount - 1, isBorderAnimation);
        }
      } else if (nextItem == totalCount) {
        if (isCycle) {
          setCurrentItem(0, isBorderAnimation);
        }
      } else {
        setCurrentItem(nextItem, isBorderAnimation);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#11
0
  public Fragment findViewFromObject(int position) {
    MyFragmentPagerAdapter fragmentAdapter;
    PagerAdapter adapter = getAdapter();

    if (adapter instanceof MyFragmentPagerAdapter) {
      fragmentAdapter = (MyFragmentPagerAdapter) adapter;
      int count = adapter.getCount();
      return fragmentAdapter.getItem(position >= count ? count - 1 : position);
    }
    return null;
  }
示例#12
0
  @Override
  protected boolean isReadyForPullEnd() {
    ViewPager refreshableView = getRefreshableView();

    PagerAdapter adapter = refreshableView.getAdapter();
    if (null != adapter) {
      return refreshableView.getCurrentItem() == adapter.getCount() - 1;
    }

    return false;
  }
 public void setTabsFromPagerAdapter(@NonNull PagerAdapter adapter) {
   removeAllTabs();
   for (int i = 0, count = adapter.getCount(); i < count; i++) {
     addTab(adapter.getPageTitle(i), getPageDrawable(adapter, i));
   }
   mSplit = new ImageView(getContext());
   mSplit.setBackgroundColor(splitColor);
   addView(mSplit, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   invalidate();
   mCurrentSelectedPos = -1;
   setTabSelected(0, true);
 }
示例#14
0
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   super.onCreateOptionsMenu(menu);
   getMenuInflater().inflate(R.menu.view_pager_activity, menu);
   menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0);
   MenuItem item =
       menu.add(
           Menu.NONE,
           R.id.action_next,
           Menu.NONE,
           (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? "FINISH" : "NEXT");
   item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
   return true;
 }
示例#15
0
  private void notifyDataSetInvalidated() {
    PagerAdapter adapter = mViewPager.getAdapter();
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
      TextView tv = getTabView(i);

      CharSequence title = adapter.getPageTitle(i);
      if (title == null) title = "NULL";

      tv.setText(title);
    }

    requestLayout();
  }
示例#16
0
  /** 加载hintview的容器 */
  private void loadHintView() {
    addView(mHintView);

    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, Util.dip2px(getContext(), 24));
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    ((View) mHintView).setLayoutParams(lp);

    GradientDrawable gd = new GradientDrawable();
    gd.setColor(color);
    gd.setAlpha(alpha);
    mHintView.setBackgroundDrawable(gd);

    ((HintView) mHintView).initView(mAdapter == null ? 0 : mAdapter.getCount(), gravity);
  }
  public void notifyDataSetChanged() {

    tabsContainer.removeAllViews();
    PagerAdapter adapter = pager.getAdapter();

    tabCount = adapter.getCount();

    for (int i = 0; i < tabCount; i++) {

      if (adapter instanceof IconTabProvider) {
        IconTabProvider ipa = ((IconTabProvider) adapter);
        if (TEKST_DER_FADER_OVER_I_IKONER) {
          Bitmap res = ipa.getPageIconBitmap(i);
          int resId = ipa.getPageIconResId(i);
          if (resId != 0 || res != null)
            addIconTabBådeTekstOgBillede(i, resId, res, ipa.getPageContentDescription(i));
          else addTextTab(i, adapter.getPageTitle(i).toString());
        } else {
          addIconTab(i, ipa.getPageIconResId(i), ipa.getPageContentDescription(i));
        }
      } else {
        addTextTab(i, adapter.getPageTitle(i).toString());
      }
    }

    updateTabStyles();

    getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {

              @SuppressWarnings("deprecation")
              @SuppressLint("NewApi")
              @Override
              public void onGlobalLayout() {

                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                  getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                  getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                currentPosition = pager.getCurrentItem();
                scrollToChild(currentPosition, 0);
              }
            });
  }
  /**
   *
   *
   * <ul>
   *   if stopScrollWhenTouch is true
   *   <li>if event is down, stop auto scroll.
   *   <li>if event is up, start auto scroll again.
   * </ul>
   */
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);

    if (stopScrollWhenTouch) {
      if ((action == MotionEvent.ACTION_DOWN) && isAutoScroll) {
        isStopByTouch = true;
        stopAutoScroll();
      } else if (ev.getAction() == MotionEvent.ACTION_UP && isStopByTouch) {
        startAutoScroll();
      }
    }

    if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT
        || slideBorderMode == SLIDE_BORDER_MODE_CYCLE) {
      touchX = ev.getX();
      if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        downX = touchX;
      }
      int currentItem = getCurrentItem();
      PagerAdapter adapter = getAdapter();
      int pageCount = adapter == null ? 0 : adapter.getCount();
      /**
       * current index is first one and slide to right or current index is last one and slide to
       * left.<br>
       * if slide border mode is to parent, then requestDisallowInterceptTouchEvent false.<br>
       * else scroll to last one when current item is first one, scroll to first one when current
       * item is last one.
       */
      if ((currentItem == 0 && downX <= touchX)
          || (currentItem == pageCount - 1 && downX >= touchX)) {
        if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT) {
          getParent().requestDisallowInterceptTouchEvent(false);
        } else {
          if (pageCount > 1) {
            setCurrentItem(pageCount - currentItem - 1, isBorderAnimation);
          }
          getParent().requestDisallowInterceptTouchEvent(true);
        }
        return super.dispatchTouchEvent(ev);
      }
    }
    getParent().requestDisallowInterceptTouchEvent(true);

    return super.dispatchTouchEvent(ev);
  }
示例#19
0
  private void notifyDataSetChanged() {
    mTabContainer.removeAllViews();

    PagerAdapter adapter = mViewPager.getAdapter();
    final int count = adapter.getCount();

    if (mSelectedPosition > count) mSelectedPosition = count - 1;

    for (int i = 0; i < count; i++) {
      CharSequence title = adapter.getPageTitle(i);
      if (title == null) title = "NULL";

      CheckedTextView tv = new CheckedTextView(getContext());
      tv.setCheckMarkDrawable(null);
      tv.setText(title);
      tv.setGravity(Gravity.CENTER);
      tv.setTextAppearance(getContext(), mTextApperance);
      tv.setSingleLine(true);
      tv.setEllipsize(TruncateAt.END);
      tv.setOnClickListener(this);
      tv.setTag(i);
      if (mTabRippleStyle > 0) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
          tv.setBackground(new RippleDrawable.Builder(getContext(), mTabRippleStyle).build());
        else
          tv.setBackgroundDrawable(
              new RippleDrawable.Builder(getContext(), mTabRippleStyle).build());
      }

      if (mMode == MODE_SCROLL) {
        tv.setPadding(mTabPadding, 0, mTabPadding, 0);
        mTabContainer.addView(
            tv,
            new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
      } else if (mMode == MODE_FIXED) {
        LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
        params.weight = 1f;
        mTabContainer.addView(tv, params);
      }
    }

    setCurrentItem(mSelectedPosition);
    requestLayout();
  }
  /*
   * return to the previously selected page in the viewPager
   */
  private void restorePreviousPage() {
    if (mViewPager == null || !hasPageAdapter()) {
      return;
    }

    String pageTitle = AppPrefs.getReaderSubsPageTitle();
    if (TextUtils.isEmpty(pageTitle)) {
      return;
    }

    PagerAdapter adapter = getPageAdapter();
    for (int i = 0; i < adapter.getCount(); i++) {
      if (pageTitle.equals(adapter.getPageTitle(i))) {
        mViewPager.setCurrentItem(i);
        return;
      }
    }
  }
 @Override
 public void notifyDataSetChanged() {
   mTabLayout.removeAllViews();
   PagerAdapter adapter = mViewPager.getAdapter();
   final int count = adapter.getCount();
   for (int i = 0; i < count; i++) {
     CharSequence title = adapter.getPageTitle(i);
     if (title == null) {
       title = EMPTY_TITLE;
     }
     addTab(title, i);
   }
   if (mSelectedTabIndex > count) {
     mSelectedTabIndex = count - 1;
   }
   setCurrentItem(mSelectedTabIndex);
   requestLayout();
 }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.screenslide, menu);

    menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0);

    // Add either a "next" or "finish" button to the action bar, depending on which page
    // is currently selected.
    MenuItem item =
        menu.add(
            Menu.NONE,
            R.id.action_next,
            Menu.NONE,
            (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1)
                ? R.string.action_finish
                : R.string.action_next);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    return true;
  }
示例#23
0
  public void notifyDataSetChanged() {
    mTabLayout.removeAllViews();
    PagerAdapter adapter = mViewPager.getAdapter();

    final int count = adapter.getCount();
    LayoutInflater layoutInflater = LayoutInflater.from(this.getContext());
    for (int i = 0; i < count; i++) {
      ViewHolderBase viewHolder = mViewHolderCreator.createViewHolder();
      viewHolder.setIndex(i);
      View view = viewHolder.createView(layoutInflater, i);
      view.setFocusable(true);
      view.setOnClickListener(mTabClickListener);
      view.setTag(viewHolder);
      mTabLayout.addView(view, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
    }
    if (mSelectedTabIndex > count) {
      mSelectedTabIndex = count - 1;
    }
    moveToItem(mSelectedTabIndex);
    requestLayout();
  }
  /** Populate TabStrip tabs. */
  private void populateTabStrip() {
    mNiceTabStrip.removeAllViews();

    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
      View tabView;

      if (mTabProvider != null) {
        tabView = mTabProvider.createTabView(mNiceTabStrip, i, adapter);
      } else {
        tabView = createDefaultTabView(i);
      }

      tabView.setOnClickListener(tabClickListener);

      mNiceTabStrip.addView(tabView);
    }
  }
  /** scroll only once */
  public void scrollOnce() {
    PagerAdapter adapter = getAdapter();
    int currentItem = getCurrentItem();
    int totalCount;
    if (adapter == null || (totalCount = adapter.getCount()) <= 1) {
      return;
    }

    int nextItem = (direction == LEFT) ? --currentItem : ++currentItem;
    if (nextItem < 0) {
      if (isCycle) {
        setCurrentItem(totalCount - 1, true);
      }
    } else if (nextItem == totalCount) {
      if (isCycle) {
        setCurrentItem(0, true);
      }
    } else {
      setCurrentItem(nextItem, true);
    }
  }
  private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
      View tabView = null;
      TextView tabTitleView = null;

      if (mTabViewLayoutId != 0) {
        // If there is a custom tab view layout id set, try and inflate it
        tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
        LinearLayout.LayoutParams loparams = (LinearLayout.LayoutParams) tabView.getLayoutParams();
        loparams.weight = 1;
        //                loparams.height = 50;
        //                loparams.gravity = Gravity.CENTER;
        tabView.setLayoutParams(loparams);
        tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        tabTitleView.setLayoutParams(
            new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f));
      }

      if (tabView == null) {
        tabView = createDefaultTabView(getContext());
        LinearLayout.LayoutParams loparams = (LinearLayout.LayoutParams) tabView.getLayoutParams();
        loparams.weight = 1;
        //                loparams.height = 50;
        //                loparams.gravity = Gravity.CENTER;
        tabView.setLayoutParams(loparams);
      }

      if (tabTitleView == null && TextView.class.isInstance(tabView)) {
        tabTitleView = (TextView) tabView;
      }

      tabTitleView.setText(adapter.getPageTitle(i));
      tabView.setOnClickListener(tabClickListener);

      mTabStrip.addView(tabView);
    }
  }
示例#27
0
 private void dataSetChanged() {
   startPlay();
   if (mHintView != null) ((HintView) mHintView).initView(mAdapter.getCount(), gravity);
 }
 @Override
 public int getCount() {
   return mAdapter.getCount() + 2;
 }
 public int getRealCount() {
   return mAdapter.getCount();
 }