Example #1
0
        internal static void ApplyProgressBarColors(this AProgressBar progressBar, Color progressColor, Color backgroundColor)
        {
            PlatformColor defaultProgress = Dark.PrimaryColor;

            if (progressColor.IsDefault)
            {
                if (backgroundColor.IsDefault)
                {
                    // reset everything to defaults
                    progressBar.ApplyProgressBarColors(defaultProgress, defaultProgress, PorterDuff.Mode.SrcIn);
                }
                else
                {
                    // handle the case where only the background is set
                    var background = backgroundColor.ToAndroid();
                    progressBar.ApplyProgressBarColors(defaultProgress, background, PorterDuff.Mode.SrcOver);
                }
            }
            else
            {
                if (backgroundColor.IsDefault)
                {
                    // handle the case where only the progress is set
                    var progress = progressColor.ToAndroid();
                    progressBar.ApplyProgressBarColors(progress, progress, PorterDuff.Mode.SrcIn);
                }
                else
                {
                    // handle the case where both are set
                    var background = backgroundColor.ToAndroid();
                    var progress   = progressColor.ToAndroid();
                    progressBar.ApplyProgressBarColors(progress, background, PorterDuff.Mode.SrcOver);
                }
            }
        }
Example #2
0
        protected override void OnAttached()
        {
            ProgressBar            switchCompat = (ProgressBar)Control;
            ProgressBarColorEffect effect       = (ProgressBarColorEffect)Element.Effects.FirstOrDefault(e => e is ProgressBarColorEffect);

            SetColor(switchCompat, effect.Color.ToAndroid());
        }
Example #3
0
        internal static void ApplyProgressBarColors(this AProgressBar progressBar, PlatformColor progressColor, PlatformColor backgroundColor, PorterDuff.Mode mode)
        {
            if ((int)Forms.SdkInt == 21 && progressBar.ProgressDrawable is ALayerDrawable progressDrawable)
            {
                progressBar.ProgressTintList           = ColorStateList.ValueOf(progressColor);
                progressBar.ProgressBackgroundTintList = ColorStateList.ValueOf(backgroundColor);
                progressBar.ProgressBackgroundTintMode = mode;

                if (progressDrawable.GetDrawable(0) is AGradientDrawable layer0)
                {
                    layer0.SetColor(backgroundColor);
                }

                if (progressDrawable.GetDrawable(1) is AScaleDrawable layer1)
                {
                    layer1.SetColorFilter(progressColor, FilterMode.SrcIn);
                }

                if (progressDrawable.GetDrawable(2) is AScaleDrawable layer2)
                {
                    layer2.SetColorFilter(progressColor, FilterMode.SrcIn);
                }
            }
            else if (Forms.IsLollipopOrNewer)
            {
                progressBar.ProgressTintList           = ColorStateList.ValueOf(progressColor);
                progressBar.ProgressBackgroundTintList = ColorStateList.ValueOf(backgroundColor);
                progressBar.ProgressBackgroundTintMode = mode;
            }
            else
            {
                (progressBar.Indeterminate ? progressBar.IndeterminateDrawable :
                 progressBar.ProgressDrawable).SetColorFilter(progressColor, FilterMode.SrcIn);
            }
        }
Example #4
0
        public void StartLoading()
        {
            CreateDialog();
            CreateAndSetWindowToDialog();
            CreateAndSetProgressBarToDialog();
            dialog.Show();

            void CreateDialog()
            {
                dialog = new Dialog(CurrentActivity);
                dialog.RequestWindowFeature((int)WindowFeatures.NoTitle);
                dialog.SetCancelable(true); // Set to true until a time out and canExecute is implemented.
                dialog.SetCanceledOnTouchOutside(false);
            }

            void CreateAndSetWindowToDialog()
            {
                var window = dialog.Window;

                window.SetLayout(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.Transparent));
            }

            void CreateAndSetProgressBarToDialog()
            {
                var progress = new Android.Widget.ProgressBar(CurrentActivity)
                {
                    LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent),
                    Indeterminate    = true
                };

                dialog.AddContentView(progress, progress.LayoutParameters);
            }
        }
Example #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            SetSupportActionBar(FindViewById <Toolbar>(Resource.Id.toolbar));

            // Azure Mobile Apps
            CurrentPlatform.Init();
            todoService = new TodoService();

            // Xamarin Essentials
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            // Find the elements in the UI
            itemList        = FindViewById <RecyclerView>(Resource.Id.item_list);
            addItemButton   = FindViewById <FloatingActionButton>(Resource.Id.add_item_button);
            isBusyIndicator = FindViewById <ProgressBar>(Resource.Id.busy_indicator);

            // Set up the List Adapter
            todoAdapter = new TodoAdapter(this);
            itemList.SetAdapter(todoAdapter);
            itemList.SetLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.Vertical, false));

            // Set up the Floating Action Button click-handler
            addItemButton.Click += OnAddItemClicked;
        }
