Exemple #1
0
        void SetImage(int height)
        {
            Drawable drawableRight = null;
            Drawable drawableLeft  = null;

            if (Element.ImageRight != null && Element.ImageRight.File != null)
            {
                var element = Element.ImageRight;
                drawableRight = Context.Resources.GetDrawable(UIHelper.GetDrawableResource(Element.ImageRight));
                drawableRight.SetBounds(0, 0, BaseUIHelper.ConvertDPToPixels(Element.ImageRightWidth), BaseUIHelper.ConvertDPToPixels(Element.ImageRightWidth));
            }

            if (Element.ImageLeft != null && Element.ImageLeft.File != null)
            {
                drawableLeft = Context.Resources.GetDrawable(UIHelper.GetDrawableResource(Element.ImageLeft));
                drawableLeft.SetBounds(0, 0, BaseUIHelper.ConvertDPToPixels(Element.ImageLeftWidth), BaseUIHelper.ConvertDPToPixels(Element.ImageLeftHeight));
            }

            textView.SetCompoundDrawablesRelative(drawableLeft, null, drawableRight, null);
        }
Exemple #2
0
 void SetCorners()
 {
     if (BaseElement.CornerRadius != 0)
     {
         CornerRadiusArray = new float[]
         {
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Top),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Top),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Right),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Right),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Bottom),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Bottom),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Left),
             BaseUIHelper.ConvertDPToPixels(BaseElement.Corner.Left)
         };
     }
     else
     {
         CornerRadiusArray = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
     }
 }
        void CreateShapeDrawable()
        {
            GradientDrawable shape = new GradientDrawable();

            shape.SetShape(ShapeType.Rectangle);

            float[] cornerRadii = new float[] { 10, 10, 10, 10, 10, 10, 10, 10 };

            if (Base.CornerRadius != "-1")
            {
                var cornerRad = Base.CornerRadius.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                cornerRadii = new float[] { BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[0])),
                                            BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[1])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[2])),
                                            BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[3])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[4])),
                                            BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[5])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[6])),
                                            BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[7])) };
            }



            shape.SetCornerRadii(cornerRadii);

            var element = Element as RoundedFrame;

            if (element.BackgroundColor != Xamarin.Forms.Color.Default)
            {
                shape.SetColor(element.BackgroundColor.ToAndroid());
            }

            if (Base.HasBorder)
            {
                shape.SetStroke(1, Base.BorderColor.ToAndroid());
            }

            Control.Background = shape;
        }
