Java Code Examples for android.support.v4.view.ViewPager#setCurrentItem()

The following examples show how to use android.support.v4.view.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: DialogFragmentFancyQrCodePager.java    From bither-android with Apache License 2.0 8 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    vContainer = inflater.inflate(R.layout.dialog_fancy_qr_code_pager, container, false);
    tvAddress = (TextView) vContainer.findViewById(R.id.tv_address);
    pager = (ViewPager) vContainer.findViewById(R.id.pager);
    tbtnShowAvatar = (ImageButton) vContainer.findViewById(R.id.cbx_show_avatar);
    ivShowAvatarSeparator = vContainer.findViewById(R.id.iv_show_avatar_separator);
    vContainer.setOnClickListener(this);
    vContainer.findViewById(R.id.ibtn_share).setOnClickListener(this);
    vContainer.findViewById(R.id.ibtn_save).setOnClickListener(this);
    pager.setOffscreenPageLimit(1);
    int size = Math.min(UIUtil.getScreenWidth(), UIUtil.getScreenHeight());
    pager.getLayoutParams().width = size;
    pager.getLayoutParams().height = (int) (size * (vanityLength > 0 ?
            DialogFragmentFancyQrCodeSinglePage.VanitySizeRate : 1));
    pager.setAdapter(adapter);
    pager.setCurrentItem(AppSharedPreference.getInstance().getFancyQrCodeTheme().ordinal());
    tbtnShowAvatar.setOnClickListener(showAvatarCheckedChange);
    configureVanityAddress();
    return vContainer;
}
 
Example 2
Source File: AppIntroBase.java    From GithubApp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int code, KeyEvent event) {
    if (code == KeyEvent.KEYCODE_ENTER || code == KeyEvent.KEYCODE_BUTTON_A ||
            code == KeyEvent.KEYCODE_DPAD_CENTER) {
        ViewPager vp = (ViewPager) this.findViewById(R.id.view_pager);
        if (vp.getCurrentItem() == vp.getAdapter().getCount() - 1) {
            onDonePressed(fragments.get(vp.getCurrentItem()));
        } else {
            vp.setCurrentItem(vp.getCurrentItem() + 1);
        }

        return false;
    }

    return super.onKeyDown(code, event);
}
 
Example 3
Source File: DestinationActivity.java    From SETransitionDemo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        postponeEnterTransition();
    }
    setContentView(R.layout.activity_destination);
    FrameLayout container = (FrameLayout) findViewById(R.id.container);
    colorDrawable = new ColorDrawable(getResources().getColor(R.color.colorPrimaryDark));
    container.setBackgroundDrawable(colorDrawable);

    Intent intent = getIntent();
    ArrayList<Uri> uris = intent.getParcelableArrayListExtra("uris");
    adapterPosition = intent.getIntExtra("adapter_position", 0);
    current = intent.getIntExtra("current", 0);

    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(new PhotoAdapter(uris, onDismissListener));
    viewPager.setCurrentItem(current);
}
 
Example 4
Source File: TVMirrorsFragment.java    From android with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.tv_mirrors_fragment, container, false);

    final ViewPager pager = (ViewPager) rootView.findViewById(R.id.pager);
    pager.setAdapter(mAdapter);
    pager.setCurrentItem(mPosition);

    final SlidingTabLayout slidingTabs = (SlidingTabLayout) rootView.findViewById(R.id.sliding_tabs);
    slidingTabs.setShouldExpand(false);
    slidingTabs.setViewPager(pager);

    return rootView;
}
 
Example 5
Source File: ImageActivity.java    From BlackLight with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	// ActionBar
	getActionBar().setTitle("");

	mApiCache = new HomeTimeLineApiCache(this);
	
	mModel = getIntent().getParcelableExtra("model");
	int def = getIntent().getIntExtra("defaultId", 0);
	
	setContentView(R.layout.image_activity);
	
	// Initialize the adapter
	ImageAdapter adapter = new ImageAdapter();
	mLoaded = new boolean[adapter.getCount()];

	mPager = (ViewPager) findViewById(R.id.image_pager);
	mPager.setAdapter(adapter);
	mPager.setCurrentItem(def);
	
}
 
