Search in sources :

Example 66 with ViewConfiguration

use of android.view.ViewConfiguration in project AndroidDevelop by 7449.

the class TabView method init.

private void init() {
    // 把一个值从dip转换成px
    mIndicatorHeight = dip2px(mIndicatorHeight);
    mDividerPadding = dip2px(mDividerPadding);
    mTabPadding = dip2px(mTabPadding);
    mDividerWidth = dip2px(mDividerWidth);
    mTabTextSize = dip2px(mTabTextSize);
    // 创建一个scroller
    mScroller = ScrollerCompat.create(getContext());
    // 获取一个系统关于View的常量配置类
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    // 获取滑动的最小距离
    mTouchSlop = configuration.getScaledTouchSlop();
    // 获取fling的最小速度
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    // 获取fling的最大速度
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(getContext());
    mRightEdge = new EdgeEffectCompat(getContext());
}
Also used : ViewConfiguration(android.view.ViewConfiguration) EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat)

Example 67 with ViewConfiguration

use of android.view.ViewConfiguration in project UltimateAndroid by cymcsg.

the class DraggableGridViewPager method initDraggableGridViewPager.

private void initDraggableGridViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    setChildrenDrawingOrderEnabled(true);
    final Context context = getContext();
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mGridGap = (int) (DEFAULT_GRID_GAP * density);
    // internal paddings
    mPaddingLeft = getPaddingLeft();
    mPaddingTop = getPaddingTop();
    mPaddingRight = getPaddingRight();
    mPaddingButtom = getPaddingBottom();
    super.setPadding(0, 0, 0, 0);
    mScroller = new Scroller(context, sInterpolator);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
}
Also used : Context(android.content.Context) ViewConfiguration(android.view.ViewConfiguration) Scroller(android.widget.Scroller)

Example 68 with ViewConfiguration

use of android.view.ViewConfiguration in project SeaStar by 13120241790.

the class PullToRefreshBase method init.

@SuppressWarnings("deprecation")
private void init(Context context, AttributeSet attrs) {
    switch(getPullToRefreshScrollDirection()) {
        case HORIZONTAL:
            setOrientation(LinearLayout.HORIZONTAL);
            break;
        case VERTICAL:
        default:
            setOrientation(LinearLayout.VERTICAL);
            break;
    }
    setGravity(Gravity.CENTER);
    ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop();
    // Styleables from XML
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullToRefresh);
    if (a.hasValue(R.styleable.PullToRefresh_ptrMode)) {
        mMode = Mode.mapIntToValue(a.getInteger(R.styleable.PullToRefresh_ptrMode, 0));
    }
    if (a.hasValue(R.styleable.PullToRefresh_ptrAnimationStyle)) {
        mLoadingAnimationStyle = AnimationStyle.mapIntToValue(a.getInteger(R.styleable.PullToRefresh_ptrAnimationStyle, 0));
    }
    // Refreshable View
    // By passing the attrs, we can add ListView/GridView params via XML
    mRefreshableView = createRefreshableView(context, attrs);
    addRefreshableView(context, mRefreshableView);
    // We need to create now layouts now
    mHeaderLayout = createLoadingLayout(context, Mode.PULL_FROM_START, a);
    mFooterLayout = createLoadingLayout(context, Mode.PULL_FROM_END, a);
    /**
		 * Styleables from XML
		 */
    if (a.hasValue(R.styleable.PullToRefresh_ptrRefreshableViewBackground)) {
        Drawable background = a.getDrawable(R.styleable.PullToRefresh_ptrRefreshableViewBackground);
        if (null != background) {
            mRefreshableView.setBackgroundDrawable(background);
        }
    } else if (a.hasValue(R.styleable.PullToRefresh_ptrAdapterViewBackground)) {
        Utils.warnDeprecation("ptrAdapterViewBackground", "ptrRefreshableViewBackground");
        Drawable background = a.getDrawable(R.styleable.PullToRefresh_ptrAdapterViewBackground);
        if (null != background) {
            mRefreshableView.setBackgroundDrawable(background);
        }
    }
    if (a.hasValue(R.styleable.PullToRefresh_ptrOverScroll)) {
        mOverScrollEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrOverScroll, true);
    }
    if (a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) {
        mScrollingWhileRefreshingEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled, false);
    }
    // Let the derivative classes have a go at handling attributes, then
    // recycle them...
    handleStyledAttributes(a);
    a.recycle();
    // Finally update the UI for the modes
    updateUIForMode();
}
Also used : ViewConfiguration(android.view.ViewConfiguration) TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable)