Exemple #4
0
        //private void CheckEnabled()
        //{
        //    if (Element.IsEnabled)
        //    {
        //        if (!Element.AllowCutCopyPaste)
        //        {
        //            Control.RequestFocus();
        //            UIHelper.OpenSoftKeyboard(Control);
        //        }

        //    }
        //    else
        //    {
        //        if (!Element.AllowCutCopyPaste)
        //        {
        //            UIHelper.CloseSoftKeyboard(Control);
        //        }
        //  }
        //}
        private void CreateShapeDrawable()
        {
            GradientDrawable shape = new GradientDrawable();

            shape.SetShape(ShapeType.Rectangle);
            shape.SetCornerRadius(BaseUIHelper.ConvertDPToPixels(Element.CornerRadius));

            if (Element.BackgroundColor != Xamarin.Forms.Color.Default)
            {
                shape.SetColor(Element.BackgroundColor.ToAndroid());
            }

            if (Element.ImageRight != null && Element.ImageRight.File != null)
            {
                Drawable drawable = Context.Resources.GetDrawable(UIHelper.GetDrawableResource(Element.ImageRight));
                drawable.SetBounds(0, 0, BaseUIHelper.ConvertDPToPixels(Element.ImageRightWidth),
                                   BaseUIHelper.ConvertDPToPixels(Element.ImageRightHeight));
                Control.SetCompoundDrawablesRelative(null, null, drawable, null);
            }
            //if (Element.CornerRadius > 0)
            //    this.SetPadding(5, 2, 5, 2);

            Control.Background = shape;
        }
 private void SetPadding()
 {
     Control.SetPadding(BaseUIHelper.ConvertDPToPixels(BaseControl.Padding.Left), BaseUIHelper.ConvertDPToPixels(BaseControl.Padding.Top),
                        BaseUIHelper.ConvertDPToPixels(BaseControl.Padding.Right), BaseUIHelper.ConvertDPToPixels(BaseControl.Padding.Bottom));
 }
        protected override void OnDraw(Canvas canvas)
        {
            var cornerRadius = BaseUIHelper.ConvertDPToPixels(Element.CornerRadius);

            if (cornerRadius > 0)
            {
                Path    clipPath = new Path();
                RectF   rect     = new RectF(0, 0, BaseUIHelper.ConvertDPToPixels(Element.WidthRequest), BaseUIHelper.ConvertDPToPixels(Element.HeightRequest));
                float[] radii    = new float[] { cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius };
                clipPath.AddRoundRect(rect, radii, Path.Direction.Cw);
                canvas.ClipPath(clipPath);
            }
            base.OnDraw(canvas);
        }
        async void SetImageSource()
        {
            if (Element.Source != null)
            {
                if (Element.Source is UriImageSource)
                {
                    isImageInitialSet = true;


                    var uri = Element.Source.GetValue(UriImageSource.UriProperty) as Uri;

                    var bitmap = await imageDownloader.GetImageAsync(uri);

                    SetImageCorners(bitmap);
                }
                else if (Element.Source is FileImageSource)
                {
                    if ((Element.Width > 0 && Element.Height > 0) || (Element.WidthRequest > 0 && Element.HeightRequest > 0))
                    {
                        isImageInitialSet = true;

                        var source = Element.Source as FileImageSource;
                        if (source != null && source.File != null)
                        {
                            var resourceID = UIHelper.GetDrawableResource(source);
                            if (resourceID > 0)
                            {
                                Bitmap imageBitmap = ImageCache.Instance.Get(resourceID.ToString());
                                if (imageBitmap == null)
                                {
                                    var width             = BaseUIHelper.ConvertDPToPixels(Element.Width <= 0 ? Element.WidthRequest : Element.Width);
                                    var height            = BaseUIHelper.ConvertDPToPixels(Element.Height <= 0 ? Element.HeightRequest : Element.Height);
                                    BitmapWorkerTask task = new BitmapWorkerTask(imageView, width, height, ImageCache.Instance);
                                    imageView.SetImageDrawable(new AsyncDrawable(imageView.Resources, null, task));
                                    task.Execute(resourceID);
                                    task.Finished += (s, e) =>
                                                     SetImageCorners(e);
                                }
                                else
                                {
                                    SetImageCorners(imageBitmap);
                                }
                            }
                            else
                            {
                                var imageBitmap = await BitmapFactory.DecodeFileAsync(source.File);

                                SetImageCorners(imageBitmap);
                            }
                        }
                    }
                }
                else if (Element.Source is StreamImageSource)
                {
                    isImageInitialSet = true;
                    var source = Element.Source as StreamImageSource;
                    var cts    = new System.Threading.CancellationTokenSource();
                    var str    = await source.Stream(cts.Token);

                    using (var reader = new System.IO.BinaryReader(str))
                    {
                        var data   = reader.ReadBytes((int)str.Length);
                        var bitmap = await BitmapFactory.DecodeByteArrayAsync(data, 0, data.Length);

                        SetImageCorners(bitmap);
                    }
                }
            }
            else
            {
                if (Element.ImagePlaceholder == null)
                {
                    imageView.SetImageBitmap(null);
                }
            }
        }
        protected ShapeDrawable GradientConverter(String Gradient)
        {
            float[] array = new float[] { 250, 250, 250, 250, 250, 250, 250, 250 };

            if (Base.CornerRadius != "-1")
            {
                var cornerRad = Base.CornerRadius.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                array = new float[] { BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[0])),
                                      BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[1])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[2])),
                                      BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[3])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[4])),
                                      BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[5])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[6])),
                                      BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[7])) };
            }

            ShapeDrawable sf = new ShapeDrawable(new RoundRectShape(array, null, null));

            // sf.SetIntrinsicHeight(100);
            //sf.SetIntrinsicWidth(200);

            sf.SetShaderFactory(new GradientShader(Gradient));

            if (Base.HasBorder)
            {
                sf.Paint.StrokeWidth = 1;
                sf.Paint.Color       = Base.BorderColor.ToAndroid();
            }


            return(sf);
        }
