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:com.example.carlitos.swipeitemrecycler.view.animation.swipe_item.swipeable.RecyclerViewSwipeManager.java

/**
 * <p>Attaches {@link android.support.v7.widget.RecyclerView} instance.</p>
 * <p>Before calling this method, the target {@link android.support.v7.widget.RecyclerView} must set
 * the wrapped adapter instance which is returned by the
 * {@link #createWrappedAdapter(android.support.v7.widget.RecyclerView.Adapter)} method.</p>
 *
 * @param rv The {@link android.support.v7.widget.RecyclerView} instance
 *//*from   w  w w.  j a  va2 s.  c o  m*/
public void attachRecyclerView(@NonNull 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");
    }

    final int layoutOrientation = CustomRecyclerViewUtils.getOrientation(rv);
    if (layoutOrientation == CustomRecyclerViewUtils.ORIENTATION_UNKNOWN) {
        throw new IllegalStateException("failed to determine layout orientation");
    }

    mRecyclerView = rv;
    mRecyclerView.addOnItemTouchListener(mInternalUseOnItemTouchListener);

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

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

    mItemSlideAnimator = new ItemSlidingAnimator(mAdapter);
    mItemSlideAnimator
            .setImmediatelySetTranslationThreshold((int) (rv.getResources().getDisplayMetrics().density
                    * SLIDE_ITEM_IMMEDIATELY_SET_TRANSLATION_THRESHOLD_DP + 0.5f));

    mSwipeHorizontal = (layoutOrientation == CustomRecyclerViewUtils.ORIENTATION_VERTICAL);
    mHandler = new InternalHandler(this);
}

From source file:com.github.shareme.gwsmaterialuikit.library.advancerv.swipeable.RecyclerViewSwipeManager.java

/**
 * <p>Attaches {@link RecyclerView} instance.</p>
 * <p>Before calling this method, the target {@link RecyclerView} must set
 * the wrapped adapter instance which is returned by the
 * {@link #createWrappedAdapter(RecyclerView.Adapter)} method.</p>
 *
 * @param rv The {@link RecyclerView} instance
 *///from   w w  w .  j  av a  2s.co m
public void attachRecyclerView(@NonNull RecyclerView rv) {
    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");
    }

    final int layoutOrientation = CustomRecyclerViewUtils.getOrientation(rv);
    if (layoutOrientation == CustomRecyclerViewUtils.ORIENTATION_UNKNOWN) {
        throw new IllegalStateException("failed to determine layout orientation");
    }

    mRecyclerView = rv;
    mRecyclerView.addOnItemTouchListener(mInternalUseOnItemTouchListener);

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

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

    mItemSlideAnimator = new ItemSlidingAnimator(mAdapter);
    mItemSlideAnimator
            .setImmediatelySetTranslationThreshold((int) (rv.getResources().getDisplayMetrics().density
                    * SLIDE_ITEM_IMMEDIATELY_SET_TRANSLATION_THRESHOLD_DP + 0.5f));

    mSwipeHorizontal = (layoutOrientation == CustomRecyclerViewUtils.ORIENTATION_VERTICAL);
    mHandler = new InternalHandler(this);
}

From source file:com.b44t.ui.ActionBar.BottomSheet.java

public BottomSheet(Context context, boolean needFocus) {
    super(context, R.style.TransparentDialog);

    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    }//ww  w.  j a  va2 s  .c o m
    ViewConfiguration vc = ViewConfiguration.get(context);
    touchSlop = vc.getScaledTouchSlop();

    Rect padding = new Rect();
    shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow);
    shadowDrawable.getPadding(padding);
    backgroundPaddingLeft = padding.left;
    backgroundPaddingTop = padding.top;

    container = new ContainerView(getContext());
    container.setBackgroundDrawable(backDrawable);
    focusable = needFocus;
    if (Build.VERSION.SDK_INT >= 21) {
        container.setFitsSystemWindows(true);
        container.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @SuppressLint("NewApi")
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                lastInsets = insets;
                v.requestLayout();
                return insets.consumeSystemWindowInsets();
            }
        });
        container.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }

    ciclePaint.setColor(0xffffffff);
    backDrawable.setAlpha(0);
}

