void HScrollViewTouch(object sender, TouchEventArgs e) { try{ e.Handled = false; switch (e.Event.Action) { case MotionEventActions.Move: _deltaXResetTimer.Stop(); _deltaX = _scrollView.ScrollX - _prevScrollX; _prevScrollX = _scrollView.ScrollX; UpdateSelectedIndex(); _deltaXResetTimer.Start(); break; case MotionEventActions.Down: _motionDown = true; _scrollStopTimer.Stop(); break; case MotionEventActions.Up: _motionDown = false; SnapScroll(); _scrollStopTimer.Start(); break; } } catch (System.Exception ex) { Insights.Send("HScrollViewTouch", ex); } }
void UpdateUi(cxLabel view, TextView control) { try{ if (!string.IsNullOrEmpty(view.FontFamily)) { string filename = view.FontFamily; if (filename.LastIndexOf(".", System.StringComparison.Ordinal) != filename.Length - 4) { filename = string.Format("{0}.ttf", filename); } control.Typeface = TrySetFont(filename); } if (view.FontSize > 0) { control.TextSize = (float)view.FontSize; } } catch (System.Exception ex) { Insights.Send("UpdateUi", ex); } }
private void UpdateUi(cxLabel view) { try{ if (view.FontSize > 0) { this.Control.Font = UIFont.FromName(this.Control.Font.Name, (float)view.FontSize); } if (!string.IsNullOrEmpty(view.FontFamily)) { var fontName = Path.GetFileNameWithoutExtension(view.FontFamily); var font = UIFont.FromName(fontName, this.Control.Font.PointSize); if (font != null) { this.Control.Font = font; } } this.Control.AttributedText = new NSMutableAttributedString(view.Text, this.Control.Font); } catch (System.Exception ex) { Insights.Send("UpdateUi", ex); } }
protected override void OnElementChanged(VisualElementChangedEventArgs e) { try{ base.OnElementChanged(e); if (e.NewElement == null) { return; } _deltaXResetTimer = new Timer(100) { AutoReset = false }; _deltaXResetTimer.Elapsed += (object sender, ElapsedEventArgs args) => _deltaX = 0; _scrollStopTimer = new Timer(200) { AutoReset = false }; _scrollStopTimer.Elapsed += (object sender, ElapsedEventArgs args2) => UpdateSelectedIndex(); e.NewElement.PropertyChanged += ElementPropertyChanged; } catch (System.Exception ex) { Insights.Send("OnElementChanged", ex); } }
private void SetMaxLength(cxEntry view) { try{ Control.SetFilters(new IInputFilter[] { new global::Android.Text.InputFilterLengthFilter(view.MaxLength) }); } catch (System.Exception ex) { Insights.Send("SetMaxLength", ex); } }
private void SetBorder(cxPicker view) { try{ this.Control.BorderStyle = view.HasBorder ? UITextBorderStyle.RoundedRect : UITextBorderStyle.None; } catch (System.Exception ex) { Insights.Send("SetBorder", ex); } }
void CollectionViewItemClick(object sender, AdapterView.ItemClickEventArgs e) { try{ var item = this.Element.ItemsSource.Cast <object>().ElementAt(e.Position); this.Element.InvokeItemSelectedEvent(this, item); } catch (System.Exception ex) { Insights.Send("CollectionViewItemClick", ex); } }
void NativeScrolled(object sender, EventArgs e) { try { var center = _native.ContentOffset.X + (_native.Bounds.Width / 2); ((cxCarouselView)Element).SelectedIndex = ((int)center) / ((int)_native.Bounds.Width); } catch (System.Exception ex) { Insights.Send("NativeScrolled", ex); } }
public cxCarouselViewRenderer() { try { PagingEnabled = true; ShowsHorizontalScrollIndicator = false; } catch (System.Exception ex) { Insights.Send("cxCarouselViewRenderer", ex); } }
public override void Draw(CoreGraphics.CGRect rect) { try { base.Draw(rect); ScrollToSelection(false); } catch (System.Exception ex) { Insights.Send("Draw", ex); } }
void UpdateSelectedIndex() { try{ var center = _scrollView.ScrollX + (_scrollView.Width / 2); var cxCarouselView = (cxCarouselView)this.Element; cxCarouselView.SelectedIndex = (center / _scrollView.Width); } catch (System.Exception ex) { Insights.Send("UpdateSelectedIndex", ex); } }
protected override void OnConfigurationChanged(Configuration newConfig) { try{ base.OnConfigurationChanged(newConfig); if (newConfig.Orientation != _orientation) { OnElementChanged(new ElementChangedEventArgs <cxGridView>(this.Element, this.Element)); } } catch (System.Exception ex) { Insights.Send("OnConfigurationChanged", ex); } }
void UpdateUi(cxEntry view) { try{ if (!string.IsNullOrEmpty(view.FontFamily)) { string filename = view.FontFamily; if (filename.LastIndexOf(".", System.StringComparison.Ordinal) != filename.Length - 4) { filename = string.Format("{0}.ttf", filename); } Control.Typeface = TrySetFont(filename); } if (view.FontSize > 0) { Control.TextSize = (float)view.FontSize; } if (view.PlaceholderTextColor != Xamarin.Forms.Color.Default) { Control.SetHintTextColor(view.PlaceholderTextColor.ToAndroid()); } if (view.HasBorder != false) { //return; } switch (view.Alignment) { case Xamarin.Forms.TextAlignment.Center: Control.Gravity = GravityFlags.CenterHorizontal; break; case Xamarin.Forms.TextAlignment.End: Control.Gravity = GravityFlags.End; break; case Xamarin.Forms.TextAlignment.Start: Control.Gravity = GravityFlags.Start; break; } } catch (System.Exception ex) { Insights.Send("UpdateUi", ex); } }
void ElementPropertyChanged(object sender, PropertyChangedEventArgs e) { try { if (e.PropertyName == cxCarouselView.SelectedIndexProperty.PropertyName && !Dragging) { ScrollToSelection(false); } } catch (System.Exception ex) { Insights.Send("ElementPropertyChanged", ex); } }
private void SetMaxLength(cxEntry view) { try{ this.Control.ShouldChangeCharacters = (textField, range, replacementString) => { var newLength = textField.Text.Length + replacementString.Length - range.Length; return(newLength <= view.MaxLength); }; } catch (System.Exception ex) { Insights.Send("SetMaxLength", ex); } }
protected override void OnSizeChanged(int w, int h, int oldw, int oldh) { try{ if (_initialized && (w != oldw)) { _initialized = false; } base.OnSizeChanged(w, h, oldw, oldh); } catch (System.Exception ex) { Insights.Send("OnSizeChanged", ex); } }
void ScrollToIndex(int targetIndex) { try{ var targetX = targetIndex * _scrollView.Width; _scrollView.Post(new Runnable(() => { _scrollView.SmoothScrollTo(targetX, 0); })); } catch (System.Exception ex) { Insights.Send("ScrollToIndex", ex); } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.DatePicker> e) { try{ base.OnElementChanged(e); var view = e.NewElement as cxDatePicker; SetView(view); } catch (System.Exception ex) { Insights.Send("OnElementChanged", ex); } }
private void UpdateUi(cxEntry view) { try{ if (view.FontSize > 0) { this.Control.Font = UIFont.FromName(this.Control.Font.Name, (float)view.FontSize); } if (!string.IsNullOrEmpty(view.FontFamily)) { var fontName = Path.GetFileNameWithoutExtension(view.FontFamily); var font = UIFont.FromName(fontName, this.Control.Font.PointSize); if (font != null) { this.Control.Font = font; } } if (string.IsNullOrEmpty(view.Placeholder) == false && view.PlaceholderTextColor != Color.Default) { NSAttributedString placeholderString = new NSAttributedString(view.Placeholder, new UIStringAttributes() { ForegroundColor = view.PlaceholderTextColor.ToUIColor() }); this.Control.AttributedPlaceholder = placeholderString; } switch (view.Alignment) { case TextAlignment.Center: Control.TextAlignment = UITextAlignment.Center; break; case TextAlignment.End: Control.TextAlignment = UITextAlignment.Right; break; case TextAlignment.Start: Control.TextAlignment = UITextAlignment.Left; break; } } catch (System.Exception ex) { Insights.Send("UpdateUi", ex); } }
private void ElementPropertyChanging(object sender, PropertyChangingEventArgs e) { try{ if (e.PropertyName == "ItemsSource") { if (this.Element.ItemsSource is INotifyCollectionChanged) { (this.Element.ItemsSource as INotifyCollectionChanged).CollectionChanged += DataCollectionChanged; } } } catch (System.Exception ex) { Insights.Send("ElementPropertyChanging", ex); } }
public override void Draw(Canvas canvas) { try{ base.Draw(canvas); if (_initialized) { return; } _initialized = true; var cxCarouselView = (cxCarouselView)this.Element; _scrollView.ScrollTo(cxCarouselView.SelectedIndex * Width, 0); } catch (System.Exception ex) { Insights.Send("Draw", ex); } }
void SnapScroll() { try{ var roughIndex = (float)_scrollView.ScrollX / _scrollView.Width; var targetIndex = _deltaX < 0 ? Java.Lang.Math.Floor(roughIndex) : _deltaX > 0 ? Java.Lang.Math.Ceil(roughIndex) : Java.Lang.Math.Round(roughIndex); ScrollToIndex((int)targetIndex); } catch (System.Exception ex) { Insights.Send("SnapScroll", ex); } }
public global::Android.Views.View GetCell(int position, global::Android.Views.View convertView, ViewGroup parent) { try{ var item = this.Element.ItemsSource.Cast <object>().ElementAt(position); var viewCellBinded = (Element.ItemTemplate.CreateContent() as ViewCell); viewCellBinded.BindingContext = item; var view = RendererFactory.GetRenderer(viewCellBinded.View); view.ViewGroup.LayoutParameters = new Android.Widget.GridView.LayoutParams(Convert.ToInt32(this.Element.ItemWidth), Convert.ToInt32(this.Element.ItemHeight)); view.ViewGroup.SetBackgroundColor(global::Android.Graphics.Color.LightGray); return(view.ViewGroup); } catch (System.Exception ex) { Insights.Send("SetMaxLength", ex); return(null); } }
private void UpdateUi(cxDatePicker view) { try{ if (view.FontSize > 0) { this.Control.Font = UIFont.FromName(this.Control.Font.Name, (float)view.FontSize); } if (!string.IsNullOrEmpty(view.FontFamily)) { var fontName = Path.GetFileNameWithoutExtension(view.FontFamily); var font = UIFont.FromName(fontName, this.Control.Font.PointSize); if (font != null) { this.Control.Font = font; } } if (view.TextColor != Xamarin.Forms.Color.Default) { Control.TextColor = view.TextColor.ToUIColor(); } switch (view.Alignment) { case TextAlignment.Center: Control.TextAlignment = UITextAlignment.Center; break; case TextAlignment.End: Control.TextAlignment = UITextAlignment.Right; break; case TextAlignment.Start: Control.TextAlignment = UITextAlignment.Left; break; } } catch (System.Exception ex) { Insights.Send("UpdateUi", ex); } }
private void Unbind(cxGridView oldElement) { try{ if (oldElement != null) { oldElement.PropertyChanging += ElementPropertyChanging; oldElement.PropertyChanged -= ElementPropertyChanged; if (oldElement.ItemsSource is INotifyCollectionChanged) { (oldElement.ItemsSource as INotifyCollectionChanged).CollectionChanged -= DataCollectionChanged; } } } catch (System.Exception ex) { Insights.Send("Unbind", ex); } }
private void Bind(cxGridView newElement) { try{ if (newElement != null) { newElement.PropertyChanging += ElementPropertyChanging; newElement.PropertyChanged += ElementPropertyChanged; if (newElement.ItemsSource is INotifyCollectionChanged) { (newElement.ItemsSource as INotifyCollectionChanged).CollectionChanged += DataCollectionChanged; } } } catch (System.Exception ex) { Insights.Send("Bind", ex); } }
protected override void OnElementChanged(ElementChangedEventArgs <Label> e) { try{ base.OnElementChanged(e); var view = e.NewElement as cxLabel; //UpdateUi(view, this.Control); if (view != null) { SetView(view); } } catch (System.Exception ex) { Insights.Send("OnElementChanged", ex); } }
protected override void OnElementChanged(ElementChangedEventArgs <cxGridView> e) { try{ base.OnElementChanged(e); var collectionView = new Android.Widget.GridView(Xamarin.Forms.Forms.Context); collectionView.SetGravity(GravityFlags.Center); collectionView.SetColumnWidth(Convert.ToInt32(Element.ItemWidth)); collectionView.StretchMode = StretchMode.StretchColumnWidth; var metrics = Resources.DisplayMetrics; var spacing = (int)e.NewElement.ColumnSpacing; var width = metrics.WidthPixels; var itemWidth = (int)e.NewElement.ItemWidth; int noOfColumns = width / (itemWidth + spacing); // If possible add another row without spacing (because the number of columns will be one less than the number of spacings) if (width - (noOfColumns * (itemWidth + spacing)) >= itemWidth) { noOfColumns++; } collectionView.SetNumColumns(noOfColumns); collectionView.SetPadding(Convert.ToInt32(Element.Padding.Left), Convert.ToInt32(Element.Padding.Top), Convert.ToInt32(Element.Padding.Right), Convert.ToInt32(Element.Padding.Bottom)); collectionView.SetBackgroundColor(Element.BackgroundColor.ToAndroid()); collectionView.SetHorizontalSpacing(Convert.ToInt32(Element.RowSpacing)); collectionView.SetVerticalSpacing(Convert.ToInt32(Element.ColumnSpacing)); this.Unbind(e.OldElement); this.Bind(e.NewElement); collectionView.Adapter = this.DataSource; collectionView.ItemClick += CollectionViewItemClick; base.SetNativeControl(collectionView); } catch (System.Exception ex) { Insights.Send("OnElementChanged", ex); } }
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { try{ base.OnElementPropertyChanged(sender, e); var view = Element as cxLabel; if (view != null && e.PropertyName == cxLabel.FontFamilyProperty.PropertyName || e.PropertyName == cxLabel.FontSizeProperty.PropertyName) { SetView(view); } } catch (System.Exception ex) { Insights.Send("OnElementPropertyChanged", ex); } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.DatePicker> e) { try{ base.OnElementChanged(e); if (this.Control == null) { return; } Control.SetBackgroundColor(global::Android.Graphics.Color.Transparent); var view = (cxDatePicker)Element; UpdateUi(view); } catch (System.Exception ex) { Insights.Send("OnElementChanged", ex); } }