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

The following examples show how to use android.support.v4.view.ViewPager#setOnPageChangeListener() . 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: TabPageIndicator.java    From letv with Apache License 2.0 6 votes vote down vote up
public void setViewPager(ViewPager view) {
    if (view == null) {
        removeAllViews();
        this.mViewPager = null;
    } else if (this.mViewPager != view) {
        if (this.mViewPager != null) {
            this.mViewPager.setOnPageChangeListener(null);
        }
        if (view.getAdapter() == null) {
            throw new IllegalStateException("ViewPager does not have adapter instance.");
        }
        this.mViewPager = view;
        view.setOnPageChangeListener(this);
        notifyDataSetChanged();
    }
}
 
Example 2
Source File: TabPageIndicator.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    final PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
Example 3
Source File: TabPageIndicator.java    From cube-sdk with Apache License 2.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    final PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
Example 4
Source File: IconPageIndicator.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
Example 5
Source File: SlidingTabLayout.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the associated view pager. Note that the assumption here is that the pager content
 * (number of tabs and tab titles) does not change after this call has been made.
 */
public void setViewPager(ViewPager viewPager) {
    mTabStrip.removeAllViews();

    mViewPager = viewPager;
    if (viewPager != null) {
        viewPager.setOnPageChangeListener(new InternalViewPagerListener());
        populateTabStrip();
    }
}
 
Example 6
Source File: PagerSlidingTabStrip.java    From droidddle with Apache License 2.0 5 votes vote down vote up
public void setViewPager(ViewPager pager) {
    this.pager = pager;

    if (pager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }

    pager.setOnPageChangeListener(pageListener);

    notifyDataSetChanged();
}
 
Example 7
Source File: SwipableIconTabActivity.java    From MaterialTabs with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_icons);
    res = this.getResources();
    // init toolbar (old action bar)

    Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar);
    toolbar.setTitleTextColor(Color.WHITE);
    this.setSupportActionBar(toolbar);

    tabHost = (MaterialTabHost) this.findViewById(R.id.tabHost);
    pager = (ViewPager) this.findViewById(R.id.pager);
    // init view pager
    pagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(pagerAdapter);
    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // when user do a swipe the selected tab change
            tabHost.setSelectedNavigationItem(position);
        }
    });
    // insert all tabs from pagerAdapter data
    for (int i = 0; i < pagerAdapter.getCount(); i++) {
        tabHost.addTab(
                tabHost.newTab()
                        .setIcon(getIcon(i))
                        .setTabListener(this)
        );
    }
}
 
Example 8
Source File: NetworkMonitorActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	overridePendingTransition(R.anim.slide_in_right, 0);
	setContentView(R.layout.network_monitor_content);

	// final ActionBar actionBar = getSupportActionBar();
	// actionBar.setDisplayHomeAsUpEnabled(true);

	final ViewPager pager = (ViewPager) findViewById(R.id.network_monitor_pager);

	final FragmentManager fm = getSupportFragmentManager();

	if (pager != null) {
		final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.network_monitor_pager_tabs);
		pagerTabs.addTabLabels(R.string.network_monitor_peer_list_title,
				R.string.network_monitor_block_list_title);

		final PagerAdapter pagerAdapter = new PagerAdapter(fm);

		pager.setAdapter(pagerAdapter);
		pager.setOnPageChangeListener(pagerTabs);
		pager.setPageMargin(2);
		pager.setPageMarginDrawable(R.color.bg);

		peerListFragment = new PeerListFragment();
		blockListFragment = new BlockListFragment();
	} else {
		peerListFragment = (PeerListFragment) fm
				.findFragmentById(R.id.peer_list_fragment);
		blockListFragment = (BlockListFragment) fm
				.findFragmentById(R.id.block_list_fragment);
	}
	// flTitleBar = (FrameLayout) findViewById(R.id.fl_title_bar);
	ibtnBack = (ImageButton) findViewById(R.id.ibtn_back);
	ibtnBack.setOnClickListener(new IBackClickListener());
       findViewById(R.id.ibtn_option).setOnClickListener(optionClick);
   }
 
Example 9
Source File: PagerSlidingTabStrip.java    From 920-text-editor-v2 with Apache License 2.0 5 votes vote down vote up
public void setViewPager(ViewPager pager) {
    this.pager = pager;

    if (pager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }

    pager.setOnPageChangeListener(pageListener);

    notifyDataSetChanged();
}
 
Example 10
Source File: CategoryTabStrip.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
public void setViewPager(ViewPager pager) {
		this.pager = pager;

		if (pager.getAdapter() == null) {
			throw new IllegalStateException("ViewPager does not have adapter instance.");
		}

		pager.setOnPageChangeListener(pageListener);

//		notifyDataSetChanged();
	}
 