Exemple #9
0
        protected override void OnElementChanged(ElementChangedEventArgs <RoundedEntry> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }

            var editText = new EditText(this.Context);

            // will remove cursor and not scrollable for tablet
            //editText.MovementMethod = null;

            editText.Ellipsize = TextUtils.TruncateAt.End;
            editText.SetCursorVisible(Element.ShowCursor);

            if (!Element.AllowCutCopyPaste)
            {
                editText.LongClickable = false;
            }

            if (Element.MaxCharacter.HasValue)
            {
                var filter = new InputFilterLengthFilter(Element.MaxCharacter.Value);
                editText.SetFilters(new IInputFilter[] { filter });
            }

            SetNativeControl(editText);

            CreateShapeDrawable();
            this.Background = new ColorDrawable(Color.Transparent.ToAndroid());

            //if (Element.IsPassword)
            //    Control.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword;

            if (Element.IsReadOnly)
            {
                Control.KeyListener = null;
            }

            if (Element.IsSingleLine)
            {
                editText.SetMaxLines(1);
                editText.SetSingleLine(true);

                if (Element.NextElement != null)
                {
                    Control.ImeOptions = ImeAction.Next;
                }

                if (Element.NextElement == null && Element.Command != null)
                {
                    Control.ImeOptions = ImeAction.Done;
                }

                if (Element.NextElement != null || (Element.NextElement == null && Element.Command != null))
                {
                    Control.SetOnEditorActionListener(this);
                }
                else
                {
                    Control.ImeOptions = ImeAction.Done;
                }
            }


            //int selectionStart = -1;
            //string previousText = "";

            editText.AfterTextChanged += (s, ev) =>
            {
                //if (editText.Text.Length > previousText.Length)
                //    selectionStart = editText.CursorPosition + 1;
                //else
                //    selectionStart = editText.CursorPosition - 1;
                ////if (!editText.Text.ToString().Replace(Environment.NewLine, "").Equals(editText.Text.ToString()))
                ////editText.Text = editText.Text.ToString().Replace(Environment.NewLine, "");

                //if (selectionStart > editText.Text.Length || selectionStart < 0)
                //    selectionStart = editText.Text.Length;

                //editText.SetSelection(selectionStart);

                ((IElementController)Element).SetValueFromRenderer(Xamarin.Forms.Entry.TextProperty, editText.Text);
                //previousText = editText.Text;
            };

            Control.SetPadding(BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Left),
                               BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Top),
                               BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Right),
                               BaseUIHelper.ConvertDPToPixels(Element.TextPadding.Bottom));

            SetText();
            SetTextColor();
            SetTextAlignment();
            SetHint();
            SetTextInputTypes();
            ShowKeyboard();
            //CheckEnabled();
        }