Example 6
Source File: FullScreenChartActivity.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fullscreen_chart);
    TabLayout tabLayout = findViewById(R.id.tab);
    final ViewPager viewPager = findViewById(R.id.view_pager);
    KLineChartFragment dayKFragment = KLineChartFragment.newInstance(1);
    KLineChartFragment weekKFragment = KLineChartFragment.newInstance(7);
    Fragment[] fragments = {TimeLineChartFragment.newInstance(1), FiveDayChartFragment.newInstance(),
            dayKFragment, weekKFragment,
            KLineChartFragment.newInstance(30)};
    String[] titles = {"分时图", "5Day", "日K", "周K", "月"};
    viewPager.setOffscreenPageLimit(fragments.length);
    viewPager.setAdapter(new SimpleFragmentPagerAdapter(getSupportFragmentManager(), fragments, titles));
    tabLayout.setupWithViewPager(viewPager);

    viewPager.setCurrentItem(getIntent().getIntExtra("index", 0));
}
 
Example 7
Source File: MainActivity.java    From HomeApplianceMall with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);
    viewPager = (ViewPager) findViewById(R.id.ViewPager_main);
    radioGroup = (RadioGroup) findViewById(R.id.RadioGroup_main);
    application = (MyApplication)getApplication();

    //viewPage
    List<Fragment> fragmentList = new ArrayList<>();
    HomeFragment homeFragment = new HomeFragment();
    SearchFragment searchFragment = new SearchFragment();
    ClassifyFragment classifyFragment = new ClassifyFragment();
    ShoppingCarFragment shoppingCarFragment = new ShoppingCarFragment();
    OrderFragment orderFragment = new OrderFragment();
    MyFragment myFragment = new MyFragment();
    fragmentList.add(homeFragment);
    fragmentList.add(searchFragment);
    fragmentList.add(classifyFragment);
    fragmentList.add(shoppingCarFragment);
    fragmentList.add(orderFragment);
    fragmentList.add(myFragment);
    application.setViewPager(viewPager);
    viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(),fragmentList));
    viewPager.setCurrentItem(0);
    viewPager.setOnPageChangeListener(new MyPageLister());

    //
    radioGroup.setOnCheckedChangeListener(new MyRadionGroupListen());
    radioGroup.check(R.id.radioButton_main_home);
    //
}
 
Example 8
Source File: TransactionActivityTest.java    From budget-watch with GNU General Public License v3.0 5 votes vote down vote up
private void checkClickAddWhileOnTap(Integer tab, int expectedType)
{
    ActivityController activityController = Robolectric.buildActivity(TransactionActivity.class).create();
    Activity activity = (Activity)activityController.get();

    activityController.start();
    activityController.resume();
    activityController.visible();

    if(tab != null)
    {
        final ViewPager viewPager = (ViewPager) activity.findViewById(R.id.pager);
        viewPager.setCurrentItem(tab);
    }

    shadowOf(activity).clickMenuItem(R.id.action_add);

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    ComponentName name = startedIntent.getComponent();
    assertNotNull(name);
    assertEquals("protect.budgetwatch/.TransactionViewActivity", name.flattenToShortString());
    Bundle bundle = startedIntent.getExtras();
    assertNotNull(bundle);

    // Fields which should not be present
    assertEquals(-1, bundle.getInt("id", -1));
    assertEquals(false, bundle.getBoolean("update", false));
    assertEquals(false, bundle.getBoolean("view", false));

    // Check the field which is expected
    assertEquals(expectedType, bundle.getInt("type", -1));
}
 
Example 9
Source File: RecipesFragment.java    From biermacht with Apache License 2.0 5 votes vote down vote up
public void updateTabletDetailsView(Recipe r) {
  // ViewPager and pagerAdapter for Slidy tabs!
  cpAdapter = new DisplayRecipeCollectionPagerAdapter(getChildFragmentManager(), r, context);

  // Set Adapter
  mViewPager = (ViewPager) detailsView.findViewById(R.id.pager);
  mViewPager.setAdapter(cpAdapter);

  // Set to the first page - the ingredients list.
  mViewPager.setCurrentItem(0);
}
 
