예제 #1
0
        //Styles selector
        void DrawLine(CustomEntry entry)
        {
            // Remove native borders
            Control.BorderStyle = UIKit.UITextBorderStyle.None;

            // Hide bottom line
            //Control.Layer.Sublayers[2].Hidden = true;

            // Creates normal layer
            var normalLayer = new CANormalLayer();
            var rect        = new CGRect(NativeView.Bounds.X, Control.Frame.Height - 3, NativeView.Bounds.Width, 1f);

            normalLayer.Frame           = rect;
            normalLayer.BackgroundColor = entry.BorderColor.ToCGColor();

            // Creates focus layer
            var focusLayer = new CAFocusLayer();

            rect                       = new CGRect(NativeView.Bounds.X, Control.Frame.Height - 4, NativeView.Bounds.Width, 2f);
            focusLayer.Frame           = rect;
            focusLayer.BackgroundColor = entry.FocusedBorderColor.ToCGColor();

            // Replace layer (if exist)
            if (NativeView.Layer.Sublayers[0] is CANormalLayer)
            {
                NativeView.Layer.ReplaceSublayer(NativeView.Layer.Sublayers[0], normalLayer);
            }
            // just add the layer if it does not exist before
            else
            {
                NativeView.Layer.InsertSublayer(normalLayer, 0);
            }

            // replace gradient (if exist)
            if (NativeView.Layer.Sublayers[1] is CAFocusLayer)
            {
                NativeView.Layer.ReplaceSublayer(NativeView.Layer.Sublayers[1], focusLayer);
            }
            // add gradient layer
            else
            {
                NativeView.Layer.InsertSublayer(focusLayer, 1);
            }

            // hide gradient layer
            NativeView.Layer.Sublayers[1].Hidden = true;
        }
예제 #2
0
        protected override void Init()
        {
            Title = "Issue 10940";

            var layout = new StackLayout();

            var instructions = new Label
            {
                Padding         = 12,
                BackgroundColor = Colors.Black,
                TextColor       = Colors.White,
                Text            = "Swipe to the left and verify that opening the SwipeView the CustomEntry is created only one time."
            };

            var customSwipeView = new CustomSwipeView
            {
                BackgroundColor = Colors.LightGray,
                HeightRequest   = 200
            };

            var swipeItemView = new SwipeItemView();

            var swipeItemViewContent = new Grid
            {
                BackgroundColor = Colors.White,
                WidthRequest    = 150
            };

            var customEntry = new CustomEntry
            {
                VerticalOptions = LayoutOptions.Center
            };

            swipeItemViewContent.Children.Add(customEntry);

            swipeItemView.Content = swipeItemViewContent;

            customSwipeView.RightItems = new SwipeItems
            {
                swipeItemView
            };

            layout.Children.Add(instructions);
            layout.Children.Add(customSwipeView);

            Content = layout;
        }
예제 #3
0
        /// <summary>
        /// Sets the text alignment.
        /// </summary>
        /// <param name="view">The view.</param>
        private void SetTextAlignment(CustomEntry view)
        {
            switch (view.XAlign)
            {
            case TextAlignment.Center:
                Control.TextAlignment = UITextAlignment.Center;
                break;

            case TextAlignment.End:
                Control.TextAlignment = UITextAlignment.Right;
                break;

            case TextAlignment.Start:
                Control.TextAlignment = UITextAlignment.Left;
                break;
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                GradientDrawable gd = new GradientDrawable();
                gd.SetColor(Android.Graphics.Color.Transparent);
                this.Control.SetBackground(gd);
                this.Control.SetPadding(20, 0, 0, 0);

                CustomEntry customEntry = (CustomEntry)e.NewElement;
                if (customEntry.IsPasswordFlag)
                {
                    this.Control.InputType = InputTypes.TextVariationVisiblePassword;
                }
            }
        }
예제 #5
0
        private void SetTextAlignment(CustomEntry view)
        {
            switch (view.XAlign)
            {
            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;
            }
        }