Exemple #10
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);


            if (e.OldElement != null || e.NewElement == null)
            {
                return;
            }

            var buttonControl = (RoundedButton)Element;

            gradientDrawable = new StateListDrawable();
            SetCorners();

            Control.Focusable = false;

            buttonControl.PropertyChanged += (s, ev) =>
            {
                if (Control == null || Element == null)
                {
                    return;
                }

                var element = (RoundedButton)s;
                switch (ev.PropertyName)
                {
                case "IsEnabled":
                    Control.SetTextColor(element.TextColor.ToAndroid());     // for samsung s4 and note5
                    break;

                case "Text":
                    Control.Text = element.Text;
                    var width = Control.Width;
                    Control.SetWidth(width);
                    break;

                case "HoverColor":
                    SetHoverColor();
                    Control.Background = gradientDrawable;
                    break;

                case "PressedColor":
                    SetPressedColor();
                    Control.Background = gradientDrawable;
                    break;

                case "GradientColor":
                    UpdateStateDrawable();

                    break;

                case "DisableColor":
                    SetDisabledColor();
                    Control.Background = gradientDrawable;
                    break;

                case "BorderColor":
                    UpdateStateDrawable();
                    break;

                //case "Width":
                //    SetImages(buttonControl);
                //    break;
                case "DisabledTextColor":
                    SetDisabledTextColor();
                    break;
                }
            };



            //SetTypeface(buttonControl);
            //SetBackground(buttonControl);
            //SetImages(buttonControl);
            //SetPadding(buttonControl);
            //SetTitlePadding(buttonControl);
            //SetTextAlignment(buttonControl);

            currentWidth = Control.Width;

            if (buttonControl.WidthRequest > 0)
            {
                Control.SetWidth(BaseUIHelper.ConvertDPToPixels(buttonControl.WidthRequest));
            }

            if (buttonControl.HeightRequest > 0)
            {
                Control.SetHeight(BaseUIHelper.ConvertDPToPixels(buttonControl.HeightRequest));
            }

            SetPressedColor();
            SetHoverColor();
            SetDisabledColor();
            SetGradientColor();
            SetDisabledTextColor();
            SetTextAlignment();
            Control.Background = gradientDrawable;

            var thisButton = Control as Android.Widget.Button;

            thisButton.Touch += async(object sender, TouchEventArgs args) =>
            {
                if (args.Event.Action == MotionEventActions.Down)
                {
                    await buttonControl.ScaleTo(0.9, 100);
                }
                else if (args.Event.Action == MotionEventActions.Up)
                {
                    await buttonControl.ScaleTo(1, 100);

                    Control.CallOnClick();
                }
            };

            this.SetWillNotDraw(false);
        }
