下面列出了android.view.ViewConfiguration#getScaledMinimumFlingVelocity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
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);
}
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
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();
}
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();
}
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);
}
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();
}
/**
* 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();
}
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();
}
/**
* 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;
}
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);
}
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();
}
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);
}
/**
* 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();
}
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();
}
FlingGestureListener(Context context) {
this.mMinFlingDistance = DipUtils.dipToPx(context, MIN_FLING_DISTANCE_DIP);
final ViewConfiguration configuration = ViewConfiguration.get(context);
this.mMinVelocity = configuration.getScaledMinimumFlingVelocity();
}
@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();
}
@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);
}