Java Code Examples for androidx.viewpager.widget.ViewPager#setCurrentItem()

The following examples show how to use androidx.viewpager.widget.ViewPager#setCurrentItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetailActivity.java    From animation-samples with Apache License 2.0 6 votes vote down vote up
private void setUpViewPager(ArrayList<Photo> photos) {
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new DetailViewPagerAdapter(this, photos, sharedElementCallback));
    viewPager.setCurrentItem(initialItem);

    viewPager.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                   int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (viewPager.getChildCount() > 0) {
                viewPager.removeOnLayoutChangeListener(this);
                startPostponedEnterTransition();
            }
        }
    });

    viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.padding_mini));
    viewPager.setPageMarginDrawable(R.drawable.page_margin);
}
 
Example 2
Source File: ViewPagerActions.java    From android-test with Apache License 2.0 6 votes vote down vote up
/** Moves <code>ViewPager</code> to the first page. */
public static ViewAction scrollToFirst(final boolean smoothScroll) {
  return new ViewPagerScrollAction() {
    @Override
    public String getDescription() {
      return "ViewPager move to first page";
    }

    @Override
    protected void performScroll(ViewPager viewPager) {
      int size = viewPager.getAdapter().getCount();
      if (size > 0) {
        viewPager.setCurrentItem(0, smoothScroll);
      }
    }
  };
}
 
Example 3
Source File: ViewPagerActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** Moves <code>ViewPager</code> to the right by one page. */
public static ViewAction scrollRight() {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isDisplayingAtLeast(90);
    }

    @Override
    public String getDescription() {
      return "ViewPager scroll one page to the right";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();

      ViewPager viewPager = (ViewPager) view;
      int current = viewPager.getCurrentItem();
      viewPager.setCurrentItem(current + 1, false);

      uiController.loopMainThreadUntilIdle();
    }
  };
}
 
Example 4
Source File: NowPlayingScreenPreferenceDialog.java    From VinylMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    @SuppressLint("InflateParams") View view = LayoutInflater.from(getContext()).inflate(R.layout.preference_dialog_now_playing_screen, null);
    ViewPager viewPager = view.findViewById(R.id.now_playing_screen_view_pager);
    viewPager.setAdapter(new NowPlayingScreenAdapter(getContext()));
    viewPager.addOnPageChangeListener(this);
    viewPager.setPageMargin((int) ViewUtil.convertDpToPixel(32, getResources()));
    viewPager.setCurrentItem(PreferenceUtil.getInstance().getNowPlayingScreen().ordinal());

    InkPageIndicator pageIndicator = view.findViewById(R.id.page_indicator);
    pageIndicator.setViewPager(viewPager);
    pageIndicator.onPageSelected(viewPager.getCurrentItem());

    return new MaterialDialog.Builder(getContext())
            .title(R.string.pref_title_now_playing_screen_appearance)
            .positiveText(android.R.string.ok)
            .negativeText(android.R.string.cancel)
            .onAny(this)
            .customView(view, false)
            .build();
}
 
Example 5
Source File: NowPlayingScreenPreferenceDialog.java    From Music-Player with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    @SuppressLint("InflateParams") View view = LayoutInflater.from(getContext()).inflate(R.layout.preference_dialog_now_playing_screen, null);
    ViewPager viewPager = view.findViewById(R.id.now_playing_screen_view_pager);
    viewPager.setAdapter(new NowPlayingScreenAdapter(getContext()));
    viewPager.addOnPageChangeListener(this);
    viewPager.setPageMargin((int) ViewUtil.convertDpToPixel(32, getResources()));
    viewPager.setCurrentItem(PreferenceUtil.getInstance(getContext()).getNowPlayingScreen().ordinal());

    InkPageIndicator pageIndicator = view.findViewById(R.id.page_indicator);
    pageIndicator.setViewPager(viewPager);
    pageIndicator.onPageSelected(viewPager.getCurrentItem());

    return new MaterialDialog.Builder(getContext())
            .title(R.string.pref_title_now_playing_screen_appearance)
            .positiveText(android.R.string.ok)
            .negativeText(android.R.string.cancel)
            .onAny(this)
            .customView(view, false)
            .build();
}
 
