void SetImagePlaceholder()
        {
            if (Element.ImagePlaceholder != null)
            {
                var placeholder = Element.ImagePlaceholder as FileImageSource;
                if (placeholder != null && placeholder.File != null)
                {
                    var resourceID = UIHelper.GetDrawableResource(placeholder);
                    //Bitmap imageBitmap = BitmapFactory.DecodeResource(Context.Resources, resourceID);

                    //SetImageCorners(imageBitmap);

                    if (resourceID > 0)
                    {
                        Bitmap imageBitmap = ImageCache.Instance.Get(resourceID.ToString());
                        if (imageBitmap == null)
                        {
                            BitmapWorkerTask task = new BitmapWorkerTask(imageView, -1, -1, ImageCache.Instance);
                            imageView.SetImageDrawable(new AsyncDrawable(imageView.Resources, null, task));
                            task.Execute(resourceID);
                            task.Finished += (s, e) =>
                                             SetImageCorners(e);
                        }
                        else
                        {
                            SetImageCorners(imageBitmap);
                        }
                    }
                }
            }
        }
        void SetBackground(MvvmAspire.Controls.Button element)
        {
            if (element.BackgroundImage != null)
            {
                // seems this is not working, LoadImageAsync returns null
                //var bitmap = await imageLoader.LoadImageAsync(element.BackgroundImage, Forms.Context);
                //button.SetBackgroundDrawable(new Android.Graphics.Drawables.BitmapDrawable(bitmap));

                var resourceId = UIHelper.GetDrawableResource(element.BackgroundImage);
                if (resourceId > 0)
                {
                    Control.SetBackgroundResource(resourceId);
                }
                else
                {
                    Control.SetBackgroundResource(Android.Resource.Drawable.ButtonDefault);
                }
            }
            else
            {
                if (element.BackgroundColor == Xamarin.Forms.Color.Transparent ||
                    element.BackgroundColor == Xamarin.Forms.Color.Default)
                {
                    Control.SetBackgroundResource(Android.Resource.Drawable.ButtonDefault);
                }
            }
        }
        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);
                }
            }
        }
示例#4
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Switch> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || this.Element == null)
            {
                return;
            }

            var customSwitch = this.Element as Switch;

            var control = base.Control;

            control.TextOn  = customSwitch.TextOn;
            control.TextOff = customSwitch.TextOff;

            if (customSwitch.TrackDrawable != null && customSwitch.TrackDrawable.File != null)
            {
                control.TrackDrawable = Resources.GetDrawable(UIHelper.GetDrawableResource(customSwitch.TrackDrawable));
            }

            if (customSwitch.ThumbDrawable != null && customSwitch.ThumbDrawable.File != null)
            {
                control.ThumbDrawable = Resources.GetDrawable(UIHelper.GetDrawableResource(customSwitch.ThumbDrawable));
            }
        }
示例#5
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.DatePicker> e)
        {
            base.OnElementChanged(e);

            var baseElement = e.NewElement as DatePicker;

            base.Control.SetTextColor(baseElement.TextColor.ToAndroid());
            Control.LongClickable = false;

            if (baseElement.BackgroundImage != null && baseElement.BackgroundImage.File != null)
            {
                base.Control.SetBackgroundResource(UIHelper.GetDrawableResource(baseElement.BackgroundImage));
            }

            //var fontName = Resolver.Get<IFontService>().GetFontName(baseElement.FontStyle);
            //if (!string.IsNullOrEmpty(fontName))
            //    SetTypeface(fontName);
            if (baseElement != null)
            {
                SetTextAlignment(baseElement);
                SetBgColor(baseElement);
                SetTextSize(baseElement);
                Control.Text       = baseElement.Date.ToString(baseElement.Format);
                Control.TextLocale = Java.Util.Locale.Default;

                baseElement.PropertyChanged += baseElement_PropertyChanged;
            }
        }
        async void SetImage()
        {
            bool hasSetImage = false;
            //if (Base.ImagePlaceholder != null)
            //    imageView.SetImageResource(UIHelper.GetDrawableResource(Base.ImagePlaceholder));
            ImageSource imageSource = Base.ImageSource;

            if (imageSource != null && imageSource is FileImageSource)
            {
                imageView.SetImageResource(UIHelper.GetDrawableResource(imageSource as FileImageSource));
                return;
            }

            if (imageSource != null)
            {
                var thisImageId = Guid.NewGuid();
                imageView.Tag = new ImageGetId {
                    Id = thisImageId
                };
                Bitmap image;
                try
                {
                    image = await imageSource.GetImage();
                }
                catch (TaskCanceledException)
                {
                    image = null;
                }
                catch (Exception ex)
                {
                    image = null;
                }

                var imageGetId = (ImageGetId)imageView.Tag;
                if (thisImageId != imageGetId.Id)
                {
                    return;
                }

                if (image != null)
                {
                    imageView.SetImageBitmap(image);
                    hasSetImage = true;
                }
            }


            //if (!hasSetImage && Base.ImagePlaceholder != null)
            //{
            //    imageView.SetImageResource(UIHelper.GetDrawableResource(Base.ImagePlaceholder));
            //}
        }