Example 10
Source File: MainPresenter.java    From YAAB with GNU General Public License v3.0 5 votes vote down vote up
public void setupViewPager(ViewPager viewPager, FragmentManager supportFragmentManager) {
    this.viewPager = viewPager;
    allFrag = new AllAudioBookViewFragment();
    newFrag = new NewAudioBookFragment();
    ongoingFrag = new OnGoingAudioBookFragment();
    finishedFrag = new FinishedAudioBookFragment();
    ViewPagerAdapter adapter = new ViewPagerAdapter(context, supportFragmentManager);
    adapter.addFragment(allFrag, R.string.all);
    adapter.addFragment(newFrag, R.string.new_txt);
    adapter.addFragment(ongoingFrag, R.string.ongoing);
    adapter.addFragment(finishedFrag, R.string.finished);
    viewPager.setAdapter(adapter);
    viewPager.setCurrentItem(interactor.getPageWithSomeData());
}
 
Example 11
Source File: FollowFansCountActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
private void initData(){
    tabLayout = (TabLayout)this.findViewById(R.id.id_follow_fans_count_activity_tablayout);
    viewPager = (ViewPager)this.findViewById(R.id.id_follow_fans_count_activity_viewpager);
    adapter = new MyFragmentPagerAdapter(getSupportFragmentManager());

    adapter.addFragment(new FollowUserFragment(username),"关注");
    adapter.addFragment(new FansUserFragment(username), "粉丝");
    viewPager.setAdapter(adapter);
    //viewPager.removeAllViews();
    tabLayout.setupWithViewPager(viewPager);
    viewPager.setOnPageChangeListener(this);
    viewPager.setCurrentItem(page_position);

}
 
Example 12
Source File: BuffersActivity.java    From tapchat-android with Apache License 2.0 5 votes vote down vote up
@Override public void onReceive(Context context, Intent intent) {
    long cid = Long.parseLong(intent.getStringExtra("cid"));
    long bid = Long.parseLong(intent.getStringExtra("bid"));
    if (cid == mConnectionId) {
        int index = mTabsAdapter.findBufferIndex(bid);
        if (index >= 0) {
            final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
            viewPager.setCurrentItem(index);
            abortBroadcast();
        }
    }
}
 
Example 13
Source File: ShowCoverFanartBrowser.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

       MizuuApplication.setupTheme(this);

       if (MizLib.hasLollipop())
           getSupportActionBar().setElevation(0);
       getSupportActionBar().setDisplayHomeAsUpEnabled(true);

	tvdbId = getIntent().getExtras().getString("id");
       mToolbarColor = getIntent().getExtras().getInt(IntentKeys.TOOLBAR_COLOR);

       mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
       mProgressBar.setVisibility(View.VISIBLE);

       mViewPager = (ViewPager) findViewById(R.id.awesomepager);
       mViewPager.setOffscreenPageLimit(2);
       mViewPager.setPageMargin(MizLib.convertDpToPixels(this, 16));

       mTabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
       mTabs.setVisibility(View.GONE);

       setupActionBarStuff();

	if (savedInstanceState != null) {
           mViewPager.setCurrentItem(savedInstanceState.getInt("tab", 0));
	}
}
 
Example 14
Source File: Intro.java    From CumulusTV with MIT License 5 votes vote down vote up
@Override
public boolean onKeyDown(int code, KeyEvent kvent) {
    if(code == KeyEvent.KEYCODE_DPAD_CENTER) {
        ViewPager vp = (ViewPager)this.findViewById(com.github.paolorotolo.appintro.R.id.view_pager);
        if(vp.getCurrentItem() == vp.getAdapter().getCount()-1) {
            onDonePressed();
        } else {
            vp.setCurrentItem(vp.getCurrentItem()+1);
        }
        return false;
    }
    return super.onKeyDown(code, kvent);
}
 
