示例#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, RequestToPixels(width), RequestToPixels(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, width, height).Drawable;

            returnValue.SetBounds(0, 0, width, height);
            return(returnValue);
        }
示例#4
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);
        }
        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)
            {
            }
        }
示例#6
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;
                }
            }