Example usage for android.support.v4.view ViewPager ViewPager

List of usage examples for android.support.v4.view ViewPager ViewPager

Introduction

In this page you can find the example usage for android.support.v4.view ViewPager ViewPager.

Prototype

public ViewPager(Context context) 

Source Link

Usage

From source file:app.umitems.greenclock.DeskClock.java

private void initViews() {
    if (mTabsAdapter == null) {
        mViewPager = new ViewPager(this);
        mViewPager.setId(R.id.desk_clock_pager);
        // Keep all four tabs to minimize jank.
        mViewPager.setOffscreenPageLimit(3);
        mTabsAdapter = new TabsAdapter(this, mViewPager);
        createTabs(mSelectedTab);//from w  ww.j  a va  2s .c  o m
    }
    setContentView(mViewPager);
    mActionBar.setSelectedNavigationItem(mSelectedTab);
}

From source file:org.vshgap.ui.Components.EmojiView.java

public EmojiView(boolean needStickers, Context context) {
    super(context);
    SharedPreferences themePrefs = ApplicationLoader.applicationContext
            .getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
    int bgColor = themePrefs.getInt("chatEmojiViewBGColor", 0xfff5f6f7);
    int tabColor = themePrefs.getInt("chatEmojiViewTabColor",
            AndroidUtilities.getIntDarkerColor("themeColor", -0x15));
    int lineColor = bgColor == 0xfff5f6f7 ? 0xffe2e5e7 : AndroidUtilities.setDarkColor(bgColor, 0x10);
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(context);
        if (AndroidUtilities.isTablet()) {
            gridView.setColumnWidth(AndroidUtilities.dp(60));
        } else {/*from  www . j a  va  2s.co  m*/
            gridView.setColumnWidth(AndroidUtilities.dp(45));
        }
        gridView.setNumColumns(-1);
        views.add(gridView);

        EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(emojiGridAdapter);
        //AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7);
        AndroidUtilities.setListViewEdgeEffectColor(gridView, bgColor);
        adapters.add(emojiGridAdapter);
    }

    if (needStickers) {
        GridView gridView = new GridView(context);
        gridView.setColumnWidth(AndroidUtilities.dp(72));
        gridView.setNumColumns(-1);
        gridView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
        gridView.setClipToPadding(false);
        views.add(gridView);
        stickersGridAdapter = new StickersGridAdapter(context);
        gridView.setAdapter(stickersGridAdapter);
        //AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7);
        AndroidUtilities.setListViewEdgeEffectColor(gridView, bgColor);
    }

    //setBackgroundColor(0xfff5f6f7);
    setBackgroundColor(bgColor);

    pager = new ViewPager(context);
    pager.setAdapter(new EmojiPagesAdapter());

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    //linearLayout.setBackgroundColor(0xfff5f6f7);
    linearLayout.setBackgroundColor(bgColor);
    addView(linearLayout, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, AndroidUtilities.dp(48)));

    PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(context);
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorHeight(AndroidUtilities.dp(2));
    tabs.setUnderlineHeight(AndroidUtilities.dp(1));
    //tabs.setIndicatorColor(0xff2b96e2);
    tabs.setIndicatorColor(tabColor);
    //tabs.setUnderlineColor(0xffe2e5e7);
    tabs.setUnderlineColor(lineColor);
    linearLayout.addView(tabs, new LinearLayout.LayoutParams(0, AndroidUtilities.dp(48), 1.0f));

    FrameLayout frameLayout = new FrameLayout(context);
    linearLayout.addView(frameLayout,
            new LinearLayout.LayoutParams(AndroidUtilities.dp(52), AndroidUtilities.dp(48)));

    backspaceButton = new ImageView(context) {
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                backspacePressed = true;
                backspaceOnce = false;
                postBackspaceRunnable(350);
            } else if (event.getAction() == MotionEvent.ACTION_CANCEL
                    || event.getAction() == MotionEvent.ACTION_UP) {
                backspacePressed = false;
                if (!backspaceOnce) {
                    if (EmojiView.this.listener != null && EmojiView.this.listener.onBackspace()) {
                        backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
                    }
                }
            }
            super.onTouchEvent(event);
            return true;
        }
    };
    backspaceButton.setImageResource(R.drawable.ic_smiles_backspace);
    backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace);
    backspaceButton.setScaleType(ImageView.ScaleType.CENTER);
    frameLayout.addView(backspaceButton,
            new FrameLayout.LayoutParams(AndroidUtilities.dp(52), AndroidUtilities.dp(48)));

    View view = new View(context);
    //view.setBackgroundColor(0xffe2e5e7);
    view.setBackgroundColor(lineColor);
    frameLayout.addView(view, new FrameLayout.LayoutParams(AndroidUtilities.dp(52), AndroidUtilities.dp(1),
            Gravity.LEFT | Gravity.BOTTOM));

    recentsWrap = new FrameLayout(context);
    recentsWrap.addView(views.get(0));

    TextView textView = new TextView(context);
    textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    textView.setTextSize(18);
    textView.setTextColor(0xff888888);
    textView.setGravity(Gravity.CENTER);
    recentsWrap.addView(textView);
    views.get(0).setEmptyView(textView);

    addView(pager);

    loadRecents();

    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }

}

