Exemplo n.º 1
0
        /// <summary>
        /// Returns a <see cref="Drawable"/> with the correct dimensions from an
        /// Android resource id.
        /// </summary>
        /// <param name="drawable">An android <see cref="Drawable"/>.</param>
        /// <param name="width">The width to scale to.</param>
        /// <param name="height">The height to scale to.</param>
        /// <returns>A scaled <see cref="Drawable"/>.</returns>
        private Drawable GetScaleDrawable(Drawable drawable, double width, double height)
        {
            var returnValue = new ScaleDrawable(drawable, GravityFlags.Center, 100, 100).Drawable;

            returnValue.SetBounds(0, 0, (int)Context.ToPixels(width), (int)Context.ToPixels(height));
            return(returnValue);
        }
        /// <summary>
        /// Returns a <see cref="Drawable"/> with the correct dimensions from an
        /// Android resource id.
        /// </summary>
        /// <param name="drawable">An android <see cref="Drawable"/>.</param>
        /// <param name="width">The width to scale to.</param>
        /// <param name="height">The height to scale to.</param>
        /// <returns>A scaled <see cref="Drawable"/>.</returns>
        private Drawable GetScaleDrawable(Drawable drawable, int width, int height)
        {
            var returnValue = new ScaleDrawable(drawable, 0, width, height).Drawable;

            returnValue.SetBounds(0, 0, width, height);
            return(returnValue);
        }
        /// <summary>
        /// Returns a <see cref="Drawable"/> with the correct dimensions from an
        /// Android resource id.
        /// </summary>
        /// <param name="drawable">An android <see cref="Drawable"/>.</param>
        /// <param name="width">The width to scale to.</param>
        /// <param name="height">The height to scale to.</param>
        /// <returns>A scaled <see cref="Drawable"/>.</returns>
        private Drawable GetScaleDrawable(Drawable drawable, int width, int height)
        {
            var returnValue = new ScaleDrawable(drawable, 0, RequestToPixels(width), RequestToPixels(height)).Drawable;

            returnValue.SetBounds(0, 0, width, height);
            return(returnValue);
        }
Exemplo n.º 4
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Entry> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement == null)
            {
                switch ((e.NewElement as UIElements.Entry).Underline)
                {
                case UIElements.Entry.UnderlineDisplay.Normal:
                    GradientDrawable gd = new GradientDrawable();
                    gd.SetShape(ShapeType.Line);
                    gd.SetStroke(5, Color.FromHex("#277db6").ToAndroid());
                    ScaleDrawable sd = new ScaleDrawable(gd, GravityFlags.Bottom, 0f, 2f);
                    sd.SetLevel(7500);
                    Control.SetBackground(sd);
                    break;

                case UIElements.Entry.UnderlineDisplay.Hidden:
                    Control.SetBackground(new GradientDrawable());
                    break;
                }
                if (!(e.NewElement as UIElements.Entry).CursorVisible)
                {
                    Control.SetCursorVisible(false);
                }
            }
        }
