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

The following examples show how to use android.view.ViewConfiguration#getScaledMinimumFlingVelocity() . 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 CodenameOne with GNU General Public License v2.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: ResolverDrawerLayout.java    From android-bottomsheet with ISC License 6 votes vote down vote up
public ResolverDrawerLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ResolverDrawerLayout,
            defStyleAttr, 0);
    mMaxWidth = a.getDimensionPixelSize(R.styleable.ResolverDrawerLayout_android_maxWidth, -1);
    mMaxCollapsedHeight = a.getDimensionPixelSize(
            R.styleable.ResolverDrawerLayout_maxCollapsedHeight, 0);
    mMaxCollapsedHeightSmall = a.getDimensionPixelSize(
            R.styleable.ResolverDrawerLayout_maxCollapsedHeightSmall,
            mMaxCollapsedHeight);
    a.recycle();

    mScroller = new OverScroller(context, AnimationUtils.loadInterpolator(context,
            android.R.interpolator.decelerate_quint));
    mVelocityTracker = VelocityTracker.obtain();

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
}
 
Example 3
Source File: ViewDragHelper.java    From WayHoo 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: HorizontalViewPager.java    From DoubleViewPager with Apache License 2.0 6 votes vote down vote up
void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);

    final float density = context.getResources().getDisplayMetrics().density;
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());

    if (ViewCompat.getImportantForAccessibility(this)
            == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this,
                ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
}
 
Example 5
Source File: ViewDragHelper.java    From AndroidSlidingUpPanel 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.
 * If the interpolator is null, the default interpolator will be used.
 *
 * @param context      Context to initialize config-dependent params from
 * @param forParent    Parent view to monitor
 * @param interpolator interpolator for scroller
 */
private ViewDragHelper(Context context, ViewGroup forParent, Interpolator interpolator, 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 = new OverScroller(context, interpolator != null ? interpolator : sInterpolator);
}
 
Example 6
Source File: ViewDragHelper.java    From Muzesto 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 7
Source File: TableFixHeaders.java    From SqliteLookup with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor that is called when inflating a view from XML. This is called
 * when a view is being constructed from an XML file, supplying attributes
 * that were specified in the XML file. This version uses a default style of
 * 0, so the only attribute values applied are those in the Context's Theme
 * and the given AttributeSet.
 * 
 * The method onFinishInflate() will be called after all children have been
 * added.
 * 
 * @param context
 *            The Context the view is running in, through which it can
 *            access the current theme, resources, etc.
 * @param attrs
 *            The attributes of the XML tag that is inflating the view.
 */