示例#7
0
        public void UpdateSelectedTab(Activity _activity, IList <string> activeIcons, List <string> icons)
        {
            if (table != null)
            {
                table.Visibility = ViewStates.Visible;
            }

            if (imageViewList != null && titleViewList != null)
            {
                for (int i = 0; i < titleViewList.Count; i++)
                {
                    ImageView icon      = imageViewList.ElementAt(i);
                    TextView  title     = titleViewList.ElementAt(i);
                    TextView  indicator = indicatorList.ElementAt(i);

                    var ivParent = icon.Parent.Parent as Android.Widget.RelativeLayout;

                    if (selectedIndex == i)
                    {
                        if (activeIcons.Count > 0)
                        {
                            icon.SetImageResource(UIHelper.GetDrawableResource(activeIcons.ElementAt(i)));
                        }
                        title.SetTextColor(selectedTextColor);
                        indicator.SetBackgroundColor(selectedTextColor);
                        if (!string.IsNullOrEmpty(selectedDrawable))
                        {
                            ivParent.Background = _activity.Resources.GetDrawable(UIHelper.GetResource(UIHelper.Drawable, selectedDrawable));
                        }
                        //ivParent.Background = _activity.Resources.GetDrawable(UIHelper.GetResource(UIHelper.Drawable, "my_menu_item_pressed"));
                    }
                    else
                    {
                        if (icons.Count > 0)
                        {
                            icon.SetImageResource(UIHelper.GetDrawableResource(icons.ElementAt(i)));
                        }
                        title.SetTextColor(textColor);
                        indicator.SetBackgroundColor(Color.Transparent);
                        if (!string.IsNullOrEmpty(backgroundDrawable))
                        {
                            ivParent.Background = _activity.Resources.GetDrawable(UIHelper.GetResource(UIHelper.Drawable, backgroundDrawable));
                        }
                        //ivParent.Background = _activity.Resources.GetDrawable(UIHelper.GetResource(UIHelper.Drawable, "segment_button_unpressed"));
                    }
                }
            }
        }
        private void SetSeparator()
        {
            if (BaseControl.SeparatorVisibility != SeparatorVisibility.None)
            {
                if (BaseControl.SeparatorBackground != null && BaseControl.SeparatorBackground.File != null)
                {
                    Control.Divider = this.Resources.GetDrawable(UIHelper.GetDrawableResource(BaseControl.SeparatorBackground));
                }
                else
                {
                    Control.Divider = CreateMyDrawable(BaseControl.SeparatorColor.ToAndroid());
                }

                Control.DividerHeight = BaseUIHelper.ConvertDPToPixels(BaseControl.SeparatorHeight);
            }
        }
        protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs <MvvmAspire.Controls.Image> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                AttachPageEvents(e.NewElement);
            }

            //if (e.OldElement != null || Element == null)
            //    return;

            if (Control == null)
            {
                imageDownloader = new AndroidImageDownloader();
                imageView       = new CustomImageView(Context);
                imageView.SetElement(Element);
                imageView.SetAdjustViewBounds(true);

                SetNativeControl(imageView);

                int resourceID = -1;
                if (Element.ImagePlaceholder != null && Element.ImagePlaceholder is FileImageSource)
                {
                    var placeholder = Element.ImagePlaceholder as FileImageSource;
                    resourceID = UIHelper.GetDrawableResource(placeholder);
                }

                if (resourceID < 0)
                {
                    resourceID = Android.Resource.Drawable.GalleryThumb;
                }
            }

            if (e.NewElement != null)
            {
                SetAspect();
                SetOpaque();
                SetImagePlaceholder();
                SetImageSource();
                SetIsClickable();

                Element.PropertyChanged += Base_PropertyChanged;
            }
        }