Example 6
Source File: DetailActivity.java    From android-instant-apps with Apache License 2.0 6 votes vote down vote up
private void setUpViewPager(ArrayList<Photo> photos) {
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new DetailViewPagerAdapter(this, photos, sharedElementCallback));
    viewPager.setCurrentItem(initialItem);

    viewPager.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                   int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (viewPager.getChildCount() > 0) {
                viewPager.removeOnLayoutChangeListener(this);
                startPostponedEnterTransition();
            }
        }
    });

    viewPager.setPageMargin(getResources().getDimensionPixelSize(
            com.example.android.unsplash.R.dimen.padding_mini));
    viewPager.setPageMarginDrawable(R.drawable.page_margin);
}
 
Example 7
Source File: ViewPagerActions.java    From android-test with Apache License 2.0 5 votes vote down vote up
/** Moves <code>ViewPager</code> to the right by one page. */
public static ViewAction scrollRight(final boolean smoothScroll) {
  return new ViewPagerScrollAction() {
    @Override
    public String getDescription() {
      return "ViewPager move one page to the right";
    }

    @Override
    protected void performScroll(ViewPager viewPager) {
      int current = viewPager.getCurrentItem();
      viewPager.setCurrentItem(current + 1, smoothScroll);
    }
  };
}
 
Example 8
Source File: ViewPagerActions.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/** Moves <code>ViewPager</code> to the last page. */
public static ViewAction scrollToLast() {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isDisplayingAtLeast(90);
    }

    @Override
    public String getDescription() {
      return "ViewPager scroll to last page";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();

      ViewPager viewPager = (ViewPager) view;
      int size = viewPager.getAdapter().getCount();
      if (size > 0) {
        viewPager.setCurrentItem(size - 1, false);
      }

      uiController.loopMainThreadUntilIdle();
    }
  };
}
 
Example 9
Source File: DefaultFragment.java    From CircleIndicator with Apache License 2.0 5 votes vote down vote up
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    ViewPager viewpager = view.findViewById(R.id.viewpager);
    CircleIndicator indicator = view.findViewById(R.id.indicator);
    viewpager.setAdapter(new SamplePagerAdapter());
    indicator.setViewPager(viewpager);
    viewpager.setCurrentItem(2);
}
 
Example 10
Source File: ViewPagerActions.java    From android-test with Apache License 2.0 5 votes vote down vote up
/** Moves <code>ViewPager</code> to specific page. */
public static ViewAction scrollToPage(final int page, final boolean smoothScroll) {
  return new ViewPagerScrollAction() {
    @Override
    public String getDescription() {
      return "ViewPager move to page";
    }

    @Override
    protected void performScroll(ViewPager viewPager) {
      viewPager.setCurrentItem(page, smoothScroll);
    }
  };
}
 
Example 11
Source File: AutoRefreshUtil.java    From SmoothRefreshLayout with MIT License 5 votes vote down vote up
public void autoRefresh(boolean atOnce, boolean autoRefreshUseSmoothScroll) {
    if (mRefreshLayout != null) {
        if (mStatus != SmoothRefreshLayout.SR_STATUS_INIT) return;
        if (mRefreshLayout.isNotYetInEdgeCannotMoveHeader()) {
            if (mRefreshLayout.isVerticalOrientation()) {
                ScrollCompat.flingCompat(mTargetView, -mMaximumFlingVelocity);
            } else {
                if (ViewCatcherUtil.isViewPager(mTargetView)) {
                    final ViewPager pager = (ViewPager) mTargetView;
                    final PagerAdapter adapter = pager.getAdapter();
                    if (adapter == null) return;
                    if (adapter.getCount() <= 0) return;
                    pager.setCurrentItem(0, true);
                } else {
                    HorizontalScrollCompat.flingCompat(mTargetView, -mMaximumFlingVelocity);
                }
            }
            mNeedToTriggerRefresh = true;
            mCachedActionAtOnce = atOnce;
            mCachedAutoRefreshUseSmoothScroll = autoRefreshUseSmoothScroll;
        } else {
            mRefreshLayout.autoRefresh(atOnce, autoRefreshUseSmoothScroll);
            mNeedToTriggerRefresh = false;
            mCachedActionAtOnce = false;
            mCachedAutoRefreshUseSmoothScroll = false;
        }
        ViewCompat.postOnAnimation(mRefreshLayout, this);
    }
}
 
