You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*/
private static final int PAGING_TOUCH_SLOP = TOUCH_SLOP * 2;
/**
定义第一次点击和第二次点击可以认为是一次双击之间的距离。单位:dips
*/
private static final int DOUBLE_TAP_SLOP = 100;
/**
Distance in dips a touch needs to be outside of a window's bounds for it to
count as outside for purposes of dismissing the window.
*/
private static final int WINDOW_TOUCH_SLOP = 16;
/**
一个fling最小的速度,单位:dips/s
*/
private static final int MINIMUM_FLING_VELOCITY = 50;
/**
一个fling最大的速度,单位:dips/s
*/
private static final int MAXIMUM_FLING_VELOCITY = 8000;
/**
分发一个重复访问事件的延迟事件,单位:milliseconds
*/
private static final long SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS = 100;
/**
The maximum size of View's drawing cache, expressed in bytes. This size
should be at least equal to the size of the screen in ARGB888 format.
*/ @deprecated
private static final int MAXIMUM_DRAWING_CACHE_SIZE = 480 * 800 * 4; // ARGB8888
/**
滚动和滑动的摩擦系数
*/
private static final float SCROLL_FRICTION = 0.015f;
/**
Max distance in dips to overscroll for edge effects
*/
private static final int OVERSCROLL_DISTANCE = 0;
/**
Max distance in dips to overfling for edge effects
*/
private static final int OVERFLING_DISTANCE = 6;
private final int mEdgeSlop;
private final int mFadingEdgeLength;
private final int mMinimumFlingVelocity;
private final int mMaximumFlingVelocity;
private final int mScrollbarSize;
private final int mTouchSlop;
private final int mDoubleTapTouchSlop;
private final int mPagingTouchSlop;
private final int mDoubleTapSlop;
private final int mWindowTouchSlop;
private final int mMaximumDrawingCacheSize;
private final int mOverscrollDistance;
private final int mOverflingDistance;
private final boolean mFadingMarqueeEnabled;
@see android.util.DisplayMetrics
*/
private ViewConfiguration(Context context) {
final Resources res = context.getResources();
final DisplayMetrics metrics = res.getDisplayMetrics();
final Configuration config = res.getConfiguration();
final float density = metrics.density;
final float sizeAndDensity;
if (config.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE)) {
sizeAndDensity = density * 1.5f;
} else {
sizeAndDensity = density;
}
// Size of the screen in bytes, in ARGB_8888 format
final WindowManager win = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
final Display display = win.getDefaultDisplay();
final Point size = new Point();
display.getRealSize(size);
mMaximumDrawingCacheSize = 4 * size.x * size.y;
跟上面一个函数一样,只不过上面一个是创建一个ViewConfiguration对象,这里是直接通过这个静态方法返回一个对象
*/
public static ViewConfiguration get(Context context) {
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
final int density = (int) (100.0f * metrics.density);
ViewConfiguration configuration = sConfigurations.get(density);
if (configuration == null) {
configuration = new ViewConfiguration(context);
sConfigurations.put(density, configuration);
}
@hide
*/
public static long getSendRecurringAccessibilityEventsInterval() {
return SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS;
}
/**
@return Distance in dips a touch must be outside the bounds of a window for it
to be counted as outside the window for purposes of dismissing that
window.
@deprecated Use {@link #getScaledWindowTouchSlop()} instead.
*/ @deprecated
public static int getWindowTouchSlop() {
return WINDOW_TOUCH_SLOP;
}
/**
@return Distance in pixels a touch must be outside the bounds of a window for it
to be counted as outside the window for purposes of dismissing that window.
*/
public int getScaledWindowTouchSlop() {
return mWindowTouchSlop;
}
/**
@return Minimum velocity to initiate a fling, as measured in dips per second.
@deprecated Use {@link #getScaledMinimumFlingVelocity()} instead.
*/ @deprecated
public static int getMinimumFlingVelocity() {
return MINIMUM_FLING_VELOCITY;
}
/**
@return 得到滑动的最小速度, 以像素/每秒来进行计算
*/
public int getScaledMinimumFlingVelocity() {
return mMinimumFlingVelocity;
}
/**
@return Maximum velocity to initiate a fling, as measured in dips per second.
@deprecated Use {@link #getScaledMaximumFlingVelocity()} instead.
*/ @deprecated
public static int getMaximumFlingVelocity() {
return MAXIMUM_FLING_VELOCITY;
}
/**
@return 得到滑动的最大速度, 以像素/每秒来进行计算
*/
public int getScaledMaximumFlingVelocity() {
return mMaximumFlingVelocity;
}
/**
The maximum drawing cache size expressed in bytes.
@return the maximum size of View's drawing cache expressed in bytes
@deprecated Use {@link #getScaledMaximumDrawingCacheSize()} instead.
*/ @deprecated
public static int getMaximumDrawingCacheSize() {
//noinspection deprecation
return MAXIMUM_DRAWING_CACHE_SIZE;
}
/**
The maximum drawing cache size expressed in bytes.
@return the maximum size of View's drawing cache expressed in bytes
*/
public int getScaledMaximumDrawingCacheSize() {
return mMaximumDrawingCacheSize;
}
/**
@return The maximum distance a View should overscroll by when showing edge effects (in
pixels).
*/
public int getScaledOverscrollDistance() {
return mOverscrollDistance;
}
/**
@return The maximum distance a View should overfling by when showing edge effects (in
pixels).
*/
public int getScaledOverflingDistance() {
return mOverflingDistance;
}
/**
The amount of time that the zoom controls should be
displayed on the screen expressed in milliseconds.
@return the time the zoom controls should be visible expressed
in milliseconds.
*/
public static long getZoomControlsTimeout() {
return ZOOM_CONTROLS_TIMEOUT;
}
/**
The amount of time a user needs to press the relevant key to bring up
the global actions dialog.
@return how long a user needs to press the relevant key to bring up
the global actions dialog.
*/
public static long getGlobalActionKeyTimeout() {
return GLOBAL_ACTIONS_KEY_TIMEOUT;
}
/**
The amount of friction applied to scrolls and flings.
@return A scalar dimensionless value representing the coefficient of
friction.
*/
public static float getScrollFriction() {
return SCROLL_FRICTION;
}
/**
Report if the device has a permanent menu key available to the user.
As of Android 3.0, devices may not have a permanent menu key available.
Apps should use the action bar to present menu options to users.
However, there are some apps where the action bar is inappropriate
or undesirable. This method may be used to detect if a menu key is present.
If not, applications should provide another on-screen affordance to access
functionality.
@return true if a permanent menu key is present, false otherwise.
*/
public boolean hasPermanentMenuKey() {
return sHasPermanentMenuKey;
}
ViewConfiguration这个类主要定义了UI中所使用到的标准常量,像超时、尺寸、距离,如果我们需要得到这些常量的数据,我们就可以通过这个类来获取,具体方法如下:
1、获取ViewConfiguration对象,由于ViewConfiguration的构造方法为私有的,只能通过这个静态方法来获取到该对象。
ViewConfiguration configure = ViewConfiguration.get(context);
2、通过该对象调用相关的函数,将返回相关的常量数据。
最后附上一些这个类文件源码,这里面所有的方法基本都是用来获取常量数据的,没有什么业务操作。
import android.app.AppGlobals;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.os.RemoteException;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.SparseArray;
/**
主要用来获取一些在UI中所使用到的标准常量,像超时、尺寸、距离
/
public class ViewConfiguration {
/*
*/
private static final int SCROLL_BAR_SIZE = 10;
/**
*/
private static final int SCROLL_BAR_FADE_DURATION = 250;
/**
*/
private static final int SCROLL_BAR_DEFAULT_DELAY = 300;
/**
*/
private static final int FADING_EDGE_LENGTH = 12;
/**
*/
private static final int PRESSED_STATE_DURATION = 64;
/**
*/
private static final int DEFAULT_LONG_PRESS_TIMEOUT = 500;
/**
*/
private static final int KEY_REPEAT_DELAY = 50;
/**
*/
private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;
/**
*/
private static final int TAP_TIMEOUT = 180;
/**
*/
private static final int JUMP_TAP_TIMEOUT = 500;
/**
*/
private static final int DOUBLE_TAP_TIMEOUT = 300;
/**
*/
private static final int DOUBLE_TAP_MIN_TIME = 40;
/**
*/
private static final int HOVER_TAP_TIMEOUT = 150;
/**
*/
private static final int HOVER_TAP_SLOP = 20;
/**
*/
private static final int ZOOM_CONTROLS_TIMEOUT = 3000;
/**
*/
private static final int EDGE_SLOP = 12;
/**
*/
private static final int TOUCH_SLOP = 8;
/**
*/
private static final int DOUBLE_TAP_TOUCH_SLOP = TOUCH_SLOP;
/**
*/
private static final int PAGING_TOUCH_SLOP = TOUCH_SLOP * 2;
/**
*/
private static final int DOUBLE_TAP_SLOP = 100;
/**
*/
private static final int WINDOW_TOUCH_SLOP = 16;
/**
*/
private static final int MINIMUM_FLING_VELOCITY = 50;
/**
*/
private static final int MAXIMUM_FLING_VELOCITY = 8000;
/**
*/
private static final long SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS = 100;
/**
*/
@deprecated
private static final int MAXIMUM_DRAWING_CACHE_SIZE = 480 * 800 * 4; // ARGB8888
/**
*/
private static final float SCROLL_FRICTION = 0.015f;
/**
*/
private static final int OVERSCROLL_DISTANCE = 0;
/**
*/
private static final int OVERFLING_DISTANCE = 6;
private final int mEdgeSlop;
private final int mFadingEdgeLength;
private final int mMinimumFlingVelocity;
private final int mMaximumFlingVelocity;
private final int mScrollbarSize;
private final int mTouchSlop;
private final int mDoubleTapTouchSlop;
private final int mPagingTouchSlop;
private final int mDoubleTapSlop;
private final int mWindowTouchSlop;
private final int mMaximumDrawingCacheSize;
private final int mOverscrollDistance;
private final int mOverflingDistance;
private final boolean mFadingMarqueeEnabled;
private boolean sHasPermanentMenuKey;
private boolean sHasPermanentMenuKeySet;
static final SparseArray sConfigurations =
new SparseArray(2);
/**
*/
@deprecated
public ViewConfiguration() {
mEdgeSlop = EDGE_SLOP;
mFadingEdgeLength = FADING_EDGE_LENGTH;
mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY;
mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
mScrollbarSize = SCROLL_BAR_SIZE;
mTouchSlop = TOUCH_SLOP;
mDoubleTapTouchSlop = DOUBLE_TAP_TOUCH_SLOP;
mPagingTouchSlop = PAGING_TOUCH_SLOP;
mDoubleTapSlop = DOUBLE_TAP_SLOP;
mWindowTouchSlop = WINDOW_TOUCH_SLOP;
//noinspection deprecation
mMaximumDrawingCacheSize = MAXIMUM_DRAWING_CACHE_SIZE;
mOverscrollDistance = OVERSCROLL_DISTANCE;
mOverflingDistance = OVERFLING_DISTANCE;
mFadingMarqueeEnabled = true;
}
/**
使用给定的context来创建一个新的配置。这个配置依赖于context里面不同的参数,例如显示的尺寸或者密度
@param context 用来初始化这个view配置的应用上下文环境
@see #get(android.content.Context)
@see android.util.DisplayMetrics
*/
private ViewConfiguration(Context context) {
final Resources res = context.getResources();
final DisplayMetrics metrics = res.getDisplayMetrics();
final Configuration config = res.getConfiguration();
final float density = metrics.density;
final float sizeAndDensity;
if (config.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE)) {
sizeAndDensity = density * 1.5f;
} else {
sizeAndDensity = density;
}
mEdgeSlop = (int) (sizeAndDensity * EDGE_SLOP + 0.5f);
mFadingEdgeLength = (int) (sizeAndDensity * FADING_EDGE_LENGTH + 0.5f);
mMinimumFlingVelocity = (int) (density * MINIMUM_FLING_VELOCITY + 0.5f);
mMaximumFlingVelocity = (int) (density * MAXIMUM_FLING_VELOCITY + 0.5f);
mScrollbarSize = (int) (density * SCROLL_BAR_SIZE + 0.5f);
mDoubleTapSlop = (int) (sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f);
mWindowTouchSlop = (int) (sizeAndDensity * WINDOW_TOUCH_SLOP + 0.5f);
// Size of the screen in bytes, in ARGB_8888 format
final WindowManager win = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
final Display display = win.getDefaultDisplay();
final Point size = new Point();
display.getRealSize(size);
mMaximumDrawingCacheSize = 4 * size.x * size.y;
mOverscrollDistance = (int) (sizeAndDensity * OVERSCROLL_DISTANCE + 0.5f);
mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f);
if (!sHasPermanentMenuKeySet) {
IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
try {
sHasPermanentMenuKey = !wm.hasNavigationBar();
sHasPermanentMenuKeySet = true;
} catch (RemoteException ex) {
sHasPermanentMenuKey = false;
}
}
mFadingMarqueeEnabled = res.getBoolean(
com.android.internal.R.bool.config_ui_enableFadingMarquee);
mTouchSlop = res.getDimensionPixelSize(
com.android.internal.R.dimen.config_viewConfigurationTouchSlop);
mPagingTouchSlop = mTouchSlop * 2;
mDoubleTapTouchSlop = mTouchSlop;
}
/**
跟上面一个函数一样,只不过上面一个是创建一个ViewConfiguration对象,这里是直接通过这个静态方法返回一个对象
*/
public static ViewConfiguration get(Context context) {
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
final int density = (int) (100.0f * metrics.density);
ViewConfiguration configuration = sConfigurations.get(density);
if (configuration == null) {
configuration = new ViewConfiguration(context);
sConfigurations.put(density, configuration);
}
return configuration;
}
/**
*/
@deprecated
public static int getScrollBarSize() {
return SCROLL_BAR_SIZE;
}
/**
*/
public int getScaledScrollBarSize() {
return mScrollbarSize;
}
/**
*/
public static int getScrollBarFadeDuration() {
return SCROLL_BAR_FADE_DURATION;
}
/**
*/
public static int getScrollDefaultDelay() {
return SCROLL_BAR_DEFAULT_DELAY;
}
/**
*/
@deprecated
public static int getFadingEdgeLength() {
return FADING_EDGE_LENGTH;
}
/**
*/
public int getScaledFadingEdgeLength() {
return mFadingEdgeLength;
}
/**
*/
public static int getPressedStateDuration() {
return PRESSED_STATE_DURATION;
}
/**
*/
public static int getLongPressTimeout() {
return AppGlobals.getIntCoreSetting(Settings.Secure.LONG_PRESS_TIMEOUT,
DEFAULT_LONG_PRESS_TIMEOUT);
}
/**
*/
public static int getKeyRepeatTimeout() {
return getLongPressTimeout();
}
/**
*/
public static int getKeyRepeatDelay() {
return KEY_REPEAT_DELAY;
}
/**
*/
public static int getTapTimeout() {
return TAP_TIMEOUT;
}
/**
*/
public static int getJumpTapTimeout() {
return JUMP_TAP_TIMEOUT;
}
/**
*/
public static int getDoubleTapTimeout() {
return DOUBLE_TAP_TIMEOUT;
}
/**
*/
public static int getDoubleTapMinTime() {
return DOUBLE_TAP_MIN_TIME;
}
/**
*/
public static int getHoverTapTimeout() {
return HOVER_TAP_TIMEOUT;
}
/**
*/
public static int getHoverTapSlop() {
return HOVER_TAP_SLOP;
}
/**
*/
@deprecated
public static int getEdgeSlop() {
return EDGE_SLOP;
}
/**
*/
public int getScaledEdgeSlop() {
return mEdgeSlop;
}
/**
*/
@deprecated
public static int getTouchSlop() {
return TOUCH_SLOP;
}
/**
*/
public int getScaledTouchSlop() {
return mTouchSlop;
}
/**
*/
public int getScaledDoubleTapTouchSlop() {
return mDoubleTapTouchSlop;
}
/**
*/
public int getScaledPagingTouchSlop() {
return mPagingTouchSlop;
}
/**
*/
@deprecated
public static int getDoubleTapSlop() {
return DOUBLE_TAP_SLOP;
}
/**
*/
public int getScaledDoubleTapSlop() {
return mDoubleTapSlop;
}
/**
*/
public static long getSendRecurringAccessibilityEventsInterval() {
return SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS;
}
/**
*/
@deprecated
public static int getWindowTouchSlop() {
return WINDOW_TOUCH_SLOP;
}
/**
*/
public int getScaledWindowTouchSlop() {
return mWindowTouchSlop;
}
/**
*/
@deprecated
public static int getMinimumFlingVelocity() {
return MINIMUM_FLING_VELOCITY;
}
/**
*/
public int getScaledMinimumFlingVelocity() {
return mMinimumFlingVelocity;
}
/**
*/
@deprecated
public static int getMaximumFlingVelocity() {
return MAXIMUM_FLING_VELOCITY;
}
/**
*/
public int getScaledMaximumFlingVelocity() {
return mMaximumFlingVelocity;
}
/**
*/
@deprecated
public static int getMaximumDrawingCacheSize() {
//noinspection deprecation
return MAXIMUM_DRAWING_CACHE_SIZE;
}
/**
*/
public int getScaledMaximumDrawingCacheSize() {
return mMaximumDrawingCacheSize;
}
/**
*/
public int getScaledOverscrollDistance() {
return mOverscrollDistance;
}
/**
*/
public int getScaledOverflingDistance() {
return mOverflingDistance;
}
/**
*/
public static long getZoomControlsTimeout() {
return ZOOM_CONTROLS_TIMEOUT;
}
/**
*/
public static long getGlobalActionKeyTimeout() {
return GLOBAL_ACTIONS_KEY_TIMEOUT;
}
/**
*/
public static float getScrollFriction() {
return SCROLL_FRICTION;
}
/**
As of Android 3.0, devices may not have a permanent menu key available.
*/
public boolean hasPermanentMenuKey() {
return sHasPermanentMenuKey;
}
/**
*/
public boolean isFadingMarqueeEnabled() {
return mFadingMarqueeEnabled;
}
}
The text was updated successfully, but these errors were encountered: