Beispiel #1
0
 public static void TestKeyboardFlags(this FormsEditText Control, KeyboardFlags?flags)
 {
     if (flags == null)
     {
         return;
     }
     if (flags.Value.HasFlag(KeyboardFlags.CapitalizeSentence))
     {
         if (!Control.InputType.HasFlag(InputTypes.TextFlagCapSentences))
         {
             throw new Exception("TextFlagCapSentences not correctly set");
         }
     }
     else if (flags.Value.HasFlag(KeyboardFlags.CapitalizeCharacter))
     {
         if (!Control.InputType.HasFlag(InputTypes.TextFlagCapCharacters))
         {
             throw new Exception("TextFlagCapCharacters not correctly set");
         }
     }
     else if (flags.Value.HasFlag(KeyboardFlags.CapitalizeWord))
     {
         if (!Control.InputType.HasFlag(InputTypes.TextFlagCapWords))
         {
             throw new Exception("TextFlagCapWords not correctly set");
         }
     }
 }
        protected override FormsEditText CreateNativeControl()
        {
            FormsEditText control = base.CreateNativeControl();

            control.Elevation = 9;
            UpdateBackground(control);

            return(control);
        }
        protected override void OnAttached()
        {
            FormsEditText formEdit = Control as FormsEditText;

            if (formEdit != null)
            {
                formEdit.SetBackgroundColor(Android.Graphics.Color.Transparent);
            }
        }
Beispiel #4
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

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

            customEntry = this.Element as CustomEntry;

            FormsEditText editText = this.Control;

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

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

            GradientDrawable gradientDrawable = new GradientDrawable();

            //Zaokraglenie
            gradientDrawable.SetCornerRadius(Context.ToPixels(customEntry.CornerRadius));
            //Obramowka
            gradientDrawable.SetStroke((int)Context.ToPixels(customEntry.BorderThickness), customEntry.BorderColor.ToAndroid());
            //Tlo elementu
            gradientDrawable.SetColor(customEntry.BackgroundColor.ToAndroid());

            Control.SetBackground(gradientDrawable);

            int paddingLeft   = (int)Context.ToPixels(customEntry.Padding.Left);
            int paddingTop    = (int)Context.ToPixels(customEntry.Padding.Top);
            int paddingRight  = (int)Context.ToPixels(customEntry.Padding.Right);
            int paddingBottom = (int)Context.ToPixels(customEntry.Padding.Bottom);

            Control.SetPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);


            IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView));

            IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I");

            JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.cursor);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            if (native == null)
            {
                source = e.NewElement as MyEntry;
                native = this.Control as FormsEditText;

                native.AfterTextChanged  += Native_AfterTextChanged;
                native.KeyPress          += Native_KeyPress;
                native.BeforeTextChanged += Native_BeforeTextChanged;

                SetNativeControl(native);
            }
        }
Beispiel #6
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                fControl = (TransparentEntry)Element;
                nControl = this.Control;


                //Control.Background = Resources.GetDrawable(Resource.Drawable.RoundedEntry);
                //Control.SetBackgroundColor(Color.Transparent.ToAndroid());

                Control.SetBackgroundColor(Android.Graphics.Color.Transparent);
                Control.SetPadding(1, 3, 1, 1);
                Control.SetImeActionLabel("Go", Android.Views.InputMethods.ImeAction.Done);
            }
        }
Beispiel #7
0
        public static void SetCursorColor(this FormsEditText control)
        {
            if (control == null)
            {
                return;
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Q)
            {
                //This API Intrduced in android 10
                control.SetTextCursorDrawable(Resource.Drawable.cursor);
            }
            else
            {
                var intPtrtextViewClass        = JNIEnv.FindClass(typeof(TextView));
                var mCursorDrawableResProperty = JNIEnv.GetFieldID(intPtrtextViewClass, "mCursorDrawableRes", "I");
                JNIEnv.SetField(control.Handle, mCursorDrawableResProperty, Resource.Drawable.cursor);
            }
        }
Beispiel #8
0
        protected void UpdateBackground(FormsEditText control)
        {
            if (control == null)
            {
                return;
            }

            var gd = new GradientDrawable();

            gd.SetColor(Element.BackgroundColor.ToAndroid());
            gd.SetCornerRadius(Context.ToPixels(ElementV2.CornerRadius));
            gd.SetStroke((int)Context.ToPixels(ElementV2.BorderThickness), ElementV2.BorderColor.ToAndroid());
            control.SetBackground(gd);

            var padTop    = (int)Context.ToPixels(ElementV2.Padding.Top);
            var padBottom = (int)Context.ToPixels(ElementV2.Padding.Bottom);
            var padLeft   = (int)Context.ToPixels(ElementV2.Padding.Left);
            var padRight  = (int)Context.ToPixels(ElementV2.Padding.Right);

            control.SetPadding(padLeft, padTop, padRight, padBottom);
        }
Beispiel #9
0
        public static void SetKeyboardFlags(this FormsEditText Control, KeyboardFlags?flags)
        {
            if (flags == null)
            {
                return;
            }

            if (flags.Value.HasFlag(KeyboardFlags.CapitalizeCharacter))
            {
                Control.InputType = Control.InputType | InputTypes.TextFlagCapCharacters;
            }

            if (flags.Value.HasFlag(KeyboardFlags.CapitalizeSentence))
            {
                Control.InputType = Control.InputType | InputTypes.TextFlagCapSentences;
            }

            if (flags.Value.HasFlag(KeyboardFlags.CapitalizeWord))
            {
                Control.InputType = Control.InputType | InputTypes.TextFlagCapWords;
            }
        }
Beispiel #10
0
 public static void RemoveHintBottomLine(this FormsEditText control)
 {
     control.SetBackground(null);
 }
Beispiel #11
0
 protected override FormsEditText CreateNativeControl()
 {
     EditTextControl = base.CreateNativeControl();
     UpdateBackground(EditTextControl);
     return(EditTextControl);
 }