@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fold); mImageView = (ImageView)findViewById(R.id.image_view); mImageView.setPadding(ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING); mImageView.setScaleType(ImageView.ScaleType.FIT_XY); mImageView.setImageDrawable(getResources().getDrawable(R.drawable.image)); mTextureView = new TextureView(this); mTextureView.setSurfaceTextureListener(mSurfaceTextureListener); mAnchorSeekBar = (SeekBar)findViewById(R.id.anchor_seek_bar); mFoldLayout = (FoldingLayout)findViewById(R.id.fold_view); mFoldLayout.setBackgroundColor(Color.BLACK); mFoldLayout.setFoldListener(mOnFoldListener); mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop(); mAnchorSeekBar.setOnSeekBarChangeListener(mSeekBarChangeListener); mScrollGestureDetector = new GestureDetector(this, new ScrollGestureDetector()); mItemSelectedListener = new ItemSelectedListener(); mDefaultPaint = new Paint(); mSepiaPaint = new Paint(); ColorMatrix m1 = new ColorMatrix(); ColorMatrix m2 = new ColorMatrix(); m1.setSaturation(0); m2.setScale(1f, .95f, .82f, 1.0f); m1.setConcat(m2, m1); mSepiaPaint.setColorFilter(new ColorMatrixColorFilter(m1)); }
public void run() { if (isPressed()) { if (mCode != 0) { if (mCode == KeyEvent.KEYCODE_DPAD_LEFT || mCode == KeyEvent.KEYCODE_DPAD_RIGHT) { sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE, System.currentTimeMillis(), false); sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE, System.currentTimeMillis(), false); removeCallbacks(mCheckLongPress); postDelayed(mCheckLongPress, ViewConfiguration.getKeyRepeatDelay()); } else { sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS); sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); } } else { mLongPressConsumed = performLongClick(); } } }
@SuppressLint({"NewApi"}) private void init(Context context, AttributeSet attrs) { setGravity(17); this.mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); DisplayMetrics localDisplayMetrics = new DisplayMetrics(); ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics); this.mScreenHeight = localDisplayMetrics.heightPixels; this.mScreenWidth = localDisplayMetrics.widthPixels; this.mRootView = createRootView(context, attrs); if (attrs != null) { LayoutInflater mLayoutInflater = LayoutInflater.from(getContext()); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PullToZoomView); int zoomViewResId = a.getResourceId(2, 0); if (zoomViewResId > 0) { this.mZoomView = mLayoutInflater.inflate(zoomViewResId, null, false); } int headerViewResId = a.getResourceId(0, 0); if (headerViewResId > 0) { this.mHeaderView = mLayoutInflater.inflate(headerViewResId, null, false); } this.isParallax = a.getBoolean(1, true); handleStyledAttributes(a); a.recycle(); } addView(this.mRootView, -1, -1); }
/** * 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); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); actionBar = getSupportActionBar(); // Hack. Forcing overflow button on actionbar on devices with hardware menu button try { ViewConfiguration config = ViewConfiguration.get(this); Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); if (menuKeyField != null) { menuKeyField.setAccessible(true); menuKeyField.setBoolean(config, false); } } catch (Exception ex) { // Ignore } }
public GooglePhotosGestureDetector(@Nullable Context context, @NonNull GooglePhotosGestureListener listener) { this.gestureListener = listener; gestureHandler = new GestureHandler(); if (context == null) { MIN_FLING_VELOCITY = ViewConfiguration.getMinimumFlingVelocity(); MAX_FLING_VELOCITY = ViewConfiguration.getMaximumFlingVelocity(); DOUBLE_TAP_SLOP = 100; SCALE_SPAN_SLOP = 16; } else { ViewConfiguration config = ViewConfiguration.get(context); MIN_FLING_VELOCITY = config.getScaledMinimumFlingVelocity(); MAX_FLING_VELOCITY = config.getScaledMaximumFlingVelocity(); DOUBLE_TAP_SLOP = config.getScaledDoubleTapSlop(); SCALE_SPAN_SLOP = config.getScaledTouchSlop() * 2; } }
@Override public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case ACTION_DOWN: view.postDelayed(repeater, ViewConfiguration.getKeyRepeatTimeout()); performHapticFeedback(KEYBOARD_TAP); return false; case ACTION_CANCEL: case ACTION_UP: view.removeCallbacks(repeater); return false; default: return false; } }
/** * Configure the scrolling touch slop for a specific use case. * * Set up the RecyclerView's scrolling motion threshold based on common usages. * Valid arguments are {@link #TOUCH_SLOP_DEFAULT} and {@link #TOUCH_SLOP_PAGING}. * * @param slopConstant One of the <code>TOUCH_SLOP_</code> constants representing * the intended usage of this RecyclerView */ public void setScrollingTouchSlop(int slopConstant) { final ViewConfiguration vc = ViewConfiguration.get(getContext()); switch (slopConstant) { default: Log.w(TAG, "setScrollingTouchSlop(): bad argument constant " + slopConstant + "; using default value"); // fall-through case TOUCH_SLOP_DEFAULT: mTouchSlop = vc.getScaledTouchSlop(); break; case TOUCH_SLOP_PAGING: mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(vc); break; } }
@TargetApi(14) private boolean hasNavBar(Context context) { Resources res = context.getResources(); int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android"); if (resourceId != 0) { boolean hasNav = res.getBoolean(resourceId); // check override flag (see static block) if ("1".equals(sNavBarOverride)) { hasNav = false; } else if ("0".equals(sNavBarOverride)) { hasNav = true; } return hasNav; } else { // fallback return !ViewConfiguration.get(context).hasPermanentMenuKey(); } }
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) { if (forParent == null) { throw new IllegalArgumentException("Parent view may not be null"); } else if (cb == null) { throw new IllegalArgumentException("Callback may not be null"); } else { this.mParentView = forParent; this.mCallback = cb; ViewConfiguration vc = ViewConfiguration.get(context); this.mEdgeSize = (int) ((20.0f * context.getResources().getDisplayMetrics().density) + 0.5f); this.mTouchSlop = vc.getScaledTouchSlop(); this.mMaxVelocity = (float) vc.getScaledMaximumFlingVelocity(); this.mMinVelocity = (float) vc.getScaledMinimumFlingVelocity(); this.mScroller = ScrollerCompat.create(context, sInterpolator); } }
@SuppressLint("ResourceAsColor") public SlidingLocaleDrawable(Drawable background, int width, int height) { mBackground = background; setDefaultBounds(mBackground); mWidth = width; mHeight = height; mTextPaint = new TextPaint(); mTextPaint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Medium, 18)); mTextPaint.setColor(R.color.latinkeyboard_transparent); mTextPaint.setTextAlign(Align.CENTER); mTextPaint.setAlpha(OPACITY_FULLY_OPAQUE); mTextPaint.setAntiAlias(true); mMiddleX = (mWidth - mBackground.getIntrinsicWidth()) / 2; mLeftDrawable = mRes.getDrawable(R.drawable.sym_keyboard_feedback_language_arrows_left); mRightDrawable = mRes.getDrawable(R.drawable.sym_keyboard_feedback_language_arrows_right); mThreshold = ViewConfiguration.get(mContext).getScaledTouchSlop(); }
/** * @param context The current Android's context. * @param updateHost The {@link LayoutUpdateHost} view for this layout. * @param renderHost The {@link LayoutRenderHost} view for this layout. * @param eventFilter The {@link EventFilter} that is needed for this view. */ public StackLayout(Context context, LayoutUpdateHost updateHost, LayoutRenderHost renderHost, EventFilter eventFilter) { super(context, updateHost, renderHost, eventFilter); final ViewConfiguration configuration = ViewConfiguration.get(context); mMinDirectionThreshold = configuration.getScaledTouchSlop(); mMinShortPressThresholdSqr = configuration.getScaledPagingTouchSlop() * configuration.getScaledPagingTouchSlop(); mMinMaxInnerMargin = (int) (MIN_INNER_MARGIN_PERCENT_DP + 0.5); mFlingSpeed = FLING_SPEED_DP; mStacks = new Stack[2]; mStacks[0] = new Stack(context, this); mStacks[1] = new Stack(context, this); mStackRects = new RectF[2]; mStackRects[0] = new RectF(); mStackRects[1] = new RectF(); mViewContainer = new FrameLayout(getContext()); mSceneLayer = new TabListSceneLayer(); }
public DraggableSquareView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mDragHelper = ViewDragHelper .create(this, 10f, new DragHelperCallback()); moveDetector = new GestureDetectorCompat(context, new MoveDetector()); moveDetector.setIsLongpressEnabled(false); // 不能处理长按事件,否则违背最初设计的初衷 spaceInterval = (int) getResources().getDimension(R.dimen.drag_square_interval); // 小方块之间的间隔 // 滑动的距离阈值由系统提供 ViewConfiguration configuration = ViewConfiguration.get(getContext()); mTouchSlop = configuration.getScaledTouchSlop(); anchorHandler = new Handler() { @Override public void handleMessage(Message msg) { if (draggingView != null) { // 开始移动重心的动画 draggingView.startAnchorAnimation(); } } }; }
/** * Determines whether the user flung the current item to delete it. * * @return the vector at which the item was flung, or null if no fling was detected. */ private PointF isFlingingToDelete(DragSource source) { if (mFlingToDeleteDropTarget == null) return null; if (!source.supportsFlingToDelete()) return null; ViewConfiguration config = ViewConfiguration.get(mLauncher); mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity()); PointF vel = new PointF(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity()); float theta = MAX_FLING_DEGREES + 1; if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) { // Do a quick dot product test to ensure that we are flinging upwards PointF upVec = new PointF(0f, -1f); theta = getAngleBetweenVectors(vel, upVec); } else if (mLauncher.getDeviceProfile().isVerticalBarLayout() && mVelocityTracker.getXVelocity() < mFlingToDeleteThresholdVelocity) { // Remove icon is on left side instead of top, so check if we are flinging to the left. PointF leftVec = new PointF(-1f, 0f); theta = getAngleBetweenVectors(vel, leftVec); } if (theta <= Math.toRadians(MAX_FLING_DEGREES)) { return vel; } return null; }
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) { if (forParent == null) { throw new IllegalArgumentException("Parent view may not be null"); } else if (cb == null) { throw new IllegalArgumentException("Callback may not be null"); } else { this.mParentView = forParent; this.mCallback = cb; ViewConfiguration vc = ViewConfiguration.get(context); this.mEdgeSize = (int) ((TitleBar.BACKBTN_LEFT_MARGIN * context.getResources().getDisplayMetrics().density) + 0.5f); this.mTouchSlop = vc.getScaledTouchSlop(); this.mMaxVelocity = (float) vc.getScaledMaximumFlingVelocity(); this.mMinVelocity = (float) vc.getScaledMinimumFlingVelocity(); this.mScroller = ScrollerCompat.create(context, sInterpolator); } }
@TargetApi(VERSION_CODES.HONEYCOMB_MR1) @Override public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: view.postDelayed(repeater, VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1 ? ViewConfiguration.getKeyRepeatTimeout() : ViewConfiguration.getLongPressTimeout()); performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); return false; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: view.removeCallbacks(repeater); return false; default: return false; } }
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); final float density = context.getResources().getDisplayMetrics().density; mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mLeftEdge = new EdgeEffectCompat(context); mRightEdge = new EdgeEffectCompat(context); 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); } }
@SuppressWarnings("deprecation") public SuperSwipeRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); /** * getScaledTouchSlop是一个距离,表示滑动的时候,手的移动要大于这个距离才开始移动控件。如果小于这个距离就不触发移动控件 */ mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mMediumAnimationDuration = getResources().getInteger( android.R.integer.config_mediumAnimTime); setWillNotDraw(false); mDecelerateInterpolator = new DecelerateInterpolator( DECELERATE_INTERPOLATION_FACTOR); final TypedArray a = context .obtainStyledAttributes(attrs, LAYOUT_ATTRS); setEnabled(a.getBoolean(0, true)); a.recycle(); WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); final DisplayMetrics metrics = getResources().getDisplayMetrics(); mHeaderViewWidth = (int) display.getWidth(); mFooterViewWidth = (int) display.getWidth(); mHeaderViewHeight = (int) (HEADER_VIEW_HEIGHT * metrics.density); mFooterViewHeight = (int) (HEADER_VIEW_HEIGHT * metrics.density); defaultProgressView = new CircleProgressView(getContext()); createHeaderViewContainer(); createFooterViewContainer(); ViewCompat.setChildrenDrawingOrderEnabled(this, true); mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density; density = metrics.density; mTotalDragDistance = mSpinnerFinalOffset; }
public PullRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.refresh_PullRefreshLayout); final int colorsId = a.getResourceId(R.styleable.refresh_PullRefreshLayout_refreshColors, 0); final int colorId = a.getResourceId(R.styleable.refresh_PullRefreshLayout_refreshColor, 0); a.recycle(); mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); int defaultDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime); mDurationToStartPosition = defaultDuration; mDurationToCorrectPosition = defaultDuration; mSpinnerFinalOffset = mTotalDragDistance = dp2px(DRAG_MAX_DISTANCE); mRefreshView = new ImageView(context); if (colorsId > 0) { mColorSchemeColors = context.getResources().getIntArray(colorsId); } else { mColorSchemeColors = new int[]{Color.rgb(0xC9, 0x34, 0x37), Color.rgb(0x37, 0x5B, 0xF1), Color.rgb(0xF7, 0xD2, 0x3E), Color.rgb(0x34, 0xA3, 0x50)}; } if (colorId > 0) { mColorSchemeColors = new int[]{ContextCompat.getColor(context, colorId)}; } setDefaultRefreshStyle(); mRefreshView.setVisibility(View.GONE); setWillNotDraw(false); ViewCompat.setChildrenDrawingOrderEnabled(this, true); }
@Override protected void initViews() { mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop(); mPresenter.initDataBase(); initDrawer(); initAdapter(); mRvNoteList.setAdapter(mAdapter); mRvNoteList.setOnTouchListener(this); mPresenter.initNoteRvLayoutManager(); }
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if (!isEnabled()) { return false; } final int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: { removeAllCallbacks(); mInputText.setVisibility(View.INVISIBLE); mLastDownOrMoveEventY = mLastDownEventY = event.getY(); mLastDownEventTime = event.getEventTime(); mIngonreMoveEvents = false; if (mLastDownEventY < mTopSelectionDividerTop) { if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { mPressedStateHelper.buttonPressDelayed(PressedStateHelper.BUTTON_DECREMENT); } } else if (mLastDownEventY > mBottomSelectionDividerBottom) { if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { mPressedStateHelper.buttonPressDelayed(PressedStateHelper.BUTTON_INCREMENT); } } getParent().requestDisallowInterceptTouchEvent(true); if (!mFlingScroller.isFinished()) { mFlingScroller.forceFinished(true); mAdjustScroller.forceFinished(true); onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } else if (!mAdjustScroller.isFinished()) { mFlingScroller.forceFinished(true); mAdjustScroller.forceFinished(true); } else if (mLastDownEventY < mTopSelectionDividerTop) { postChangeCurrentByOneFromLongPress(false, ViewConfiguration.getLongPressTimeout()); } else if (mLastDownEventY > mBottomSelectionDividerBottom) { postChangeCurrentByOneFromLongPress(true, ViewConfiguration.getLongPressTimeout()); } return true; } } return false; }
/** * initialize method, called inside the Chart.init() method. backwards * compatibility - to not break existing code * * @param res */ @Deprecated public static void init(Resources res) { mMetrics = res.getDisplayMetrics(); // noinspection deprecation mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity(); // noinspection deprecation mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity(); }
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; //Load defaults from resources final Resources res = getResources(); final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color); final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color); final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation); final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color); final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width); final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius); final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered); final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0); mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered); mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation); mPaintPageFill.setStyle(Style.FILL); mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor)); mPaintStroke.setStyle(Style.STROKE); mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor)); mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintFill.setStyle(Style.FILL); mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor)); mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius); mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap); Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setScrollContainer(true); setFocusableInTouchMode(true); final int version = Build.VERSION.SDK_INT; mPostUpdatesOnAnimation = version >= 16; final ViewConfiguration vc = ViewConfiguration.get(context); mTouchSlop = vc.getScaledTouchSlop(); mMinFlingVelocity = vc.getScaledMinimumFlingVelocity(); mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity(); setWillNotDraw(ViewCompat.getOverScrollMode(this) == ViewCompat.OVER_SCROLL_NEVER); mItemAnimator.setListener(mItemAnimatorListener); initAdapterManager(); initChildrenHelper(); // If not explicitly specified this view is important for accessibility. if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } mAccessibilityManager = (AccessibilityManager) getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); setAccessibilityDelegateCompat(new RecyclerViewAccessibilityDelegate(this)); // Create the layoutManager if specified. // Re-set whether nested scrolling is enabled so that it is set on all API levels setNestedScrollingEnabled(true); }
/** * 判断当前用户触摸是否超出了Dialog的显示区域 * * @param context * @param event * @return */ private boolean isOutOfBounds(Context context, MotionEvent event) { final int x = (int) event.getX(); final int y = (int) event.getY(); final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop(); final View decorView = getWindow().getDecorView(); return (x < -slop) || (y < -slop) || (x > (decorView.getWidth() + slop)) || (y > (decorView.getHeight() + slop)); }
/** * Constructor that is called when inflating ISwipeRefreshLayout from XML. * * @param context * @param attrs */ public ISwipeRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mMediumAnimationDuration = getResources().getInteger( android.R.integer.config_mediumAnimTime); setWillNotDraw(false); mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR); final DisplayMetrics metrics = getResources().getDisplayMetrics(); mRefreshViewHeight = (int) (DEFAULT_HEADER_HEIGHT * metrics.density); HEADER_VIEW_MIN_HEIGHT = mRefreshViewHeight; ViewCompat.setChildrenDrawingOrderEnabled(this, true); mTotalDragDistance = (int) (DEFAULT_HEADER_TARGET * metrics.density); mNestedScrollingParentHelper = new NestedScrollingParentHelper(this); mNestedScrollingChildHelper = new NestedScrollingChildHelper(this); setNestedScrollingEnabled(true); final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS); setEnabled(a.getBoolean(0, true)); a.recycle(); //add default refreshview setRefreshHeaderView(new ClassicIRefreshHeaderView(getContext())); }
private void init(Context context, AttributeSet attrs){ //Initially the View is not visible until it is alerted to show at a specific position, sX and sY setVisibility(View.GONE); setLayoutTransition(new ReactionLayoutTransition()); visibilityListeners = new ArrayList<>(); reactionListeners = new ArrayList<>(); vc = ViewConfiguration.get(context); sX = 0f; sY = 0f; //backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); //backgroundPaint.setColor(Color.parseColor("#FFFFFF")); //backgroundPaint.setStyle(Paint.Style.FILL); //backgroundPaint.setAlpha(230); addIcons(context); }
private void init(AttributeSet attrs) { maxFlingVelocity = ViewConfiguration.get(getContext()).getScaledMaximumFlingVelocity(); minFlingVelocity = ViewConfiguration.get(getContext()).getScaledMinimumFlingVelocity(); // touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); gestureDetector = new GestureDetector(getContext(), this); selector = getSelector(); int menuContainerId = 0; HashMap<Gesture, Integer> gestureMenuMap = new HashMap<>(); /* Get attributes from XML. */ if (attrs != null) { TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.GesturedListView); menuContainerId = typedArray.getResourceId(R.styleable.GesturedListView_menu_container, 0); int child; child = typedArray.getInt(R.styleable.GesturedListView_menu_for_fling_left, -1); if (child != -1) { gestureMenuMap.put(Gesture.FLING_LEFT, child); } child = typedArray.getInt(R.styleable.GesturedListView_menu_for_fling_right, -1); if (child != -1) { gestureMenuMap.put(Gesture.FLING_RIGHT, child); } typedArray.recycle(); } /* Disable selector. */ // setSelector(android.R.color.transparent); itemMenus = new GesturedListViewItemMenus(this, gestureMenuMap, menuContainerId); }
/** * 初始化一些滚动的属性 */ private void initScroll() { mScroller = new Scroller(getContext()); //水平垂直 setGravity(Gravity.CENTER_VERTICAL); //水平方向 setOrientation(HORIZONTAL); //视图滚动配置 final ViewConfiguration configuration = ViewConfiguration.get(getContext()); //获取最小滚动距离 mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); //最大滚动距离 mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }
private void init() { scroller = new OverScroller(getContext()); //the touch distance for distinguish touch event between click and scroll touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); popUpView = new PopUpView(); dateData = new ArrayList<>(); currentYear = calendar.get(Calendar.YEAR); addMoreDays(); }
private void init(Context context, AttributeSet attrs, int defStyleAttr) { mScaleTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mMaxVelocity = ViewConfiguration.get(context).getScaledMaximumFlingVelocity(); //初始化滑动帮助类对象 //mScroller = new Scroller(context); //右滑删除功能的开关,默认开 isSwipeEnable = true; //IOS、QQ式交互,默认开 isIos = true; //左滑右滑的开关,默认左滑打开菜单 isLeftSwipe = true; TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeMenuLayout, defStyleAttr, 0); int count = ta.getIndexCount(); for (int i = 0; i < count; i++) { int attr = ta.getIndex(i); //如果引用成AndroidLib 资源都不是常量,无法使用switch case if (attr == R.styleable.SwipeMenuLayout_swipeEnable) { isSwipeEnable = ta.getBoolean(attr, true); } else if (attr == R.styleable.SwipeMenuLayout_ios) { isIos = ta.getBoolean(attr, true); } else if (attr == R.styleable.SwipeMenuLayout_leftSwipe) { isLeftSwipe = ta.getBoolean(attr, true); } } ta.recycle(); }
private void init() { if (pullRefreshEnabled) { mRefreshHeader = new ArrowRefreshHeader(getContext()); mRefreshHeader.setProgressStyle(mRefreshProgressStyle); } LoadingMoreFooter footView = new LoadingMoreFooter(getContext()); footView.setProgressStyle(mLoadingMoreProgressStyle); mFootView = footView; mFootView.setVisibility(GONE); mScaleTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); }
/** * 设备是否有实体菜单 * * @param context * @return */ public static boolean hasHardwareMenuKey(Context context) { boolean flag = false; if (PRE_HC) flag = true; else if (GTE_ICS) { flag = ViewConfiguration.get(context).hasPermanentMenuKey(); } else flag = false; return flag; }
public SwipeMenuLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SwipeMenuLayout); mLeftViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_leftViewId, mLeftViewId); mContentViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_contentViewId, mContentViewId); mRightViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_rightViewId, mRightViewId); typedArray.recycle(); ViewConfiguration mViewConfig = ViewConfiguration.get(getContext()); mScaledTouchSlop = mViewConfig.getScaledTouchSlop(); mScroller = new OverScroller(getContext()); mScaledMinimumFlingVelocity = mViewConfig.getScaledMinimumFlingVelocity(); mScaledMaximumFlingVelocity = mViewConfig.getScaledMaximumFlingVelocity(); }