Exemple #11
0
        public override void Draw(Canvas canvas)
        {
            //RoundedBoxView rbv = (RoundedBoxView)this.Element;

            //int value;
            //try
            //{
            //    value = int.Parse(rbv.Text.Trim());
            //}
            //catch (Exception)
            //{
            //    value = 0;
            //}

            //if (value <= 0) return;

            //if (value < 10)
            //{
            //    rbv.WidthRequest = 20;
            //}
            //else if (value >= 10 && value < 100)
            //{
            //    rbv.WidthRequest = 25;
            //}
            //else
            //{
            //    rbv.WidthRequest = 30;
            //}

            //Rect rc = new Rect(0, 0, BaseUIHelper.ConvertDPToPixels(rbv.WidthRequest), BaseUIHelper.ConvertDPToPixels(rbv.HeightRequest));

            //GetDrawingRect(rc);

            //Rect interior = rc;
            //interior.Inset((int)rbv.StrokeThickness, (int)rbv.StrokeThickness);

            ////            paint.Color = Android.Graphics.Color.White;
            ////            paint.TextSize = BaseUIHelper.ConvertDPToPixels(rbv.TextSize);
            ////            paint.AntiAlias = true;
            ////            paint.TextAlign = Paint.Align.Center;
            ////
            ////            Rect bounds = new Rect();
            ////            paint.GetTextBounds(rbv.Text, 0, rbv.Text.Length, bounds);

            //int radius = BaseUIHelper.ConvertDPToPixels(rbv.CornerRadius);
            ////int radius = bounds.Width();

            circlePaint.Color     = Base.BackgroundColor.ToAndroid();
            circlePaint.AntiAlias = true;
            circlePaint.SetStyle(Paint.Style.Fill);

            //canvas.DrawRoundRect(new RectF(interior), radius, radius, circlePaint);
            ////canvas.DrawCircle(x, y - (bounds.Height() / 2), radius, circlePaint);

            //circlePaint.Color = rbv.Stroke.ToAndroid();
            //circlePaint.StrokeWidth = (float)rbv.StrokeThickness;
            //circlePaint.SetStyle(Paint.Style.Stroke);

            //canvas.DrawRoundRect(new RectF(interior), radius, radius, circlePaint);
            ////canvas.DrawCircle(x, y - (bounds.Height() / 2), radius, circlePaint); //FOR the border

            ////canvas.DrawText(rbv.Text, rc.CenterX(), (BaseUIHelper.ConvertDPToPixels(rbv.HeightRequest) / 2) + (bounds.Height() / 2), paint);

            RectF rect         = new RectF(0, 0, this.Width, this.Height);
            int   cornerRadius = BaseUIHelper.ConvertDPToPixels(Base.CornerRadius);

            canvas.DrawRoundRect(rect, cornerRadius, cornerRadius, circlePaint);
        }
        void SetImages(MvvmAspire.Controls.Button element)
        {
            try
            {
                ButtonText = Element.Text;

                if (!HaseResource(element.ImageLeft) && !HaseResource(element.ImageTop) && !HaseResource(element.ImageRight) && !HaseResource(element.ImageBottom))
                {
                    Control.SetCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
                    Control.Invalidate();
                    return;
                }

                Drawable leftResource = null, topResource = null, rightResource = null, bottomResource = null;

                if (element.ImageLeft != null && element.ImageLeft.File != null)
                {
                    leftResource = ContextCompat.GetDrawable(UIHelper.Context, UIHelper.GetDrawableResource(element.ImageLeft));
                }
                if (element.ImageTop != null && element.ImageTop.File != null)
                {
                    topResource = ContextCompat.GetDrawable(UIHelper.Context, UIHelper.GetDrawableResource(element.ImageTop));
                }
                if (element.ImageRight != null && element.ImageRight.File != null)
                {
                    rightResource = ContextCompat.GetDrawable(UIHelper.Context, UIHelper.GetDrawableResource(element.ImageRight));
                }
                if (element.ImageBottom != null && element.ImageBottom.File != null)
                {
                    bottomResource = ContextCompat.GetDrawable(UIHelper.Context, UIHelper.GetDrawableResource(element.ImageBottom));
                }

                bool hasResource = leftResource != null || rightResource != null || topResource != null || bottomResource != null;
                if (hasResource && !element.CenterImage)
                {
                    Control.SetCompoundDrawablesWithIntrinsicBounds(leftResource, topResource, rightResource, bottomResource);
                }

                if (hasResource && element.CenterImage)
                {
                    Xamarin.Forms.Size size = new Xamarin.Forms.Size();

                    if (leftResource != null)
                    {
                        if (element.ImageLeftHeight > 0 && element.ImageLeftWidth > 0)
                        {
                            size.Width  = element.ImageLeftWidth;
                            size.Height = element.ImageLeftHeight;
                        }
                        else
                        {
                            var maxWidth  = BaseUIHelper.ConvertDPToPixels(element.Padding.Left) - BaseUIHelper.ConvertDPToPixels(element.Padding.Right) - Control.MeasuredWidth;
                            var maxHeight = BaseUIHelper.ConvertDPToPixels(element.Padding.Top) - BaseUIHelper.ConvertDPToPixels(element.Padding.Bottom) - Control.MeasuredHeight;

                            var temp = GetSize(leftResource.IntrinsicWidth, leftResource.IntrinsicHeight, Math.Abs(maxWidth), Math.Abs(maxHeight));
                            size.Width  = temp.Width;
                            size.Height = temp.Height;
                        }

                        var scaledDrawable = new ScaleDrawable(leftResource, 0, (int)size.Width, (int)size.Height).Drawable;
                        scaledDrawable.SetBounds(0, 0, (int)size.Width, (int)size.Height);

                        Control.SetCompoundDrawables(scaledDrawable, null, null, null);
                    }

                    if (rightResource != null)
                    {
                        if (element.ImageRightHeight > 0 && element.ImageRightWidth > 0)
                        {
                            size.Width  = element.ImageRightWidth;
                            size.Height = element.ImageRightHeight;
                        }
                        else
                        {
                            var maxWidth  = BaseUIHelper.ConvertDPToPixels(element.Padding.Left) - BaseUIHelper.ConvertDPToPixels(element.Padding.Right) - Control.MeasuredWidth;
                            var maxHeight = BaseUIHelper.ConvertDPToPixels(element.Padding.Top) - BaseUIHelper.ConvertDPToPixels(element.Padding.Bottom) - Control.MeasuredHeight;
                            var temp      = GetSize(rightResource.IntrinsicWidth, rightResource.IntrinsicHeight, Math.Abs(maxWidth), Math.Abs(maxHeight));
                            size.Width  = temp.Width;
                            size.Height = temp.Height;
                        }

                        var scaledDrawable = new ScaleDrawable(rightResource, 0, (int)size.Width, (int)size.Height).Drawable;
                        scaledDrawable.SetBounds(0, 0, (int)size.Width, (int)size.Height);

                        Control.SetCompoundDrawables(null, null, scaledDrawable, null);
                    }

                    if (!element.CenterImage)
                    {
                        SetImagePadding((int)size.Width);
                    }

                    Control.Invalidate();
                }
            }
            catch (Exception e)
            {
            }
        }
 void SetTitlePadding(MvvmAspire.Controls.Button element)
 {
     Control.CompoundDrawablePadding = BaseUIHelper.ConvertDPToPixels(element.TextPadding.Left);
 }