Exemplo n.º 5
0
        public bool OnTouch(Android.Views.View v, MotionEvent e)
        {
            context = Android.App.Application.Context;

            if (v is EditText && e.Action == MotionEventActions.Up)
            {
                EditText editText = (EditText)v;
                if (e.RawX >= (editText.Right - editText.GetCompoundDrawables()[2].Bounds.Width()))
                {
                    Drawable img = ContextCompat.GetDrawable(context, Resource.Drawable.Group_23);

                    var sd = new ScaleDrawable(img, 0, 35, 20);

                    if (editText.TransformationMethod == null)
                    {
                        editText.TransformationMethod = PasswordTransformationMethod.Instance;
                        editText.SetCompoundDrawablesRelativeWithIntrinsicBounds(null, null, sd.Drawable, null);
                    }
                    else
                    {
                        editText.TransformationMethod = null;
                        editText.SetCompoundDrawablesRelativeWithIntrinsicBounds(null, null, sd.Drawable, null);
                    }

                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns a <see cref="Drawable"/> with the correct dimensions from an
        /// Android resource id.
        /// </summary>
        /// <param name="resId">The android resource id to load the drawable from.</param>
        /// <param name="width">The width to scale to.</param>
        /// <param name="height">The height to scale to.</param>
        /// <returns>A scaled <see cref="Drawable"/>.</returns>
        public Drawable GetScaleDrawableFromResourceId(int resId, int width, int height)
        {
            var drawable = Resources.GetDrawable(resId);

            var returnValue = new ScaleDrawable(drawable, 0, width, height).Drawable;

            returnValue.SetBounds(0, 0, width, height);
            return(returnValue);
        }
        /// <summary>
        /// Just a Helper to rescale button icons.
        /// </summary>
        /// <param name="button">Button</param>
        /// <param name="scale">Icon</param>
        public static void ScaleButtonDrawable(Button button, float scale)
        {
            Drawable d = button.GetCompoundDrawables()[0];

            d.SetBounds(0, 0, (int)(d.IntrinsicWidth * scale), (int)(d.IntrinsicHeight * scale));
            ScaleDrawable sd = new ScaleDrawable(d, GravityFlags.Center, d.IntrinsicWidth * scale, d.IntrinsicWidth * scale);

            button.SetCompoundDrawables(sd.Drawable, null, null, null);
        }
Exemplo n.º 8
0
        private void ConfigureControl()
        {
            context = Android.App.Application.Context;

            Drawable img = ContextCompat.GetDrawable(context, Resource.Drawable.Group_23);

            var sd = new ScaleDrawable(img, 0, 35, 20);

            EditText editText = ((EditText)Control);

            editText.SetCompoundDrawablesRelativeWithIntrinsicBounds(null, null, sd.Drawable, null);
            editText.SetOnTouchListener(new OnDrawableTouchListener());
        }
        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)
            {
            }
        }
Exemplo n.º 10
0
            public void DrawWallpaper(Canvas c)
            {
                try
                {
                    if (bIsLockScreen)
                    {
                        if (!myKM.IsDeviceLocked && !myKM.IsKeyguardLocked)
                        {
                            bIsLockScreen     = false;
                            tstAnimationStart = DateTime.Now;
                            tstAnimationEnd   = tstAnimationStart.AddSeconds(.5);
                            //Tools.ShowToast(mContext, "LockScreenMode end");
                        }
                    }
                }
                catch { }

                try
                {
                    if (background == null)
                    {
                        if (wallpaperDrawable != null)
                        {
                            var    drw    = new ScaleDrawable(wallpaperDrawable, GravityFlags.Center, size.X, size.Y).Drawable;
                            Bitmap bmp    = Bitmap.CreateBitmap(size.X, size.Y, Bitmap.Config.Argb8888);
                            Canvas canvas = new Canvas(bmp);
                            drw.SetBounds(0, 0, size.X, size.Y);
                            drw.Draw(canvas);
                            background = bmp;
                        }
                    }
                }
                catch { }

                try
                {
                    c.DrawColor(Color.White);
                    if (wallpaperDrawable != null)
                    {
                        wallpaperDrawable.Draw(c);
                    }

                    int x = 0;
                    int y = 0;
                    int w = size.X;
                    int h = size.Y;

                    if (bIsLockScreen)
                    {
                        y  = size.Y / 10;
                        h -= y;
                    }
                    else
                    {
                        w -= size.X / 2;
                        y  = size.Y * 3 / 11;
                        h -= size.Y / 2;
                    }

                    if (tstAnimationEnd > DateTime.Now)
                    {
                        double nTotal = (tstAnimationEnd - tstAnimationStart).TotalMilliseconds;
                        double nDone  = (DateTime.Now - tstAnimationStart).TotalMilliseconds;

                        double x1 = 0;
                        double y1 = size.Y / 10;
                        double w1 = size.X;
                        double h1 = size.Y - y;

                        double x2 = 0;
                        double y2 = size.Y * 3 / 11;
                        double w2 = size.X - size.X / 2;
                        double h2 = size.Y - size.Y / 2;

                        double nx = x1 + (x2 - x1) * nDone / nTotal;
                        double ny = y1 + (y2 - y1) * nDone / nTotal;
                        double nw = w1 + (w2 - w1) * nDone / nTotal;
                        double nh = h1 + (h2 - h1) * nDone / nTotal;

                        x = (int)nx;
                        y = (int)ny;
                        w = (int)nw;
                        h = (int)nh;
                    }

                    clockView.DrawClock(c, lth.RealSunTime, x, y, w, h);
                }
                catch (Exception ex)
                {
                    Paint p = new Paint();
                    p.Color = Color.Red;
                    c.DrawColor(Color.White);
                    c.DrawText(ex.Message, 0, 0, p);
                }

                if (tstAnimationEnd != DateTime.MinValue && tstAnimationEnd < DateTime.Now)
                {
                    tstAnimationStart = DateTime.MinValue;
                    tstAnimationEnd   = DateTime.MinValue;
                }
            }