Example 15
Source File: EmojiView.java    From Yahala-Messenger with MIT License 4 votes vote down vote up
private void init() {
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(getContext());
        gridView.setColumnWidth(OSUtilities.dpf(45.0f));
        gridView.setNumColumns(-1);
        views.add(gridView);

        EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(localEmojiGridAdapter);
        adapters.add(localEmojiGridAdapter);
    }

    setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{-14145496, -16777216}));
    pager = new ViewPager(getContext());
    pager.setAdapter(new EmojiPagesAdapter());
    PagerSlidingTabStripEmoji tabs = new PagerSlidingTabStripEmoji(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorColor(0xff33b5e5);
    tabs.setIndicatorHeight(OSUtilities.dpf(2.0f));
    tabs.setUnderlineHeight(OSUtilities.dpf(2.0f));
    tabs.setUnderlineColor(1711276032);
    tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (EmojiView.this.listener != null) {
                EmojiView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView, new LinearLayout.LayoutParams(OSUtilities.dpf(61.0f), LayoutParams.MATCH_PARENT));
    recentsWrap = new FrameLayout(getContext());
    recentsWrap.addView(views.get(0));
    TextView localTextView = new TextView(getContext());
    localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    localTextView.setTextSize(18.0f);
    localTextView.setTextColor(-7829368);
    localTextView.setGravity(17);
    recentsWrap.addView(localTextView);
    views.get(0).setEmptyView(localTextView);
    addView(localLinearLayout, new LinearLayout.LayoutParams(-1, OSUtilities.dpf(48.0f)));
    addView(pager);
    loadRecents();
    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }
}
 
Example 16
Source File: ChatActivity.java    From MaterialQQLite with Apache License 2.0 4 votes vote down vote up
@SuppressLint("NewApi")
    private void initView() {
    //    m_txtName = (TextView)findViewById(R.id.chat_txtName);
        m_lvMsg = (ListView)findViewById(R.id.chat_lvMsg);
        swipeRefreshLayout_chat= (PullRefreshLayout) findViewById(R.id.swipeRefreshLayout_chat);
        m_btnFace = (ImageButton)findViewById(R.id.chat_btnFace);
    //    m_btnMore = (ImageButton)findViewById(R.id.chat_btnMore);
        m_edtMsg = (EditText) findViewById(R.id.chat_edtMsg);
        m_btnSend = (Button) findViewById(R.id.chat_btnSend);
        m_faceBar = findViewById(R.id.chat_facebar);
        m_vpFace = (ViewPager)findViewById(R.id.chat_vpFace);
        m_dotBar = (LinearLayout) findViewById(R.id.chat_dotbar);



        m_btnFace.setOnClickListener(this);
        m_edtMsg.setOnClickListener(this);
        m_btnSend.setOnClickListener(this);

        if (m_nType != IS_GROUP)
          //  m_txtName.setText(m_strBuddyName);
            m_txtName=m_strBuddyName;
        else
         //   m_txtName.setText(m_strGroupName);
        m_txtName=m_strGroupName;

        initChatMsgListView();	// 初始化聊天消息列表框
        initFaceBar();			// 初始化表情栏

        m_nCurFacePage = 0;
        m_vpFace.setCurrentItem(1);

        toolbar = (Toolbar) findViewById(R.id.toolbar_chat);
        toolbar.setNavigationIcon(R.drawable.qqicon);
        toolbar.setTitle(m_txtName);

        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        chat_inputbar= (LinearLayout) findViewById(R.id.chat_inputbar);

        toolbar.setBackgroundColor(color_theme);
        chat_inputbar.setBackgroundColor(color_theme);

        // 去除 ListView 上下边界蓝色或黄色阴影
//		ListView actualListView = m_lvMsg.getRefreshableView();
//		if (Integer.parseInt(Build.VERSION.SDK) >= 9) {
//			actualListView.setOverScrollMode(View.OVER_SCROLL_NEVER);
//        }
    }
 