Example 12
Source File: ViewPagerActions.java    From android-test with Apache License 2.0 5 votes vote down vote up
/** Moves <code>ViewPager</code> to the left by one page. */
public static ViewAction scrollLeft(final boolean smoothScroll) {
  return new ViewPagerScrollAction() {
    @Override
    public String getDescription() {
      return "ViewPager move one page to the left";
    }

    @Override
    protected void performScroll(ViewPager viewPager) {
      int current = viewPager.getCurrentItem();
      viewPager.setCurrentItem(current - 1, smoothScroll);
    }
  };
}
 
Example 13
Source File: ItemPagerAdapter.java    From materialistic with Apache License 2.0 5 votes vote down vote up
public void bind(ViewPager viewPager, TabLayout tabLayout,
                 FloatingActionButton navigationFab, FloatingActionButton genericFab) {
    viewPager.setPageMargin(viewPager.getResources().getDimensionPixelOffset(R.dimen.divider));
    viewPager.setPageMarginDrawable(R.color.blackT12);
    viewPager.setOffscreenPageLimit(2);
    viewPager.setAdapter(this);
    tabLayout.setupWithViewPager(viewPager);
    mTabListener = new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            super.onTabSelected(tab);
            toggleFabs(viewPager.getCurrentItem() == 0, navigationFab, genericFab);
            Fragment fragment = getItem(viewPager.getCurrentItem());
            if (fragment != null) {
                ((LazyLoadFragment) fragment).loadNow();
            }
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            Fragment fragment = getItem(viewPager.getCurrentItem());
            if (fragment != null) {
                ((Scrollable) fragment).scrollToTop();
            }
        }
    };
    tabLayout.addOnTabSelectedListener(mTabListener);
    viewPager.setCurrentItem(mDefaultItem);
    toggleFabs(mDefaultItem == 0, navigationFab, genericFab);

}
 
Example 14
Source File: EmojiView.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
EmojiView(final Context context, final OnEmojiClickedListener onEmojiClickedListener, @NonNull final RecentEmoji recentEmoji) {
    super(context);

    View.inflate(context, R.layout.emoji_view, this);

    final ViewPager emojisPager = (ViewPager) findViewById(R.id.emojis_pager);
    emojisPager.addOnPageChangeListener(this);

    final List<FrameLayout> views = getViews(context, onEmojiClickedListener, recentEmoji);
    final EmojiPagerAdapter emojisAdapter = new EmojiPagerAdapter(views);
    emojisPager.setAdapter(emojisAdapter);

    emojiTabs = new ImageView[DUMB_INDEX + 1];
    emojiTabs[RECENT_INDEX] = (ImageView) findViewById(R.id.emojis_tab_0_recent);
    emojiTabs[DEFAULT_INDEX] = (ImageView) findViewById(R.id.emojis_tab_1_default);
    emojiTabs[MONKEY_INDEX] = (ImageView) findViewById(R.id.emojis_tab_2_monkey);
    emojiTabs[DUMB_INDEX] = (ImageView) findViewById(R.id.emojis_tab_3_dumb);

    handleOnClicks(emojisPager);

    findViewById(R.id.emojis_backspace).setOnTouchListener(new RepeatListener(INITIAL_INTERVAL, NORMAL_INTERVAL, new OnClickListener() {
        @Override
        public void onClick(final View view) {
            if (onEmojiBackspaceClickListener != null) {
                onEmojiBackspaceClickListener.onEmojiBackspaceClicked(view);
            }
        }
    }));

    final TypedValue value = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorAccent, value, true);
    themeAccentColor = value.data;

    final int startIndex = recentGridView.numberOfRecentEmojis() > 0 ? RECENT_INDEX : DEFAULT_INDEX;
    emojisPager.setCurrentItem(startIndex);
    onPageSelected(startIndex);
}
 