示例#10
0
        void SetImage(int height)
        {
            Drawable drawableRight = null;
            Drawable drawableLeft  = null;

            if (Element.ImageRight != null && Element.ImageRight.File != null)
            {
                var element = Element.ImageRight;
                drawableRight = Context.Resources.GetDrawable(UIHelper.GetDrawableResource(Element.ImageRight));
                drawableRight.SetBounds(0, 0, BaseUIHelper.ConvertDPToPixels(Element.ImageRightWidth), BaseUIHelper.ConvertDPToPixels(Element.ImageRightWidth));
            }

            if (Element.ImageLeft != null && Element.ImageLeft.File != null)
            {
                drawableLeft = Context.Resources.GetDrawable(UIHelper.GetDrawableResource(Element.ImageLeft));
                drawableLeft.SetBounds(0, 0, BaseUIHelper.ConvertDPToPixels(Element.ImageLeftWidth), BaseUIHelper.ConvertDPToPixels(Element.ImageLeftHeight));
            }

            textView.SetCompoundDrawablesRelative(drawableLeft, null, drawableRight, null);
        }
示例#11
0
        public void UpdateSelectedTab(Activity _activity, IList <string> activeIcons, List <string> icons)
        {
            if (imageViewList != null && titleViewList != null)
            {
                for (int i = 0; i < imageViewList.Count; i++)
                {
                    ImageView icon  = imageViewList.ElementAt(i);
                    TextView  title = titleViewList.ElementAt(i);

                    var ivParent = icon.Parent.Parent as Android.Widget.RelativeLayout;

                    if (selectedIndex == i)
                    {
                        if (activeIcons.Count > 0)
                        {
                            icon.SetImageResource(UIHelper.GetDrawableResource(activeIcons.ElementAt(i)));
                        }
                        title.SetTextColor(selectedTextColor);

                        if (!string.IsNullOrEmpty(selectedDrawable))
                        {
                            ivParent.Background = _activity.Resources.GetDrawable(UIHelper.GetResource(UIHelper.Drawable, selectedDrawable));
                        }
                    }
                    else
                    {
                        if (icons.Count > 0)
                        {
                            icon.SetImageResource(UIHelper.GetDrawableResource(icons.ElementAt(i)));
                        }
                        title.SetTextColor(textColor);

                        if (!string.IsNullOrEmpty(backgroundDrawable))
                        {
                            ivParent.Background = _activity.Resources.GetDrawable(UIHelper.GetResource(UIHelper.Drawable, backgroundDrawable));
                        }
                    }
                }
            }
        }
