Java Code Examples for android.view.ViewConfiguration#getScaledTouchSlop()

The following examples show how to use android.view.ViewConfiguration#getScaledTouchSlop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewDragHelper.java    From ting with Apache License 2.0 6 votes vote down vote up
/**
 * Apps should use ViewDragHelper.create() to get a new instance.
 * This will allow VDH to use internal compatibility implementations for different
 * platform versions.
 *
 * @param context Context to initialize config-dependent params from
 * @param forParent Parent view to monitor
 */
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    }
    if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    }

    mParentView = forParent;
    mCallback = cb;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);

    mTouchSlop = vc.getScaledTouchSlop();
    mMaxVelocity = vc.getScaledMaximumFlingVelocity();
    mMinVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.create(context, sInterpolator);
}
 
Example 2
Source File: ViewDragHelper.java    From UltimateSwipeTool with Apache License 2.0 6 votes vote down vote up
/**
 * Apps should use ViewDragHelper.create() to get a new instance. This will
 * allow VDH to use internal compatibility implementations for different
 * platform versions.
 *
 * @param context   Context to init config-dependent params from
 * @param forParent Parent view to monitor
 */
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    }
    if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    }

    mParentView = forParent;
    mCallback = cb;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);

    mTouchSlop = vc.getScaledTouchSlop();
    mMaxVelocity = vc.getScaledMaximumFlingVelocity();
    mMinVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.create(context, sInterpolator);
}
 
Example 3
Source File: ViewDragHelper.java    From CoreModule with Apache License 2.0 6 votes vote down vote up
/**
 * Apps should use ViewDragHelper.create() to get a new instance. This will
 * allow VDH to use internal compatibility implementations for different
 * platform versions.
 *
 * @param context   Context to initialize config-dependent params from
 * @param forParent Parent view to monitor
 */
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    }
    if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    }

    mParentView = forParent;
    mCallback = cb;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);

    mTouchSlop = vc.getScaledTouchSlop();
    mMaxVelocity = vc.getScaledMaximumFlingVelocity();
    mMinVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.create(context, sInterpolator);
}
 
Example 4
Source File: ViewDragHelper.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Apps should use ViewDragHelper.create() to get a new instance. This will
 * allow VDH to use internal compatibility implementations for different
 * platform versions.
 *
 * @param context   Context to initialize config-dependent params from
 * @param forParent Parent view to monitor
 */
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    }
    if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    }

    mParentView = forParent;
    mCallback = cb;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);

    mTouchSlop = vc.getScaledTouchSlop();
    mMaxVelocity = vc.getScaledMaximumFlingVelocity();
    mMinVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.create(context, sInterpolator);
}
 
Example 5
Source File: Switch.java    From PreferenceFragment with Apache License 2.0 5 votes vote down vote up
/**
     * 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 defStyle An attribute ID within the active theme containing a reference to the
     *                 default style for this widget. e.g. android.R.attr.switchStyle.
     */
    public Switch(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        Resources res = getResources();
        mTextPaint.density = res.getDisplayMetrics().density;
//        mTextPaint.setCompatibilityScaling(res.getCompatibilityInfo().applicationScale);

        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.Switch, defStyle, 0);

        mThumbDrawable = a.getDrawable(R.styleable.Switch_thumb);
        mTrackDrawable = a.getDrawable(R.styleable.Switch_track);
        mTextOn = a.getText(R.styleable.Switch_textOn);
        mTextOff = a.getText(R.styleable.Switch_textOff);
        mThumbTextPadding = a.getDimensionPixelSize(
                R.styleable.Switch_thumbTextPadding, 0);
        mSwitchMinWidth = a.getDimensionPixelSize(
                R.styleable.Switch_switchMinWidth, 0);
        mSwitchPadding = a.getDimensionPixelSize(
                R.styleable.Switch_switchPadding, 0);

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

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

        // Refresh display with current params
        refreshDrawableState();
        setChecked(isChecked());
    }
 
Example 6
Source File: ScrollableViewGroup.java    From Klyph with MIT License 5 votes vote down vote up
public ScrollableViewGroup(Context paramContext, AttributeSet paramAttributeSet)
{
  super(paramContext, paramAttributeSet);
  Context localContext = getContext();
  setFocusable(false);
  ViewConfiguration localViewConfiguration = ViewConfiguration.get(localContext);
  this.mTouchSlop = localViewConfiguration.getScaledTouchSlop();
  this.mMinimumVelocity = localViewConfiguration.getScaledMinimumFlingVelocity();
  this.mMaximumVelocity = localViewConfiguration.getScaledMaximumFlingVelocity();
  this.mScroller = new Scroller(localContext, sInterpolator);
}
 