예제 #6
0
 protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     base.OnElementPropertyChanged(sender, e);
     try
     {
         CustomEntry element = Element as CustomEntry;
         if (Control != null)
         {
             // do whatever you want to the UITextField here
             //var element = Element as CustomEntry;
             Control.BorderStyle        = UITextBorderStyle.None;
             Control.Layer.CornerRadius = 10;
             Control.ExclusiveTouch     = true;
             //Control.MinimumFontSize = 15f;
             Control.AdjustsFontSizeToFitWidth = true;
             Control.TextColor = UIColor.Black; //for place holder
                                                //var entry1 = new Entry();
                                                //Control.Layer.BorderColor = Color.FromHex("#0000").ToCGColor();
                                                //Control.Layer.BorderWidth = 0;
                                                //entry1.Layer.BorderWidth = 1f;
             if (element.CustomFontFamily == "Avenir65")
             {
                 Control.Font = UIFont.FromName("AvenirLTStd-Medium.ttf", 20.0f);
             }
             else if (element.CustomFontFamily == "Avenir45")
             {
                 Control.Font = UIFont.FromName("AvenirLTStd-Book.ttf", 20.0f);
             }
             else
             {
             }
             if (element.CustomFontSize != 0)
             {
                 UIFont font = Control.Font.WithSize(element.CustomFontSize);
                 Control.Font = font;
             }
             else
             {
             }
         }
     }
     catch (Exception ex)
     {
         var msg = ex.Message;
     }
 }
예제 #7
0
        private void BuildStep2()
        {
            currentStep = 2;
            bottomLayout.Children.Clear();
            var label = new CustomLabel()
            {
                Text       = "We have sent a confirmation code to the mobile number below. Please enter the confirmation code.",
                TextColor  = Color.Black,
                FontSize   = 16,
                FontFamily = UIUtils.FONT_SFUIDISPLAY_REGULAR,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                Margin        = new Thickness(20),
                HeightRequest = 70
            };

            bottomLayout.Children.Add(label);

            var phoneNumberLabel = new CustomLabel()
            {
                Text       = phoneEntry.PhoneNumber,
                TextColor  = Color.Black,
                FontSize   = 16,
                FontFamily = UIUtils.FONT_SFUIDISPLAY_REGULAR,
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment   = TextAlignment.Center,
                Margin        = new Thickness(20, 10, 20, 0),
                HeightRequest = 70
            };

            bottomLayout.Children.Add(phoneNumberLabel);
            bottomLayout.Children.Add(UIUtils.MakeSeparator());

            codeEntry = UIUtils.MakeEntry("Confirmation code", UIUtils.FONT_SFUIDISPLAY_BOLD);
            bottomLayout.Children.Add(codeEntry);
            bottomLayout.Children.Add(UIUtils.MakeSeparator());

            var continueButton = UIUtils.MakeButton("CONTINUE", UIUtils.FONT_SFUIDISPLAY_REGULAR);

            continueButton.Clicked += OnContinue;
            bottomLayout.Children.Add(continueButton);

            bottomLayout.ForceLayout();
            MakeEntryVisibleWithKeybord(new Entry[] { codeEntry });
        }
        protected override void OnElementPropertyChanged(
            object sender
            , System.ComponentModel.PropertyChangedEventArgs e
            )
        {
            base.OnElementPropertyChanged(sender, e);

            CustomEntry temp = (CustomEntry)Element;

            if (!String.IsNullOrWhiteSpace(temp.ErrorMessage))
            {
                Control.Error = temp.ErrorMessage;
            }
            else
            {
                Control.Error = null;
            }
        }
예제 #9
0
 private void BuildLayout()
 {
     picker              = new Picker();
     picker.TextColor    = Props.ButtonColor;
     picker.WidthRequest = 80;
     foreach (var phoneCode in phoneCodes)
     {
         picker.Items.Add(phoneCode.ToString());
     }
     picker.SelectedIndex         = NigeriaIndex;
     picker.SelectedIndexChanged += Picker_SelectedIndexChanged;
     Children.Add(picker);
     entry = UIUtils.MakeEntry("Phone Number", UIUtils.FONT_SFUIDISPLAY_BOLD);
     entry.HorizontalOptions = LayoutOptions.FillAndExpand;
     entry.Margin            = new Thickness(5, 0, 0, 0);
     Children.Add(entry);
     this.HorizontalOptions = LayoutOptions.FillAndExpand;
 }
 void SetIcon(CustomEntry view)
 {
     if (!string.IsNullOrEmpty(view.Icon))
     {
         Control.LeftViewMode = UITextFieldViewMode.Always;
         var uiImageView = new UIImageView();
         var image       = UIImage.FromBundle(view.Icon);
         uiImageView.Image       = image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
         uiImageView.Frame       = new CGRect(0, 0, 16, 16);
         uiImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
         Control.LeftView        = uiImageView;
     }
     else
     {
         Control.LeftViewMode = UITextFieldViewMode.Never;
         Control.LeftView     = null;
     }
 }