示例#12
0
        //private void CheckEnabled()
        //{
        //    if (Element.IsEnabled)
        //    {
        //        if (!Element.AllowCutCopyPaste)
        //        {
        //            Control.RequestFocus();
        //            UIHelper.OpenSoftKeyboard(Control);
        //        }

        //    }
        //    else
        //    {
        //        if (!Element.AllowCutCopyPaste)
        //        {
        //            UIHelper.CloseSoftKeyboard(Control);
        //        }
        //  }
        //}
        private void CreateShapeDrawable()
        {
            GradientDrawable shape = new GradientDrawable();

            shape.SetShape(ShapeType.Rectangle);
            shape.SetCornerRadius(BaseUIHelper.ConvertDPToPixels(Element.CornerRadius));

            if (Element.BackgroundColor != Xamarin.Forms.Color.Default)
            {
                shape.SetColor(Element.BackgroundColor.ToAndroid());
            }

            if (Element.ImageRight != null && Element.ImageRight.File != null)
            {
                Drawable drawable = Context.Resources.GetDrawable(UIHelper.GetDrawableResource(Element.ImageRight));
                drawable.SetBounds(0, 0, BaseUIHelper.ConvertDPToPixels(Element.ImageRightWidth),
                                   BaseUIHelper.ConvertDPToPixels(Element.ImageRightHeight));
                Control.SetCompoundDrawablesRelative(null, null, drawable, null);
            }
            //if (Element.CornerRadius > 0)
            //    this.SetPadding(5, 2, 5, 2);

            Control.Background = shape;
        }
        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)
            {
            }
        }
        async void SetImageSource()
        {
            if (Element.Source != null)
            {
                if (Element.Source is UriImageSource)
                {
                    isImageInitialSet = true;


                    var uri = Element.Source.GetValue(UriImageSource.UriProperty) as Uri;

                    var bitmap = await imageDownloader.GetImageAsync(uri);

                    SetImageCorners(bitmap);
                }
                else if (Element.Source is FileImageSource)
                {
                    if ((Element.Width > 0 && Element.Height > 0) || (Element.WidthRequest > 0 && Element.HeightRequest > 0))
                    {
                        isImageInitialSet = true;

                        var source = Element.Source as FileImageSource;
                        if (source != null && source.File != null)
                        {
                            var resourceID = UIHelper.GetDrawableResource(source);
                            if (resourceID > 0)
                            {
                                Bitmap imageBitmap = ImageCache.Instance.Get(resourceID.ToString());
                                if (imageBitmap == null)
                                {
                                    var width             = BaseUIHelper.ConvertDPToPixels(Element.Width <= 0 ? Element.WidthRequest : Element.Width);
                                    var height            = BaseUIHelper.ConvertDPToPixels(Element.Height <= 0 ? Element.HeightRequest : Element.Height);
                                    BitmapWorkerTask task = new BitmapWorkerTask(imageView, width, height, ImageCache.Instance);
                                    imageView.SetImageDrawable(new AsyncDrawable(imageView.Resources, null, task));
                                    task.Execute(resourceID);
                                    task.Finished += (s, e) =>
                                                     SetImageCorners(e);
                                }
                                else
                                {
                                    SetImageCorners(imageBitmap);
                                }
                            }
                            else
                            {
                                var imageBitmap = await BitmapFactory.DecodeFileAsync(source.File);

                                SetImageCorners(imageBitmap);
                            }
                        }
                    }
                }
                else if (Element.Source is StreamImageSource)
                {
                    isImageInitialSet = true;
                    var source = Element.Source as StreamImageSource;
                    var cts    = new System.Threading.CancellationTokenSource();
                    var str    = await source.Stream(cts.Token);

                    using (var reader = new System.IO.BinaryReader(str))
                    {
                        var data   = reader.ReadBytes((int)str.Length);
                        var bitmap = await BitmapFactory.DecodeByteArrayAsync(data, 0, data.Length);

                        SetImageCorners(bitmap);
                    }
                }
            }
            else
            {
                if (Element.ImagePlaceholder == null)
                {
                    imageView.SetImageBitmap(null);
                }
            }
        }
        private async void UpdateBitmap(Image previous = null)
        {
            if (Element == null || Control == null)
            {
                return;
            }

            Bitmap      bitmap = null;
            ImageSource source = Element.Source;

            if (previous == null || !object.Equals(previous.Source, Element.Source))
            {
                SetIsLoading(true);
                ((CustomImageView)base.Control).SkipInvalidate();

                // I'm not sure where this comes from.
                //   Control.SetImageResource(17170445);

                if (BaseControl.ImagePlaceholder != null)
                {
                    var placeholder = BaseControl.ImagePlaceholder as FileImageSource;

                    var resourceID = UIHelper.GetDrawableResource(placeholder);
                    if (resourceID > 0)
                    {
                        Bitmap imageBitmap = imageCache.Get(resourceID.ToString());
                        //imageBitmap = BitmapFactory.DecodeResource(Context.Resources, resourceID);

                        if (imageBitmap == null)
                        {
                            BitmapWorkerTask task = new BitmapWorkerTask(Control, -1, -1, imageCache);
                            Control.SetImageDrawable(new AsyncDrawable(Control.Resources, null, task));
                            task.Execute(resourceID);
                            task.Finished += (s, e) =>
                            {
                                Control.SetImageBitmap(e);
                                e.Dispose();
                            };
                        }
                        else
                        {
                            Control.SetImageBitmap(imageBitmap);
                            imageBitmap.Dispose();
                        }
                    }
                }


                if (source != null)
                {
                    try
                    {
                        bitmap = await GetImageFromImageSource(source, Context);
                    }
                    catch (TaskCanceledException)
                    {
                    }
                    catch (IOException)
                    {
                    }
                    catch (NotImplementedException)
                    {
                    }
                }

                if (Element != null && object.Equals(Element.Source, source))
                {
                    if (!_isDisposed)
                    {
                        if (bitmap == null && BaseControl.ImagePlaceholder != null)
                        {
                        }
                        else
                        {
                            Control.SetImageBitmap(bitmap);
                        }

                        if (bitmap != null)
                        {
                            bitmap.Dispose();
                        }
                        SetIsLoading(false);
                        ((IVisualElementController)base.Element).NativeSizeChanged();
                    }
                }
            }
        }
