Example usage for android.view ViewConfiguration getScaledTouchSlop

List of usage examples for android.view ViewConfiguration getScaledTouchSlop

Introduction

In this page you can find the example usage for android.view ViewConfiguration getScaledTouchSlop.

Prototype

public int getScaledTouchSlop() 

Source Link

Usage

From source file:vc908.stickerfactory.ui.advancedrecyclerview.swipeable.RecyclerViewSwipeManager.java

/**
 * Attaches {@link RecyclerView} instance.
 *
 * Before calling this method, the target {@link RecyclerView} must set
 * the wrapped adapter instance which is returned by the
 * {@link #createWrappedAdapter(RecyclerView.Adapter)} method.
 *
 * @param rv The {@link RecyclerView} instance
 *//*from   w w w  .  j  a v a  2  s.  c o  m*/
public void attachRecyclerView(RecyclerView rv) {
    if (rv == null) {
        throw new IllegalArgumentException("RecyclerView cannot be null");
    }

    if (isReleased()) {
        throw new IllegalStateException("Accessing released object");
    }

    if (mRecyclerView != null) {
        throw new IllegalStateException("RecyclerView instance has already been set");
    }

    if (mAdapter == null || getSwipeableItemWrapperAdapter(rv) != mAdapter) {
        throw new IllegalStateException("adapter is not set properly");
    }

    mRecyclerView = rv;
    mRecyclerView.addOnItemTouchListener(mInternalUseOnItemTouchListener);

    final ViewConfiguration vc = ViewConfiguration.get(rv.getContext());

    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();

    mItemSlideAnimator
            .setImmediatelySetTranslationThreshold((int) (rv.getResources().getDisplayMetrics().density
                    * SLIDE_ITEM_IMMEDIATELY_SET_TRANSLATION_THRESHOLD_DP + 0.5f));
}

From source file:com.lfq.pulltorefresh.library.sideslip.SwipeMenuLayout.java

public SwipeMenuLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SwipeMenuLayout);
    mContentViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_contentViewId, mContentViewId);
    mRightViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_rightViewId, mRightViewId);
    typedArray.recycle();/*from  w w  w. ja  v a2s.  c o  m*/

    ViewConfiguration mViewConfig = ViewConfiguration.get(getContext());
    /**
     *  getScaledTouchSlop????????viewpager???
     */
    mScaledTouchSlop = mViewConfig.getScaledTouchSlop();
    mScroller = new OverScroller(getContext());
    mScaledMinimumFlingVelocity = mViewConfig.getScaledMinimumFlingVelocity();
    mScaledMaximumFlingVelocity = mViewConfig.getScaledMaximumFlingVelocity();
}

From source file:com.tasomaniac.openwith.resolver.ResolverDrawerLayout.java

public ResolverDrawerLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ResolverDrawerLayout, defStyleAttr,
            0);//www . j  ava2s  .  c om
    mMaxWidth = a.getDimensionPixelSize(R.styleable.ResolverDrawerLayout_resolverMaxWidth, -1);
    mMaxCollapsedHeight = a.getDimensionPixelSize(R.styleable.ResolverDrawerLayout_maxCollapsedHeight, 0);
    mMaxCollapsedHeightSmall = a.getDimensionPixelSize(R.styleable.ResolverDrawerLayout_maxCollapsedHeightSmall,
            mMaxCollapsedHeight);
    a.recycle();

    mParentHelper = new NestedScrollingParentHelper(this);

    //noinspection ResourceType
    mScroller = ScrollerCompat.create(context,
            AnimationUtils.loadInterpolator(context, android.R.interpolator.decelerate_quint));
    mVelocityTracker = VelocityTracker.obtain();

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
}

From source file:com.doomonafireball.betterpickers.radialtimepicker.RadialPickerLayout.java

public RadialPickerLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    setOnTouchListener(this);
    ViewConfiguration vc = ViewConfiguration.get(context);
    TOUCH_SLOP = vc.getScaledTouchSlop();
    TAP_TIMEOUT = ViewConfiguration.getTapTimeout();
    mDoingMove = false;//from   www . ja va  2  s  .c om

    mCircleView = new CircleView(context);
    addView(mCircleView);

    mAmPmCirclesView = new AmPmCirclesView(context);
    addView(mAmPmCirclesView);

    mHourRadialTextsView = new RadialTextsView(context);
    addView(mHourRadialTextsView);
    mMinuteRadialTextsView = new RadialTextsView(context);
    addView(mMinuteRadialTextsView);

    mHourRadialSelectorView = new RadialSelectorView(context);
    addView(mHourRadialSelectorView);
    mMinuteRadialSelectorView = new RadialSelectorView(context);
    addView(mMinuteRadialSelectorView);

    // Prepare mapping to snap touchable degrees to selectable degrees.
    preparePrefer30sMap();

    mLastValueSelected = -1;

    mInputEnabled = true;
    mGrayBox = new View(context);
    mGrayBox.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    mGrayBox.setBackgroundColor(getResources().getColor(R.color.transparent_black));
    mGrayBox.setVisibility(View.INVISIBLE);
    addView(mGrayBox);

    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    mTimeInitialized = false;
}