From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java

/**
 * Handles the touch events to dismiss all apps when clicking outside the bounds of the
 * recycler view.// w  w  w.j  ava2  s  .  c  om
 */
private boolean handleTouchEvent(MotionEvent ev) {
    DeviceProfile grid = mLauncher.getDeviceProfile();
    int x = (int) ev.getX();
    int y = (int) ev.getY();

    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mContentBounds.isEmpty()) {
            // Outset the fixed bounds and check if the touch is outside all apps
            Rect tmpRect = new Rect(mContentBounds);
            tmpRect.inset(-grid.allAppsIconSizePx / 2, 0);
            if (ev.getX() < tmpRect.left || ev.getX() > tmpRect.right) {
                mBoundsCheckLastTouchDownPos.set(x, y);
                return true;
            }
        } else {
            // Check if the touch is outside all apps
            if (ev.getX() < getPaddingLeft() || ev.getX() > (getWidth() - getPaddingRight())) {
                mBoundsCheckLastTouchDownPos.set(x, y);
                return true;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mBoundsCheckLastTouchDownPos.x > -1) {
            ViewConfiguration viewConfig = ViewConfiguration.get(getContext());
            float dx = ev.getX() - mBoundsCheckLastTouchDownPos.x;
            float dy = ev.getY() - mBoundsCheckLastTouchDownPos.y;
            float distance = (float) Math.hypot(dx, dy);
            if (distance < viewConfig.getScaledTouchSlop()) {
                // The background was clicked, so just go home
                Launcher launcher = Launcher.getLauncher(getContext());
                launcher.showWorkspace(true);
                return true;
            }
        }
        // Fall through
    case MotionEvent.ACTION_CANCEL:
        mBoundsCheckLastTouchDownPos.set(-1, -1);
        break;
    }
    return false;
}

From source file:com.shizhefei.view.coolrefreshview.CoolRefreshView.java

private void init() {
    mPullHandler = new ProxyPullHeader(HEADER_FACTORY.made(getContext()));
    mIsPinContent = HEADER_FACTORY.isPinContent();
    if (mIsPinContent) {
        scrollerHelper = new PinContentScroller();
    } else {//from w  ww. j  a v  a2  s  . co  m
        scrollerHelper = new AllScroller();
    }
    setWillNotDraw(false);
    addHeadView();
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();

    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);

    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}

From source file:kr.wdream.ui.ActionBar.BottomSheet.java

public BottomSheet(Context context, boolean needFocus) {
    super(context, kr.wdream.storyshop.R.style.TransparentDialog);

    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    }/*www .  j a  va  2 s  .com*/
    ViewConfiguration vc = ViewConfiguration.get(context);
    touchSlop = vc.getScaledTouchSlop();

    Rect padding = new Rect();
    shadowDrawable = context.getResources().getDrawable(kr.wdream.storyshop.R.drawable.sheet_shadow);
    shadowDrawable.getPadding(padding);
    backgroundPaddingLeft = padding.left;
    backgroundPaddingTop = padding.top;

    container = new ContainerView(getContext());
    container.setBackgroundDrawable(backDrawable);
    focusable = needFocus;
    if (Build.VERSION.SDK_INT >= 21) {
        container.setFitsSystemWindows(true);
        container.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @SuppressLint("NewApi")
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                lastInsets = insets;
                v.requestLayout();
                return insets.consumeSystemWindowInsets();
            }
        });
        container.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }

    ciclePaint.setColor(0xffffffff);
    backDrawable.setAlpha(0);
}