예제 #11
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

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

            element = (CustomEntry)this.Element;

            /*******************IMAGE*******************/
            var editText = this.Control;

            if (!string.IsNullOrEmpty(element.Image))
            {
                switch (element.ImageAlignment)
                {
                case EnumImageAlignment.Left:
                    editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(element.Image), null, null, null);
                    break;

                case EnumImageAlignment.Right:
                    editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, GetDrawable(element.Image), null);
                    break;
                }
            }
            editText.CompoundDrawablePadding = 25;
            Control.Background.SetColorFilter(element.LineColor.ToAndroid(), PorterDuff.Mode.SrcAtop);

            /*******************RETURN TYPE*******************/
            SetReturnType(element);
            // Editor Action is called when the return button is pressed
            Control.EditorAction += (object sender, TextView.EditorActionEventArgs args) =>
            {
                if (element?.ReturnType != EnumReturnType.Next)
                {
                    element?.Unfocus();
                }

                // Call all the methods attached to base_entry event handler Completed
                element?.InvokeCompleted();
            };
        }
예제 #12
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                CustomEntry control = e.NewElement as CustomEntry;
                var         entry   = (TextView)Control;
                entry.SetTextSize(Android.Util.ComplexUnitType.Dip, control.Size);

                //====================================================

                GradientDrawable gd = new GradientDrawable();
                gd.SetColor(global::Android.Graphics.Color.Transparent);
                this.Control.SetBackgroundDrawable(gd);
                this.Control.SetRawInputType(InputTypes.TextFlagNoSuggestions);
                Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.LightGray));
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null || e.NewElement == null)
            {
                return;
            }

            element = (CustomEntry)this.Element;

            var editText = this.Control;

            var entryEx = Element as CustomEntry;

            UpdateBackground(entryEx);
            UpdatePadding(entryEx);
            UpdateTextAlighnment(entryEx);

            //if (!string.IsNullOrEmpty(element.Image))
            //{
            //    //switch (element.ImageAlignment)
            //    //{
            //    //    case ImageAlignment.Left:
            //    //        editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(element.Image), null, null, null);
            //    //        break;
            //    //    case ImageAlignment.Right:
            //    //        editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, GetDrawable(element.Image), null);
            //    //        break;
            //    //}
            //    //  UpdateBorders();

            //}

            //editText.CompoundDrawablePadding = 25;
            //editText.Gravity = GravityFlags.CenterVertical;
            //editText.SetPadding(10, 10, 10, 10);

            //editText.Background = new ColorDrawable(Android.Graphics.Color.Transparent);


            // editText.Background.SetColorFilter(element.LineColor.ToAndroid(), Android.Graphics.Color.White);
            // editText.Background =  Android.App.Application.Context.GetColor(Resource.Color.ripple_material_light);
        }
예제 #14
0
        void OnEntryTextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                CustomEntry entry = (CustomEntry)sender;

                StackLayout temp = (StackLayout)entry.Parent;

                // if Entry text is longer then valid length
                if (entry.Text.Length > this.MaxLength)
                {
                    entry.ErrorMessage = "ERROR";
                }
                else
                {
                    entry.ErrorMessage = "";
                }
            } catch { }
        }
예제 #15
0
        void DrawFrame(CustomEntry entry)
        {
            var bas = Control as TextView;

            //Get the measure to get the ViewSize
            bas.Measure(0, 0);

            //is common always get the heigh value instead of width, we can "pre define" this value as a reference
            var h = (entry.HeightRequest > 0 ? entry.HeightRequest : bas.MeasuredHeight / 2);

            var side            = Math.Max(h, 0);
            var radius          = side * entry.BorderRadius / 100;
            GradientDrawable gd = new GradientDrawable();

            gd.SetColor(entry.BackgroundColor.ToAndroid());                  //background
            gd.SetCornerRadius((float)radius);                               //Border radius
            gd.SetStroke(entry.BorderStroke, entry.BorderColor.ToAndroid()); //stroke
            Control.SetBackground(gd);
        }