Exemple #14
0
        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            var propertyName = e.PropertyName;

            switch (propertyName)
            {
            case "ItemsSource":
                SetItemsSource(); break;

            case "Padding": SetPadding(); break;

            case "SeparatorVisibility": SetSeparator(); break;

            case "Selector": SetSelector(); break;

            case "EmptyText":
                if (_emptyViewTv != null && BaseControl != null)
                {
                    _emptyViewTv.Text = BaseControl.EmptyText;
                }
                break;

            case "IsRefreshing":

                UpdateEmptyLabelVisibility();
                //if (Element.IsRefreshing)
                //    shouldExecuteCommand = false;
                if (_swipeContainer != null && Element != null)
                {
                    if (Control != null)
                    {
                        Control.Post(() =>
                        {
                            if (Element != null)
                            {
                                _swipeContainer.Refreshing = Element.IsRefreshing;
                            }
                        });
                    }
                }
                break;

            case "Height":
                if (!isRefreshEnabled)
                {
                    if (Element != null && _emptyViewTv != null && !string.IsNullOrWhiteSpace(BaseControl.EmptyText))
                    {
                        _emptyViewTv.SetHeight(BaseUIHelper.ConvertDPToPixels(Element.Height));
                    }
                }

                break;

            case "ScrollToTopChange":
                ScrollToTop();
                break;

            case "ScrollToIndex":
                if (BaseControl.ScrollToIndex > 0)
                {
                    DeterminedScrollTo(BaseControl.ScrollToIndex, 3);
                    //Control.SmoothScrollToPosition(BaseControl.ScrollToIndex, 100);
                }
                break;
            }
        }