Example 11
Source File: UIViewController.java    From Auie with GNU General Public License v2.0 5 votes vote down vote up
public void setViewPager(ViewPager pager) {
	this.pager = pager;

	if (pager.getAdapter() == null) {
		throw new IllegalStateException("ViewPager does not have adapter instance.");
	}

	pager.setOnPageChangeListener(pageListener);

	notifyDataSetChanged();
}
 
Example 12
Source File: SlidingTabLayout.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the associated view pager. Note that the assumption here is that the pager content
 * (number of tabs and tab titles) does not change after this call has been made.
 */
public void setViewPager(ViewPager viewPager) {
    mTabStrip.removeAllViews();

    mViewPager = viewPager;
    if (viewPager != null) {
        viewPager.setOnPageChangeListener(new InternalViewPagerListener());
        populateTabStrip();
    }
}
 
Example 13
Source File: MediaLayout.java    From ChatKeyboard with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context
            .LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.keyboard_media_layout, this);
    vpContent = (ViewPager) findViewById(R.id.popup_media_pager);
    ivIndicator = (IndicatorView) findViewById(R.id.popup_media_indicator);
    vpContent.setOnPageChangeListener(this);  //compatible for android 22
}
 
Example 14
Source File: MainActivity.java    From android-IconicFontEngine with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    // createFontAwesomeEngine();
    IconicFontEngine.addDefaultEngine(
            new FontAwesomeEngine(Typeface.createFromAsset(getAssets(), "fonts/fontawesome-webfont.ttf")));
    IconicFontEngine.addDefaultEngine(
            new TypiconsEngine(Typeface.createFromAsset(getAssets(), "fonts/typicons.ttf")));

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(
                actionBar.newTab()
                        .setText(mSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }
}
 
Example 15
Source File: ImageViewerActivity.java    From android-imageviewer with Apache License 2.0 4 votes vote down vote up
public void initUI() {
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setOnPageChangeListener(this);
}
 
Example 16
Source File: FreeFragment.java    From freepager with Apache License 2.0 4 votes vote down vote up
private void synchronizePager(ViewPager pager, int i) {
	pager.setOnPageChangeListener(null);
	pager.setCurrentItem(i);
	pager.setOnPageChangeListener(FreeFragment.this);
}
 
Example 17
Source File: UIImagePager.java    From Auie with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 初始化控件
 */
private View createContentView() {
	
	rootContainer = new RelativeLayout(context);
	rootContainer.setBackgroundColor(Color.parseColor("#000000"));
	rootContainer.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
	
	LayoutParams contentParams = new LayoutParams(MATCH_PARENT, WRAP_CONTENT);
	contentParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	contentContainer = new ViewPager(context);
	contentContainer.setAdapter(imageAdapter);
	contentContainer.setLayoutParams(contentParams);
	contentContainer.setOnPageChangeListener(onPageChangeListener);
	
	LayoutParams params = new LayoutParams(MATCH_PARENT, WRAP_CONTENT);
	params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
	indexContainer = new LinearLayout(context);
	indexContainer.setLayoutParams(params);
	indexContainer.setPadding(0, 0, 0, DP * 20);
	indexContainer.setGravity(Gravity.CENTER);
	indexContainer.setOrientation(LinearLayout.HORIZONTAL);
	
	LayoutParams params2 = new LayoutParams(60 * DP, 32 * DP);
	params2.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
	params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
	params2.setMargins(10 * DP, 0, 0, 10 * DP);
	actionButton = new UIButton(context);
	actionButton.setLayoutParams(params2);
	actionButton.setText("删除");
	actionButton.setTextSize(14);
	actionButton.setVisibility(View.GONE);
	actionButton.setTextColor(Color.WHITE);
	actionButton.setBackgroundColor(Color.RED);
	actionButton.setOnClickListener(onClickListener);
	
	rootContainer.addView(contentContainer);
	rootContainer.addView(indexContainer);
	rootContainer.addView(actionButton);
	
	return rootContainer;
}
 
Example 18
Source File: Settings.java    From Hangar with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mInstance = this;

    setContentView(R.layout.activity_settings);

    prefs = new PrefsGet(getSharedPreferences(getPackageName(), Context.MODE_MULTI_PROCESS));

    mContext = this;
    mIsLollipop = Tools.isLollipop(true);
    mIsAtLeastLollipop = Tools.isLollipop(false);

    if (showChangelog(prefs)) {
        launchChangelog();
    }

    if (mIsAtLeastLollipop && needsUsPermission()) {
        launchUsPermission(mContext);
    }

    display = getWindowManager().getDefaultDisplay();
    updateDisplayWidth();

    myService = new ServiceCall(mContext);
    myService.setConnection(mConnection);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    actionBar.setTitle(R.string.title_activity_settings);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setCustomView(R.layout.action_spinner);
    setUpSpinner((Spinner) actionBar.getCustomView().findViewById(R.id.config_spinner));
    actionBar.setDisplayShowCustomEnabled(true);


    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(4);

    mGetFragments = new GetFragments();
    mGetFragments.setFm(getFragmentManager());
    mGetFragments.setVp(mViewPager);

    ViewPager.OnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    };

    mViewPager.setOnPageChangeListener(pageChangeListener);

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab()
                        .setText(mSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }
    pageChangeListener.onPageSelected(GENERAL_TAB);

}
 
