Exemplo n.º 1
0
 /// <summary>
 /// Sets the font.
 /// </summary>
 /// <param name="view">The view.</param>
 private void SetFont(ExtendedEntry view)
 {
     if (view.Font != Font.Default)
     {
         Control.TextSize = view.Font.ToScaledPixel();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the text alignment.
        /// </summary>
        /// <param name="view">The view.</param>
        private void SetTextAlignment(ExtendedEntry view)
        {
            if (view.IsPassword && _thisPasswordBox != null)
            {
                switch (view.XAlign)
                {
                    //NotCurrentlySupported: Text alaignement not available on Windows Phone for Password Entry
                }
            }
            else if (!view.IsPassword && _thisPhoneTextBox != null)
            {
                switch (view.XAlign)
                {
                case TextAlignment.Center:
                    _thisPhoneTextBox.TextAlignment = System.Windows.TextAlignment.Center;
                    break;

                case TextAlignment.End:
                    _thisPhoneTextBox.TextAlignment = System.Windows.TextAlignment.Right;
                    break;

                case TextAlignment.Start:
                    _thisPhoneTextBox.TextAlignment = System.Windows.TextAlignment.Left;
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public MainContentPage()
        {
            var extendedEntry = new ExtendedEntry();

            var extended1 = new ExtendedEntry()
            {
                PlaceholderTextColor = Color.Fuchsia,
                Placeholder          = "Hello from placeholder"
            };

            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                Children        =
                {
                    new Label
                    {
                        XAlign = TextAlignment.Center,
                        Text   = "Welcome to Xamarin Forms!"
                    },
                    extendedEntry,
                    extended1
                }
            };
        }
Exemplo n.º 4
0
 private void SetPassword(ExtendedEntry view)
 {
     if (view.Password)
     {
         Control.InputType = InputTypes.TextVariationWebPassword;
     }
 }
        /// <summary>
        /// Sets the type of the return.
        /// </summary>
        /// <param name="entry">Entry.</param>
        private void SetReturnType(ExtendedEntry entry)
        {
            Xamarin.Forms.ReturnType type = (Xamarin.Forms.ReturnType)entry.ReturnType;

            switch (type)
            {
            case Xamarin.Forms.ReturnType.Go:
                Control.ReturnKeyType = UIReturnKeyType.Go;
                break;

            case Xamarin.Forms.ReturnType.Next:
                Control.ReturnKeyType = UIReturnKeyType.Next;
                break;

            case Xamarin.Forms.ReturnType.Send:
                Control.ReturnKeyType = UIReturnKeyType.Send;
                break;

            case Xamarin.Forms.ReturnType.Search:
                Control.ReturnKeyType = UIReturnKeyType.Search;
                break;

            case Xamarin.Forms.ReturnType.Done:
                Control.ReturnKeyType = UIReturnKeyType.Done;
                break;

            default:
                Control.ReturnKeyType = UIReturnKeyType.Default;
                break;
            }
        }
        /// <summary>
        /// Immediately cache all synchronized values and return whether something actually changed.
        /// </summary>

        bool Cache()
        {
            bool initial = false;
            bool changed = false;

            if (mCached == null)
            {
                initial = true;
                mCached = new Par()
                {
                    vals = new object[mList.size]
                };
            }

            for (int i = 0; i < mList.size; ++i)
            {
                ExtendedEntry ext = mList[i];

                object val = (ext.field != null) ?
                             val             = ext.field.GetValue(ext.target) :
                                         val = ext.property.GetValue(ext.target, null);

                if (!val.Equals(ext.lastValue))
                {
                    changed = true;
                }

                if (initial || changed)
                {
                    ext.lastValue   = val;
                    mCached.vals[i] = val;
                }
            }
            return(changed);
        }
Exemplo n.º 7
0
        public CameraPage()
        {
            btnTakePicture = new Button {
                Text = "Take Picture"
            };
            btnPickPicture = new Button {
                Text = "Select Image from Picture Library"
            };
            btnPickVideo = new Button {
                Text = "Select Video from Picture Library"
            };
            imgPicked = new Image {
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            entDetails = new ExtendedEntry {
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            btnTakePicture.Clicked += btnTakePicture_Clicked;
            btnPickPicture.Clicked += btnPickPicture_Clicked;
            btnPickVideo.Clicked   += btnPickVideo_Clicked;

            Content = new StackLayout
            {
                Children =
                {
                    btnTakePicture,
                    btnPickPicture,
                    btnPickVideo,
                    imgPicked,
                    entDetails
                }
            };

            cameraOps = new CameraViewModel();
        }
 void SetTextColor(ExtendedEntry view)
 {
     //if (view.TextColor == null || view.TextColor == Color.Default)
     //    Control.TextColor = Color.Default.ToUIColor();
     //else
     //Control.TextColor = view.TextColor.ToUIColor();
 }
Exemplo n.º 9
0
 private void SetBorder(ExtendedEntry view)
 {
     if (Control != null)
     {
         Control.SetBackgroundColor(Color.Transparent.ToAndroid());
     }
 }
        void OnSync(Par par)
        {
            if (enabled)
            {
                int len = (par.vals != null) ? par.vals.Length : 0;

                if (mList.size == len)
                {
                    for (int i = 0; i < len; ++i)
                    {
                        ExtendedEntry ext = mList[i];
                        ext.lastValue = par.vals[i];
                        if (ext.field != null)
                        {
                            ext.field.SetValue(ext.target, ext.lastValue);
                        }
                        else
                        {
                            ext.property.SetValue(ext.target, ext.lastValue, null);
                        }
                    }
                }
                else
                {
                    Debug.LogError("Mismatched number of parameters sent via TNAutoSync!");
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Sets the color of the placeholder text.
 /// </summary>
 /// <param name="view">The view.</param>
 private void SetPlaceholderTextColor(ExtendedEntry view)
 {
     if (view.PlaceholderTextColor != Xamarin.Forms.Color.Default)
     {
         Control.SetHintTextColor(view.PlaceholderTextColor.ToAndroid());
     }
 }
Exemplo n.º 12
0
        private void SetReturnType(ExtendedEntry view)
        {
            if (view.ReturnType.HasValue)
            {
                switch (view.ReturnType.Value)
                {
                case ReturnType.Go:
                    Control.ImeOptions = ImeAction.Go;
                    Control.SetImeActionLabel("Go", ImeAction.Go);
                    break;

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

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

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

                default:
                    Control.SetImeActionLabel("Done", ImeAction.Done);
                    break;
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Sets the border.
        /// </summary>
        /// <param name="view">The view.</param>
        //private void SetBorder(ExtendedEntry view)
        //{
        //    //NotCurrentlySupported: HasBorder property not supported on Android
        //}

        /// <summary>
        /// Sets the Text alignment.
        /// </summary>
        /// <param name="view">The view.</param>
        private void SetTextAlignment(ExtendedEntry view)
        {
            var gravity = GravityFlags.NoGravity;

            switch (view.XAlign)
            {
            case Xamarin.Forms.TextAlignment.Center:
                gravity |= GravityFlags.CenterHorizontal;
                break;

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

            case Xamarin.Forms.TextAlignment.Start:
                gravity |= GravityFlags.Start;
                break;
            }

            switch (view.YAlign)
            {
            case Xamarin.Forms.TextAlignment.Center:
                gravity |= GravityFlags.CenterVertical;
                break;

            case Xamarin.Forms.TextAlignment.End:
                gravity |= GravityFlags.Bottom;
                break;

            case Xamarin.Forms.TextAlignment.Start:
                gravity |= GravityFlags.Top;
                break;
            }
            Control.Gravity = gravity;
        }
Exemplo n.º 14
0
        private void Awake()
        {
            GetComponent <Identity>().sync = this;
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                var tns = GetComponents <SteamSync>();
                if (tns.Length <= 1 || tns[0] == this)
                {
                    return;
                }
                Debug.LogError("Can't have more than one " + GetType() + " per game object", gameObject);
                DestroyImmediate(this);
            }
            else
#endif
            {
                for (int i = 0, imax = entries.Count; i < imax; ++i)
                {
                    var ent = entries[i];
                    if (ent.target == null || string.IsNullOrEmpty(ent.property_name))
                    {
                        continue;
                    }
                    var field = ent.target.GetType()
                                .GetField(ent.property_name, BindingFlags.Instance | BindingFlags.Public);
                    if (field != null)
                    {
                        var ext = new ExtendedEntry
                        {
                            target     = ent.target,
                            field      = field,
                            last_value = field.GetValue(ent.target)
                        };
                        mList.Add(ext);
                    }
                    else
                    {
                        var pro = ent.target.GetType()
                                  .GetProperty(ent.property_name, BindingFlags.Instance | BindingFlags.Public);

                        if (pro != null)
                        {
                            var ext = new ExtendedEntry
                            {
                                target     = ent.target,
                                property   = pro,
                                last_value = pro.GetValue(ent.target, null)
                            };
                            mList.Add(ext);
                        }
                        else
                        {
                            Debug.LogError("Unable to find property: '" + ent.property_name + "' on " +
                                           ent.target.GetType());
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Sets the type of the return.
        /// </summary>
        /// <param name="entry">Entry.</param>
        private void SetReturnType(ExtendedEntry entry)
        {
            ExpeditionStories.Helpers.Renderers.ReturnType type = (ExpeditionStories.Helpers.Renderers.ReturnType)entry.ReturnType;

            switch (type)
            {
            case ExpeditionStories.Helpers.Renderers.ReturnType.Go:
                Control.ImeOptions = Android.Views.InputMethods.ImeAction.Go;
                Control.SetImeActionLabel("Go", ImeAction.Go);
                break;

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

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

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

            default:
                Control.ImeOptions = ImeAction.Done;
                Control.SetImeActionLabel("Done", ImeAction.Done);
                break;
            }
        }
Exemplo n.º 16
0
 private void SetMaxLength(ExtendedEntry view)
 {
     Control.ShouldChangeCharacters = (textField, range, replacementString) =>
     {
         var newLength = textField.Text.Length + replacementString.Length - range.Length;
         return(newLength <= view.TargetMaxLength);
     };
 }
Exemplo n.º 17
0
 /// <summary>
 /// Sets the font.
 /// </summary>
 /// <param name="view">The view.</param>
 private void SetFont(ExtendedEntry view)
 {
     if (view.Font != Font.Default)
     {
         Control.TextSize = view.Font.ToScaledPixel();
         Control.Typeface = view.Font.ToTypeface(); // ToExtendedTypeface(Context);
     }
 }
Exemplo n.º 18
0
 /// <summary>
 /// SetBackground
 /// </summary>
 /// <param name="view">The view.</param>
 private void SetBackground(ExtendedEntry view)
 {
     if (!view.BackGround)
     {
         Control.SetBackgroundColor(Android.Graphics.Color.Transparent);
     }
     Control.SetPadding(10, 0, 0, 0);
     Control.Gravity = GravityFlags.CenterVertical;
 }
Exemplo n.º 19
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            _view       = (ExtendedEntry)Element;
            _isPassword = _view.IsPassword;

            if (Control != null)
            {
                Control.SetIncludeFontPadding(false);
                if (e.NewElement != null && e.NewElement.IsPassword)
                {
                    Control.SetTypeface(Typeface.Default, TypefaceStyle.Normal);
                    Control.TransformationMethod = new PasswordTransformationMethod();
                }
            }

            SetBorder(_view);
            SetMaxLength(_view);
            SetReturnType(_view);

            // Editor Action is called when the return button is pressed
            Control.EditorAction += Control_EditorAction;

            if (_view.DisableAutocapitalize)
            {
                Control.SetRawInputType(Control.InputType |= InputTypes.TextVariationEmailAddress);
            }

            if (_view.Autocorrect.HasValue)
            {
                Control.SetRawInputType(Control.InputType |= InputTypes.TextFlagNoSuggestions);
            }

            if (_view.IsPassword)
            {
                Control.SetRawInputType(InputTypes.TextFlagNoSuggestions | InputTypes.TextVariationVisiblePassword);
            }

            if (_view.NumbersOnly)
            {
                Control.SetRawInputType(InputTypes.ClassNumber | InputTypes.NumberVariationPassword);
            }

            _view.ToggleIsPassword += ToggleIsPassword;

            if (_view.FontFamily == "monospace")
            {
                Control.Typeface = Typeface.Monospace;
            }

            if (_view.HideCursor)
            {
                Control.SetCursorVisible(false);
            }
        }
Exemplo n.º 20
0
        private void UpdateUi(ExtendedEntry view)
        {
            if (!string.IsNullOrEmpty(view.Text))
            {
                var strikethrough = view.IsStrikeThrough ? NSUnderlineStyle.Single : NSUnderlineStyle.None;

                Control.AttributedText = new NSMutableAttributedString(view.Text, Control.Font, strikethroughStyle: strikethrough);
                LayoutSubviews();
            }
        }
        /// <summary>
        /// Updates the font.
        /// </summary>
        private void UpdateFont(ExtendedEntry element)
        {
            if (string.IsNullOrEmpty(element.FontFamily))
            {
                return;
            }

            (Control as UITextField).Font = UIFont.FromName(element.FontFamily,
                                                            (Control as UITextField).Font.PointSize);
        }
Exemplo n.º 22
0
 /// <summary>
 /// Sets the color of the placeholder text.
 /// </summary>
 /// <param name="view">The view.</param>
 void SetPlaceholderTextColor(ExtendedEntry view)
 {
     if (!string.IsNullOrEmpty(view.Placeholder) && view.PlaceholderTextColor != Color.Default)
     {
         var placeholderString = new NSAttributedString(view.Placeholder, new UIStringAttributes {
             ForegroundColor = view.PlaceholderTextColor.ToUIColor()
         });
         Control.AttributedPlaceholder = placeholderString;
     }
 }
Exemplo n.º 23
0
        /// <summary>
        /// Called when [element changed].
        /// </summary>
        /// <param name="e">The e.</param>
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);
            if (!string.IsNullOrEmpty(e.NewElement?.FontFamily))
            {
                try
                {
                    var font = Typeface.CreateFromAsset(Forms.Context.ApplicationContext.Assets, e.NewElement.FontFamily + ".ttf");
                    Control.Typeface = font;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            var view = (ExtendedEntry)Element;

            if (Control != null && e.NewElement != null && e.NewElement.IsPassword)
            {
                //Control.SetTypeface(Typeface.Default, TypefaceStyle.Normal);
                Control.TransformationMethod = new PasswordTransformationMethod();
            }

            if ((Control != null) && (e.NewElement != null))
            {
                var entryExt = (e.NewElement as ExtendedEntry);
                Control.ImeOptions = entryExt.ReturnKeyType.GetValueFromDescription();
                // This is hackie ;-) / A Android-only bindable property should be added to the EntryExt class
                Control.SetImeActionLabel(entryExt.ReturnKeyType.ToString(), Control.ImeOptions);

                ExtendedEntry entry = (ExtendedEntry)this.Element;
                Control.EditorAction += (object sender, TextView.EditorActionEventArgs args) =>
                {
                    entry.InvokeCompleted();
                };
            }


            SetFont(view);
            SetTextAlignment(view);
            //SetBorder(view);
            SetPlaceholderTextColor(view);
            SetMaxLength(view);

            if (e.NewElement == null)
            {
                this.Touch -= HandleTouch;
            }

            if (e.OldElement == null)
            {
                this.Touch += HandleTouch;
            }
        }
Exemplo n.º 24
0
 /// <summary>
 /// Sets the border.
 /// </summary>
 /// <param name="view">The view.</param>
 private void SetBorder(ExtendedEntry view)
 {
     if (view.IsPassword && _thisPasswordBox != null)
     {
         _thisPasswordBox.BorderThickness = view.HasBorder ? new System.Windows.Thickness(2) : new System.Windows.Thickness(0);
     }
     else if (!view.IsPassword && _thisPhoneTextBox != null)
     {
         _thisPhoneTextBox.BorderThickness = view.HasBorder ? new System.Windows.Thickness(2) : new System.Windows.Thickness(0);
     }
 }
Exemplo n.º 25
0
 private void SetBorder(ExtendedEntry view)
 {
     if (!view.HasBorder)
     {
         Control.SetBackgroundColor(global::Android.Graphics.Color.Transparent);
     }
     else
     {
         Control.SetBackgroundColor(view.BottomBorderColor.ToAndroid());
     }
 }
Exemplo n.º 26
0
        /// <summary>
        /// Creates a new instance of the <see cref="ExtendedEntryPage"/> class
        /// </summary>
        public ExtendedEntryPage()
        {
            InitializeComponent();
            var entryFromCode = new ExtendedEntry()
            {
                Placeholder = "Aded from code, custom font",
                Font        = Font.OfSize("Open 24 Display St", NamedSize.Medium)
            };

            stackLayout.Children.Add(entryFromCode);
        }
Exemplo n.º 27
0
 private void SetAutocapitalization(ExtendedEntry view)
 {
     if (view.IsAutocapitalize)
     {
         Control.SetRawInputType(InputTypes.ClassText | InputTypes.TextFlagCapCharacters);
     }
     else
     {
         Control.SetRawInputType(InputTypes.ClassText | InputTypes.TextVariationNormal);
     }
 }
Exemplo n.º 28
0
 void SetAutocapitalization(ExtendedEntry view)
 {
     if (view.IsAutocapitalize)
     {
         Control.AutocapitalizationType = UITextAutocapitalizationType.AllCharacters;
     }
     else
     {
         Control.AutocapitalizationType = UITextAutocapitalizationType.None;
     }
 }
Exemplo n.º 29
0
 private void UpdateUi(ExtendedEntry extendedElement)
 {
     if (extendedElement.IsStrikeThrough)
     {
         PaintFlagsOriginal = Control.PaintFlags;
         Control.PaintFlags = Control.PaintFlags | PaintFlags.StrikeThruText;
     }
     else
     {
         Control.PaintFlags = PaintFlagsOriginal;
     }
 }
Exemplo n.º 30
0
        /// <summary>
        /// Sets the font.
        /// </summary>
        /// <param name="view">The view.</param>
        private void SetFont(ExtendedEntry view)
        {
            UIFont uiFont = view.Font.ToUIFont();

            if (view.Font != Font.Default && uiFont != null)
            {
                Control.Font = uiFont;
            }
            else if (view.Font == Font.Default)
            {
                Control.Font = UIFont.SystemFontOfSize(17f);
            }
        }
Exemplo n.º 31
0
    /// <summary>
    /// Locate the property that we should be synchronizing.
    /// </summary>
    void Awake()
    {
        #if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            TNAutoSync[] tns = GetComponents<TNAutoSync>();

            if (tns.Length > 1 && tns[0] != this)
            {
                Debug.LogError("Can't have more than one " + GetType() + " per game object", gameObject);
                DestroyImmediate(this);
            }
        }
        else
        #endif
        {
            // Find all properties, converting the saved list into the usable list of reflected properties
            for (int i = 0, imax = entries.Count; i < imax; ++i)
            {
                SavedEntry ent = entries[i];

                if (ent.target != null && !string.IsNullOrEmpty(ent.propertyName))
                {
                    FieldInfo field = ent.target.GetType().GetField(ent.propertyName, BindingFlags.Instance | BindingFlags.Public);

                    if (field != null)
                    {
                        ExtendedEntry ext = new ExtendedEntry();
                        ext.target = ent.target;
                        ext.field = field;
                        ext.lastValue = field.GetValue(ent.target);
                        mList.Add(ext);
                        continue;
                    }
                    else
                    {
                        PropertyInfo pro = ent.target.GetType().GetProperty(ent.propertyName, BindingFlags.Instance | BindingFlags.Public);

                        if (pro != null)
                        {
                            ExtendedEntry ext = new ExtendedEntry();
                            ext.target = ent.target;
                            ext.property = pro;
                            ext.lastValue = pro.GetValue(ent.target, null);
                            mList.Add(ext);
                            continue;
                        }
                        else Debug.LogError("Unable to find property: '" + ent.propertyName + "' on " + ent.target.GetType());
                    }
                }
            }

            if (mList.size > 0f)
            {
                if (updatesPerSecond > 0f)
                    StartCoroutine(PeriodicSync());
            }
            else
            {
                Debug.LogWarning("Nothing to sync", this);
                enabled = false;
            }
        }
    }