Example #1
0
        public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode)
        {
            if (drawable == null)
            {
                return;
            }

            if (PlatformVersion.Supports(PlatformApis.BlendModeColorFilter))
            {
                BlendMode?filterMode29 = GetFilterMode(mode);

                if (filterMode29 != null)
                {
                    drawable.SetColorFilter(new BlendModeColorFilter(color, filterMode29));
                }
            }
            else
            {
#pragma warning disable CS0612 // Type or member is obsolete
                PorterDuff.Mode?filterModePre29 = GetFilterModePre29(mode);
#pragma warning restore CS0612 // Type or member is obsolete

                if (filterModePre29 != null)
#pragma warning disable CS0618 // Type or member is obsolete
                {
                    drawable.SetColorFilter(color, filterModePre29);
                }
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
Example #2
0
 private void DeactivateAllBtn()
 {
     Android.Graphics.Drawables.Drawable colorr = btnLove.Background;
     btnTroll.Background = btnTroll.Background;
     btnBus.Background   = btnTroll.Background;
     btnMetro.Background = btnTroll.Background;
 }
Example #3
0
        private bool ValidateDeedInfo()
        {
            Validations   validation    = new Validations();
            MessageDialog messageDialog = new MessageDialog();

            Android.Graphics.Drawables.Drawable icon = Resources.GetDrawable(Resource.Drawable.error);
            icon.SetBounds(0, 0, icon.IntrinsicWidth, icon.IntrinsicHeight);

            bool isValid = true;

            if (!validation.IsRequired(erfNumber.Text))
            {
                erfNumber.SetError("This field is required", icon);
                isValid = false;
            }
            if (!validation.IsRequired(titleDeedNumber.Text))
            {
                titleDeedNumber.SetError("This field is required", icon);
                isValid = false;
            }
            if (!validation.IsRequired(extentm2.Text))
            {
                extentm2.SetError("This field is required", icon);
                isValid = false;
            }
            if (!validation.IsRequired(ownerInformation.Text))
            {
                ownerInformation.SetError("This field is required", icon);
                isValid = false;
            }
            return(isValid);
        }
        private bool ValidateForm()
        {
            Validations validation = new Validations();

            Android.Graphics.Drawables.Drawable icon = Resources.GetDrawable(Resource.Drawable.error);
            icon.SetBounds(0, 0, icon.IntrinsicWidth, icon.IntrinsicHeight);

            FormIsValid = true;

            if (!validation.IsValidEmail(username.Text))
            {
                username.SetError("Invalid username", icon);
                FormIsValid = false;
            }
            if (!validation.IsRequired(username.Text))
            {
                username.SetError("This field is required", icon);
                FormIsValid = false;
            }

            if (!validation.IsRequired(password.Text))
            {
                password.SetError("This field is required", icon);
                FormIsValid = false;
            }

            return(FormIsValid);
        }
Example #5
0
 public virtual Com.Zhy.Adapter.Abslistview.ViewHolder SetImageDrawable(int viewId
                                                                        , Android.Graphics.Drawables.Drawable drawable)
 {
     Android.Widget.ImageView view = GetView <ImageView>(viewId);
     view.SetImageDrawable(drawable);
     return(this);
 }
        private bool ValidateForm()
        {
            Validations validation = new Validations();

            Android.Graphics.Drawables.Drawable icon = Resources.GetDrawable(Resource.Drawable.error);
            icon.SetBounds(0, 0, icon.IntrinsicWidth, icon.IntrinsicHeight);

            FormIsValid = true;

            if (!validation.IsValidPhone(courierMobileNumber.Text))
            {
                courierMobileNumber.SetError("Invaild phone number", icon);
                FormIsValid = false;
            }
            if (!validation.IsRequired(pricePerKM.Text))
            {
                pricePerKM.SetError("This field is required", icon);
                FormIsValid = false;
            }

            if (!validation.IsRequired(displayName.Text))
            {
                displayName.SetError("This field is required", icon);
                FormIsValid = false;
            }
            return(FormIsValid);
        }
Example #7
0
        /// <summary>
        /// 缩放图片
        /// </summary>
        /// <param name="drawable"></param>
        /// <param name="maxWidth"></param>
        /// <returns></returns>
        private Bitmap ScalingDrawable(Android.Graphics.Drawables.Drawable drawable, int maxWidth)
        {
            if (drawable == null || drawable.IntrinsicWidth == 0 || drawable.IntrinsicHeight == 0)
            {
                return(null);
            }

            int width  = drawable.IntrinsicWidth;
            int height = drawable.IntrinsicHeight;

            try
            {
                Bitmap image  = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
                Canvas canvas = new Canvas(image);
                drawable.SetBounds(0, 0, width, height);
                drawable.Draw(canvas);
                // 精确缩放
                if (maxWidth <= 0 || width <= maxWidth)
                {
                    return(image);
                }

                float  scale  = maxWidth / (float)width;
                Matrix matrix = new Matrix();
                matrix.PostScale(scale, scale);
                Bitmap resizeImage = Bitmap.CreateBitmap(image, 0, 0, width, height, matrix, true);
                image.Recycle();
                return(resizeImage);
            }
            catch (OutOfMemoryError)
            {
                return(null);
            }
        }
        void SetBackground(MvvmAspire.Controls.Editor element)
        {
            bool hasSetOriginal = false;

            if (originalBackground == null)
            {
                originalBackground = Control.Background;
                hasSetOriginal     = true;
            }

            if (element.BackgroundImage != null)
            {
                var resourceId = UIHelper.GetDrawableResource(element.BackgroundImage);
                if (resourceId > 0)
                {
                    Control.SetBackgroundResource(resourceId);
                }
                else
                {
                    if (!hasSetOriginal)
                    {
                        Control.SetBackgroundDrawable(originalBackground);
                    }
                }
            }
            else
            {
                if (!hasSetOriginal)
                {
                    Control.SetBackgroundDrawable(originalBackground);
                }
            }
        }
Example #9
0
        public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode)
        {
            if (drawable == null)
            {
                return;
            }

            if (OperatingSystem.IsAndroidVersionAtLeast(29))
            {
                BlendMode?filterMode29 = GetFilterMode(mode);

                if (filterMode29 != null)
                {
                    drawable.SetColorFilter(new BlendModeColorFilter(color, filterMode29));
                }
            }
            else
            {
#pragma warning disable CS0612 // Type or member is obsolete
                PorterDuff.Mode?filterModePre29 = GetFilterModePre29(mode);
#pragma warning restore CS0612 // Type or member is obsolete

                if (filterModePre29 != null)
#pragma warning disable CS0618 // Type or member is obsolete
                {
                    drawable.SetColorFilter(color, filterModePre29);
                }
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
Example #10
0
        public void CalculateContentSizes()
        {
            Android.Graphics.Drawables.Drawable drawable = Drawable;
            if (drawable == null || drawable.IntrinsicWidth == 0 || drawable.IntrinsicHeight == 0)
            {
                return;
            }
            int bmWidth  = drawable.IntrinsicWidth;
            int bmHeight = drawable.IntrinsicHeight;

            float scaleX = (float)viewWidth / (float)bmWidth;
            float scaleY = (float)viewHeight / (float)bmHeight;
            float scale  = Math.Min(scaleX, scaleY);

            matrix.SetScale(scale * saveScale, scale * saveScale);

            // Center the image
            float redundantYSpace = (float)viewHeight - (scale * (float)bmHeight);
            float redundantXSpace = (float)viewWidth - (scale * (float)bmWidth);

            redundantYSpace /= (float)2;
            redundantXSpace /= (float)2;

            matrix.PostTranslate(redundantXSpace, redundantYSpace);

            origWidth  = viewWidth - 2 * redundantXSpace;
            origHeight = viewHeight - 2 * redundantYSpace;

            fixTrans();

            ImageMatrix = matrix;

            // Invalidate();
        }
Example #11
0
 public override void SetImageDrawable(Android.Graphics.Drawables.Drawable drawable)
 {
     base.SetImageDrawable(drawable);
     if (null != mAttacher)
     {
         mAttacher.Update();
     }
 }
Example #12
0
        public static void SetColorFilter(this ADrawable drawable, Graphics.Color color, FilterMode mode)
        {
            if (drawable == null)
            {
                return;
            }

            drawable.SetColorFilter(color.ToNative(), mode);
        }
Example #13
0
        public static AColorFilter?GetColorFilter(this ADrawable drawable)
        {
            if (drawable == null)
            {
                return(null);
            }

            return(ADrawableCompat.GetColorFilter(drawable));
        }
 /// <summary>
 /// By default library will switch the color of icon provided (in between active and in-active icons)
 /// This method is used, if people need to set different icons for active and in-active modes.
 /// </summary>
 /// <param name="mInactiveIcon"> in-active drawable icon </param>
 /// <returns> this, to allow builder pattern </returns>
 public virtual BottomNavigationItem setInactiveIcon(Drawable mInactiveIcon)
 {
     if (mInactiveIcon != null)
     {
         this.mInactiveIcon    = mInactiveIcon;
         inActiveIconAvailable = true;
     }
     return(this);
 }
Example #15
0
        protected void InitRadioButtons(string[,] aLaunchExtensions, string aUrl, string aResourceID, RadioGroup aRadioGroup)
        {
            aRadioGroup.RemoveAllViews();

            SortedList <int, RadioButton> _myList = new SortedList <int, RadioButton>();

            for (int i = 0; i < aLaunchExtensions.GetLength(0); i++)
            {
                string _curS     = aLaunchExtensions[i, 0];
                string _curParam = aLaunchExtensions[i, 1];

                RadioButton _button = new RadioButton(this);
                _button.Text = string.Format("{0} [{1}]", _curS, _curParam);
                _button.Tag  = i;

                string _resourceName = aResourceID + _curParam;
                if (_resourceName == aResourceID)
                {
                    _resourceName = aResourceID + "nothing";
                }
                ;

                // int _resourceID = Resources.GetIdentifier(_resourceName, "drawable", this.PackageName);
                if (_resourceName != "nothing")
                {
                    try
                    {
                        var _resourceID = (int)typeof(Resource.Drawable).GetField(_resourceName).GetValue(null);
                        if (_resourceID > 0)
                        {
                            Android.Graphics.Drawables.Drawable _d = Resources.GetDrawable(_resourceID);
                            _d.SetBounds(0, 0, 120, 120);
                            _button.SetCompoundDrawables(_d, null, null, null);
                        }
                        ;
                    }
                    catch { };
                }
                ;
                aRadioGroup.AddView(_button);

                if ((aUrl.IndexOf(_curParam) >= 0) && (_curParam != ""))
                {
                    _myList.Add(_curParam.Length, _button);
                }
                ;
            }
            ;

            if (_myList.Count > 0)
            {
                RadioButton _button = _myList.Values[_myList.Count() - 1];
                aRadioGroup.Check(_button.Id);
            }
            ;
        }
 public void ShowDialog(string title, string message, Android.Graphics.Drawables.Drawable icon = null)
 {
     if (_progressDialog != null)
     {
         _progressDialog.SetTitle(title);
         _progressDialog.SetMessage(message);
         _progressDialog.SetIcon(icon);
         _progressDialog.Show();
     }
 }
        protected override void OnAttached()
        {
            if (!(Element is Xamarin.Forms.Button))
            {
                return;
            }

            _oldDrawable = Control.Background;
            SetGradient();
        }
        void ResolveFlagDrawable(string CountryCode)
        {
            int FlagId = this.Resources.GetIdentifier(CountryCode?.ToLower() ?? "", nameof(Resource.Drawable).ToLower(), this.Activity.PackageName);

            if (FlagId == 0)
            {
                FlagId = Resource.Drawable.flag_unknown;
            }
            Android.Graphics.Drawables.Drawable draw = this.Context.GetDrawable(FlagId);
            this.txtCountryName.SetCompoundDrawablesRelativeWithIntrinsicBounds(null, draw, null, null);
        }
Example #19
0
        public void UnscheduleDrawable(Android.Graphics.Drawables.Drawable who, Action what)
        {
            var runnable = Java.Lang.Thread.RunnableImplementor.Remove(what);

            if (runnable == null)
            {
                return;
            }
            UnscheduleDrawable(who, runnable);
            runnable.Dispose();
        }
Example #20
0
        public static void SetColorFilter(this ADrawable drawable, Graphics.Color color, FilterMode mode)
        {
            if (drawable == null)
            {
                return;
            }

            if (color != null)
            {
                drawable.SetColorFilter(color.ToPlatform(), mode);
            }
        }
Example #21
0
        public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode)
        {
            if ((int)global::Android.OS.Build.VERSION.SdkInt >= 29)
            {
                drawable.SetColorFilter(new BlendModeColorFilter(color, GetFilterMode(mode)));
            }
            else
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
            {
                drawable.SetColorFilter(color, GetFilterModePre29(mode));
            }
        }
Example #22
0
        public static void SetColorFilter(this ADrawable drawable, AColorFilter colorFilter)
        {
            if (drawable == null)
            {
                return;
            }

            if (colorFilter == null)
            {
                ADrawableCompat.ClearColorFilter(drawable);
            }

            drawable.SetColorFilter(colorFilter);
        }
Example #23
0
        /// <summary>
        /// 获取图片数据流
        /// </summary>
        /// <param name="drawable"></param>
        /// <returns></returns>
        public List <byte[]> GetImageByte(Android.Graphics.Drawables.Drawable drawable)
        {
            int    maxWidth = GetDrawableMaxWidth();
            Bitmap image    = ScalingDrawable(drawable, maxWidth);

            if (image == null)
            {
                return(null);
            }
            List <byte[]> data = PrinterUtils.DecodeBitmapToDataList(image, heightParting);

            image.Recycle();
            return(data);
        }
Example #24
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
            viewWidth  = MeasureSpec.GetSize(widthMeasureSpec);
            viewHeight = MeasureSpec.GetSize(heightMeasureSpec);

            //
            // Rescales image on rotation
            //
            if (oldMeasuredHeight == viewWidth && oldMeasuredHeight == viewHeight ||
                viewWidth == 0 || viewHeight == 0)
            {
                return;
            }
            oldMeasuredHeight = viewHeight;

            if (saveScale == 1)
            {
                //Fit to screen.
                float scale;

                Android.Graphics.Drawables.Drawable drawable = Drawable;
                if (drawable == null || drawable.IntrinsicWidth == 0 || drawable.IntrinsicHeight == 0)
                {
                    return;
                }
                int bmWidth  = drawable.IntrinsicWidth;
                int bmHeight = drawable.IntrinsicHeight;

                Log.Debug("bmSize", "bmWidth: " + bmWidth + " bmHeight : " + bmHeight);

                float scaleX = (float)viewWidth / (float)bmWidth;
                float scaleY = (float)viewHeight / (float)bmHeight;
                scale = Math.Min(scaleX, scaleY);
                matrix.SetScale(scale, scale);

                // Center the image
                float redundantYSpace = (float)viewHeight - (scale * (float)bmHeight);
                float redundantXSpace = (float)viewWidth - (scale * (float)bmWidth);
                redundantYSpace /= (float)2;
                redundantXSpace /= (float)2;

                matrix.PostTranslate(redundantXSpace, redundantYSpace);

                origWidth   = viewWidth - 2 * redundantXSpace;
                origHeight  = viewHeight - 2 * redundantYSpace;
                ImageMatrix = matrix;
            }
            fixTrans();
        }
Example #25
0
        public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode)
        {
            if (Forms.Is29OrNewer)
            {
                drawable.SetColorFilter(new BlendModeColorFilter(color, GetFilterMode(mode)));
            }
            else
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
            {
                drawable.SetColorFilter(color, GetFilterModePre29(mode));
            }
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CS0612 // Type or member is obsolete
        }