Example 15
Source File: AddressDetailActivity.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    address = getIntent().getStringExtra("ADDRESS");
    type = getIntent().getByteExtra("TYPE", SCANNED_WALLET);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    title = (TextView) findViewById(R.id.toolbar_title);
    String walletname = AddressNameConverter.getInstance(this).get(address);
    title.setText(type == OWN_WALLET ? (walletname == null ? "Unnamed Wallet" : walletname) : "Address");

    coord = (CoordinatorLayout) findViewById(R.id.main_content);
    appbar = (AppBarLayout) findViewById(R.id.appbar);

    fragments = new Fragment[3];
    fragments[0] = new FragmentDetailShare();
    fragments[1] = new FragmentDetailOverview();
    fragments[2] = new FragmentTransactions();
    Bundle bundle = new Bundle();
    bundle.putString("ADDRESS", address);
    bundle.putDouble("BALANCE", getIntent().getDoubleExtra("BALANCE", 0));
    bundle.putByte("TYPE", type);
    fragments[0].setArguments(bundle);
    fragments[1].setArguments(bundle);
    fragments[2].setArguments(bundle);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    tabLayout.setupWithViewPager(mViewPager);

    tabLayout.getTabAt(0).setIcon(R.drawable.ic_action_share);
    tabLayout.getTabAt(1).setIcon(R.drawable.ic_wallet);
    tabLayout.getTabAt(2).setIcon(R.drawable.ic_transactions);
    mViewPager.setCurrentItem(1);

    mViewPager.setOffscreenPageLimit(3);
}
 
Example 16
Source File: SlidingTabActivity.java    From UIWidget with Apache License 2.0 4 votes vote down vote up
@Override
protected void initView(Bundle var1) {
    for (String title : mTitles) {
        mFragments.add(SimpleCardFragment.getInstance(title));
    }


    View decorView = getWindow().getDecorView();
    ViewPager vp = FindViewUtil.getTargetView(decorView, R.id.vp);
    mAdapter = new MyPagerAdapter(getSupportFragmentManager());
    vp.setAdapter(mAdapter);

    /** 默认 */
    SlidingTabLayout tabLayout_1 = FindViewUtil.getTargetView(decorView, R.id.tl_1);
    /**自定义部分属性*/
    tabLayout_2 = FindViewUtil.getTargetView(decorView, R.id.tl_2);
    /** 字体加粗,大写 */
    SlidingTabLayout tabLayout_3 = FindViewUtil.getTargetView(decorView, R.id.tl_3);
    /** tab固定宽度 */
    SlidingTabLayout tabLayout_4 = FindViewUtil.getTargetView(decorView, R.id.tl_4);
    /** indicator固定宽度 */
    SlidingTabLayout tabLayout_5 = FindViewUtil.getTargetView(decorView, R.id.tl_5);
    /** indicator圆 */
    SlidingTabLayout tabLayout_6 = FindViewUtil.getTargetView(decorView, R.id.tl_6);
    /** indicator矩形圆角 */
    final SlidingTabLayout tabLayout_7 = FindViewUtil.getTargetView(decorView, R.id.tl_7);
    /** indicator三角形 */
    SlidingTabLayout tabLayout_8 = FindViewUtil.getTargetView(decorView, R.id.tl_8);
    /** indicator圆角色块 */
    SlidingTabLayout tabLayout_9 = FindViewUtil.getTargetView(decorView, R.id.tl_9);
    /** indicator圆角色块 */
    SlidingTabLayout tabLayout_10 = FindViewUtil.getTargetView(decorView, R.id.tl_10);

    tabLayout_1.setViewPager(vp);
    tabLayout_2.setViewPager(vp);
    tabLayout_2.setOnTabSelectListener(this);
    tabLayout_3.setViewPager(vp);
    tabLayout_4.setViewPager(vp);
    tabLayout_5.setViewPager(vp);
    tabLayout_6.setViewPager(vp);
    tabLayout_7.setViewPager(vp, mTitles);
    tabLayout_8.setViewPager(vp, mTitles, this, mFragments);
    tabLayout_9.setViewPager(vp);
    tabLayout_10.setViewPager(vp);

    vp.setCurrentItem(4);

    tabLayout_1.showDot(4);
    tabLayout_3.showDot(4);
    tabLayout_2.showDot(4);

    tabLayout_2.showMsg(3, 5);
    tabLayout_2.setMsgMargin(3, 0, 10);
    MsgView rtv_2_3 = tabLayout_2.getMsgView(3);
    if (rtv_2_3 != null) {
        rtv_2_3.setBackgroundColor(Color.parseColor("#6D8FB0"));
    }

    tabLayout_2.showMsg(5, 5);
    tabLayout_2.setMsgMargin(5, 0, 10);

    SlidingTabLayout slidingTabLayout = new SlidingTabLayout(mContext);
    slidingTabLayout.getDelegate()
            .setIndicatorColor(Color.BLUE)
            .setIndicatorGravity(Gravity.BOTTOM)
            .setIndicatorHeight(3f)
            .setIndicatorStyle(IndicatorStyle.NORMAL)
            .setIndicatorWidthEqualTitle(false)
            .setTabPadding(6f)
            .setTextBold(TextBold.SELECT)
            .setTextSelectColor(Color.BLUE)
            .setTabSpaceEqual(true)
            .setTextUnSelectColor(Color.parseColor("#99333333"))
            .setTextSelectSize(TypedValue.COMPLEX_UNIT_DIP, 16f)
            .setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16f);

    ((ViewGroup) tabLayout_1.getParent()).addView(slidingTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, SizeUtil.dp2px(48)));
    slidingTabLayout.setViewPager(vp, mTitles);
    slidingTabLayout.setOnTabSelectListener(this);

    findViewById(R.id.btn_eventTab).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(SlidingTabActivity.this, EventBusActivity.class));
        }
    });
}
 