예제 #16
0
 private StackLayout MakeDiscountEntry()
 {
     if (!_isInfo)
     {
         discountNameEntry = new CustomEntry()
         {
             HorizontalOptions = LayoutOptions.FillAndExpand,
             VerticalOptions   = LayoutOptions.Center,
             Placeholder       = "Enter Discount Code",
             PlaceholderColor  = Props.GrayColor,
             TextColor         = Color.Black,
             FontSize          = 16,
             FontFamily        = UIUtils.FONT_SFUIDISPLAY_REGULAR
         };
         var discountButton = new Button()
         {
             Text              = "APPLY",
             FontFamily        = UIUtils.FONT_SFUIDISPLAY_MEDIUM,
             HeightRequest     = 35,
             FontSize          = 15,
             HorizontalOptions = LayoutOptions.End,
             BackgroundColor   = Props.ButtonColor,
             BorderRadius      = Props.ButtonBorderRadius,
             TextColor         = Color.White
         };
         discountButton.Clicked += OnDiscountButtonClicked;
         var discountRow2 = new StackLayout
         {
             Orientation = StackOrientation.Horizontal,
             Margin      = new Thickness(20, 0, 20, 0),
             IsVisible   = true,
             Children    = { discountNameEntry, discountButton }
         };
         return(discountRow2);
     }
     else
     {
         return(new StackLayout {
             Spacing = 0
         });
     }
 }
예제 #17
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            CustomEntry entry = (CustomEntry)this.Element;

            if (this.Control != null)
            {
                if (entry != null)
                {
                    SetReturnType(entry);

                    Control.ShouldReturn += (UITextField tf) =>
                    {
                        entry.InvokeCompleted();
                        return(true);
                    };
                }
            }
        }
예제 #18
0
        private CustomEntry GenerateEntryDefault(string placeHolder, string fieldName, FontType fontType, Keyboard keyboard)
        {
            var result = new CustomEntry
            {
                Placeholder             = placeHolder,
                PlaceholderColor        = Palette.Green,
                Keyboard                = keyboard,
                HorizontalTextAlignment = TextAlignment.Center,
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                VerticalOptions         = LayoutOptions.Center,
                FontSize                = PaletteText.FontSizeM,
                MaxLength               = 200,
                FontType                = fontType,
                HeightRequest           = 45
            };

            result.SetBinding(Entry.TextProperty, fieldName, BindingMode.TwoWay);

            return(result);
        }
        private void UpdateTextAlighnment(CustomEntry entryEx)
        {
            var gravity = DefaultGravity;

            switch (entryEx.HorizontalTextAlignment)
            {
            case Xamarin.Forms.TextAlignment.Start:
                gravity |= GravityFlags.Start;
                break;

            case Xamarin.Forms.TextAlignment.Center:
                gravity |= GravityFlags.CenterHorizontal;
                break;

            case Xamarin.Forms.TextAlignment.End:
                gravity |= GravityFlags.End;
                break;
            }
            Control.Gravity = gravity;
        }
예제 #20
0
 private void SetIcon(CustomEntry view)
 {
     if (!string.IsNullOrEmpty(view.IconLeft))
     {
         try
         {
             var context = Context;
             var resId   = context.Resources.GetIdentifier(System.IO.Path.GetFileNameWithoutExtension(view.IconLeft),
                                                           "drawable", context.PackageName);
             if (resId != 0)
             {
                 Control.SetCompoundDrawablesWithIntrinsicBounds(resId, 0, 0, 0);
                 Control.CompoundDrawablePadding = 15;
             }
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
             throw;
         }
     }
     if (!string.IsNullOrEmpty(view.IconRight))
     {
         try
         {
             var context = Context;
             var resId   = context.Resources.GetIdentifier(System.IO.Path.GetFileNameWithoutExtension(view.IconRight),
                                                           "drawable", context.PackageName);
             if (resId != 0)
             {
                 Control.SetCompoundDrawablesWithIntrinsicBounds(0, 0, resId, 0);
                 Control.CompoundDrawablePadding = 15;
             }
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
             throw;
         }
     }
 }
예제 #21
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

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

            element = (CustomEntry)this.Element;

            var editText = this.Control;

            if (!string.IsNullOrEmpty(element.IconSource))
            {
                switch (element.IconAlignment)
                {
                case IconAlignment.Left:
                    editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(element.IconSource), null, null, null);
                    break;

                case IconAlignment.Right:
                    editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, GetDrawable(element.IconSource), null);
                    break;
                }
            }
            editText.CompoundDrawablePadding = 25;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                editText.BackgroundTintList = ColorStateList.ValueOf(element.BorderColor.ToAndroid());
            }
            else
            {
                editText.Background.SetColorFilter(element.BorderColor.ToAndroid(), PorterDuff.Mode.SrcAtop);
            }

            editText.SetHintTextColor(ColorStateList.ValueOf(element.BorderColor.ToAndroid()));

            SetReturnType(element);
        }