Example #6
0
        private void SetColor(ProgressBar bar, Color color)
        {
            LayerDrawable progressDrawable = (LayerDrawable)bar.ProgressDrawable;
            Drawable      primaryColor     = progressDrawable.GetDrawable(2);

            primaryColor.SetColorFilter(new LightingColorFilter(0, color));
            progressDrawable.SetDrawableByLayerId(progressDrawable.GetId(2), new ClipDrawable(primaryColor, GravityFlags.Left, ClipDrawableOrientation.Horizontal));
        }
Example #7
0
 internal static void ApplyProgressBarColors(this AProgressBar progressBar, PlatformColor progressColor, PlatformColor backgroundColor, PorterDuff.Mode mode)
 {
     if (Forms.IsLollipopOrNewer)
     {
         progressBar.ProgressTintList           = ColorStateList.ValueOf(progressColor);
         progressBar.ProgressBackgroundTintList = ColorStateList.ValueOf(backgroundColor);
         progressBar.ProgressBackgroundTintMode = mode;
     }
     else
     {
         (progressBar.Indeterminate ? progressBar.IndeterminateDrawable :
          progressBar.ProgressDrawable).SetColorFilter(progressColor, PorterDuff.Mode.SrcIn);
     }
 }
		internal static void ApplyProgressBarColors(this AProgressBar progressBar, Color progressColor, Color backgroundColor)
		{
			PlatformColor defaultProgress = Dark.PrimaryColor;

			if (progressColor.IsDefault)
			{
				if (backgroundColor.IsDefault)
				{
					// reset everything to defaults
					progressBar.ProgressTintList = ColorStateList.ValueOf(defaultProgress);
					progressBar.ProgressBackgroundTintList = ColorStateList.ValueOf(defaultProgress);
					progressBar.ProgressBackgroundTintMode = PorterDuff.Mode.SrcIn;
				}
				else
				{
					// handle the case where only the background is set
					var background = backgroundColor.ToAndroid();

					progressBar.ProgressTintList = ColorStateList.ValueOf(defaultProgress);
					progressBar.ProgressBackgroundTintList = ColorStateList.ValueOf(background);
					progressBar.ProgressBackgroundTintMode = PorterDuff.Mode.SrcOver;
				}
			}
			else
			{
				if (backgroundColor.IsDefault)
				{
					// handle the case where only the progress is set
					var progress = progressColor.ToAndroid();

					progressBar.ProgressTintList = ColorStateList.ValueOf(progress);
					progressBar.ProgressBackgroundTintList = ColorStateList.ValueOf(progress);
					progressBar.ProgressBackgroundTintMode = PorterDuff.Mode.SrcIn;
				}
				else
				{
					// handle the case where both are set
					var background = backgroundColor.ToAndroid();
					var progress = progressColor.ToAndroid();

					progressBar.ProgressTintList = ColorStateList.ValueOf(progress);
					progressBar.ProgressBackgroundTintList = ColorStateList.ValueOf(background);
					progressBar.ProgressBackgroundTintMode = PorterDuff.Mode.SrcOver;
				}
			}
		}
Example #9
0
        public static void UpdateProgressColor(this AProgressBar platformProgressBar, IProgress progress)
        {
            Color color = progress.ProgressColor;

            if (color == null)
            {
                (platformProgressBar.Indeterminate ? platformProgressBar.IndeterminateDrawable :
                 platformProgressBar.ProgressDrawable)?.ClearColorFilter();
            }
            else
            {
                var tintList = ColorStateList.ValueOf(color.ToPlatform());

                if (platformProgressBar.Indeterminate)
                {
                    platformProgressBar.IndeterminateTintList = tintList;
                }
                else
                {
                    platformProgressBar.ProgressTintList = tintList;
                }
            }
        }
Example #10
0
        public static void UpdateProgressColor(this AProgressBar nativeProgressBar, IProgress progress)
        {
            Color color = progress.ProgressColor;

            if (color == null)
            {
                (nativeProgressBar.Indeterminate ? nativeProgressBar.IndeterminateDrawable :
                 nativeProgressBar.ProgressDrawable)?.ClearColorFilter();
            }
            else
            {
                var tintList = ColorStateList.ValueOf(color.ToNative());

                if (nativeProgressBar.Indeterminate)
                {
                    nativeProgressBar.IndeterminateTintList = tintList;
                }
                else
                {
                    nativeProgressBar.ProgressTintList = tintList;
                }
            }
        }
Example #11
0
 public static void UpdateProgress(this AProgressBar platformProgressBar, IProgress progress)
 {
     platformProgressBar.Progress = (int)(progress.Progress * Maximum);
 }
Example #12
0
 public static void UpdateProgress(this AProgressBar nativeProgressBar, IProgress progress)
 {
     nativeProgressBar.Progress = (int)(progress.Progress * Maximum);
 }