Esempio n. 1
0
    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);
        }
    }
Esempio n. 2
0
    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);
        }
    }
Esempio n. 3
0
    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);
        }
    }
Esempio n. 4
0
    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);
        }
    }
Esempio n. 5
0
 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);
     }
 }
Esempio n. 6
0
 private void SetBorder(cxPicker view)
 {
     try{
         this.Control.BorderStyle = view.HasBorder ? UITextBorderStyle.RoundedRect : UITextBorderStyle.None;
     }
     catch (System.Exception ex)
     {
         Insights.Send("SetBorder", ex);
     }
 }
Esempio n. 7
0
 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);
     }
 }
Esempio n. 8
0
 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);
     }
 }
Esempio n. 9
0
 public cxCarouselViewRenderer()
 {
     try
     {
         PagingEnabled = true;
         ShowsHorizontalScrollIndicator = false;
     }
     catch (System.Exception ex)
     {
         Insights.Send("cxCarouselViewRenderer", ex);
     }
 }
Esempio n. 10
0
 public override void Draw(CoreGraphics.CGRect rect)
 {
     try
     {
         base.Draw(rect);
         ScrollToSelection(false);
     }
     catch (System.Exception ex)
     {
         Insights.Send("Draw", ex);
     }
 }
Esempio n. 11
0
 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);
     }
 }
Esempio n. 12
0
 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);
     }
 }
Esempio n. 13
0
    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);
        }
    }
Esempio n. 14
0
 void ElementPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     try
     {
         if (e.PropertyName == cxCarouselView.SelectedIndexProperty.PropertyName && !Dragging)
         {
             ScrollToSelection(false);
         }
     }
     catch (System.Exception ex)
     {
         Insights.Send("ElementPropertyChanged", ex);
     }
 }
Esempio n. 15
0
 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);
     }
 }
Esempio n. 16
0
 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);
     }
 }
Esempio n. 17
0
 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);
     }
 }
Esempio n. 18
0
    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);
        }
    }
Esempio n. 19
0
    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);
        }
    }
Esempio n. 20
0
 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);
     }
 }
Esempio n. 21
0
 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);
     }
 }
Esempio n. 22
0
    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);
        }
    }
Esempio n. 23
0
 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);
     }
 }
Esempio n. 24
0
    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);
        }
    }
Esempio n. 25
0
 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);
     }
 }
Esempio n. 26
0
 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);
     }
 }
Esempio n. 27
0
    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);
        }
    }
Esempio n. 28
0
    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);
        }
    }
Esempio n. 29
0
    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);
        }
    }
Esempio n. 30
0
    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);
        }
    }