示例#16
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.SearchBar> e)
        {
            base.OnElementChanged(e);

            var element = (MvvmAspire.Controls.SearchBar)Element;

            // Get native control (background set in shared code, but can use SetBackgroundColor here)
            Android.Widget.SearchView searchView = (base.Control as Android.Widget.SearchView);
            searchView.SetInputType(InputTypes.ClassText | InputTypes.TextVariationNormal);

            int textViewId = searchView.Context.Resources.GetIdentifier("android:id/search_src_text", null, null);

            editText = (searchView.FindViewById(textViewId) as EditText);
            editText.SetTextColor(element.TextColor.ToAndroid());
            //editText.TextAlignment = Android.Views.TextAlignment.
            editText.Gravity = GravityFlags.CenterVertical | GravityFlags.Start;

            if (element.PlaceholderColor != Xamarin.Forms.Color.Default)
            {
                editText.SetHintTextColor(element.PlaceholderColor.ToAndroid());
            }

            //if (element.ShowSearchIconAsPlaceHolder)
            //    editText.SetCompoundDrawablesRelativeWithIntrinsicBounds(Android.Resource.Drawable.IcMenuSearch, 0, 0, 0);

            //editText.TextChanged += editText_TextChanged;

            int          searchPlateId     = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null);
            LinearLayout searchPlateLayout = (searchView.FindViewById(searchPlateId) as LinearLayout);

            //searchPlateLayout.SetBackgroundColor(Android.Graphics.Color.Red);

            if (element.Background != null && element.Background.File != null)
            {
                searchPlateLayout.SetBackgroundResource(UIHelper.GetDrawableResource(element.Background));
            }
            else
            {
                if (element.BackgroundColor != Xamarin.Forms.Color.Default)
                {
                    searchPlateLayout.SetBackgroundColor(element.BackgroundColor.ToAndroid());
                }
            }

            int frameId = searchView.Context.Resources.GetIdentifier("android:id/search_edit_frame", null, null);
            //Android.Views.View frameView = (searchView.FindViewById(frameId) as Android.Views.View);
            LinearLayout frameView = (searchView.FindViewById(frameId) as LinearLayout);

            if (element.Background != null && element.Background.File != null)
            {
                frameView.SetBackgroundResource(UIHelper.GetDrawableResource(element.Background));
            }

            int       searchIconId = searchView.Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
            ImageView searchIcon   = (searchView.FindViewById(searchIconId) as ImageView);

            if (element.SearchIcon != null && element.SearchIcon.File != null)
            {
                searchIcon.SetImageResource(UIHelper.GetDrawableResource(element.SearchIcon));
            }
            else
            {
                searchIcon.SetImageResource(Android.Resource.Drawable.IcMenuSearch);
            }

            if (element.AlignSearchIconRight)
            {
                searchIcon.LayoutParameters = new LinearLayout.LayoutParams(0, 0);

                var iv = new ImageView(this.Context);
                iv.Click += (s, ev) =>
                {
                    if (Element.SearchCommand != null && Element.SearchCommand.CanExecute(Element.SearchCommandParameter))
                    {
                        Element.SearchCommand.Execute(Element.SearchCommandParameter);
                    }
                };

                if (searchIcon.Drawable != null)
                {
                    iv.SetImageDrawable(searchIcon.Drawable);
                }

                frameView.AddView(iv);

                this.SetBackgroundColor(Android.Graphics.Color.Transparent);
            }


            int       search_close_btnID = searchView.Context.Resources.GetIdentifier("android:id/search_close_btn", null, null);
            ImageView search_close_btn   = (searchView.FindViewById(search_close_btnID) as ImageView);

            search_close_btn.Click += search_close_btn_Click;

            SetTextInputTypes(element);
            search_close_btn.SetImageResource(Android.Resource.Drawable.IcMenuCloseClearCancel);

            //if (GetThemeName() == Android.Resource.Style.ThemeMaterialLightDarkActionBar)
            //{

            //}

            CreateShapeDrawable(element);
            SetTypeface();
            //if (element.HeightRequest > 0)
            //{
            //    editText.SetHeight(BaseUIHelper.ConvertDPToPixels(element.HeightRequest));
            //}
        }