From source file:de.timroes.swipetodismiss.SwipeDismissList.java

/**
 * Constructs a new swipe-to-dismiss touch listener for the given list view.
 *
 * @param listView The list view whose items should be dismissable.
 * @param callback The callback to trigger when the user has indicated that
 * she would like to dismiss one or more list items.
 * @param mode The mode this list handles multiple undos.
 *///w  w w.  j  a va  2 s .  c om
public SwipeDismissList(AbsListView listView, OnDismissCallback callback, UndoMode mode) {

    if (listView == null) {
        throw new IllegalArgumentException("listview must not be null.");
    }

    mHandler = new HideUndoPopupHandler(this);
    mListView = listView;
    mCallback = callback;
    mMode = mode;

    ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime = listView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);

    mDensity = mListView.getResources().getDisplayMetrics().density;

    // -- Load undo popup --
    LayoutInflater inflater = (LayoutInflater) mListView.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.undo_popup, null);
    mUndoButton = (Button) v.findViewById(R.id.undo);
    mUndoButton.setOnClickListener(new UndoHandler());
    mUndoButton.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            // If user tabs "undo" button, reset delay time to remove popup
            mDelayedMsgId++;
            return false;
        }
    });
    mUndoText = (TextView) v.findViewById(R.id.text);

    mUndoPopup = new PopupWindow(v);
    mUndoPopup.setAnimationStyle(R.style.fade_animation);
    // Get scren width in dp and set width respectively
    int xdensity = (int) (mListView.getContext().getResources().getDisplayMetrics().widthPixels / mDensity);
    if (xdensity < 300) {
        mUndoPopup.setWidth((int) (mDensity * 280));
    } else if (xdensity < 350) {
        mUndoPopup.setWidth((int) (mDensity * 300));
    } else if (xdensity < 500) {
        mUndoPopup.setWidth((int) (mDensity * 330));
    } else {
        mUndoPopup.setWidth((int) (mDensity * 450));
    }
    mUndoPopup.setHeight((int) (mDensity * 56));
    // -- END Load undo popu --

    listView.setOnTouchListener(this);
    listView.setOnScrollListener(this.makeScrollListener());
    mEnabled = true;

    switch (mode) {
    case SINGLE_UNDO:
        mUndoActions = new ArrayList<Undoable>(1);
        break;
    default:
        mUndoActions = new ArrayList<Undoable>(10);
        break;
    }

}

From source file:com.codetroopers.betterpickers.radialtimepicker.RadialPickerLayout.java

public RadialPickerLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    setOnTouchListener(this);
    ViewConfiguration vc = ViewConfiguration.get(context);
    TOUCH_SLOP = vc.getScaledTouchSlop();
    TAP_TIMEOUT = ViewConfiguration.getTapTimeout();
    mDoingMove = false;//from  www . j  a v  a  2 s.com

    mCircleView = new CircleView(context);
    addView(mCircleView);

    mAmPmCirclesView = new AmPmCirclesView(context);
    addView(mAmPmCirclesView);

    mHourRadialTextsView = new RadialTextsView(context);
    addView(mHourRadialTextsView);
    mMinuteRadialTextsView = new RadialTextsView(context);
    addView(mMinuteRadialTextsView);

    mHourRadialSelectorView = new RadialSelectorView(context);
    addView(mHourRadialSelectorView);
    mMinuteRadialSelectorView = new RadialSelectorView(context);
    addView(mMinuteRadialSelectorView);

    // Prepare mapping to snap touchable degrees to selectable degrees.
    preparePrefer30sMap();

    mLastValueSelected = -1;

    mInputEnabled = true;
    mGrayBox = new View(context);
    mGrayBox.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    mGrayBox.setBackgroundColor(getResources().getColor(R.color.bpTransparent_black));
    mGrayBox.setVisibility(View.INVISIBLE);
    addView(mGrayBox);

    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    mTimeInitialized = false;
}

From source file:com.ninghoo.beta17ma27.weydio2.FastScrollView.FastScroller.java

/**
 * Handles the touch event and determines whether to show the fast scroller (or updates it if
 * it is already showing)./*  w ww  . ja  va2  s.  c o  m*/
 */