Example 7
Source File: ScaleDragDetector.java    From PicKing with Apache License 2.0 5 votes vote down vote up
public ScaleDragDetector(Context context, OnScaleDragGestureListener scaleDragGestureListener) {
    mScaleDetector = new ScaleGestureDetector(context, this);
    mScaleDragGestureListener = scaleDragGestureListener;

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mTouchSlop = configuration.getScaledTouchSlop();
}
 
Example 8
Source File: SwitchButton.java    From umeng_community_android with MIT License 5 votes vote down vote up
/**
 * 初始化
 * 
 * @param attrs 属性
 */
private void init(AttributeSet attrs) {
    setGravity(Gravity.CENTER_VERTICAL);
    paint = new Paint();
    paint.setColor(Color.RED);
    porterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
    switchScroller = new SwitchScroller(getContext(), new AccelerateDecelerateInterpolator());
    buttonRectF = new RectF();

    setDrawables();
    ViewConfiguration config = ViewConfiguration.get(getContext());
    touchSlop = config.getScaledTouchSlop();
    setChecked(isChecked());
    setClickable(true); // 设置允许点击,当用户点击在按钮其它区域的时候就会切换状态
}
 
Example 9
Source File: UVideoMainView.java    From UCDMediaPlayer_Android with MIT License 5 votes vote down vote up
void init() {
    x1 = -1;
    y1 = -1;
    ViewConfiguration mViewConfiguration = ViewConfiguration.get(getContext());
    minSlideDistance = mViewConfiguration.getScaledTouchSlop();
    minHorizontalSlideDistance = minVerticalSlideDistance = minSlideDistance;
}
 
Example 10
Source File: ScrollableLayout.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
private void init(Context context) {
    mHelper = new ScrollableHelper();
    mScroller = new Scroller(context);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
 
Example 11
Source File: ScaleDragDetector.java    From WaveForm with GNU General Public License v3.0 5 votes vote down vote up
public ScaleDragDetector(Context context, OnScaleDragGestureListener scaleDragGestureListener) {
    mScaleDetector = new ScaleGestureDetector(context, this);
    mScaleDragGestureListener = scaleDragGestureListener;

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mTouchSlop = configuration.getScaledTouchSlop();
}
 
Example 12
Source File: PullRefreshListView.java    From Android-BluetoothKit with Apache License 2.0 5 votes vote down vote up
public void initView() {
	if (hasHeader) {
		mListHeaderView = new PullHeadView(mContext);
		mListHeaderView.setStateListener(this);
		setHeaderDividersEnabled(false);
		setFooterDividersEnabled(false);
		addHeaderView(mListHeaderView, null, false);
		mState = STATE_NORMAL;
		final ViewConfiguration configuration = ViewConfiguration
				.get(mContext);
		mTouchSlop = configuration.getScaledTouchSlop();
	}
	
	super.setOnScrollListener(this);
}
 
Example 13
Source File: TwoDScrollView.java    From AndroidQuick with MIT License 5 votes vote down vote up
private void initTwoDScrollView() {
    mScroller = new Scroller(getContext());
    setFocusable(true);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setWillNotDraw(false);
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
 
Example 14
Source File: CupcakeGestureDetector.java    From RotatePhotoView with Apache License 2.0 4 votes vote down vote up
public CupcakeGestureDetector(Context context) {
    final ViewConfiguration configuration = ViewConfiguration
            .get(context);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mTouchSlop = configuration.getScaledTouchSlop();
}
 
Example 15
Source File: FlexibleSpaceWithImageWithViewPagerTab2Activity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flexiblespacewithimagewithviewpagertab2);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    ViewCompat.setElevation(findViewById(R.id.header), getResources().getDimension(R.dimen.toolbar_elevation));
    mPagerAdapter = new NavigationAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mImageView = findViewById(R.id.image);
    mOverlayView = findViewById(R.id.overlay);
    // Padding for ViewPager must be set outside the ViewPager itself
    // because with padding, EdgeEffect of ViewPager become strange.
    mFlexibleSpaceHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mTabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);
    findViewById(R.id.pager_wrapper).setPadding(0, mFlexibleSpaceHeight, 0, 0);
    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);

    SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    slidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1);
    slidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.accent));
    slidingTabLayout.setDistributeEvenly(true);
    slidingTabLayout.setViewPager(mPager);
    ((FrameLayout.LayoutParams) slidingTabLayout.getLayoutParams()).topMargin = mFlexibleSpaceHeight - mTabHeight;

    ViewConfiguration vc = ViewConfiguration.get(this);
    mSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.container);
    mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);
    mScroller = new OverScroller(getApplicationContext());
    ScrollUtils.addOnGlobalLayoutListener(mInterceptionLayout, new Runnable() {
        @Override
        public void run() {
            // Extra space is required to move mInterceptionLayout when it's scrolled.
            // It's better to adjust its height when it's laid out
            // than to adjust the height when scroll events (onMoveMotionEvent) occur
            // because it causes lagging.
            // See #87: https://github.com/ksoichiro/Android-ObservableScrollView/issues/87
            FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams();
            lp.height = getScreenHeight() + mFlexibleSpaceHeight;
            mInterceptionLayout.requestLayout();

            updateFlexibleSpace();
        }
    });
}
 