Example 17
Source File: CarouseActivity.java    From ViewPagerIndicator with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        mViewpager = (ViewPager) findViewById(R.id.viewpager);
        ArrayList<String> strings = new ArrayList<>();
        strings.add("NO.1");
        strings.add("NO.2");
        strings.add("NO.3");
        strings.add("NO.4");
//        strings.add("NO.5");
//        strings.add("NO.6");
//        strings.add("NO.7");
        ArrayList<Fragment> fragments = new ArrayList<>();
        for (int i=0;i<strings.size();i++){
            Fragment fragment = new BlankFragment();
            Bundle bundle = new Bundle();
            bundle.putString("key",strings.get(i));
            fragment.setArguments(bundle);
            fragments.add(fragment);
        }


        int allNum=100000;
        final int num= strings.size();  // 100/7=14..2    7*7=49  20/7=2..6   7   30/7=4..2    14   40/7=5..5   14
        int firstIndex=0;
        if(num>0)
        {
            firstIndex=allNum/num/2*num;
        }


        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(),strings,num,allNum);
        mViewpager.setAdapter(adapter);
        mViewpager.setCurrentItem(firstIndex);


        mIndicatorDefault = (ViewPagerIndicator) findViewById(R.id.indicator_default);
        mIndicatorCircle = (ViewPagerIndicator) findViewById(R.id.indicator_circle);
        mIndicatorLine = (ViewPagerIndicator) findViewById(R.id.indicator_line);
        mIndicatorCircleLine = (ViewPagerIndicator) findViewById(R.id.indicator_circle_line);
        mIndicatorBazier = (ViewPagerIndicator) findViewById(R.id.indicator_bezier);
        mIndicatorSpring = (ViewPagerIndicator) findViewById(R.id.indicator_spring);
        mIndicatorProgress = (ViewPagerIndicator) findViewById(R.id.indicator_progress);

        mIndicatorDefault.setViewPager(mViewpager,num);
        mIndicatorCircle.setViewPager(mViewpager,num);
        mIndicatorLine.setViewPager(mViewpager,num);
        mIndicatorCircleLine.setViewPager(mViewpager,num);
        mIndicatorBazier.setViewPager(mViewpager,num);
        mIndicatorSpring.setViewPager(mViewpager,num);
        mIndicatorProgress.setViewPager(mViewpager,num);

    }
 