public void handleTouchEvent(MotionEvent ev, int downX, int downY, int lastY,
        OnFastScrollStateChangeListener stateChangeListener) {
    ViewConfiguration config = ViewConfiguration.get(mRecyclerView.getContext());

    int action = ev.getAction();
    int y = (int) ev.getY();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (isNearPoint(downX, downY)) {
            mTouchOffset = downY - mThumbPosition.y;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        // Check if we should start scrolling
        if (!mIsDragging && isNearPoint(downX, downY) && Math.abs(y - downY) > config.getScaledTouchSlop()) {
            mRecyclerView.getParent().requestDisallowInterceptTouchEvent(true);
            mIsDragging = true;
            mTouchOffset += (lastY - downY);
            mPopup.animateVisibility(true);
            if (stateChangeListener != null) {
                stateChangeListener.onFastScrollStart();
            }
        }
        if (mIsDragging) {
            // Update the fastscroller section name at this touch position
            int top = 0;
            int bottom = mRecyclerView.getHeight() - mThumbHeight;
            float boundedY = (float) Math.max(top, Math.min(bottom, y - mTouchOffset));
            String sectionName = mRecyclerView.scrollToPositionAtProgress((boundedY - top) / (bottom - top));
            mPopup.setSectionName(sectionName);
            mPopup.animateVisibility(!sectionName.isEmpty());
            mRecyclerView.invalidate(mPopup.updateFastScrollerBounds(mRecyclerView, mThumbPosition.y));
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mTouchOffset = 0;
        if (mIsDragging) {
            mIsDragging = false;
            mPopup.animateVisibility(false);
            if (stateChangeListener != null) {
                stateChangeListener.onFastScrollStop();
            }
        }
        break;
    }
}

From source file:com.simplecityapps.recyclerview_fastscroll.views.FastScroller.java

/**
 * Handles the touch event and determines whether to show the fast scroller (or updates it if
 * it is already showing).//from w ww.  ja va  2  s  .  co m
 */
public void handleTouchEvent(MotionEvent ev, int downX, int downY, int lastY) {
    ViewConfiguration config = ViewConfiguration.get(mRecyclerView.getContext());

    int action = ev.getAction();
    int y = (int) ev.getY();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (isNearPoint(downX, downY)) {
            mTouchOffset = downY - mThumbPosition.y;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        // Check if we should start scrolling
        if (!mIsDragging && isNearPoint(downX, downY) && Math.abs(y - downY) > config.getScaledTouchSlop()) {
            mRecyclerView.getParent().requestDisallowInterceptTouchEvent(true);
            mIsDragging = true;
            mTouchOffset += (lastY - downY);
            mPopup.animateVisibility(true);
        }
        if (mIsDragging) {
            // Update the fastscroller section name at this touch position
            int top = 0;
            int bottom = mRecyclerView.getHeight() - mThumbHeight;
            float boundedY = (float) Math.max(top, Math.min(bottom, y - mTouchOffset));
            String sectionName = mRecyclerView.scrollToPositionAtProgress((boundedY - top) / (bottom - top));
            mPopup.setSectionName(sectionName);
            mPopup.animateVisibility(sectionName.length() > 0);
            mRecyclerView.invalidate(mPopup.updateFastScrollerBounds(mRecyclerView, mThumbPosition.y));
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mTouchOffset = 0;
        if (mIsDragging) {
            mIsDragging = false;
            mPopup.animateVisibility(false);
        }
        break;
    }
}

From source file:com.android.yijiang.kzx.widget.betterpickers.radialtimepicker.RadialPickerLayout.java

public RadialPickerLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    setOnTouchListener(this);
    ViewConfiguration vc = ViewConfiguration.get(context);
    touchSlop = vc.getScaledTouchSlop();
    tapTimeout = ViewConfiguration.getTapTimeout();
    mDoingMove = false;// w w w  .  ja va  2  s .c o m

    mCircleView = new CircleView(context);
    addView(mCircleView);

    mAmPmCirclesView = new AmPmCirclesView(context);
    addView(mAmPmCirclesView);

    mHourRadialTextsView = new RadialTextsView(context);
    addView(mHourRadialTextsView);
    mMinuteRadialTextsView = new RadialTextsView(context);
    addView(mMinuteRadialTextsView);

    mHourRadialSelectorView = new RadialSelectorView(context);
    addView(mHourRadialSelectorView);
    mMinuteRadialSelectorView = new RadialSelectorView(context);
    addView(mMinuteRadialSelectorView);

    // Prepare mapping to snap touchable degrees to selectable degrees.
    preparePrefer30sMap();

    mVibrator = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
    mLastVibrate = 0;
    mLastValueSelected = -1;

    mInputEnabled = true;
    mGrayBox = new View(context);
    mGrayBox.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    mGrayBox.setBackgroundColor(getResources().getColor(R.color.transparent_black));
    mGrayBox.setVisibility(View.INVISIBLE);
    addView(mGrayBox);

    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    mTimeInitialized = false;
}

From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java

/**
 * Constructs a new {@code SwipeTouchListener} for the given {@link android.widget.AbsListView}.
 *///from  w  w  w .  j  a v  a 2 s  .c o  m
@SuppressWarnings("UnnecessaryFullyQualifiedName")
protected SwipeTouchListener(@NonNull final ListViewWrapper listViewWrapper) {
    ViewConfiguration vc = ViewConfiguration.get(listViewWrapper.getListView().getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * MIN_FLING_VELOCITY_FACTOR;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime = listViewWrapper.getListView().getContext().getResources()
            .getInteger(android.R.integer.config_shortAnimTime);
    mListViewWrapper = listViewWrapper;
}