Exemple #15
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Entry> e)
        {
            bool hasSet = false;

            if (e.OldElement == null && this.Element != null)
            {
                //SetNativeControl(new EditTextCustom(Context));
                //SetNativeControl(new EditTextCustom());
                hasSet = true;
            }

            if (inputMethodManager == null)
            {
                inputMethodManager = base.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
            }

            base.OnElementChanged(e);

            if (!hasSet)
            {
                return;
            }

            var entryControl = (MvvmAspire.Controls.Entry)Element;


            DefaultKeyListener = Control.KeyListener;

            entryControl.PropertyChanged += (s, ev) =>
            {
                var element = (MvvmAspire.Controls.Entry)s;

                switch (ev.PropertyName)
                {
                case "TextPadding":
                case "ImageLeft":
                case "ImageRight":
                case "ImageTop":
                case "ImageBottom":
                    SetImages(element);
                    break;

                case "ClearFocusTrigger": HideSoftKeyBoardOnTextChanged(element); break;

                case "IsFocused": element.ClearFocus = !element.IsFocused; break;

                case "BackgroundImage": SetBackground(element); break;

                case "FontFamily": SetTypeface(element); break;

                case "FontSize": SetTextSize(element); break;

                case "SuppressKeyboard": SetShowSoftInputOnFocus(element); break;

                case "Text":
                    if (element.ClearFocus)
                    {
                        HideSoftKeyBoardOnTextChanged(element);
                    }
                    break;

                case "ClearFocus":
                    //if (!EntryControl.IsNumeric) break;
                    if (element.ClearFocus)
                    {
                        //inputMethodManager.HideSoftInputFromWindow(base.Control.WindowToken, HideSoftInputFlags.None);
                        //Control.Focusable = false;
                        //Control.ClearFocus();
                        HideSoftKeyBoardOnTextChanged(element);
                    }
                    break;

                case "NextFocus":
                    inputMethodManager.ShowSoftInput(Control, ShowFlags.Implicit);
                    //inputMethodManager.ToggleSoftInput(ShowFlags.Forced, InputMethodManager.ShowImplicit);
                    break;

                case "IsEnabled":
                    if (base.Control == null)
                    {
                        return;
                    }

                    if (!element.IsEnabled)
                    {
                        base.Control.KeyListener = null;
                    }
                    else
                    {
                        base.Control.KeyListener = DefaultKeyListener;
                    }
                    break;

                case "IsReadOnly":
                    SetIsReadOnly(element);
                    break;

                    //case "Padding": SetPadding(element); break;
                }
            };

            //if (EntryControl.IsNumeric)
            //    Control.Touch += Control_Touch;

            SetBackground(entryControl);
            SetImages(entryControl);
            SetTypeface(entryControl);
            SetTextSize(entryControl);
            SetShowSoftInputOnFocus(entryControl);
            SetHintColor(entryControl);
            SetIsReadOnly(entryControl);
            SetTextAlignment();
            //SetPadding(entryControl);
            SetGravity(entryControl);

            if (BaseElement.NextElement != null)
            {
                Control.ImeOptions = ImeAction.Next;
            }
            if (BaseElement.NextElement == null && BaseElement.Command != null)
            {
                Control.ImeOptions = ImeAction.Done;
            }

            if (BaseElement.MaxCharacter.HasValue)
            {
                var filter = new InputFilterLengthFilter(BaseElement.MaxCharacter.Value);
                Control.SetFilters(new IInputFilter[] { filter });
            }

            Control.ViewAttachedToWindow += Control_ViewAttachedToWindow;
            Control.SetPadding(BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Left),
                               BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Top),
                               BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Right),
                               BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Bottom));

            if (BaseElement.NextElement != null || BaseElement.Command != null)
            {
                Control.SetOnEditorActionListener(this);
            }

            SetTextInputTypes(entryControl);

            if (!entryControl.IsEnabled)
            {
                base.Control.KeyListener = null;
            }

            base.Control.Focusable = !BaseElement.IsReadOnly;

            //Control.Touch += Control_Touch;
            //Control.FocusChange += Control_FocusChange;
            if (BaseElement.IsSingleLine)
            {
                Control.SetMaxLines(1);
                Control.SetSingleLine(true);
                Control.Ellipsize = TextUtils.TruncateAt.End;
            }
            //Control.Gravity = GravityFlags.CenterVertical;
            Control.Background.SetColorFilter(Android.Graphics.Color.Transparent, PorterDuff.Mode.SrcIn);
        }