public TableFixHeaders(Context context, AttributeSet attrs) {
	super(context, attrs);

	this.headView = null;
	this.rowViewList = new ArrayList<View>();
	this.columnViewList = new ArrayList<View>();
	this.bodyViewTable = new ArrayList<List<View>>();

	this.needRelayout = true;

	this.shadows = new ImageView[4];
	this.shadows[0] = new ImageView(context);
	this.shadows[0].setImageResource(R.drawable.shadow_left);
	this.shadows[1] = new ImageView(context);
	this.shadows[1].setImageResource(R.drawable.shadow_top);
	this.shadows[2] = new ImageView(context);
	this.shadows[2].setImageResource(R.drawable.shadow_right);
	this.shadows[3] = new ImageView(context);
	this.shadows[3].setImageResource(R.drawable.shadow_bottom);

	this.shadowSize = getResources().getDimensionPixelSize(R.dimen.shadow_size);

	this.flinger = new Flinger(context);
	final ViewConfiguration configuration = ViewConfiguration.get(context);
	this.touchSlop = configuration.getScaledTouchSlop();
	this.minimumVelocity = configuration.getScaledMinimumFlingVelocity();
	this.maximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
 
Example 8
Source File: ScrollableLayout.java    From ScrollableLayout 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 9
Source File: ScrollableViewGroup.java    From Klyph with MIT License 5 votes vote down vote up
public ScrollableViewGroup(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
{
  super(paramContext, paramAttributeSet, paramInt);
  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 10
Source File: NestedScrollView.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
private void initScrollView() {
    mScroller = ScrollerCompat.create(getContext(), null);
    setFocusable(true);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setWillNotDraw(false);
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
 
Example 11
Source File: SwipeDialogLayout.java    From UltimateSwipeTool with Apache License 2.0 5 votes vote down vote up
private void init() {
    ViewConfiguration vc = ViewConfiguration.get(mContext);
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime = mContext.getResources().getInteger(
            android.R.integer.config_shortAnimTime);
    setOnTouchListener(this);
}
 
Example 12
Source File: SwipeDismissTouchListener.java    From SimplePomodoro-android with MIT License 5 votes vote down vote up
/**
 * Constructs a new swipe-to-dismiss touch listener for the given view.
 *
 * @param view     The view to make dismissable.
 * @param token    An optional token/cookie object to be passed through to the callback.
 * @param callback The callback to trigger when the user has indicated that she would like to
 *                 dismiss this view.
 */
public SwipeDismissTouchListener(View view, Object token, OnDismissCallback callback) {
    ViewConfiguration vc = ViewConfiguration.get(view.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime = view.getContext().getResources().getInteger(
            android.R.integer.config_shortAnimTime);
    mView = view;
    mToken = token;
    mCallback = callback;
}
 
Example 13
Source File: RefreshLayout.java    From SimpleProject with MIT License 5 votes vote down vote up
private void initView(Context context) {
	setOrientation(VERTICAL);
	mRefreshStatus = REFRESH_STATUS_NONE;
	mScroller = new Scroller(context);
	mScreenHeight = Resources.getSystem().getDisplayMetrics().heightPixels;
	mVelocityTracker = VelocityTracker.obtain();
	ViewConfiguration configuration = ViewConfiguration.get(context);
	mMinVelocity = configuration.getScaledMinimumFlingVelocity();
}
 
Example 14
Source File: SwipeToDismissTouchListener.java    From android-swipe-to-dismiss-undo with MIT License 5 votes vote down vote up
/**
 * Constructs a new swipe-to-dismiss touch listener for the given list view.
 *
 * @param recyclerView  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.
 */
public SwipeToDismissTouchListener(SomeCollectionView recyclerView,
                                   DismissCallbacks<SomeCollectionView> callbacks) {
    ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime = recyclerView.getContext().getResources().getInteger(
            android.R.integer.config_shortAnimTime);
    mRecyclerView = recyclerView;
    mCallbacks = callbacks;
    mHandler = new Handler();
}
 
Example 15
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 16
Source File: RuleView.java    From RulerView with Apache License 2.0 5 votes vote down vote up
public RuleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    initAttrs(context, attrs);

    // 初始化final常量,必须在构造中赋初值
    ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
    TOUCH_SLOP = viewConfiguration.getScaledTouchSlop();
    MIN_FLING_VELOCITY = viewConfiguration.getScaledMinimumFlingVelocity();
    MAX_FLING_VELOCITY = viewConfiguration.getScaledMaximumFlingVelocity();

    convertValue2Number();
    init(context);
}
 
Example 17
Source File: AcDisplayFragment.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Resources res = getResources();
    mConfigWidgetPinDuration = res.getInteger(R.integer.config_maxPinTime);
    mConfigWidgetSelectDelay = res.getInteger(R.integer.config_iconSelectDelayMillis);
    ViewConfiguration vc = ViewConfiguration.get(getActivity());
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();

    // Clock widget
    mClockWidget = getConfig().isCustomWidgetEnabled()
            ? new HostWidget(this, this)
            : new ClockWidget(this, this);

    // Media widget
    MediaController2 mc = MediaController2.newInstance(getActivity()).asyncWrap();
    mMediaControlsHelper = new MediaControlsHelper(mc);
    mMediaControlsHelper.registerListener(new MediaControlsHelper.Callback() {
        @Override
        public void onStateChanged(boolean showing) {
            if (showing) {
                makeMediaWidgetActive();
            } else makeMediaWidgetInactive();
        }
    });
    mMediaWidget = new MediaWidget(this, this);

    // Transitions
    if (Device.hasKitKatApi()) {
        mTransitionJit = new TransitionSet()
                .setOrdering(TransitionSet.ORDERING_TOGETHER)
                .addTransition(new Fade())
                .addTransition(new ChangeBounds());
        mTransitionSwitchScene = new TransitionSet()
                .setOrdering(TransitionSet.ORDERING_TOGETHER)
                .addTransition(new Fade(Fade.OUT).setDuration(200))
                .addTransition(new Fade(Fade.IN).setStartDelay(80))
                .addTransition(new ChangeBounds().setStartDelay(80));
    }

    // Timeout
    mTimeout = isNotDemo()
            ? mActivityAcd.getTimeout()
            : new Timeout();
}
 
Example 18
Source File: ScrollableLayout.java    From Scrollable with Apache License 2.0 4 votes vote down vote up
FlingGestureListener(Context context) {
    this.mMinFlingDistance = DipUtils.dipToPx(context, MIN_FLING_DISTANCE_DIP);

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    this.mMinVelocity = configuration.getScaledMinimumFlingVelocity();
}
 
Example 19
Source File: WheelPicker.java    From WheelPicker with Apache License 2.0 4 votes vote down vote up
public WheelPicker(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WheelPicker);
    int idData = a.getResourceId(R.styleable.WheelPicker_wheel_data, 0);
    mData = Arrays.asList(getResources()
            .getStringArray(idData == 0 ? R.array.WheelArrayDefault : idData));
    mItemTextSize = a.getDimensionPixelSize(R.styleable.WheelPicker_wheel_item_text_size,
            getResources().getDimensionPixelSize(R.dimen.WheelItemTextSize));
    mVisibleItemCount = a.getInt(R.styleable.WheelPicker_wheel_visible_item_count, 7);
    mSelectedItemPosition = a.getInt(R.styleable.WheelPicker_wheel_selected_item_position, 0);
    hasSameWidth = a.getBoolean(R.styleable.WheelPicker_wheel_same_width, false);
    mTextMaxWidthPosition =
            a.getInt(R.styleable.WheelPicker_wheel_maximum_width_text_position, -1);
    mMaxWidthText = a.getString(R.styleable.WheelPicker_wheel_maximum_width_text);
    mSelectedItemTextColor = a.getColor
            (R.styleable.WheelPicker_wheel_selected_item_text_color, -1);
    mItemTextColor = a.getColor(R.styleable.WheelPicker_wheel_item_text_color, 0xFF888888);
    mItemSpace = a.getDimensionPixelSize(R.styleable.WheelPicker_wheel_item_space,
            getResources().getDimensionPixelSize(R.dimen.WheelItemSpace));
    isCyclic = a.getBoolean(R.styleable.WheelPicker_wheel_cyclic, false);
    hasIndicator = a.getBoolean(R.styleable.WheelPicker_wheel_indicator, false);
    mIndicatorColor = a.getColor(R.styleable.WheelPicker_wheel_indicator_color, 0xFFEE3333);
    mIndicatorSize = a.getDimensionPixelSize(R.styleable.WheelPicker_wheel_indicator_size,
            getResources().getDimensionPixelSize(R.dimen.WheelIndicatorSize));
    hasCurtain = a.getBoolean(R.styleable.WheelPicker_wheel_curtain, false);
    mCurtainColor = a.getColor(R.styleable.WheelPicker_wheel_curtain_color, 0x88FFFFFF);
    hasAtmospheric = a.getBoolean(R.styleable.WheelPicker_wheel_atmospheric, false);
    isCurved = a.getBoolean(R.styleable.WheelPicker_wheel_curved, false);
    mItemAlign = a.getInt(R.styleable.WheelPicker_wheel_item_align, ALIGN_CENTER);
    fontPath = a.getString(R.styleable.WheelPicker_wheel_font_path);
    a.recycle();

    // 可见数据项改变后更新与之相关的参数
    // Update relevant parameters when the count of visible item changed
    updateVisibleItemCount();

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.LINEAR_TEXT_FLAG);
    mPaint.setTextSize(mItemTextSize);

    if (fontPath != null) {
        Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontPath);
        setTypeface(typeface);
    }

    // 更新文本对齐方式
    // Update alignment of text
    updateItemTextAlign();

    // 计算文本尺寸
    // Correct sizes of text
    computeTextSize();

    mScroller = new Scroller(getContext());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {
        ViewConfiguration conf = ViewConfiguration.get(getContext());
        mMinimumVelocity = conf.getScaledMinimumFlingVelocity();
        mMaximumVelocity = conf.getScaledMaximumFlingVelocity();
        mTouchSlop = conf.getScaledTouchSlop();
    }
    mRectDrawn = new Rect();

    mRectIndicatorHead = new Rect();
    mRectIndicatorFoot = new Rect();

    mRectCurrentItem = new Rect();

    mCamera = new Camera();

    mMatrixRotate = new Matrix();
    mMatrixDepth = new Matrix();
}
 
Example 20
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);

}