Example #26
0
        public static void SetColorFilter(this ADrawable drawable, Color color, AColorFilter defaultColorFilter)
        {
            if (drawable == null)
            {
                return;
            }

            if (color == Color.Default)
            {
                SetColorFilter(drawable, defaultColorFilter);
                return;
            }

            drawable.SetColorFilter(color.ToAndroid(), PorterDuff.Mode.SrcIn);
        }
Example #27
0
        public static void SetColorFilter(this ADrawable drawable, Color color, AColorFilter defaultColorFilter, FilterMode mode)
        {
            if (drawable == null)
            {
                return;
            }

            if (color == null)
            {
                SetColorFilter(drawable, defaultColorFilter);
                return;
            }

            drawable.SetColorFilter(color.ToAndroid(), mode);
        }
Example #28
0
        private bool ValidateForm()
        {
            Validations validation = new Validations();

            Android.Graphics.Drawables.Drawable icon = Resources.GetDrawable(Resource.Drawable.error);
            icon.SetBounds(0, 0, icon.IntrinsicWidth, icon.IntrinsicHeight);

            bool formIsValid = true;

            if (!validation.IsRequired(message.Text))
            {
                message.SetError("This field is required", icon);
                formIsValid = false;
            }
            return(formIsValid);
        }
Example #29
0
        private Android.Graphics.Drawables.Drawable MaxResizeImage(Android.Graphics.Drawables.Drawable image, float maxWidth, float maxHeight)
        {
            var originalSize  = image.Bounds;
            var maxSizeFactor = Math.Min(maxWidth / originalSize.Width(), maxHeight / originalSize.Height());

            if (maxSizeFactor > 1)
            {
                return(image);
            }

            var width  = originalSize.Width() * maxSizeFactor;
            var height = originalSize.Height() * maxSizeFactor;

            image.Bounds = new Android.Graphics.Rect(0, 0, (int)width, (int)height);
            return(image);
        }
Example #30
0
        public static void SetColorFilter(this ADrawable drawable, Graphics.Color color, FilterMode mode, AColorFilter?defaultColorFilter)
        {
            if (drawable == null)
            {
                return;
            }

            if (color == null)
            {
                SetColorFilter(drawable, defaultColorFilter);
            }
            else
            {
                drawable.SetColorFilter(color.ToNative(), mode);
            }
        }