public bool HasSoftKeys() { bool hasSoftwareKeys; var c = Android.App.Application.Context; if (Build.VERSION.SdkInt >= Build.VERSION_CODES.JellyBeanMr1) { Display d = c.GetSystemService(Context.WindowService).JavaCast <IWindowManager>().DefaultDisplay; DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.GetRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.HeightPixels; int realWidth = realDisplayMetrics.WidthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.GetMetrics(displayMetrics); int displayHeight = displayMetrics.HeightPixels; int displayWidth = displayMetrics.WidthPixels; BottomBarHeight = (realHeight - displayHeight); hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; } else { bool hasMenuKey = ViewConfiguration.Get(c).HasPermanentMenuKey; bool hasBackKey = KeyCharacterMap.DeviceHasKey(Keycode.Back); hasSoftwareKeys = !hasMenuKey && !hasBackKey; } return(hasSoftwareKeys); }
/** * Constructor that is called when inflating SwipeRefreshLayout from XML. * * @param context * @param attrs */ public SwipeRefreshLayout(Context context, IAttributeSet attrs) : base(context, attrs) { mRefreshListener = new CustomRefreshListener(this); mAnimateToCorrectPosition = new CustommAnimateToCorrectPosition(this); mAnimateToStartPosition = new CustommAnimateToStartPosition(this); mTouchSlop = ViewConfiguration.Get(context).ScaledTouchSlop; mMediumAnimationDuration = Resources.GetInteger( AndroidResource.Integer.ConfigMediumAnimTime); SetWillNotDraw(false); mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR); TypedArray a = context.ObtainStyledAttributes(attrs, LAYOUT_ATTRS); Enabled = (a.GetBoolean(0, true)); a.Recycle(); DisplayMetrics metrics = Resources.DisplayMetrics; mCircleWidth = (int)(CIRCLE_DIAMETER * metrics.Density); mCircleHeight = (int)(CIRCLE_DIAMETER * metrics.Density); createProgressView(); ViewCompat.SetChildrenDrawingOrderEnabled(this, true); // the absolute offset has to take into account that the circle starts at an offset mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.Density; mTotalDragDistance = mSpinnerFinalOffset; RequestDisallowInterceptTouchEvent(true); }
void InitCustomViewAbove() { TouchMode = TouchMode.Margin; SetWillNotDraw(false); DescendantFocusability = DescendantFocusability.AfterDescendants; Focusable = true; _scroller = new Scroller(Context, _interpolator); var configuration = ViewConfiguration.Get(Context); _touchSlop = ViewConfigurationCompat.GetScaledPagingTouchSlop(configuration); _minimumVelocity = configuration.ScaledMinimumFlingVelocity; MaximumVelocity = configuration.ScaledMaximumFlingVelocity; var density = Context.Resources.DisplayMetrics.Density; _flingDistance = (int) (MinDistanceForFling*density); PageSelected += (sender, args) => { if (_viewBehind == null) return; switch (args.Position) { case 0: case 2: _viewBehind.ChildrenEnabled = true; break; case 1: _viewBehind.ChildrenEnabled = false; break; } }; }
public CupcakeGestureDetector(Context context) { var configuration = ViewConfiguration.Get(context); MinimumVelocity = configuration.ScaledMinimumFlingVelocity; TouchSlop = configuration.ScaledTouchSlop; }
void ConceptView_Touch_StartDrag(object sender, EventArgs e) { var v = sender as View; var motionEvent = (e as View.TouchEventArgs).Event; switch (motionEvent.Action & MotionEventActions.Mask) { case MotionEventActions.Down: touchDownX = motionEvent.RawX; touchDownY = motionEvent.RawY; break; case MotionEventActions.Move: float deltaX = motionEvent.RawX - touchDownX; float deltaY = motionEvent.RawY - touchDownY; int touchSlop = ViewConfiguration.Get(v.Context).ScaledTouchSlop / 4; if (Math.Abs(deltaX) > touchSlop || Math.Abs(deltaY) > touchSlop) { v.StartDrag(ClipData.NewPlainText("", ""), new View.DragShadowBuilder(v), v, 0); } break; case MotionEventActions.Up: if (!dragActionStartedHandled) { v.PerformClick(); } break; default: break; } }
private bool PointInView(float localX, float localY) { float slop = ViewConfiguration.Get(this.owner.Context).ScaledTouchSlop; return(localX >= -slop && localY >= -slop && localX < ((this.owner.Right - this.owner.Left) + slop) && localY < ((this.owner.Bottom - this.owner.Top) + slop)); }
public CupcakeDetector(Context context) { ViewConfiguration configuration = ViewConfiguration.Get(context); mMinimumVelocity = configuration.ScaledMinimumFlingVelocity; mTouchSlop = configuration.ScaledTouchSlop; }
/** * Constructor that is called when inflating SwipeRefreshLayout from XML. * * @param context * @param attrs */ public SwipeRefreshLayout(Context context, IAttributeSet attrs = null) : base(context, attrs) { _refreshListener = new CustomRefreshListener(this); _animateToCorrectPosition = new CustommAnimateToCorrectPosition(this); _animateToStartPosition = new CustommAnimateToStartPosition(this); _touchSlop = ViewConfiguration.Get(context).ScaledTouchSlop; _mediumAnimationDuration = Resources.GetInteger( AndroidResource.Integer.ConfigMediumAnimTime); SetWillNotDraw(false); _decelerateInterpolator = new DecelerateInterpolator(DecelerateInterpolationFactor); var a = context.ObtainStyledAttributes(attrs, LayoutAttrs); Enabled = (a.GetBoolean(0, true)); a.Recycle(); var metrics = Resources.DisplayMetrics; _circleWidth = (int)(CircleDiameter * metrics.Density); _circleHeight = (int)(CircleDiameter * metrics.Density); CreateProgressView(); #pragma warning disable 618 ViewCompat.SetChildrenDrawingOrderEnabled(this, true); #pragma warning restore 618 // the absolute offset has to take into account that the circle starts at an offset _spinnerFinalOffset = DefaultCircleTarget * metrics.Density; _totalDragDistance = _spinnerFinalOffset; RequestDisallowInterceptTouchEvent(true); }
private void LoadItems() { if (_pages != null) { return; } _pages = new List <PageInfo>(); for (int i = 0; i < TutorialItemModel.Count(); i++) { var page = new PageInfo { ItemModel = TutorialItemModel[i], RootView = new View(Context) }; _pages.Add(page); AddView(page.RootView); } LoadItem(0); PostDelayed(() => LoadItem(1), 200); _mScroller = new Scroller(Context); var configuration = ViewConfiguration.Get(Context); _mTouchSlop = configuration.ScaledTouchSlop; _mMaximumVelocity = configuration.ScaledMaximumFlingVelocity; }
public BottomSheet4StateBehaviour(Context context, IAttributeSet attrs) : base(context, attrs) { using (TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.BottomSheetBehavior_Layout)) { PeekHeight = a.GetDimensionPixelSize(Resource.Styleable.BottomSheetBehavior_Layout_behavior_peekHeight, 0); Hideable = a.GetBoolean(Resource.Styleable.BottomSheetBehavior_Layout_behavior_hideable, false); } /** * Getting the anchorPoint... */ AnchorPoint = DefaultAnchorPoint > PeekHeight ? DefaultAnchorPoint : 0; Collapsible = true; using (TypedArray a1 = context.ObtainStyledAttributes(attrs, Resource.Styleable.CustomBottomSheetBehavior)) { AnchorPoint = (int)a1.GetDimension(Resource.Styleable.CustomBottomSheetBehavior_anchorPoint, DefaultAnchorPoint); // _state = a1.GetInt(Resource.Styleable.CustomBottomSheetBehavior_defaultState, StateCollapsed); _state = a1.GetInt(Resource.Styleable.CustomBottomSheetBehavior_defaultState, StateAnchorPoint); } ViewConfiguration configuration = ViewConfiguration.Get(context); _minimumVelocity = configuration.ScaledMinimumFlingVelocity; _dragCallback = new ViewDragHelperCallback(this); }
public AndroidInputContext(View hostView, Context context, BaseInputHandler inputHandler, IDisplayMetrics displayMetrics) { _hostView = hostView; _inputHandler = inputHandler; _activeInputActions = InputAction.None; var viewConfig = ViewConfiguration.Get(context) ?? throw new NotSupportedException(); _maximumFlingVelocity = viewConfig.ScaledMaximumFlingVelocity; _minimumFlingVelocity = viewConfig.ScaledMinimumFlingVelocity; _touchSlop = viewConfig.ScaledTouchSlop; if (displayMetrics.ZoomLevel.AreEqualEnough(1.0)) { _dpiRatio = 1; _isOffsetPositions = false; } else { _dpiRatio = 1 / displayMetrics.ZoomLevel; _isOffsetPositions = true; } _gestureDetector = new GestureDetectorCompat(context, this); _gestureDetector.SetOnDoubleTapListener(this); hostView.SetOnTouchListener(this); }
/// <summary> /// Initializes the recycler view. /// </summary> public void Init() { handler = new Handler(this); Clickable = true; foreground = FindViewById(Resource.Id.swipe_recycler_view_foreground); if (foreground == null) { throw new Exception("Attempted to create a " + typeof(SwipeMenuLayout).Name + " without a foreground view"); } background = FindViewById(Resource.Id.swipe_recycler_view_background); if (background == null) { throw new Exception("Attempted to create a " + typeof(SwipeMenuLayout).Name + " without a background view"); } viewConfig = ViewConfiguration.Get(Context); isOpen = false; gestureDetector = new GestureDetector(Context, this); openScroller = new Scroller(Context, recyclerView.openInterpolator); closeScroller = new Scroller(Context, recyclerView.closeInterpolator); }
protected TwoFingerGestureDetector(Context context) : base(context) { var config = ViewConfiguration.Get(context); this.mEdgeSlop = config.ScaledEdgeSlop; }
private void Initialize(Context context) { if (!_initialized) { m_TouchSlop = ViewConfiguration.Get(this.Context).ScaledTouchSlop; m_DataSetObserver = new StickyListHeadersListViewObserver(this); m_AdapterHeaderAdapterClickListener = new AdapterHeaderAdapterClickListener(OnHeaderListClickListener, this); base.SetOnScrollListener(this); //null out divider, dividers are handled by adapter so they look good with headers base.Divider = null; base.DividerHeight = 0; m_ViewConfiguration = ViewConfiguration.Get(context); m_ClippingToPadding = true; try { //reflection to get selector ref var absListViewClass = JNIEnv.FindClass(typeof(AbsListView)); var selectorRectId = JNIEnv.GetFieldID(absListViewClass, "mSelectorRect", "()Landroid/graphics/Rect"); var selectorRectField = JNIEnv.GetObjectField(absListViewClass, selectorRectId); m_SelectorRect = Java.Lang.Object.GetObject <Rect>(selectorRectField, JniHandleOwnership.TransferLocalRef); var selectorPositionId = JNIEnv.GetFieldID(absListViewClass, "mSelectorPosition", "()Ljava/lang/Integer"); m_SelectorPositionField = JNIEnv.GetObjectField(absListViewClass, selectorPositionId); } catch (Exception) { } _initialized = true; } }
public int GetNavBarHeight(Context c) { int result = 0; if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich) { bool hasMenuKey = ViewConfiguration.Get(c).HasPermanentMenuKey; bool hasBackKey = KeyCharacterMap.DeviceHasKey(Keycode.Back); if (!hasMenuKey && !hasBackKey) { //The device has a navigation bar Resources resources = c.Resources; var orientation = Resources.Configuration.Orientation; int resourceId; if (IsTablet(c)) { resourceId = resources.GetIdentifier(orientation == AContRes_O.Portrait ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android"); } else { resourceId = resources.GetIdentifier(orientation == AContRes_O.Portrait ? "navigation_bar_height" : "navigation_bar_width", "dimen", "android"); } if (resourceId > 0) { return(Resources.GetDimensionPixelSize(resourceId)); } } } return(result); }
public SlidingUpPanelLayout(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { if (attrs != null) { var defAttrs = context.ObtainStyledAttributes(attrs, DefaultAttrs); if (defAttrs.Length() > 0) { var gravity = defAttrs.GetInt(0, (int)GravityFlags.NoGravity); var gravityFlag = (GravityFlags)gravity; if (gravityFlag != GravityFlags.Top && gravityFlag != GravityFlags.Bottom) { throw new ArgumentException("layout_gravity must be set to either top or bottom"); } _isSlidingUp = gravityFlag == GravityFlags.Bottom; } defAttrs.Recycle(); var ta = context.ObtainStyledAttributes(attrs, Resource.Styleable.SlidingUpPanelLayout); if (ta.Length() > 0) { _panelHeight = ta.GetDimensionPixelSize(Resource.Styleable.SlidingUpPanelLayout_collapsedHeight, -1); _shadowHeight = ta.GetDimensionPixelSize(Resource.Styleable.SlidingUpPanelLayout_shadowHeight, -1); _minFlingVelocity = ta.GetInt(Resource.Styleable.SlidingUpPanelLayout_flingVelocity, DefaultMinFlingVelocity); _coveredFadeColor = ta.GetColor(Resource.Styleable.SlidingUpPanelLayout_fadeColor, DefaultFadeColor); _dragViewResId = ta.GetResourceId(Resource.Styleable.SlidingUpPanelLayout_dragView, -1); } ta.Recycle(); } var density = context.Resources.DisplayMetrics.Density; if (_panelHeight == -1) { _panelHeight = (int)(DefaultPanelHeight * density + 0.5f); } if (_shadowHeight == -1) { _shadowHeight = (int)(DefaultShadowHeight * density + 0.5f); } SetWillNotDraw(false); _dragHelper = ViewDragHelper.Create(this, 0.5f, new DragHelperCallback(this)); _dragHelper.MinVelocity = _minFlingVelocity * density; _canSlide = true; SlidingEnabled = true; var vc = ViewConfiguration.Get(context); _scrollTouchSlop = vc.ScaledTouchSlop; }
/** * Creates a new {@code DragAndDropHandler} for the listview implementation * in given {@link com.nhaarman.listviewanimations.itemmanipulation.dragdrop.DragAndDropListViewWrapper} * * @param dragAndDropListViewWrapper the {@code DragAndDropListViewWrapper} which wraps the listview implementation to use. */ public DragAndDropHandler(DragAndDropListViewWrapper dragAndDropListViewWrapper) { mWrapper = dragAndDropListViewWrapper; if (mWrapper.getAdapter() != null) { setAdapterInternal(mWrapper.getAdapter()); } mScrollHandler = new ScrollHandler(this); mWrapper.setOnScrollListener(mScrollHandler); mDraggableManager = new DefaultDraggableManager(); if (Build.VERSION.SdkInt <= BuildVersionCodes.Kitkat) { mSwitchViewAnimator = new KitKatSwitchViewAnimator(this); } else { mSwitchViewAnimator = new LSwitchViewAnimator(this); } mMobileItemId = INVALID_ID; ViewConfiguration vc = ViewConfiguration.Get(dragAndDropListViewWrapper.getListView().Context); mSlop = vc.ScaledTouchSlop; }
private void init(Context context) { setUseWeekDayAbbreviation(false); dayPaint.TextAlign = Paint.Align.Center; dayPaint.SetStyle(Paint.Style.Stroke); dayPaint.Flags = PaintFlags.AntiAlias; dayPaint.SetTypeface(Typeface.SansSerif); dayPaint.TextSize = textSize; dayPaint.Color = new Color(calenderTextColor); dayPaint.GetTextBounds("31", 0, "31".Length, rect); textHeight = rect.Height() * 3; textWidth = rect.Width() * 2; todayCalender.Time = currentDate; setToMidnight(todayCalender); currentCalender.Time = currentDate; setCalenderToFirstDayOfMonth(calendarWithFirstDayOfMonth, currentDate, -monthsScrolledSoFar, 0); eventsCalendar.FirstDayOfWeek = Calendar.Monday; if (context != null) { screenDensity = context.Resources.DisplayMetrics.Density; ViewConfiguration configuration = ViewConfiguration.Get(context); densityAdjustedSnapVelocity = (int)(screenDensity * SNAP_VELOCITY_DIP_PER_SECOND); maximumVelocity = configuration.ScaledMaximumFlingVelocity; } //just set a default growFactor to draw full calendar when initialised growFactor = Integer.MaxValue; }
/// <summary> /// Initializes a new instance of the <see cref="OsmSharp.Android.UI.TwoFingerGestureDetector"/> class. /// </summary> /// <param name="context">Context.</param> public TwoFingerGestureDetector(Context context) : base(context) { ViewConfiguration config = ViewConfiguration.Get(context); _edgeSlop = config.ScaledEdgeSlop; }
public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (e1 != null && e2 != null) { ViewConfiguration vc = ViewConfiguration.Get(iContext); int swipeMinDistance = vc.ScaledPagingTouchSlop; int swipeThresholdVelocity = vc.ScaledMinimumFlingVelocity; //int swipeMaxOffPath = vc.ScaledTouchSlop; float length = Math.Abs(e1.GetX() - e2.GetX()); float height = Math.Abs(e1.GetY() - e2.GetY()); if (height / length > 0.5f) { return(false); } // right to left swipe if (e1.GetX() - e2.GetX() > swipeMinDistance && Math.Abs(velocityX) > swipeThresholdVelocity) { OnEventSwipe(ESwipeDirection.Left); return(true); } else if (e2.GetX() - e1.GetX() > swipeMinDistance && Math.Abs(velocityX) > swipeThresholdVelocity) { OnEventSwipe(ESwipeDirection.Right); return(true); } } } catch (Exception) { } return(false); }
public SnappyRecyclerView(Context context, Action <int> selectItemAction) : base(context) { var config = ViewConfiguration.Get(Context); _flingThreshold = (int)(config.ScaledMinimumFlingVelocity + 0.3 * config.ScaledMaximumFlingVelocity); SelectItemAction = selectItemAction; }
private void init() { Focusable = true; DescendantFocusability = DescendantFocusability.AfterDescendants; SetWillNotDraw(false); Clickable = true; mTouchSlop = ViewConfiguration.Get(Context).ScaledTouchSlop * 2f; }
private void Initialize() { _scroller = new Scroller(Context); var configuration = ViewConfiguration.Get(Context); _touchSlop = configuration.ScaledTouchSlop; _maximumVelocity = configuration.ScaledMaximumFlingVelocity; }
private void initView() { mDataSetObserver = new DataSetObserverImpl(this); mOnScrollListener = new OnScrollListenerImpl(this); SetOnScrollListener(mOnScrollListener); mTouchSlop = ViewConfiguration.Get(Context).ScaledTouchSlop; initShadow(true); }
internal NativeGestureListener(Android.Views.View view, List <Listener> listeners) { _id = _instances++; //_view = view; _weakReferenceView = new Java.Lang.Ref.WeakReference(view); //Views.Add(_view); _listeners = listeners; _touchSlop = ViewConfiguration.Get(Droid.Settings.Context).ScaledTouchSlop; }
private void InitView() { mDataSetObserver = new PRADataSetObserver(RecreatePinnedShadow, null); // SetOnScrollListener(this); mTouchSlop = ViewConfiguration.Get(Context).ScaledTouchSlop; InitShadow(true); ItemClick -= PRAListView_ItemClick; ItemClick += PRAListView_ItemClick; }
/** * Constructs a new {@code SwipeTouchListener} for the given {@link android.widget.AbsListView}. */ //@SuppressWarnings("UnnecessaryFullyQualifiedName") protected SwipeTouchListener(IListViewWrapper listViewWrapper) { ViewConfiguration vc = ViewConfiguration.Get(listViewWrapper.getListView().Context); mSlop = vc.ScaledTouchSlop; mMinFlingVelocity = vc.ScaledMinimumFlingVelocity * MIN_FLING_VELOCITY_FACTOR; mMaxFlingVelocity = vc.ScaledMaximumFlingVelocity; mAnimationTime = listViewWrapper.getListView().Context.Resources.GetInteger(Android.Resource.Integer.ConfigShortAnimTime); mListViewWrapper = listViewWrapper; }
private void Initialize() { var dm = Resources.DisplayMetrics; scrollThreshold = TypedValue.ApplyDimension(ComplexUnitType.Dip, 75, dm); var conf = ViewConfiguration.Get(Context); touchSlop = conf.ScaledTouchSlop; }
/// <summary> /// Create a ListViewTouchListener for the spoecified list view /// </summary> /// <param name="parentView"></param> public ListViewTouchListener(ListView parentView) { monitoredView = parentView; // Get standard fling specific UI values ViewConfiguration vc = ViewConfiguration.Get(monitoredView.Context); wander = vc.ScaledTouchSlop; minimumFlingVelocity = 2500; }
/// <summary> /// Initializes the recycler view. /// </summary> private void Init() { SetLayoutManager(new LinearLayoutManager(Context)); touchState = ETouchState.None; viewConfig = ViewConfiguration.Get(Context); openInterpolator = new BounceInterpolator(); closeInterpolator = new BounceInterpolator(); swipeDirection = EDirection.Left; swipingEnabled = true; }