Example 69 with ViewConfiguration

use of android.view.ViewConfiguration in project android-undergarment by EddieRingle.

the class DrawerGarment method onInterceptTouchEvent.

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final ViewConfiguration vc = ViewConfiguration.get(getContext());
    final float touchThreshold = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30.0f, getResources().getDisplayMetrics());
    final int widthPixels = getResources().getDisplayMetrics().widthPixels;
    final double hypo;
    final boolean overcameSlop;
    /* Immediately bomb out if the drawer is disabled */
    if (!mDrawerEnabled) {
        return false;
    }
    /*
         * ...otherwise, handle the various types of input events.
         */
    switch(ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            /*
                * Record the starting X and Y positions for the possible gesture.
                */
            mGestureStartX = mGestureCurrentX = (int) (ev.getX() + 0.5f);
            mGestureStartY = mGestureCurrentY = (int) (ev.getY() + 0.5f);
            if (mGestureStartX < touchThreshold && !mDrawerOpened) {
                mGestureStarted = true;
            }
            if (mGestureStartX > mDrawerWidth && mDrawerOpened) {
                mGestureStarted = true;
            }
            if (mDrawerMoving && mGestureStartX > mDecorOffsetX) {
                return true;
            }
            /*
                * We still want to return false here since we aren't positive we've got a gesture
                * we want just yet.
                */
            return false;
        case MotionEvent.ACTION_MOVE:
            /* Make sure the gesture was started within 30dp of the screen's left edge. */
            if (!mGestureStarted) {
                return false;
            }
            /* Make sure we're not going backwards, but only if the drawer isn't open yet */
            if (!mDrawerOpened && (ev.getX() < mGestureCurrentX || ev.getX() < mGestureStartX)) {
                return (mGestureStarted = false);
            }
            /*
                * Update the current X and Y positions for the gesture.
                */
            mGestureCurrentX = (int) (ev.getX() + 0.5f);
            mGestureCurrentY = (int) (ev.getY() + 0.5f);
            /*
                * Decide whether there is enough movement to do anything real.
                */
            hypo = Math.hypot(mGestureCurrentX - mGestureStartX, mGestureCurrentY - mGestureStartY);
            overcameSlop = hypo > vc.getScaledTouchSlop();
            /*
                * If the last check is true, we'll start handling events in DrawerGarment's
                * onTouchEvent(MotionEvent) method from now on.
                */
            return overcameSlop;
        case MotionEvent.ACTION_UP:
            mGestureStarted = false;
            /*
                * If we just tapped the right edge with the drawer open, close the drawer.
                */
            if (mGestureStartX > mDrawerWidth && mDrawerOpened) {
                closeDrawer();
                mGestureStartX = mGestureCurrentX = -1;
                mGestureStartY = mGestureCurrentY = -1;
                return true;
            } else {
                mGestureStartX = mGestureCurrentX = -1;
                mGestureStartY = mGestureCurrentY = -1;
                return false;
            }
    }
    return false;
}
Also used : ViewConfiguration(android.view.ViewConfiguration)

Example 70 with ViewConfiguration

use of android.view.ViewConfiguration in project android-undergarment by EddieRingle.

the class DrawerGarment method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent event) {
    final ViewConfiguration vc = ViewConfiguration.get(getContext());
    final int widthPixels = getResources().getDisplayMetrics().widthPixels;
    final int deltaX = (int) (event.getX() + 0.5f) - mGestureCurrentX;
    final int deltaY = (int) (event.getY() + 0.5f) - mGestureCurrentY;
    /*
         * Obtain a new VelocityTracker if we don't already have one. Also add this MotionEvent
         * to the new/existing VelocityTracker so we can determine flings later on.
         */
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    /*
         * Update the current X and Y positions for the ongoing gesture.
         */
    mGestureCurrentX = (int) (event.getX() + 0.5f);
    mGestureCurrentY = (int) (event.getY() + 0.5f);
    switch(event.getAction()) {
        case MotionEvent.ACTION_MOVE:
            mDrawerContent.setVisibility(VISIBLE);
            mDrawerMoving = true;
            if (mDecorOffsetX + deltaX > mDrawerWidth) {
                if (mDecorOffsetX != mDrawerWidth) {
                    mDrawerOpened = true;
                    mDecorContent.offsetLeftAndRight(mDrawerWidth - mDecorOffsetX);
                    mDecorOffsetX = mDrawerWidth;
                    invalidate();
                }
            } else if (mDecorOffsetX + deltaX < 0) {
                if (mDecorOffsetX != 0) {
                    mDrawerOpened = false;
                    mDecorContent.offsetLeftAndRight(0 - mDecorContent.getLeft());
                    mDecorOffsetX = 0;
                    invalidate();
                }
            } else {
                mDecorContent.offsetLeftAndRight(deltaX);
                mDecorOffsetX += deltaX;
                invalidate();
            }
            return true;
        case MotionEvent.ACTION_UP:
            mGestureStarted = false;
            mDrawerMoving = false;
            /*
                * Determine if the user performed a fling based on the final velocity of the
                * gesture.
                */
            mVelocityTracker.computeCurrentVelocity(1000);
            if (Math.abs(mVelocityTracker.getXVelocity()) > vc.getScaledMinimumFlingVelocity()) {
                /*
                    * Okay, the user did a fling, so determine the direction in which
                    * the fling was flung so we know which way to toggle the drawer state.
                    */
                if (mVelocityTracker.getXVelocity() > 0) {
                    mDrawerOpened = false;
                    openDrawer();
                } else {
                    mDrawerOpened = true;
                    closeDrawer();
                }
            } else {
                /*
                    * No sizable fling has been flung, so fling the drawer towards whichever side
                    * we're closest to being flung at.
                    */
                if (mDecorOffsetX > (widthPixels / 2.0)) {
                    mDrawerOpened = false;
                    openDrawer();
                } else {
                    mDrawerOpened = true;
                    closeDrawer();
                }
            }
            return true;
    }
    return false;
}
Also used : ViewConfiguration(android.view.ViewConfiguration)

Aggregations

ViewConfiguration (android.view.ViewConfiguration)186 Scroller (android.widget.Scroller)41 Context (android.content.Context)28 TypedArray (android.content.res.TypedArray)23 EdgeEffectCompat (android.support.v4.widget.EdgeEffectCompat)16 Point (android.graphics.Point)12 View (android.view.View)12 OverScroller (android.widget.OverScroller)10 Field (java.lang.reflect.Field)9 Resources (android.content.res.Resources)8 Paint (android.graphics.Paint)7 RectF (android.graphics.RectF)7 DisplayMetrics (android.util.DisplayMetrics)7 Drawable (android.graphics.drawable.Drawable)6 GestureDetector (android.view.GestureDetector)6 PointF (android.graphics.PointF)5 ImageView (android.widget.ImageView)5 FlingAnimationUtils (com.android.systemui.statusbar.FlingAnimationUtils)5 SlidingTabLayout (com.google.samples.apps.iosched.ui.widget.SlidingTabLayout)4 TimeInterpolator (android.animation.TimeInterpolator)3