示例#17
0
        private void ActionBarTabsSetup(ActionBar actionBar)
        {
            if (actionBar.TabCount == 0)
            {
                return;
            }

            if (menuItems.Count > 0)
            {
                menuItems.Clear();
            }

            mMenu.SetTextColor(myTabbedPage.TextColor.ToAndroid(), myTabbedPage.SelectedTextColor.ToAndroid());

            int ctr = 0;

            foreach (var page in myTabbedPage.Children)
            {
                try
                {
                    var cmi = new CustomMenuItem();
                    cmi.Id      = ctr;
                    cmi.Caption = (myTabbedPage.TextVisible) ? page.Title : "";

                    if (myTabbedPage.ActiveIcons.Count > 0)
                    {
                        cmi.ActiveImageId = UIHelper.GetDrawableResource(myTabbedPage.ActiveIcons.ElementAt(ctr));
                    }

                    if (page.Icon != null && page.Icon.File != null)
                    {
                        cmi.ImageResourceId = UIHelper.GetDrawableResource(page.Icon);
                    }

                    if (cmi.Id == myTabbedPage.BadgeLocation)
                    {
                        cmi.Badge = myTabbedPage.BadgeCount.ToString();
                    }

                    menuItems.Add(cmi);

                    if (!mMenu.IsShowing())
                    {
                        try
                        {
                            mMenu.SetMenuItems(menuItems);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }

                    ctr++;
                }
                catch (Exception)
                {
                    continue;
                }

                _isFirstDesign = false;
            }

            mMenu.SetSelectedIndex(currentTabIndex);

            if (mMenu.IsShowing())
            {
                return;
            }

            if (myTabbedPage.TabScreenLocation == TabGravity.Bottom)
            {
                myTabbedPage.Padding = new Thickness(0, 0, 0, originalPadding);
            }
            else
            {
                myTabbedPage.Padding = new Thickness(0, originalPadding, 0, 0);
            }

            ShowCustomMenu();

            mMenu.UpdateBadgeCount(myTabbedPage.BadgeCount);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Editor> e)
        {
            bool hasSet = false;


            if (e.OldElement == null && this.Element != null)
            {
                //SetNativeControl(new EditTextCustom(Context));
                //SetNativeControl(new EditTextCustom());
                hasSet = true;
            }

            base.OnElementChanged(e);

            if (!hasSet)
            {
                return;
            }

            if (Control != null)
            {
                DefaultKeyListener = Control.KeyListener;
                // do whatever you want to the textField here!
                Control.SetBackgroundColor(global::Android.Graphics.Color.Transparent);

                if (BaseElement.BackgroundImage != null && BaseElement.BackgroundImage.File != null)
                {
                    var resourceId = UIHelper.GetDrawableResource(BaseElement.BackgroundImage);
                    Control.SetBackgroundResource(resourceId);
                }

                Control.Hint = BaseElement.Placeholder;
                Control.SetHintTextColor(BaseElement.PlaceHolderColor.ToAndroid());

                if (BaseElement.MaxCharacter.HasValue)
                {
                    Control.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(BaseElement.MaxCharacter.Value) });
                }
            }
            var editorControl = (Editor)Element;



            editorControl.PropertyChanged += async(s, ev) =>
            {
                if (Element == null || Control == null)
                {
                    return;
                }

                var element = (Editor)s;

                switch (ev.PropertyName)
                {
                case "BackgroundImage": SetBackground(element); break;

                case "FontFamily": SetTypeface(element); break;

                case "FontSize": SetTextSize(element); break;

                case "TextAlignment": SetTextAlignment(element); break;

                case "SuppressKeyboard": SetShowSoftInputOnFocus(element); break;

                case "Text": HideSoftKeyBoardOnTextChanged(element); break;

                case "IsReadOnly": SetIsReadOnly(element); break;

                case "IsFocused":
                    var x = Control.IsInTouchMode;
                    if (!element.IsFocused)
                    {
                        try
                        {
                            //Control.EditorAction += (object sender, Android.Widget.TextView.EditorActionEventArgs evt) => evt.Handled = true;
                            await Task.Delay(10);

                            //Control.Focusable = false;
                            //Control.Clickable = false;
                            Control.ClearFocus();
                            ////Control.ClearFocus();
                            //await Task.Delay(10);

                            Control.Focusable            = false;
                            Control.FocusableInTouchMode = false;
                            Control.Focusable            = true;
                            Control.FocusableInTouchMode = true;
                        }
                        catch (Exception)
                        {
                        }
                    }
                    break;
                }
            };

            //Control.TextChanged += (s, ev) => Element.Raise("TextChanged", ev);
            //Control.Completed += (s, ev) => Element.Raise("Completed", ev);
            Control.SetPadding(5, 5, 5, 5);
            //Control.Focusable = false;
            //Control.FocusableInTouchMode = true;
            SetBackground(editorControl);
            SetTypeface(editorControl);
            SetTextSize(editorControl);
            SetTextAlignment(editorControl);
            SetShowSoftInputOnFocus(editorControl);
            SetIsReadOnly(editorControl);

            Control.ViewAttachedToWindow += Control_ViewAttachedToWindow;
            //Control.Touch += Control_Touch;
            //Control.FocusChange += Control_FocusChange;
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null || e.NewElement == null)
            {
                return;
            }

            var view = new Android.Widget.RelativeLayout(this.Context);


            if (Base.BackgroundImage != null)
            {
                var imageView = new ImageView(this.Context);
                imageView.SetScaleType(ImageView.ScaleType.FitXy);
                var cornerRad  = Base.CornerRadius.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                var res        = this.Context.Resources;
                var resourceId = UIHelper.GetDrawableResource(Base.BackgroundImage);

                Bitmap src = BitmapFactory.DecodeResource(res, resourceId);
                var    dr  = RoundedBitmapDrawableFactory.Create(res, src);
                dr.CornerRadius            = float.Parse(cornerRad[0]);
                imageView.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
                imageView.SetBackground(dr);
                imageView.SetImageBitmap(src);

                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    imageView.ClipToOutline = true;
                }


                view.AddView(imageView);
            }

            this.SetBackgroundColor(Xamarin.Forms.Color.Default.ToAndroid());
            SetNativeControl(view);

            if (!string.IsNullOrWhiteSpace(Base.GradientColor))
            {
                view.Background = GradientConverter(Base.GradientColor);
            }
            else
            {
                CreateShapeDrawable();
            }

            Element.PropertyChanged += (s, ev) =>
            {
                if (Element == null)
                {
                    return;
                }
                switch (ev.PropertyName)
                {
                case "GradientColor": view.Background = GradientConverter(Base.GradientColor); break;

                case "HasBorder": break;
                }
            };
        }