Exemple #16
0
        void SetImages(MvvmAspire.Controls.Entry element)
        {
            int leftResourceId = 0, topResourceId = 0, rightResourceId = 0, bottomResourceId = 0;

            if (element.ImageLeft != null && element.ImageLeft.File != null)
            {
                leftResourceId = UIHelper.GetDrawableResource(element.ImageLeft);
            }
            if (element.ImageTop != null && element.ImageTop.File != null)
            {
                topResourceId = UIHelper.GetDrawableResource(element.ImageTop);
            }
            if (element.ImageRight != null && element.ImageRight.File != null)
            {
                rightResourceId = UIHelper.GetDrawableResource(element.ImageRight);
            }
            if (element.ImageBottom != null && element.ImageBottom.File != null)
            {
                bottomResourceId = UIHelper.GetDrawableResource(element.ImageBottom);
            }

            bool hasResource = leftResourceId > 0 || rightResourceId > 0 || topResourceId > 0 || bottomResourceId > 0;

            if (hasCompoundDrawable || hasResource)
            {
                hasCompoundDrawable = true;

                //Android.Graphics.Drawables.Drawable leftDrawable = leftResourceId > 0 ? Resources.GetDrawable(leftResourceId) : null;
                //if (leftDrawable != null)
                //    leftDrawable.SetBounds(0, 0, leftDrawable.IntrinsicWidth, leftDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable topDrawable = topResourceId > 0 ? Resources.GetDrawable(topResourceId) : null;
                //if (topDrawable != null)
                //    topDrawable.SetBounds(0, 0, topDrawable.IntrinsicWidth, topDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable rightDrawable = rightResourceId > 0 ? Resources.GetDrawable(rightResourceId) : null;
                //if (rightDrawable != null)
                //    rightDrawable.SetBounds(0, 0, rightDrawable.IntrinsicWidth, rightDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable bottomDrawable = bottomResourceId > 0 ? Resources.GetDrawable(bottomResourceId) : null;
                //if (bottomDrawable != null)
                //    bottomDrawable.SetBounds(0, 0, bottomDrawable.IntrinsicWidth, bottomDrawable.IntrinsicHeight);

                //Control.SetCompoundDrawablesRelative(leftDrawable, topDrawable, rightDrawable, bottomDrawable);
                //Control.SetCompoundDrawables(leftDrawable, topDrawable, rightDrawable, bottomDrawable);


                var leftDrawable = (leftResourceId > 0) ? Resources.GetDrawable(leftResourceId) : null;
                if (leftDrawable != null)
                {
                    if (element.ImageLeftWidth > 0)
                    {
                        leftDrawable = ResizeImage(leftDrawable, BaseUIHelper.ConvertDPToPixels(element.ImageLeftWidth), BaseUIHelper.ConvertDPToPixels(element.ImageLeftWidth));
                    }
                    else
                    {
                        Resources.GetDrawable(leftResourceId);
                    }
                }

                var topDrawable    = (topResourceId > 0) ? Resources.GetDrawable(topResourceId) : null;
                var rightDrawable  = (rightResourceId > 0) ? Resources.GetDrawable(rightResourceId) : null;
                var bottomDrawable = (bottomResourceId > 0) ? Resources.GetDrawable(bottomResourceId) : null;

                //Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, topResourceId, rightResourceId, bottomResourceId);
                Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable);
                Control.CompoundDrawablePadding = 20;

                if (!hasResource)
                {
                    hasCompoundDrawable = false;
                }
            }

            if (element.ImageCenter != null)
            {
                Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(base.Resources.GetDrawable(UIHelper.GetDrawableResource(element.ImageCenter)), null, null, null);
                Control.Gravity = GravityFlags.Center;
            }
        }