Exemplo n.º 1
0
 public void Focus()
 {
     try
     {
         if (CurrentFocus != this)
         {
             CurrentFocus?.Blur(false);
             CurrentFocus = this;
             if (!IsFocused)
             {
                 _isFocused = true;
                 this.RaiseEvent(nameof(GotFocus), EventArgs.Empty);
                 this.OnPropertyChanged(nameof(IsFocused));
             }
         }
         Device.Thread.ExecuteOnMainThread(() =>
         {
             Focusable            = true;
             FocusableInTouchMode = true;
             DroidFactory.ShowKeyboard(this);
         });
     }
     catch (ObjectDisposedException)
     {
         _isFocused = false;
         /*GULLPPPP!!*/
     }
 }
Exemplo n.º 2
0
 public void Focus()
 {
     FocusRequested = true;
     DroidFactory.ShowKeyboard(this);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Measure the view and its content to determine the measured width and the measured height.
        /// This method is invoked by <see cref="View.Measure"/> and should be overriden by subclasses to provide accurate and efficient measurement of their contents.
        /// </summary>
        /// <param name="widthMeasureSpec">Horizontal space requirements as imposed by the parent. The requirements are encoded with <see cref="View.MeasureSpec"/>.</param>
        /// <param name="heightMeasureSpec">Vertical space requirements as imposed by the parent. The requirements are encoded with <see cref="View.MeasureSpec"/>.</param>
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            int  parentHeight;
            int  parentWidth;
            View frame      = null;
            var  fragmentId = ((Parent as BaseFragment)?.Stack as FragmentHistoryStack)?.FragmentId;

            if (fragmentId != null)
            {
                frame = DroidFactory.MainActivity.FindViewById <FrameLayout>(fragmentId.Value);
            }
            else
            {
                frame = base.Parent as View;
            }

            if (frame != null)
            {
                parentWidth  = frame.MeasuredWidth;
                parentHeight = (int)(frame.MeasuredHeight / DroidFactory.DisplayScale);
            }
            else
            {
                var metrics = new DisplayMetrics();
                DroidFactory.MainActivity.WindowManager.DefaultDisplay.GetMetrics(metrics);
                parentWidth  = (int)(metrics.WidthPixels * .6);
                parentHeight = (int)(parentWidth * .75);
            }

            var basicGrid = !(this is GridCell) && !(this is Grid);

            if (MinWidth < 1)
            {
                MinWidth = parentWidth;
            }
            if (MaxWidth < MinWidth)
            {
                MaxWidth = MinWidth;
            }
            if (basicGrid && MinHeight < 1 && parentHeight > 0)
            {
                MinHeight = parentHeight;
            }
            if (MaxHeight < 1 && parentHeight > 0)
            {
                MaxHeight = basicGrid ? parentHeight : double.PositiveInfinity;
            }

            var size = new Size(MeasuredWidth, MeasuredHeight);

            if (MinWidth < 0 || MinHeight < 0 || MaxWidth < 0 || MaxHeight < 0)
            {
                SetMeasuredDimension(ResolveSize((int)size.Width, widthMeasureSpec), ResolveSize((int)size.Height, heightMeasureSpec));
                return;
            }

            if (ResizeRequested ||
                size.Width < MinWidth || size.Height < MinHeight * DroidFactory.DisplayScale ||
                size.Width > MaxWidth || size.Height > MaxHeight * DroidFactory.DisplayScale)
            {
                var minSize = new Size(Math.Min(MaxWidth, MinWidth), Math.Min(MinHeight, MaxHeight));
                var maxSize = new Size(Math.Max(MaxWidth, MinWidth), Math.Max(MinHeight, MaxHeight));
                size            = this.PerformLayout(minSize, maxSize);
                ResizeRequested = false;
            }
            SetMeasuredDimension(ResolveSize((int)size.Width, widthMeasureSpec), ResolveSize((int)size.Height, heightMeasureSpec));
            DroidFactory.ShowKeyboard(TextBase.CurrentFocus);
        }