Example 16
Source File: RadialPickerLayout.java    From cathode with Apache License 2.0 4 votes vote down vote up
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;

  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;
}
 
Example 17
Source File: CupcakeGestureDetector.java    From AndroidPickPhotoDialog with Apache License 2.0 4 votes vote down vote up
public CupcakeGestureDetector(Context context) {
    final ViewConfiguration configuration = ViewConfiguration
            .get(context);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mTouchSlop = configuration.getScaledTouchSlop();
}
 
Example 18
Source File: FreeFlowContainer.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
protected void init(Context context) {

	viewpool = new ViewPool();
	frames = new LinkedHashMap<Object, FreeFlowItem>();

	ViewConfiguration configuration = ViewConfiguration.get(context);
	maxFlingVelocity = configuration.getScaledMaximumFlingVelocity();
	minFlingVelocity = configuration.getScaledMinimumFlingVelocity();
	overflingDistance = configuration.getScaledOverflingDistance();
	/*overscrollDistance = configuration.getScaledOverscrollDistance();*/

	touchSlop = configuration.getScaledTouchSlop();

	scroller = new OverScroller(context);

	setEdgeEffectsEnabled(true);

}
 
Example 19
Source File: NumberPicker.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void init() {
    mSolidColor = 0;
    mSelectionDivider = new Paint();
    mSelectionDivider.setColor(Theme.getColor(Theme.key_dialogButton));

    mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics());
    mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics());

    mMinHeight = SIZE_UNSPECIFIED;

    mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, getResources().getDisplayMetrics());
    if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) {
        throw new IllegalArgumentException("minHeight > maxHeight");
    }

    mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, getResources().getDisplayMetrics());

    mMaxWidth = SIZE_UNSPECIFIED;
    if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) {
        throw new IllegalArgumentException("minWidth > maxWidth");
    }

    mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED);

    mPressedStateHelper = new PressedStateHelper();

    setWillNotDraw(false);

    mInputText = new TextView(getContext());
    mInputText.setGravity(Gravity.CENTER);
    mInputText.setSingleLine(true);
    mInputText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    mInputText.setBackgroundResource(0);
    mInputText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    mInputText.setVisibility(INVISIBLE);
    addView(mInputText, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mTextSize = (int) mInputText.getTextSize();

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(mTextSize);
    paint.setTypeface(mInputText.getTypeface());
    ColorStateList colors = mInputText.getTextColors();
    int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE);
    paint.setColor(color);
    mSelectorWheelPaint = paint;

    mFlingScroller = new Scroller(getContext(), null, true);
    mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f));

    updateInputTextView();
}
 
Example 20
Source File: ViewDragHelper.java    From ExpressHelper with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the sensitivity of the dragger.
 *
 * @param context     The application context.
 * @param sensitivity value between 0 and 1, the final value for touchSlop =
 *                    ViewConfiguration.getScaledTouchSlop * (1 / s);
 */
public void setSensitivity(Context context, float sensitivity) {
    float s = Math.max(0f, Math.min(1.0f, sensitivity));
    ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
    mTouchSlop = (int) (viewConfiguration.getScaledTouchSlop() * (1 / s));
}