Example 17
Source File: TableOfContentsBookmarksActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    ((IslamicLibraryApplication) getApplication()).refreshLocale(this, false);
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    int initial_section = intent.getIntExtra(ReadingActivity.KEY_TAB_NAME, 0);
    bookId = intent.getIntExtra(BooksInformationDBContract.BooksAuthors.COLUMN_NAME_BOOK_ID, 0);
    bookName = intent.getStringExtra(BooksInformationDBContract.BookInformationEntery.COLUMN_NAME_TITLE);
    setContentView(R.layout.activity_book_toc_bookmarks);
    bookCardEventsCallback.intializeListener();
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        supportActionBar.setTitle(bookName);
    }


    SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());


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

    if (intent.hasExtra(BookDatabaseContract.TitlesEntry.COLUMN_NAME_PAGE_ID)) {
        pageId = intent.getIntExtra(BookDatabaseContract.TitlesEntry.COLUMN_NAME_PAGE_ID, 0);
        titleId = intent.getIntExtra(BookDatabaseContract.TitlesEntry.COLUMN_NAME_ID, 0);
        buildHistory = true;
        mViewPager.setCurrentItem(initial_section);
    } else {
        mViewPager.setCurrentItem(initial_section);
    }
    TabLayout tabLayout = findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    try {
        mBooksPartInfo = BookDatabaseHelper.getInstance(this, bookId).getBookPartsInfo();
    } catch (BookDatabaseException e) {
        Timber.e(e);
        finish();
    }
    mIsArabic = Util.isArabicUi(this);


}
 
Example 18
Source File: PlayerFragment.java    From Android-Remote with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_player,
            container, false);

    mPlayerPageFragment = new PlayerPageFragment();

    mSongDetailFragment = new SongDetailFragment();

    mConnectionFragment = new ConnectionFragment();

    PlayerPageAdapter playerPageAdapter;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        playerPageAdapter = new PlayerPageAdapter(getActivity(), getChildFragmentManager());
    } else {
        playerPageAdapter = new PlayerPageAdapter(getActivity(), getFragmentManager());
    }
    playerPageAdapter.addFragment(mPlayerPageFragment);
    playerPageAdapter.addFragment(mSongDetailFragment);
    playerPageAdapter.addFragment(mConnectionFragment);
    myPager = (ViewPager) view.findViewById(R.id.player_pager);
    myPager.setAdapter(playerPageAdapter);
    myPager.setCurrentItem(0);

    // Get the Views
    mBtnNext = (ImageButton) view.findViewById(R.id.btnNext);
    mBtnPrev = (ImageButton) view.findViewById(R.id.btnPrev);
    mBtnPlayPause = (ImageButton) view.findViewById(R.id.btnPlaypause);

    // Set the onclicklistener for the buttons
    mBtnNext.setOnClickListener(oclControl);
    mBtnPrev.setOnClickListener(oclControl);
    mBtnPlayPause.setOnClickListener(oclControl);
    mBtnPlayPause.setOnLongClickListener(olclControl);

    // Initialize interface
    stateChanged();
    metadataChanged();

    mTabs = (SlidingTabLayout) getActivity().findViewById(R.id.tabs);

    setHasOptionsMenu(true);

    return view;
}
 
Example 19
Source File: TabPagerIndicator.java    From PLDroidShortVideo with Apache License 2.0 4 votes vote down vote up
/**
 * 必须先设置ViewPager
 * @param viewPager
 * @param currentPos
 */
public void setViewPager(ViewPager viewPager, int currentPos){
    mViewPager = viewPager;
    viewPager.addOnPageChangeListener(mListener);
    viewPager.setCurrentItem(currentPos);
}
 
Example 20
Source File: StylePreferenceDialogFragment.java    From Camera-Roll-Android-App with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    //get initial value from pref
    if (preference instanceof StylePreference) {
        selectedStyle = ((StylePreference) preference).getStyle();
    }

    styles = getContext().getResources().getIntArray(R.array.style_values);

    @SuppressLint("InflateParams")
    View view = LayoutInflater.from(getContext()).inflate(R.layout.pref_dialog_style, null);

    ViewPager viewPager = view.findViewById(R.id.view_pager);
    viewPager.setAdapter(new ViewPagerAdapter(getContext()));
    viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            selectedStyle = styles[position];
        }
    });

    int currentItem = 0;
    for (int i = 0; i < styles.length; i++) {
        if (styles[i] == selectedStyle) {
            currentItem = i;
            break;
        }
    }

    viewPager.setCurrentItem(currentItem);

    PageIndicatorView indicator = view.findViewById(R.id.indicator);
    indicator.setAnimationType(AnimationType.WORM);

    return new AlertDialog.Builder(getContext())
            .setTitle(R.string.style)
            .setView(view)
            .setPositiveButton(R.string.ok, this)
            .setNegativeButton(R.string.cancel, null)
            .create();
}