예제 #22
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            element = (CustomEntry)this.Element;
            var editText = this.Control;

            if (e.PropertyName == nameof(element.IsPassword))
            {
                ChangeFont();
                Control.SetSelection(Control.Text.Length);
            }
            if (e.PropertyName == nameof(element.BorderColor))
            {
                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    editText.BackgroundTintList = ColorStateList.ValueOf(element.BorderColor.ToAndroid());
                }
                else
                {
                    editText.Background.SetColorFilter(element.BorderColor.ToAndroid(), PorterDuff.Mode.SrcAtop);
                }

                editText.SetHintTextColor(ColorStateList.ValueOf(element.BorderColor.ToAndroid()));
            }
            if (e.PropertyName == nameof(element.IconSource))
            {
                if (!string.IsNullOrEmpty(element.IconSource))
                {
                    switch (element.IconAlignment)
                    {
                    case IconAlignment.Left:
                        editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(element.IconSource), null, null, null);
                        break;

                    case IconAlignment.Right:
                        editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, GetDrawable(element.IconSource), null);
                        break;
                    }
                }
            }
        }
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            Entry entry = sender as Entry;

            if (e.PropertyName.Equals("Width") || e.PropertyName.Equals("Height"))
            {
                if (_borderLayer != null)
                {
                    _borderLayer.Frame = new CGRect(0f, entry.Bounds.Height, entry.Bounds.Width, 0.5f);
                }
            }
            else if (e.PropertyName == CustomEntry.ShowCautionImageProperty.PropertyName)
            {
                CustomEntry customEntry = Element as CustomEntry;
                if (customEntry.ShowCautionImage)
                {
                    // check if we already added this image, if so then no need to proceed.
                    if (Control.RightView != null)
                    {
                        return;
                    }

                    UIImageView uiImage = new UIImageView(UIImage.FromBundle("caution.png"))
                    {
                        Frame = new CGRect(0, 0, Control.Frame.Height, Control.Frame.Height),
                    };

                    UIView objRightView = new UIView(new CGRect(0, 0, Control.Frame.Height + 5, Control.Frame.Height + 5));
                    objRightView.AddSubview(uiImage);

                    Control.RightView     = objRightView;
                    Control.RightViewMode = UITextFieldViewMode.Always;
                }
                else
                {
                    Control.RightView = null;
                }
            }
        }
        /// <summary>
        /// Sets the font.
        /// </summary>
        /// <param name="view">The view.</param>
        private void SetFont(CustomEntry view)
        {
            //UIFont uiFont;
            //if (view.Font != Font.Default && (uiFont = view.Font.ToUIFont()) != null)
            //    Control.Font = uiFont;
            //else if (view.Font == Font.Default)
            //{
            //    Control.Font = UIFont.SystemFontOfSize(17f);
            //}
            //nfloat fontsize = new nfloat(view.FontSize);
            //Control.Font = UIFont.SystemFontOfSize(fontsize);

            var fontsize = view.FontSize;

            var font = UIKit.UIFont.FromName("LatoRegular", (System.nfloat)fontsize);

            if (font != null)
            {
                Control.Font = font;
            }
        }
예제 #25
0
        private void SetReturnType(CustomEntry entry)
        {
            CustomControls.ReturnType type = entry.ReturnType;

            switch (type)
            {
            case CustomControls.ReturnType.Go:
                Control.ImeOptions = ImeAction.Go;
                Control.SetImeActionLabel("Go", ImeAction.Go);
                break;

            case CustomControls.ReturnType.Next:
                Control.ImeOptions = ImeAction.Next;
                Control.SetImeActionLabel("Next", ImeAction.Next);
                break;

            case CustomControls.ReturnType.Previous:
                Control.ImeOptions = ImeAction.Previous;
                Control.SetImeActionLabel("Prev", ImeAction.Previous);
                break;

            case CustomControls.ReturnType.Send:
                Control.ImeOptions = ImeAction.Send;
                Control.SetImeActionLabel("Send", ImeAction.Send);
                break;

            case CustomControls.ReturnType.Search:
                Control.ImeOptions = ImeAction.Search;
                Control.SetImeActionLabel("Search", ImeAction.Search);
                break;

            case CustomControls.ReturnType.Done:
                Control.ImeOptions = ImeAction.Done;
                Control.SetImeActionLabel("Done", ImeAction.Done);
                break;

            default:
                break;
            }
        }
