Exemplo n.º 1
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();
    }
  }
Exemplo n.º 2
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);
     }
   }
 }
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Map<String, String> map = mLocalMusicAdapter.getItem(position);
    // 取得铃声名
    String ringName = map.get(WeacConstants.RING_NAME);
    // 取得播放地址
    String ringUrl = map.get(WeacConstants.RING_URL);
    // 更新当前铃声选中的位置
    mLocalMusicAdapter.updateSelection(ringName);
    // 更新适配器刷新铃声列表显示
    mLocalMusicAdapter.notifyDataSetChanged();
    // 设置最后一次选中的铃声选择界面位置为本地音乐界面
    RingSelectItem.getInstance().setRingPager(1);

    // 播放音频文件
    AudioPlayer.getInstance(getActivity()).play(ringUrl, false, false);

    ViewPager pager = (ViewPager) getActivity().findViewById(R.id.fragment_ring_select_sort);
    PagerAdapter f = pager.getAdapter();
    SystemRingFragment systemRingFragment = (SystemRingFragment) f.instantiateItem(pager, 0);
    RecorderFragment recorderFragment = (RecorderFragment) f.instantiateItem(pager, 2);
    // 取消系统铃声选中标记
    if (systemRingFragment.mSystemRingAdapter != null) {
      systemRingFragment.mSystemRingAdapter.updateSelection("");
      systemRingFragment.mSystemRingAdapter.notifyDataSetChanged();
    }
    // 取消录音选中标记
    if (recorderFragment.mRecorderAdapter != null) {
      recorderFragment.mRecorderAdapter.updateSelection("");
      recorderFragment.mRecorderAdapter.notifyDataSetChanged();
    }
  }
Exemplo n.º 4
0
 @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());
 }
  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);
      }
    }
  }
 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();
 }
Exemplo n.º 7
0
  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();
  }
Exemplo n.º 8
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 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);
   }
 }
Exemplo n.º 10
0
 @Override
 public int getCount() {
   if (wrappedAdapter == null) {
     return 0;
   } else if (wrappedAdapter.getCount() > 1) {
     return wrappedAdapter.getCount() + 2;
   } else {
     return wrappedAdapter.getCount();
   }
 }
Exemplo n.º 11
0
 /**
  * clear self means unregister the dataset observer and remove all the child views(indicators).
  */
 public void destroySelf() {
   if (mPager == null || mPager.getAdapter() == null) {
     return;
   }
   InfinitePagerAdapter wrapper = (InfinitePagerAdapter) mPager.getAdapter();
   PagerAdapter adapter = wrapper.getRealAdapter();
   if (adapter != null) {
     adapter.unregisterDataSetObserver(dataChangeObserver);
   }
   removeAllViews();
 }
Exemplo n.º 12
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;
  }
Exemplo n.º 13
0
  @Override
  protected boolean isReadyForPullEnd() {
    ViewPager refreshableView = getRefreshableView();

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

    return false;
  }
Exemplo n.º 14
0
 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);
 }
Exemplo n.º 15
0
 public View findViewFromObject(int position) {
   Object o = mObjs.get(Integer.valueOf(position));
   if (o == null) {
     return null;
   }
   PagerAdapter a = getAdapter();
   View v;
   for (int i = 0; i < getChildCount(); i++) {
     v = getChildAt(i);
     if (a.isViewFromObject(v, o)) return v;
   }
   return null;
 }
Exemplo n.º 16
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();
  }
Exemplo n.º 17
0
    @Override
    public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
      View tabView = mInflater.inflate(mTabViewLayoutId, container, false);

      View tabTextOrImageView = tabView.findViewById(mTabViewTextOrImageViewId);

      switch (mTabMode) {
        case TITLE_ONLY:
          {
            TextView tabTextView = (TextView) tabTextOrImageView;
            tabTextView.setText(adapter.getPageTitle(position));
            // TODO Set Color?
            break;
          }
        case ICON_ONLY:
          {
            if (adapter instanceof IconTabProvider) {
              ImageView tabImageView = (ImageView) tabTextOrImageView;
              tabImageView.setImageResource(((IconTabProvider) adapter).getPageIconResId(position));
              // TODO Set Color?
            } else {
              throw new ClassCastException(
                  "pager adapter must implements NiceTabLayout.IconTabProvider");
            }
            break;
          }
        case BOTH:
          {
            TextView tabTextView = (TextView) tabTextOrImageView;
            tabTextView.setText(adapter.getPageTitle(position));
            if (adapter instanceof IconTabProvider) {
              final int drawablePadding = tabTextView.getCompoundDrawablePadding();
              tabTextView.setCompoundDrawablesWithIntrinsicBounds(
                  0, ((IconTabProvider) adapter).getPageIconResId(position), 0, 0);
              tabTextView.setCompoundDrawablePadding(drawablePadding);
            } else {
              throw new ClassCastException(
                  "pager adapter must implements NiceTabLayout.IconTabProvider");
            }
            // TODO Set Color?
            break;
          }
        default:
          {
            throw new IllegalStateException("Invalid tab mode: " + mTabMode);
          }
      }

      return tabView;
    }
  /** 重新获取嵌套的内容视图 */
  private void regetNestedContentView() {
    int currentItem = mDirectViewPager.getCurrentItem();
    PagerAdapter adapter = mDirectViewPager.getAdapter();
    if (adapter instanceof FragmentPagerAdapter || adapter instanceof FragmentStatePagerAdapter) {
      Fragment item = (Fragment) adapter.instantiateItem(mDirectViewPager, currentItem);
      mNestedContentView = item.getView();

      // 清空之前的
      mNestedNormalView = null;
      mNestedAbsListView = null;
      mNestedRecyclerView = null;
      mNestedScrollView = null;
      mNestedWebView = null;

      if (mNestedContentView instanceof AbsListView) {
        mNestedAbsListView = (AbsListView) mNestedContentView;
        mNestedAbsListView.setOnScrollListener(mLvOnScrollListener);

        if (!isHeaderViewCompleteInvisible()) {
          mNestedAbsListView.setSelection(0);
        }
      } else if (mNestedContentView instanceof RecyclerView) {
        mNestedRecyclerView = (RecyclerView) mNestedContentView;
        mNestedRecyclerView.removeOnScrollListener(mRvOnScrollListener);
        mNestedRecyclerView.addOnScrollListener(mRvOnScrollListener);

        if (!isHeaderViewCompleteInvisible()) {
          mNestedRecyclerView.scrollToPosition(0);
        }
      } else if (mNestedContentView instanceof ScrollView) {
        mNestedScrollView = (ScrollView) mNestedContentView;

        if (!isHeaderViewCompleteInvisible()) {
          mNestedScrollView.scrollTo(mNestedScrollView.getScrollX(), 0);
        }
      } else if (mNestedContentView instanceof WebView) {
        mNestedWebView = (WebView) mNestedContentView;

        if (!isHeaderViewCompleteInvisible()) {
          mNestedWebView.scrollTo(mNestedWebView.getScrollX(), 0);
        }
      } else {
        mNestedNormalView = mNestedContentView;
      }
    } else {
      throw new IllegalStateException(
          BGAStickyNavLayout.class.getSimpleName()
              + "的第三个子控件为ViewPager时,其adapter必须是FragmentPagerAdapter或者FragmentStatePagerAdapter");
    }
  }
    @Override
    void showDetail(int position) {
      clearMultiChoice();
      detailEmptyView.setVisibility(View.GONE);
      detailSource.startUpdate(detailTarget);

      if (lastPosition > -1) {
        detailSource.destroyItem(detailTarget, lastPosition, handle);
      }

      lastPosition = position;

      handle = detailSource.instantiateItem(detailTarget, position);
      detailSource.finishUpdate(detailTarget);
    }
 private CharSequence getTitle(int i) {
   CharSequence title = mPagerAdapter.getPageTitle(i);
   if (title == null) {
     title = EMPTY_TITLE;
   }
   return title.toString();
 }
