Search in sources :

Example 21 with ViewPager

use of android.support.v4.view.ViewPager in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final ViewPager pager = (ViewPager) findViewById(R.id.pager);
    final MaterialTabs tabs = (MaterialTabs) findViewById(R.id.tabs);
    observable = (Observable<PermissionRoster>) getLastNonConfigurationInstance();
    if (observable == null) {
        observable = Observable.create(new PermissionSource(this)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).cache();
    }
    sub = observable.subscribe(new Consumer<PermissionRoster>() {

        @Override
        public void accept(PermissionRoster roster) throws Exception {
            pager.setAdapter(new PermissionTabAdapter(MainActivity.this, getFragmentManager(), roster));
            tabs.setViewPager(pager);
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable error) throws Exception {
            Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
            Log.e(getClass().getSimpleName(), "Exception processing request", error);
        }
    });
}
Also used : MaterialTabs(io.karim.MaterialTabs) Consumer(io.reactivex.functions.Consumer) ViewPager(android.support.v4.view.ViewPager)

Example 22 with ViewPager

use of android.support.v4.view.ViewPager in project UltimateAndroid by cymcsg.

the class SlidingLayout method canScroll.

/**
     * Tests scrollability within child views of v given a delta of dx.
     *
     * @param v      View to test for horizontal scrollability
     * @param checkV Whether the view v passed should itself be checked for scrollability (true),
     *               or just its children (false).
     * @param dx     Delta scrolled in pixels
     * @param x      X coordinate of the active touch point
     * @param y      Y coordinate of the active touch point
     * @return true if child views of v can be scrolled by delta of dx.
     */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }
    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ((v instanceof ViewPager) && canViewPagerScrollHorizontally((ViewPager) v, -dx)));
}
Also used : ViewGroup(android.view.ViewGroup) View(android.view.View) ViewPager(android.support.v4.view.ViewPager) Paint(android.graphics.Paint)

Example 23 with ViewPager

use of android.support.v4.view.ViewPager in project MPAndroidChart by PhilJay.

the class SimpleChartDemo method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_awesomedesign);
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setOffscreenPageLimit(3);
    PageAdapter a = new PageAdapter(getSupportFragmentManager());
    pager.setAdapter(a);
    AlertDialog.Builder b = new AlertDialog.Builder(this);
    b.setTitle("This is a ViewPager.");
    b.setMessage("Swipe left and right for more awesome design examples!");
    b.setPositiveButton("OK", new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    b.show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) ViewPager(android.support.v4.view.ViewPager)

Example 24 with ViewPager

use of android.support.v4.view.ViewPager in project material-intro-screen by TangoAgency.

the class OverScrollViewPager method canOverScrollAtEnd.

private boolean canOverScrollAtEnd() {
    SwipeableViewPager viewPager = getOverScrollView();
    PagerAdapter adapter = viewPager.getAdapter();
    if (null != adapter && adapter.getCount() > 0) {
        if (viewPager.alphaExitTransitionEnabled() && viewPager.getCurrentItem() == adapter.getCount() - 1) {
            return true;
        }
        return false;
    }
    return false;
}
Also used : PagerAdapter(android.support.v4.view.PagerAdapter)

Example 25 with ViewPager

use of android.support.v4.view.ViewPager in project material-intro-screen by TangoAgency.

the class CustomViewPager method initViewPager.

void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mTouchSlop = configuration.getScaledPagingTouchSlop();
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);
    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {

        private final Rect mTempRect = new Rect();

        @Override
        public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat originalInsets) {
            // First let the ViewPager itself try and consume them...
            final WindowInsetsCompat applied = ViewCompat.onApplyWindowInsets(v, originalInsets);
            if (applied.isConsumed()) {
                // If the ViewPager consumed all insets, return now
                return applied;
            }
            // Now we'll manually dispatch the insets to our children. Since ViewPager
            // children are always full-height, we do not want to use the standard
            // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them,
            // the rest of the children will not receive any insets. To workaround this
            // we manually dispatch the applied insets, not allowing children to
            // consume them from each other. We do however keep track of any insets
            // which are consumed, returning the union of our children's consumption
            final Rect res = mTempRect;
            res.left = applied.getSystemWindowInsetLeft();
            res.top = applied.getSystemWindowInsetTop();
            res.right = applied.getSystemWindowInsetRight();
            res.bottom = applied.getSystemWindowInsetBottom();
            for (int i = 0, count = getChildCount(); i < count; i++) {
                final WindowInsetsCompat childInsets = ViewCompat.dispatchApplyWindowInsets(getChildAt(i), applied);
                // Now keep track of any consumed by tracking each dimension's min
                // value
                res.left = Math.min(childInsets.getSystemWindowInsetLeft(), res.left);
                res.top = Math.min(childInsets.getSystemWindowInsetTop(), res.top);
                res.right = Math.min(childInsets.getSystemWindowInsetRight(), res.right);
                res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(), res.bottom);
            }
            // Now return a new WindowInsets, using the consumed window insets
            return applied.replaceSystemWindowInsets(res.left, res.top, res.right, res.bottom);
        }
    });
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) View(android.view.View) ViewConfiguration(android.view.ViewConfiguration) EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat) Scroller(android.widget.Scroller)

Aggregations

ViewPager (android.support.v4.view.ViewPager)235 View (android.view.View)94 PagerAdapter (android.support.v4.view.PagerAdapter)55 Fragment (android.support.v4.app.Fragment)40 TabLayout (android.support.design.widget.TabLayout)34 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)34 TextView (android.widget.TextView)34 Toolbar (android.support.v7.widget.Toolbar)30 Bundle (android.os.Bundle)27 ViewGroup (android.view.ViewGroup)27 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)20 ImageView (android.widget.ImageView)20 ArrayList (java.util.ArrayList)19 Intent (android.content.Intent)14 ActionBar (android.support.v7.app.ActionBar)13 RecyclerView (android.support.v7.widget.RecyclerView)10 ViewTreeObserver (android.view.ViewTreeObserver)10 AdapterView (android.widget.AdapterView)9 LinearLayout (android.widget.LinearLayout)9 UiController (android.support.test.espresso.UiController)8