예제 #26
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

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



            element = (CustomEntry)this.Element;


            var editText = this.Control;

            if (!string.IsNullOrEmpty(element.Image))
            {
                switch (element.ImageAlignment)
                {
                case ImageAlignment.Left:
                    editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(element.Image), null, null, null);
                    break;

                case ImageAlignment.Right:
                    editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, GetDrawable(element.Image), null);
                    break;
                }
            }
            editText.CompoundDrawablePadding = 25;

            if (Control != null)
            {
                Control.Background = this.Resources.GetDrawable(Resource.Drawable.RoundedCornerEntry);
                Control.SetPadding(10, 10, 10, 3);
            }

            //    Control.Background.SetColorFilter(element.LineColor.ToAndroid(), PorterDuff.Mode.SrcAtop);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);
            if (this.Control != null)
            {
                this.Control.BorderStyle = UITextBorderStyle.None;

                CustomEntry customEntry = (CustomEntry)(e.NewElement == null ? e.OldElement : e.NewElement);
                if (customEntry != null)
                {
                    if (customEntry.IsCode && UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
                    {
                        this.Control.TextContentType = UITextContentType.OneTimeCode;
                    }

                    if (customEntry.IsPassword && UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
                    {
                        this.Control.TextContentType = UITextContentType.NewPassword;
                    }
                }
            }
        }
        public CalibrationEntry(StackLayout stackLayout, string labelText, string setting, float settingDefault)
        {
            this.stack          = stackLayout;
            this.setting        = setting;
            this.settingDefault = settingDefault;

            line             = new StackLayout();
            line.Orientation = StackOrientation.Horizontal;

            label                   = new Label();
            label.Text              = labelText;
            label.FontSize          = 17;
            label.HorizontalOptions = LayoutOptions.Start;
            label.VerticalOptions   = LayoutOptions.Center;

            entry                   = new CustomEntry();
            entry.Text              = Settings.GetValueOrDefault(setting, settingDefault).ToString();
            entry.BackgroundColor   = Color.Black;
            entry.WidthRequest      = 70;
            entry.Keyboard          = Keyboard.Numeric;
            entry.Completed        += OnEntryComplete;
            entry.Unfocused        += OnEntryComplete;
            entry.HorizontalOptions = LayoutOptions.EndAndExpand;

            line.Children.Add(label);
            line.Children.Add(entry);

            this.stack.Children.Add(line);

            if (label.Text.Equals(""))
            {
                label.Text = "- - - - - - - - - - - - - - - - -";
                label.HorizontalOptions = LayoutOptions.CenterAndExpand;
                entry.IsVisible         = false;
            }

            label.SizeChanged += ((obj, sender) => this.stack.ForceLayout());
            entry.SizeChanged += ((obj, sender) => this.stack.ForceLayout());
        }
예제 #29
0
        private void SetIcon(CustomEntry view)
        {
            if (!string.IsNullOrEmpty(view.IconLeft))
            {
                Control.LeftViewMode = UITextFieldViewMode.Always;
                Control.LeftViewRect(new CGRect(5, 5, 5, 5));
                Control.LeftView = new UIImageView(UIImage.FromBundle(view.IconLeft));
            }

            if (!string.IsNullOrEmpty(view.IconRight))
            {
                Control.LeftViewMode = UITextFieldViewMode.Always;
                Control.RightViewRect(new CGRect(5, 5, 5, 5));
                Control.RightView = new UIImageView(UIImage.FromBundle(view.IconRight));
            }

            if (string.IsNullOrEmpty(view.IconLeft) && string.IsNullOrEmpty(view.IconRight))
            {
                Control.LeftViewMode = UITextFieldViewMode.Never;
                Control.LeftView     = null;
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            try
            {
                element = Element as CustomEntry;
                if (e.NewElement != null)
                {
                    element = Element as CustomEntry;
                }
                else
                {
                    element = e.OldElement as CustomEntry;
                }
                UpdateElementWithChanges();
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
            }
        }
예제 #31
0
 public static Dictionary<string, string> ToDictionary(CustomEntry[] array) {
     if(array == null) return new Dictionary<string, string>();
     Dictionary<string, string> dict = new Dictionary<string,string>();
     for(int i = 0; i < array.Length; i++) {
         if(array[i] == null) continue;
         if(string.IsNullOrEmpty(array[i].key) || string.IsNullOrEmpty(array[i].value)) continue;
         if(dict.ContainsKey(array[i].key)) {
             Debug.LogError("Key \"" + array[i].key + "\" is already in dictionary!");
             continue;
         }
         dict.Add(array[i].key, array[i].value);
     }
     return dict;
 }