From source file:com.dreamchen.useful.mouserace.view.sliding.AbSlidingSmoothFixTabView.java

/**
 * Instantiates a new ab sliding smooth fix tab view.
 *
 * @param context the context//from  w  ww .j a  v  a2 s  .  c o  m
 * @param attrs the attrs
 */
public AbSlidingSmoothFixTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    layoutParamsFW = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    layoutParamsFF = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    layoutParamsWW = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    this.setOrientation(LinearLayout.VERTICAL);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();

    this.addView(mTabLayout, layoutParamsFW);

    //?
    mTabImg = new ImageView(context);
    this.addView(mTabImg, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, tabSlidingHeight));

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();

    this.addView(mViewPager, layoutParamsFF);

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingSmoothFixTabView.class,
                "AbSlidingSmoothTabView?context,FragmentActivity");
    }

    DisplayMetrics mDisplayMetrics = AbAppUtil.getDisplayMetrics(context);
    mWidth = mDisplayMetrics.widthPixels;

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getSupportFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

}

From source file:com.tony.selene.sliding.AbSlidingSmoothFixTabView.java

/**
 * Instantiates a new ab sliding smooth fix tab view.
 *
 * @param context//from   www  .ja  v  a 2 s  . com
 *            the context
 * @param attrs
 *            the attrs
 */
public AbSlidingSmoothFixTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    layoutParamsFW = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    layoutParamsFF = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    layoutParamsWW = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    this.setOrientation(LinearLayout.VERTICAL);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    // Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();

    this.addView(mTabLayout, layoutParamsFW);

    // ?
    mTabImg = new ImageView(context);
    this.addView(mTabImg, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, tabSlidingHeight));

    // View?
    mViewPager = new ViewPager(context);
    // ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();

    this.addView(mViewPager, layoutParamsFF);

    // ?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingSmoothFixTabView.class,
                "AbSlidingSmoothTabView?context,FragmentActivity");
    }

    DisplayMetrics mDisplayMetrics = AbAppUtil.getDisplayMetrics(context);
    mWidth = mDisplayMetrics.widthPixels;

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

}

From source file:com.sanbo.moveonapp.TabsUserActivity.java

/**
 * Initializes the view pager and sets it as a content view.
 *///from  ww  w . j  a  va  2 s  .  co  m
private void initViewPager() {
    if (Config.DEBUG)
        Log.d(Config.LOGTAG, "TabsUserActivity.initViewPager()");
    _viewPager = new ViewPager(this);
    _viewPager.setId(R.id.pager1);
    setContentView(_viewPager);
}

From source file:com.ab.view.sliding.AbSlidingTabView.java

/**
 * Instantiates a new ab sliding tab view.
 *
 * @param context the context// w ww  . j  a va 2s  .  co m
 * @param attrs the attrs
 */
public AbSlidingTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new HorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    this.addView(mTabScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingTabView.class,
                "AbSlidingTabView?context,FragmentActivity");
    }

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

    this.addView(mViewPager, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

}

From source file:com.githang.androidkit.app.IntroActivity.java

/**
 * /*from ww  w.j a  v a2 s  .c  o m*/
 */
private void createContentView() {
    // ?
    mIntroResource = new IntroResource();
    setIntroViews(mIntroResource);

    // 
    RelativeLayout rootView = new RelativeLayout(this);
    rootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    // 
    mViewPager = new ViewPager(this);
    RelativeLayout.LayoutParams pagerParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    rootView.addView(mViewPager, pagerParams);

    // 
    LinearLayout indicatorLayout = new LinearLayout(this);
    RelativeLayout.LayoutParams indicatorParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    indicatorParams.bottomMargin = mIntroResource.indicatorMarginBottom;
    indicatorParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    indicatorParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    indicatorLayout.setLayoutParams(indicatorParams);
    indicatorLayout.setOrientation(LinearLayout.HORIZONTAL);

    // 
    int indicatorCount = mIntroResource.views.size();
    int padding = mIntroResource.indicatorImagePadding;
    mIndicator = new ArrayList<ImageView>();
    for (int i = 0; i < indicatorCount; i++) {
        ImageView imageView = new ImageView(this);
        LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        imageView.setPadding(padding, padding, padding, padding);
        imageView.setClickable(true);
        imageView.setOnClickListener(this);
        imageView.setImageResource(mIntroResource.indicatorNoSelectedId);
        imageView.setTag(i);
        mIndicator.add(imageView);
        indicatorLayout.addView(imageView, imageParams);
    }

    rootView.addView(indicatorLayout);

    setContentView(rootView);
}

From source file:com.dreamchen.useful.mouserace.view.sliding.AbSlidingTabView.java

/**
 * Instantiates a new ab sliding tab view.
 *
 * @param context the context//from   www .  j a  v a  2 s  .c  om
 * @param attrs the attrs
 */
public AbSlidingTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new HorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    this.addView(mTabScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingTabView.class,
                "AbSlidingTabView?context,FragmentActivity");
    }

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getSupportFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

    this.addView(mViewPager, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

}

From source file:com.lurencun.cfuture09.androidkit.uilibs.IntroActivity.java

/**
 * /*  w w  w  . j  av a2  s. c  o  m*/
 */
private void createContentView() {
    // ?
    mIntroResource = new IntroResource();
    setIntroViews(mIntroResource);

    // 
    RelativeLayout rootView = new RelativeLayout(this);
    rootView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    // 
    mViewPager = new ViewPager(this);
    RelativeLayout.LayoutParams pagerParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    rootView.addView(mViewPager, pagerParams);

    // 
    LinearLayout indicatorLayout = new LinearLayout(this);
    RelativeLayout.LayoutParams indicatorParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    indicatorParams.bottomMargin = mIntroResource.indicatorMarginBottom;
    indicatorParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    indicatorParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    indicatorLayout.setLayoutParams(indicatorParams);
    indicatorLayout.setOrientation(LinearLayout.HORIZONTAL);

    // 
    int indicatorCount = mIntroResource.views.size();
    int padding = mIntroResource.indicatorImagePadding;
    mIndicator = new ArrayList<ImageView>();
    for (int i = 0; i < indicatorCount; i++) {
        ImageView imageView = new ImageView(this);
        LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        imageView.setPadding(padding, padding, padding, padding);
        imageView.setClickable(true);
        imageView.setOnClickListener(this);
        imageView.setImageResource(mIntroResource.indicatorNoSelectedId);
        imageView.setTag(i);
        mIndicator.add(imageView);
        indicatorLayout.addView(imageView, imageParams);
    }

    rootView.addView(indicatorLayout);

    setContentView(rootView);
}

From source file:com.ylq.commonui.AbSlidingTabView.java

/**
 * Instantiates a new ab sliding tab view.
 *
 * @param context the context// w w w . j a v a 2s. co m
 * @param attrs the attrs
 */
public AbSlidingTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new HorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    this.addView(mTabScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        Log.e(TAG, "AbSlidingTabView?context,FragmentActivity");
    }

}