Example 19
Source File: IntroActivity.java    From UTubeTV with The Unlicense 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_intro);

  FragmentManager fm = getFragmentManager();
  mTaskFragment = (IntroXMLTaskFragment) fm.findFragmentByTag("task");

  // If the Fragment is non-null, then it is currently being
  // retained across a configuration change.
  if (mTaskFragment == null) {
    mTaskFragment = new IntroXMLTaskFragment();
    fm.beginTransaction().add(mTaskFragment, "task").commit();
  }

  mCloseButton = (Button) findViewById(R.id.close_button);
  mCloseButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
      finish();
    }
  });

  mViewPager = (ViewPager) findViewById(R.id.intro_pager);

  introPagerAdapter = new IntroPagerAdapter(this, getSupportFragmentManager());
  introPagerAdapter.setPages(mTaskFragment.getPages());
  mViewPager.setAdapter(introPagerAdapter);

  final LinePageIndicator ind = (LinePageIndicator) findViewById(R.id.line_indicator);
  ind.setViewPager(mViewPager);

  mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
    @Override
    public void onPageSelected(int position) {
      ind.updatePage(position);
      boolean lastPage = position == introPagerAdapter.getCount() - 1;

      mCloseButton.setText((lastPage) ? "Close" : "Read later");
    }
  });

  // show player if activity was destroyed and recreated
  if (savedInstanceState != null) {
    // must wait for the pages to load before we can restore it, so save it here
    mSavedIndex = savedInstanceState.getInt("pager_index");
  }
}
 
Example 20
Source File: EmojiPalettesView.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
@Override
protected void onFinishInflate() {
    mTabHost = (TabHost)findViewById(R.id.emoji_category_tabhost);
    mTabHost.setup();
    for (final EmojiCategory.CategoryProperties properties
            : mEmojiCategory.getShownCategories()) {
        addTab(mTabHost, properties.mCategoryId);
    }
    mTabHost.setOnTabChangedListener(this);
    final TabWidget tabWidget = mTabHost.getTabWidget();
    tabWidget.setStripEnabled(mCategoryIndicatorEnabled);
    if (mCategoryIndicatorEnabled) {
        // On TabWidget's strip, what looks like an indicator is actually a background.
        // And what looks like a background are actually left and right drawables.
        tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId);
        tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId);
        tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId);
    }

    mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this);

    mEmojiPager = (ViewPager)findViewById(R.id.emoji_keyboard_pager);
    mEmojiPager.setAdapter(mEmojiPalettesAdapter);
    mEmojiPager.setOnPageChangeListener(this);
    mEmojiPager.setOffscreenPageLimit(0);
    mEmojiPager.setPersistentDrawingCache(PERSISTENT_NO_CACHE);
    mEmojiLayoutParams.setPagerProperties(mEmojiPager);

    mEmojiCategoryPageIndicatorView =
            (EmojiCategoryPageIndicatorView)findViewById(R.id.emoji_category_page_id_view);
    mEmojiCategoryPageIndicatorView.setColors(
            mCategoryPageIndicatorColor, mCategoryPageIndicatorBackground);
    mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView);

    setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true /* force */);

    final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar);
    mEmojiLayoutParams.setActionBarProperties(actionBar);

    // deleteKey depends only on OnTouchListener.
    mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete);
    mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
    mDeleteKey.setTag(Constants.CODE_DELETE);
    mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);

    // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
    // {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
    // {@link View.OnTouchListener} is used as the trigger of key-press, while
    // {@link View.OnClickListener} is used as the trigger of key-release which does not occur
    // if the event is canceled by moving off the finger from the view.
    // The text on alphabet keys are set at
    // {@link #startEmojiPalettes(String,int,float,Typeface)}.
    mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left);
    mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyLeft.setOnTouchListener(this);
    mAlphabetKeyLeft.setOnClickListener(this);
    mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right);
    mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyRight.setOnTouchListener(this);
    mAlphabetKeyRight.setOnClickListener(this);
    mSpacebar = findViewById(R.id.emoji_keyboard_space);
    mSpacebar.setBackgroundResource(mSpacebarBackgroundId);
    mSpacebar.setTag(Constants.CODE_SPACE);
    mSpacebar.setOnTouchListener(this);
    mSpacebar.setOnClickListener(this);
    mEmojiLayoutParams.setKeyProperties(mSpacebar);
    mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
}