Example 18
Source File: EmojiView.java    From Emoji with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("PMD.CyclomaticComplexity") public EmojiView(final Context context,
    final OnEmojiClickListener onEmojiClickListener,
    final OnEmojiLongClickListener onEmojiLongClickListener, @NonNull final EmojiPopup.Builder builder) {
  super(context);

  View.inflate(context, R.layout.emoji_view, this);

  setOrientation(VERTICAL);
  setBackgroundColor(builder.backgroundColor != 0 ? builder.backgroundColor : Utils.resolveColor(context, R.attr.emojiBackground, R.color.emoji_background));
  themeIconColor = builder.iconColor != 0 ? builder.iconColor : Utils.resolveColor(context, R.attr.emojiIcons, R.color.emoji_icons);

  final TypedValue value = new TypedValue();
  context.getTheme().resolveAttribute(R.attr.colorAccent, value, true);
  themeAccentColor = builder.selectedIconColor != 0 ? builder.selectedIconColor : value.data;

  final ViewPager emojisPager = findViewById(R.id.emojiViewPager);
  final View emojiDivider = findViewById(R.id.emojiViewDivider);
  emojiDivider.setBackgroundColor(builder.dividerColor != 0 ? builder.dividerColor : Utils.resolveColor(context, R.attr.emojiDivider, R.color.emoji_divider));

  if (builder.pageTransformer != null) {
    emojisPager.setPageTransformer(true, builder.pageTransformer);
  }

  final LinearLayout emojisTab = findViewById(R.id.emojiViewTab);
  emojisPager.addOnPageChangeListener(this);

  final EmojiCategory[] categories = EmojiManager.getInstance().getCategories();

  emojiTabs = new ImageButton[categories.length + 2];
  emojiTabs[0] = inflateButton(context, R.drawable.emoji_recent, R.string.emoji_category_recent, emojisTab);
  for (int i = 0; i < categories.length; i++) {
    emojiTabs[i + 1] = inflateButton(context, categories[i].getIcon(), categories[i].getCategoryName(), emojisTab);
  }
  emojiTabs[emojiTabs.length - 1] = inflateButton(context, R.drawable.emoji_backspace, R.string.emoji_backspace, emojisTab);

  handleOnClicks(emojisPager);

  emojiPagerAdapter = new EmojiPagerAdapter(onEmojiClickListener, onEmojiLongClickListener, builder.recentEmoji, builder.variantEmoji);
  emojisPager.setAdapter(emojiPagerAdapter);

  final int startIndex = emojiPagerAdapter.numberOfRecentEmojis() > 0 ? 0 : 1;
  emojisPager.setCurrentItem(startIndex);
  onPageSelected(startIndex);
}
 
Example 19
Source File: AddressDetailActivity.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    address = getIntent().getStringExtra("ADDRESS");
    type = getIntent().getByteExtra("TYPE", SCANNED_WALLET);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    title = (TextView) findViewById(R.id.toolbar_title);
    String walletname = AddressNameConverter.getInstance(this).get(address);
    title.setText(type == OWN_WALLET ? (walletname == null ? "Unnamed Wallet" : walletname) : "Address");

    coord = (CoordinatorLayout) findViewById(R.id.main_content);
    appbar = (AppBarLayout) findViewById(R.id.appbar);

    fragments = new Fragment[3];
    fragments[0] = new FragmentDetailShare();
    fragments[1] = new FragmentDetailOverview();
    fragments[2] = new FragmentTransactions();
    Bundle bundle = new Bundle();
    bundle.putString("ADDRESS", address);
    bundle.putDouble("BALANCE", getIntent().getDoubleExtra("BALANCE", 0));
    bundle.putByte("TYPE", type);
    fragments[0].setArguments(bundle);
    fragments[1].setArguments(bundle);
    fragments[2].setArguments(bundle);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    tabLayout.setupWithViewPager(mViewPager);

    tabLayout.getTabAt(0).setIcon(R.drawable.ic_action_share);
    tabLayout.getTabAt(1).setIcon(R.drawable.ic_wallet);
    tabLayout.getTabAt(2).setIcon(R.drawable.ic_transactions);
    mViewPager.setCurrentItem(1);

    mViewPager.setOffscreenPageLimit(3);
}
 
Example 20
Source File: ViewPagerBindingAdapters.java    From Jockey with Apache License 2.0 4 votes vote down vote up
@BindingAdapter("page")
public static void setPage(ViewPager pager, int page) {
    pager.setCurrentItem(page, false);
}