List of usage examples for android.view ViewConfiguration getScaledMaximumFlingVelocity
public int getScaledMaximumFlingVelocity()
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 2s .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: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. *///ww w . j a va 2s.c o m 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.coco.slidinguppanel.SlidingUpPanel.java
private void initSlidingUpPanel() { setWillNotDraw(false);/*from w ww . ja v a 2s . c o m*/ setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); final ViewConfiguration configuration = ViewConfiguration.get(context); final float density = context.getResources().getDisplayMetrics().density; mScroller = new Scroller(context, new BounceInterpolator()); mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.blestep.sportsbracelet.view.TimelineChartViewSleep.java
private void init(Context ctx, AttributeSet attrs, int defStyleAttr) { mUiHandler = new Handler(Looper.getMainLooper(), mMessenger); final Resources res = getResources(); final ViewConfiguration vc = ViewConfiguration.get(ctx); mTouchSlop = vc.getScaledTouchSlop() / 2; mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity(); mScroller = new OverScroller(ctx); int footerLabelColor = ContextCompat.getColor(getContext(), R.color.tlcSleepFooterLabelColor); int barItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepBarItemBg); int highlightBarItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepHighlightBarItemBg); int barDeepItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepBarDeepItemBg); int highlightBarDeepItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepHighlightBarDeepItemBg); mBarItemBgPaint = new Paint(); mBarItemBgPaint.setColor(barItemBg); mHighlightBarItemBgPaint = new Paint(); mHighlightBarItemBgPaint.setColor(highlightBarItemBg); mBarDeepItemBgPaint = new Paint(); mBarDeepItemBgPaint.setColor(barDeepItemBg); mHighlightBarDeepItemBgPaint = new Paint(); mHighlightBarDeepItemBgPaint.setColor(highlightBarDeepItemBg); mFooterBarHeight = res.getDimension(R.dimen.tlcDefFooterBarHeight); mViewAreaBgPaint = new Paint(); mGraphAreaBgPaint = new Paint(); mGraphAreaBgPaint.setColor(Color.TRANSPARENT); mFooterAreaBgPaint = new Paint(); mFooterAreaBgPaint.setColor(Color.TRANSPARENT); mGraphBottomLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mGraphBottomLinePaint.setColor(Color.WHITE); mGraphBottomLinePaint.setStrokeWidth(1); // labelPaint?? mLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mLabelFgPaint.setColor(footerLabelColor); // DisplayMetrics dp = getResources().getDisplayMetrics(); // float labelSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, res.getDimension(R.dimen.tlcDefFooterLabelSize), dp); mLabelFgPaint.setTextSize(res.getDimension(R.dimen.tlcDefFooterLabelSize)); mHighlightLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mHighlightLabelFgPaint.setColor(Color.WHITE); mHighlightLabelFgPaint.setTextSize(res.getDimension(R.dimen.tlcDefFooterLabelSize)); mBarItemWidth = res.getDimension(R.dimen.tlcDefBarItemWidth); mBarItemSpace = res.getDimension(R.dimen.tlcDefBarItemSpace); mTopSpaceHeight = res.getDimension(R.dimen.tlcDefTopSpace); // SurfaceView requires a background if (getBackground() == null) { setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); }//from ww w . ja v a2s . c om // Initialize stuff setupBackgroundHandler(); setupTickLabels(); // Initialize the drawing refs (this will be update when we have // the real size of the canvas) computeBoundAreas(); }
From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java
/** * Constructs a new {@code SwipeTouchListener} for the given {@link android.widget.AbsListView}. */// ww w . j av a 2 s. co 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; }
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);// w ww .ja v a 2s . 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. *//*from w w w. j ava2 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.blestep.sportsbracelet.view.TimelineChartView.java
private void init(Context ctx, AttributeSet attrs, int defStyleAttr) { mUiHandler = new Handler(Looper.getMainLooper(), mMessenger); final Resources res = getResources(); final ViewConfiguration vc = ViewConfiguration.get(ctx); mTouchSlop = vc.getScaledTouchSlop() / 2; mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity(); mScroller = new OverScroller(ctx); int footerLabelColor = ContextCompat.getColor(getContext(), R.color.tlcStepsFooterLabelColor); int barItemBg = ContextCompat.getColor(getContext(), R.color.tlcStepsBarItemBg); int highlightBarItemBg = ContextCompat.getColor(getContext(), R.color.tlcStepsHighlightBarItemBg); mBarItemBgPaint = new Paint(); mBarItemBgPaint.setColor(barItemBg); mHighlightBarItemBgPaint = new Paint(); mHighlightBarItemBgPaint.setColor(highlightBarItemBg); mFooterBarHeight = res.getDimension(R.dimen.tlcDefFooterBarHeight); mViewAreaBgPaint = new Paint(); mGraphAreaBgPaint = new Paint(); mGraphAreaBgPaint.setColor(Color.TRANSPARENT); mFooterAreaBgPaint = new Paint(); mFooterAreaBgPaint.setColor(Color.TRANSPARENT); mGraphBottomLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mGraphBottomLinePaint.setColor(Color.WHITE); mGraphBottomLinePaint.setStrokeWidth(1); // /*from w w w . j a v a 2 s .c o m*/ mGraphTargetDashedLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mGraphTargetDashedLinePaint.setStyle(Paint.Style.STROKE); mGraphTargetDashedLinePaint.setColor(Color.WHITE); mGraphTargetDashedLinePaint.setStrokeWidth(1); PathEffect pathEffect = new DashPathEffect(new float[] { 9, 3 }, 1); mGraphTargetDashedLinePaint.setPathEffect(pathEffect); // labelPaint?? mLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mLabelFgPaint.setColor(footerLabelColor); // DisplayMetrics dp = getResources().getDisplayMetrics(); // float labelSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, res.getDimension(R.dimen.tlcDefFooterLabelSize), dp); mLabelFgPaint.setTextSize(res.getDimension(R.dimen.tlcDefFooterLabelSize)); mHighlightLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mHighlightLabelFgPaint.setColor(Color.WHITE); mHighlightLabelFgPaint.setTextSize(res.getDimension(R.dimen.tlcDefFooterLabelSize)); mBarItemWidth = res.getDimension(R.dimen.tlcDefBarItemWidth); mBarItemSpace = res.getDimension(R.dimen.tlcDefBarItemSpace); mTopSpaceHeight = res.getDimension(R.dimen.tlcDefTopSpace); // SurfaceView requires a background if (getBackground() == null) { setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); } // Initialize stuff setupBackgroundHandler(); setupTickLabels(); // Initialize the drawing refs (this will be update when we have // the real size of the canvas) computeBoundAreas(); }
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();/* ww w. j a v a 2s . c om*/ ViewConfiguration mViewConfig = ViewConfiguration.get(getContext()); /** * getScaledTouchSlop????????viewpager??? */ mScaledTouchSlop = mViewConfig.getScaledTouchSlop(); mScroller = new OverScroller(getContext()); mScaledMinimumFlingVelocity = mViewConfig.getScaledMinimumFlingVelocity(); mScaledMaximumFlingVelocity = mViewConfig.getScaledMaximumFlingVelocity(); }
From source file:com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior.java
/** * Default constructor for inflating AnchorBottomSheetBehaviors from layout. * * @param context The {@link Context}./*from ww w . java2s. co m*/ * @param attrs The {@link AttributeSet}. */ public AnchorBottomSheetBehavior(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.BottomSheetBehavior_Layout); TypedValue value = a .peekValue(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight); if (value != null && value.data == PEEK_HEIGHT_AUTO) { setPeekHeight(value.data); } else { setPeekHeight(a.getDimensionPixelSize( android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight, PEEK_HEIGHT_AUTO)); } setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false)); setSkipCollapsed(a.getBoolean( android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false)); a.recycle(); a = context.obtainStyledAttributes(attrs, R.styleable.AnchorBottomSheetBehavior_Layout); mAnchorOffset = (int) a.getDimension(R.styleable.AnchorBottomSheetBehavior_Layout_behavior_anchorOffset, 0); //noinspection WrongConstant mState = a.getInt(R.styleable.AnchorBottomSheetBehavior_Layout_behavior_defaultState, mState); mShouldAnchoredBeforeExpand = a.getBoolean( R.styleable.AnchorBottomSheetBehavior_Layout_behavior_shouldAnchoredBeforeExpand, false); mShouldAnchoredBeforeCollapse = a.getBoolean( R.styleable.AnchorBottomSheetBehavior_Layout_behavior_shouldAnchoredBeforeCollapse, false); mExpandable = a.getBoolean(R.styleable.AnchorBottomSheetBehavior_Layout_behavior_expandable, true); a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); }