Example usage for android.view ViewConfiguration getScaledMinimumFlingVelocity

List of usage examples for android.view ViewConfiguration getScaledMinimumFlingVelocity

Introduction

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

Prototype

public int getScaledMinimumFlingVelocity() 

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
 */// w w  w . j  a  v a2 s  .  com
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.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);//from w  ww.  j  a  va2s .co  m
    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: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.  ja v  a  2 s .  com
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.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java

/**
 * Constructs a new {@code SwipeTouchListener} for the given {@link android.widget.AbsListView}.
 *//*from   www  . ja  v  a 2  s . com*/
@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;
}

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  . j  a 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.goka.flickableview.ImageViewTouchBase.java

protected void init(Context context, AttributeSet attrs, int defStyle) {
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMinFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = configuration.getScaledMaximumFlingVelocity();
    mDefaultAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    setScaleType(ScaleType.MATRIX);//from  w ww .j av a2 s .  c  o  m
}

From source file:net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.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 callbacks The callback to trigger when the user has indicated that she would like to
 *                  dismiss one or more list items.
 *//* www. j a va2  s .  c  o  m*/
public SwipeDismissListViewTouchListener(ListView listView, DismissCallbacks callbacks) {
    ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime = listView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
    mListView = listView;
    mCallbacks = callbacks;

    // Initialize undo popup
    LayoutInflater inflater = (LayoutInflater) listView.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View undoView = inflater.inflate(R.layout.undo_popup, null);
    mUndoButton = (Button) undoView.findViewById(R.id.undo);
    mUndoButton.setOnClickListener(new UndoClickListener());
    mUndoButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // If the user touches the screen invalidate the current running delay by incrementing
            // the valid message id. So this delay won't hide the undo popup anymore
            mValidDelayedMsgId++;
            return false;
        }
    });
    mUndoPopupTextView = (TextView) undoView.findViewById(R.id.text);

    mUndoPopup = new PopupWindow(undoView, ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, false);
    mUndoPopup.setAnimationStyle(R.style.Animations_PopUpMenu_Fade);

    mScreenDensity = listView.getResources().getDisplayMetrics().density;
    // END initialize undo popup

    mListView.setOnTouchListener(this);
    // Setting this scroll listener is required to ensure that during ListView scrolling,
    // we don't look for swipes.
    mListView.setOnScrollListener(makeScrollListener());
}

From source file:com.slidinglayer.SlidingPanel.java

private void init() {
    setWillNotDraw(false);//from ww w.j  av a2s . c  om
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sMenuInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    final float density = context.getResources().getDisplayMetrics().density;
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    setOffsetWidth((int) (DEFAULT_OFFSET * density + 0.5f));
}

From source file:com.android.photos.views.GalleryThumbnailView.java

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

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = new OverScroller(context);

    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);
    setWillNotDraw(false);/*  www .  j a  va2s.co m*/
    setClipToPadding(false);
}

From source file:com.gu.swiperefresh.SwipeRefreshPlush.java

public SwipeRefreshPlush(Context context, AttributeSet attrs) {
    super(context, attrs);
    mLoadViewController = new LoadViewController(context, this);
    mRefreshController = new RefreshViewController(context, this);
    //   mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
    mScroller = ScrollerCompat.create(getContext());
    createProgressView();//from w w w  .jav a2s  .c  o  m
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
}