示例#20
0
        void SetImages(MvvmAspire.Controls.Entry element)
        {
            int leftResourceId = 0, topResourceId = 0, rightResourceId = 0, bottomResourceId = 0;

            if (element.ImageLeft != null && element.ImageLeft.File != null)
            {
                leftResourceId = UIHelper.GetDrawableResource(element.ImageLeft);
            }
            if (element.ImageTop != null && element.ImageTop.File != null)
            {
                topResourceId = UIHelper.GetDrawableResource(element.ImageTop);
            }
            if (element.ImageRight != null && element.ImageRight.File != null)
            {
                rightResourceId = UIHelper.GetDrawableResource(element.ImageRight);
            }
            if (element.ImageBottom != null && element.ImageBottom.File != null)
            {
                bottomResourceId = UIHelper.GetDrawableResource(element.ImageBottom);
            }

            bool hasResource = leftResourceId > 0 || rightResourceId > 0 || topResourceId > 0 || bottomResourceId > 0;

            if (hasCompoundDrawable || hasResource)
            {
                hasCompoundDrawable = true;

                //Android.Graphics.Drawables.Drawable leftDrawable = leftResourceId > 0 ? Resources.GetDrawable(leftResourceId) : null;
                //if (leftDrawable != null)
                //    leftDrawable.SetBounds(0, 0, leftDrawable.IntrinsicWidth, leftDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable topDrawable = topResourceId > 0 ? Resources.GetDrawable(topResourceId) : null;
                //if (topDrawable != null)
                //    topDrawable.SetBounds(0, 0, topDrawable.IntrinsicWidth, topDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable rightDrawable = rightResourceId > 0 ? Resources.GetDrawable(rightResourceId) : null;
                //if (rightDrawable != null)
                //    rightDrawable.SetBounds(0, 0, rightDrawable.IntrinsicWidth, rightDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable bottomDrawable = bottomResourceId > 0 ? Resources.GetDrawable(bottomResourceId) : null;
                //if (bottomDrawable != null)
                //    bottomDrawable.SetBounds(0, 0, bottomDrawable.IntrinsicWidth, bottomDrawable.IntrinsicHeight);

                //Control.SetCompoundDrawablesRelative(leftDrawable, topDrawable, rightDrawable, bottomDrawable);
                //Control.SetCompoundDrawables(leftDrawable, topDrawable, rightDrawable, bottomDrawable);


                var leftDrawable = (leftResourceId > 0) ? Resources.GetDrawable(leftResourceId) : null;
                if (leftDrawable != null)
                {
                    if (element.ImageLeftWidth > 0)
                    {
                        leftDrawable = ResizeImage(leftDrawable, BaseUIHelper.ConvertDPToPixels(element.ImageLeftWidth), BaseUIHelper.ConvertDPToPixels(element.ImageLeftWidth));
                    }
                    else
                    {
                        Resources.GetDrawable(leftResourceId);
                    }
                }

                var topDrawable    = (topResourceId > 0) ? Resources.GetDrawable(topResourceId) : null;
                var rightDrawable  = (rightResourceId > 0) ? Resources.GetDrawable(rightResourceId) : null;
                var bottomDrawable = (bottomResourceId > 0) ? Resources.GetDrawable(bottomResourceId) : null;

                //Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, topResourceId, rightResourceId, bottomResourceId);
                Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable);
                Control.CompoundDrawablePadding = 20;

                if (!hasResource)
                {
                    hasCompoundDrawable = false;
                }
            }

            if (element.ImageCenter != null)
            {
                Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(base.Resources.GetDrawable(UIHelper.GetDrawableResource(element.ImageCenter)), null, null, null);
                Control.Gravity = GravityFlags.Center;
            }
        }