Exemplo n.º 21
0
 /**
  * 设置Adapter
  *
  * @param adapter
  */
 public void setAdapter(PagerAdapter adapter) {
   mViewPager.setAdapter(adapter);
   mViewPager.addOnPageChangeListener(this);
   mAdapter = adapter;
   dataSetChanged();
   adapter.registerDataSetObserver(new JPagerObserver());
 }
Exemplo n.º 22
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);
  }
    private void clearDetail(boolean showEmptyView) {
      clearMultiChoice();
      detailSource.startUpdate(detailTarget);

      if (lastPosition > -1) {
        detailSource.destroyItem(detailTarget, lastPosition, handle);
      }

      lastPosition = -1;

      detailSource.finishUpdate(detailTarget);

      if (showEmptyView) {
        detailEmptyView.setVisibility(View.VISIBLE);
      }
    }
  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);
              }
            });
  }
Exemplo n.º 25
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();
  }
Exemplo n.º 26
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);
  }
Exemplo n.º 27
0
 private int getPageDrawable(@NonNull PagerAdapter adapter, int position) {
   try {
     Method method = adapter.getClass().getMethod("getPageDrawable", int.class);
     return (int) method.invoke(adapter, position);
   } catch (Exception e) {
     throw new RuntimeException("public int getPageDrawable(int postiion) Method not impl!");
   }
 }
Exemplo n.º 28
0
 /**
  * 移除表情组
  *
  * @param position
  */
 public void removeEmojiconGroup(int position) {
   if (position > groupEntities.size() - 1) {
     return;
   }
   if (pagerAdapter != null) {
     pagerAdapter.notifyDataSetChanged();
   }
 }
 @Override
 public void notifyDataSetChanged() {
   mLogger.d("notifyDataSetChanged");
   super.notifyDataSetChanged();
   for (ViewHolder viewHolder : getAttachedViewHolders()) {
     onNotifyItemChanged(viewHolder);
   }
 }
Exemplo n.º 30
0
  private void updateDataDetail(Integer index) {
    Log.i("StoreMainActivity - updateData", "Start");
    List<Fragment> fragments = this.getProductDetailFragments();
    // Instantiate a ViewPager and a PagerAdapter.
    mPager = (ViewPager) findViewById(R.id.storeDetailPager);
    mPagerAdapter = new CustomPagerAdapter(getSupportFragmentManager(), fragments);
    mPager.setAdapter(mPagerAdapter);
    mPagerAdapter.notifyDataSetChanged();
    mPager.setCurrentItem(index);
    mPager.setOnPageChangeListener(
        new OnPageChangeListener() {

          @Override
          public void onPageSelected(int arg0) {}

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

          @Override
          public void onPageScrollStateChanged(int arg0) {

            Log.i("StoreMainActivity - onPageScrollStateChanged", "Start");
            TextView tvPage = (TextView) findViewById(R.id.tvStoreDetailPage);
            if (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);
            }

            ProductInfo product = listProduct.get(mPager.getCurrentItem());
            if (productTransactionDetailInfo == null) {
              productTransactionDetailInfo = new TransactionDetailInfo();
            }
            productTransactionDetailInfo.setCategoryId(product.getCategoryId());
            productTransactionDetailInfo.setProductId(product.getProductId());
            productTransactionDetailInfo.setProductName(product.getName());
            productTransactionDetailInfo.setUnitPrice(product.getUnitPrice());
          }
        });
    this.updatePageNumView();
  }