From source file:com.borax12.materialdaterangepicker.single.time.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   w w w.  jav  a 2  s.  com

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

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

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

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

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

    mLastValueSelected = null;

    mInputEnabled = true;

    mGrayBox = new View(context);
    mGrayBox.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    mGrayBox.setBackgroundColor(ContextCompat.getColor(context, R.color.mdtp_transparent_black));
    mGrayBox.setVisibility(View.INVISIBLE);
    addView(mGrayBox);

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

    mTimeInitialized = false;
}

From source file:com.bw.luzz.monkeyapplication.View.DateTimePicker.time.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;//  w ww. j  av  a2 s.  co m

    mCircleView = new com.bw.luzz.monkeyapplication.View.DateTimePicker.time.CircleView(context);
    addView(mCircleView);

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

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

    mHourRadialTextsView = new com.bw.luzz.monkeyapplication.View.DateTimePicker.time.RadialTextsView(context);
    addView(mHourRadialTextsView);
    mMinuteRadialTextsView = new com.bw.luzz.monkeyapplication.View.DateTimePicker.time.RadialTextsView(
            context);
    addView(mMinuteRadialTextsView);
    mSecondRadialTextsView = new com.bw.luzz.monkeyapplication.View.DateTimePicker.time.RadialTextsView(
            context);
    addView(mSecondRadialTextsView);

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

    mLastValueSelected = null;

    mInputEnabled = true;

    mGrayBox = new View(context);
    mGrayBox.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    mGrayBox.setBackgroundColor(ContextCompat.getColor(context, R.color.mdtp_transparent_black));
    mGrayBox.setVisibility(View.INVISIBLE);
    addView(mGrayBox);

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

    mTimeInitialized = false;
}

From source file:SwipeListViewTouchListener.java

/**
 * Constructor//from  www. j a v  a 2s  .c om
 *
 * @param swipeListView  SwipeListView
 * @param swipeFrontView front view Identifier
 * @param swipeBackView  back view Identifier
 */
public SwipeListViewTouchListener(SwipeListView swipeListView, int swipeFrontView, int swipeBackView) {
    this.swipeFrontView = swipeFrontView;
    this.swipeBackView = swipeBackView;
    ViewConfiguration vc = ViewConfiguration.get(swipeListView.getContext());
    slop = vc.getScaledTouchSlop();
    minFlingVelocity = vc.getScaledMinimumFlingVelocity();
    maxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    configShortAnimationTime = swipeListView.getContext().getResources()
            .getInteger(android.R.integer.config_shortAnimTime);
    animationTime = configShortAnimationTime;
    this.swipeListView = swipeListView;
}

From source file:lewa.support.v7.widget.SwitchCompat.java

/**
 * Construct a new Switch with a default style determined by the given theme attribute,
 * overriding specific style attributes as requested.
 *
 * @param context The Context that will determine this widget's theming.
 * @param attrs Specification of attributes that should deviate from the default styling.
 * @param defStyleAttr An attribute in the current theme that contains a
 *        reference to a style resource that supplies default values for
 *        the view. Can be 0 to not look for defaults.
 *///ww  w.jav a2s.c o m
public SwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);

    final Resources res = getResources();
    mTextPaint.density = res.getDisplayMetrics().density;

    final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SwitchCompat,
            defStyleAttr, 0);
    mThumbDrawable = a.getDrawable(R.styleable.SwitchCompat_android_thumb);
    mTrackDrawable = a.getDrawable(R.styleable.SwitchCompat_track);
    mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn);
    mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff);
    mShowText = a.getBoolean(R.styleable.SwitchCompat_showText, true);
    mThumbTextPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0);
    mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0);
    mSwitchPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0);
    mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false);

    final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0);
    if (appearance != 0) {
        setSwitchTextAppearance(context, appearance);
    }

    mTintManager = a.getTintManager();

    a.recycle();

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

    // Refresh display with current params
    refreshDrawableState();
    setChecked(isChecked());
}