Example #1
0
        public async Task Onrefresh()
        {
            bool res = await Pull(true);

            ToastView.ShowToast("刷新成功", ToastIconType.None);
            return;
        }
        public void Show(ToastView view, object viewModel = null)
        {
            if (viewModel != null)
            {
                view.BindingContext = viewModel;
            }
            view.Parent = Application.Current.MainPage;

            var renderer = Dialogs.CreateNativeView(view);

            var measure = Dialogs.Measure(view);

            renderer.SetElementSize(measure);

            renderer.NativeView.Alpha = 0;
            if (view.CornerRadius > 0)
            {
                renderer.NativeView.Layer.CornerRadius  = view.CornerRadius;
                renderer.NativeView.Layer.MasksToBounds = true;
            }
            if (view.BorderWidth > 0)
            {
                renderer.NativeView.Layer.BorderWidth = (float)view.BorderWidth;
                renderer.NativeView.Layer.BorderColor = view.BorderColor.ToCGColor();
            }

            SetView(view, renderer.NativeView, renderer);

            view.Parent = null;

            view.RunPresentationAnimation();
            UIView.Animate(
                0.25,
                () => renderer.NativeView.Alpha = (System.nfloat)view.Opacity
                );

            Device.StartTimer(TimeSpan.FromMilliseconds(Math.Max(view.Duration - 250, 0)), () =>
            {
                view.RunDismissalAnimation();
                UIView.Animate(
                    0.25,
                    () => renderer.NativeView.Alpha = 0,
                    () => {
                    view.Parent = null;
                    renderer.NativeView.RemoveConstraints(renderer.NativeView.Constraints);
                    Dialogs.DisposeModelAndChildrenRenderers(view);
                    renderer = null;
                    view.Destroy();
                    view.BindingContext = null;
                    view = null;
                }
                    );

                return(false);
            });
        }
        protected virtual ToastView CreateToast(object content, UIView owner, float duration, ToastPosition position,
                                                IDataContext context, TaskCompletionSource <object> tcs)
        {
            ToastView toastView = null;
            var       factory   = Factory;

            if (factory != null)
            {
                toastView = factory(content, owner, duration, position, context, tcs);
            }
            return(toastView ?? new ToastView(content, owner, duration, position, tcs));
        }
 public ToastViewModel(string ToastMessage, int ShowTime)
 {
     _closer                  = new DispatcherTimer();
     _closer.Interval         = new TimeSpan(0, 0, 0, 0, ShowTime);
     _closer.Tick            += _closer_Tick;
     _closer.IsEnabled        = true;
     this.ToastMessage        = ToastMessage;
     _toastWindow             = new ToastView();
     _toastWindow.DataContext = this;
     _toastWindow.Show();
     _closer.Start();
 }
        private void Show(object content, float duration, ToastPosition position, IDataContext context,
                          TaskCompletionSource <object> tcs)
        {
            UIView    owner = GetOwner() ?? UIApplication.SharedApplication.KeyWindow;
            ToastView toast = CreateToast(content, owner, duration, position, context ?? DataContext.Empty, tcs);

            ServiceProvider.AttachedValueProvider.AddOrUpdate(owner, Key, toast,
                                                              (item, value, currentValue, state) =>
            {
                currentValue.Hide();
                return(value);
            }).Show();
        }
        void SetView(ToastView view, UIView nativeView, IVisualElementRenderer renderer)
        {
            var window = UIApplication.SharedApplication.KeyWindow;

            nativeView.TranslatesAutoresizingMaskIntoConstraints = false;

            window.AddSubview(nativeView);

            nativeView.WidthAnchor.ConstraintEqualTo((System.nfloat)view.Bounds.Width).Active   = true;
            nativeView.HeightAnchor.ConstraintEqualTo((System.nfloat)view.Bounds.Height).Active = true;

            Dialogs.SetLayoutAlignment(nativeView, window, view);
        }
 public static void Launch(ToastView toastView)
 {
     if (_current != null)
     {
         _current.Activate();
         _current.SetMouseHook(true);
     }
     else
     {
         SettingsView settingsView = new SettingsView(toastView);
         SettingsLaunched?.Invoke(_current, new SettingsViewLaunchedEventArgs(settingsView.Settings));
         settingsView.SetMouseHook(true);
         settingsView.ShowDialog();
     }
 }
Example #8
0
    /// <summary>
    /// 创建toast
    /// </summary>
    /// <param name="toastType"></param>
    /// <param name="toastIconSp"></param>
    /// <param name="toastContentStr"></param>
    /// <param name="destoryTime"></param>
    public void CreateToast <T>(ToastEnum toastType, Sprite toastIconSp, string toastContentStr, float destoryTime) where T : ToastView
    {
        string     toastName = EnumUtil.GetEnumName(toastType);
        GameObject objToast  = CreateToast(toastName);

        if (objToast)
        {
            ToastView toastView = objToast.GetComponent <ToastView>();
            toastView.SetData(toastIconSp, toastContentStr, destoryTime);
        }
        else
        {
            LogUtil.LogError("没有找到指定Msg:" + "Resources/" + resUrl + toastName);
        }
    }
Example #9
0
 public static void Show(string content, ToastIconType iconType = ToastIconType.None, bool isUsePopup = false)
 {
     if (!string.IsNullOrEmpty(content))
     {
         DispatcherUtil.Run(() =>
         {
             try
             {
                 ToastView.ShowToast(content, iconType);
             }
             catch (Exception ex)
             {
                 System.Diagnostics.Debug.WriteLine(ex.Message);
             }
         }, Windows.UI.Core.CoreDispatcherPriority.High);
     }
 }
        public ToastViewModel(ToastView owner)
        {
            CloseCommand = new CloseCommand(owner);

            toastLifeTimeTimer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(5), IsEnabled = true
            };
            toastLifeTimeTimer.Tick += ToastLifeTimeTimerTick;

            opacityTimer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(75), IsEnabled = false
            };
            opacityTimer.Tick += OpacityTimerTick;

            owner.MouseDown += ToastViewMouseDown;
            owner.MouseMove += ToastViewMouseMove;
            owner.Closing   += ToastViewClosing;
        }
Example #11
0
        protected override async Task <IEnumerable <string> > GetDatas(bool isFirst)
        {
            await Task.Delay(3000);

            var _result = new List <String>();
            int start   = isFirst ? 0 : (_currentPos + 1);

            for (int i = 0; i < 20; i++)
            {
                _result.Add("item  " + (start + i));
            }
            _currentPos = start + 20;
            if (!isFirst)
            {
                ToastView.ShowToast("加载成功20条", ToastIconType.None);
            }
            return(_result);
        }
Example #12
0
        private SettingsView(ToastView toastView)
        {
            Analytics.TrackEvent(Analytics.ToastifyEventCategory.General, Analytics.ToastifyEvent.SettingsLaunched);

            this.settingsViewModel = new SettingsViewModel();
            this.settingsViewModel.SettingsSaved += this.SettingsViewModel_SettingsSaved;

            this.toastView = toastView;

            this.InitializeComponent();

            this.DataContext           = this.settingsViewModel;
            this.WindowStartupLocation = this.StartupLocation;

            if (_current == null)
            {
                _current = this;
            }
        }
Example #13
0
        private static void showToast(IInteraction interaction)
        {
            var call     = interaction as ICall;
            var cxScreen = Screen.PrimaryScreen;

            if (call.CallType == CallType.Outbound)
            {
                return;
            }
            if (Application.OpenForms.Count > 0)
            {
                cxScreen = Screen.FromHandle(Application.OpenForms[0].Handle);
            }
            else
            {
                cxScreen = Screen.FromHandle(findHandle());
            }


            var toast = new ToastView {
                Model = new ToastViewModel {
                    Interaction  = interaction,
                    LastActivity = DateTime.Now.AddSeconds(5),
                    Inactive     = true
                }
            };

            interaction.StateChanged += interaction_StateChanged;

            toast.Left        = (cxScreen.WorkingArea.X + cxScreen.WorkingArea.Width) - (toast.Width + 1);
            toast.Top         = (cxScreen.WorkingArea.Y + cxScreen.WorkingArea.Height) - (toast.Height + 1) - (_openToasts.Count * toast.Height);
            toast.MouseEnter += toast_MouseEnter;
            toast.MouseLeave += toast_MouseLeave;
            toast.Closed     += toast_Closed;
            _openToasts.Add(toast);
            toast.Show();

            if (_openToasts.Count == 1)
            {
                _timer.Change(5000, 1000);
            }
        }
        protected virtual ToastView CreateToast(object content, UIView owner, float duration, ToastPosition position,
                                                IDataContext context, TaskCompletionSource <object> tcs)
        {
            ToastView toastView = null;

#if !XAMARIN_FORMS
            var window = owner as UIWindow;
            if (window != null)
            {
                UIViewController controller = window.RootViewController;
                var navigationController    = controller as MvvmNavigationController;
                if (navigationController != null)
                {
                    controller = navigationController.TopViewController;
                }
                if (controller != null)
                {
                    var selector = controller.GetBindingMemberValue(AttachedMembers.UIViewController.ToastTemplateSelector);
                    if (selector != null)
                    {
                        toastView = (ToastView)selector.SelectTemplate(content, owner);
                    }
                }
            }
#endif
            if (toastView == null)
            {
                var factory = Factory;
                if (factory != null)
                {
                    toastView = factory(content, owner, duration, position, context, tcs);
                }
            }
            if (toastView == null)
            {
                toastView = new ToastView(content, owner);
            }
            toastView.DisplayDuration      = duration / 1000;
            toastView.Position             = position;
            toastView.TaskCompletionSource = tcs;
            return(toastView);
        }
Example #15
0
        private static ToastView GetToast(string text, ToastOptions options, ToastLayout layout)
        {
            var toast = new ToastView
            {
                Text         = text,
                ToastOptions = options,
                ToastLayout  = layout,
                Margin       = new Thickness(layout.HorizontalMargin, layout.PositionY, layout.HorizontalMargin, 0)
            };

            if (toast.ToastOptions.ToastAction != null)
            {
                toast.GestureRecognizers.Add(new TapGestureRecognizer()
                {
                    Command = new Command((toast.ToastOptions.ToastAction))
                });
            }

            return(toast);
        }
        protected async Task ShowToast(string message = null)
        {
            if (RootGrid == null)
            {
                return;
            }
            if (_toast == null)
            {
                _toast = new ToastView
                {
                    Text = message ?? nameof(AppResources.SuccessToastMessage).Translate()
                };
                var columnSpan = RootGrid.ColumnDefinitions.Count == 0 ? 1 : RootGrid.ColumnDefinitions.Count;
                var rowSpan    = RootGrid.RowDefinitions.Count == 0 ? 1 : RootGrid.RowDefinitions.Count;

                Grid.SetColumnSpan(_toast, columnSpan);
                Grid.SetRowSpan(_toast, rowSpan);
                RootGrid.Children.Add(_toast);
            }

            await _toast.Show();
        }
Example #17
0
        public static Task <bool> Show(string message)
        {
            return(UIApplication.SharedApplication.InvokeOnMainThreadAsync(() =>
            {
                if (IsTopMostViewSplashScreen())
                {
                    return false;
                }

                //If we are displaying he splashscreen or extended splashscreen.
                if (IsTopMostViewSplashScreen())
                {
                    return false;
                }

                Toast = new ToastView(message);

                Toast.Show();

                return true;
            }));
        }
Example #18
0
    /// <summary>
    /// 创建toast
    /// </summary>
    /// <param name="toastType"></param>
    /// <param name="toastIconSp"></param>
    /// <param name="toastContentStr"></param>
    /// <param name="destoryTime"></param>
    public void CreateToast <T>(ToastEnum toastType, Sprite toastIconSp, string toastContentStr, float destoryTime) where T : ToastView
    {
        string     toastName     = EnumUtil.GetEnumName(toastType);
        GameObject objToastModel = manager.GetToastModel(toastName);

        if (objToastModel == null)
        {
            LogUtil.LogError("没有找到指定Toast:" + toastName);
            return;
        }
        GameObject objToast = Instantiate(manager.objToastContainer, objToastModel);

        if (objToast)
        {
            ToastView toastView = objToast.GetComponent <ToastView>();
            toastView.SetData(toastIconSp, toastContentStr, destoryTime);
        }
        else
        {
            LogUtil.LogError("实例化Toast失败" + toastName);
        }
    }
Example #19
0
        private static void ToastBase(string title, System.Drawing.Bitmap bitmap, Brush color, string msg = null, Action func = null)
        {
            IncrementToastCount();
            var toast = new ToastView();

            var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;

            var toastHeight   = (int)(toast.Height + 10);
            var desktopHeight = (int)(desktopWorkingArea.Height / toastHeight);

            var XOffset = (ToastController.Instance.Offset / desktopHeight) + 1;
            var YOffset = XOffset > 1
                ? (ToastController.Instance.Offset % desktopHeight) + 1
                : (ToastController.Instance.Offset % desktopHeight);

            toast.Left = desktopWorkingArea.Right - XOffset * toast.Width;
            toast.Top  = desktopWorkingArea.Bottom - YOffset * toastHeight;

            toast.Image.Source        = BitmapSourceConverter.ConvertFromImage(bitmap);
            toast.bgColour.Background = color;
            toast.Title.Text          = title;
            if (msg == null)
            {
                toast.Message.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                toast.Message.Text = msg;
            }

            if (func != null)
            {
                toast.OnClickEvent += new ToastView.OnClick(func);
            }

            toast.Show();
        }
        protected virtual ToastView CreateToast(object content, UIView owner, float duration, ToastPosition position,
            IDataContext context, TaskCompletionSource<object> tcs)
        {
            ToastView toastView = null;
#if !XAMARIN_FORMS
            var window = owner as UIWindow;
            if (window != null)
            {
                UIViewController controller = window.RootViewController;
                var navigationController = controller as MvvmNavigationController;
                if (navigationController != null)
                    controller = navigationController.TopViewController;
                if (controller != null)
                {
                    var selector = controller.GetBindingMemberValue(AttachedMembers.UIViewController.ToastTemplateSelector);
                    if (selector != null)
                        toastView = (ToastView)selector.SelectTemplate(content, owner);
                }
            }
#endif
            if (toastView == null)
            {
                var factory = Factory;
                if (factory != null)
                    toastView = factory(content, owner, duration, position, context, tcs);
            }
            if (toastView == null)
                toastView = new ToastView(content, owner);
            toastView.DisplayDuration = duration / 1000;
            toastView.Position = position;
            toastView.TaskCompletionSource = tcs;
            return toastView;
        }
Example #21
0
        /// <summary>
        /// Creates the toast notification.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <param name="isForTest">if set to <c>true</c> [is for test].</param>
        /// <param name="toastOnActivated">The toast on activated.</param>
        internal static void CreateToastNotification(BuildResult result, bool isForTest, EventHandler <EventArgs> toastOnActivated)
        {
            var toastView  = new ToastView();
            var toastModel = new ToastViewModel(toastView)
            {
                Title        = result.Name,
                MessageLine1 = isForTest ? "Running build will fail" : result.Status.ToString(),
                MessageLine2 = isForTest ? result.RunningBuildRequestedBy : result.RequestedBy,
            };

            toastView.DataContext = toastModel;

            toastView.Left = SystemParameters.FullPrimaryScreenWidth - toastView.Width - 10;
            var top = SystemParameters.FullPrimaryScreenHeight - toastView.Height;

            while (DisplayedToastViewHeights.Contains(top))
            {
                top -= toastView.Height + 10;
            }

            toastView.Top = top;
            DisplayedToastViewHeights.Add(top);

            string image = null;

            switch (result.Status)
            {
            case BuildStatus.InProgress:
                image = "inprogress_128";
                break;

            case BuildStatus.Stopped:
                image = "stop_128";
                break;

            case BuildStatus.PartiallySucceeded:
                image = "orange_128";
                break;

            case BuildStatus.Failed:
                image = "red_128";
                break;
            }

            if (isForTest)
            {
                image = "build_128";
            }

            if (image != null)
            {
                var uri = new Uri("pack://application:,,,/BuildMonitorWpf;component/Images/" + image + ".png");
                toastModel.Image = new BitmapImage(uri);
            }

            System.Media.SystemSounds.Hand.Play();
            toastView.Closing += ToastViewClosing;
            if (toastOnActivated != null)
            {
                toastView.MouseDown += (o, e) => toastOnActivated(o, e);
            }

            toastView.Show();
        }
Example #22
0
        public App()
        {
            InitializeComponent();

            MainPage = new ToastView();
        }
Example #23
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.Title = "Menú";


            //Ocultamos el boton de tiendas registradas temporalmente
            //btnTiendas.Hidden = true;
            //btnInfo2.Hidden = true;

            var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            _pathToDatabase = Path.Combine(documents, "db_sqlite-net.db");

            //Creamos la base de datos y la tabla de persona, en caso de que ya exista no hace nada.
            using (var conn = new SQLite.SQLiteConnection(_pathToDatabase))
            {
                conn.CreateTable <Person>();
            }

            //Hacemos la conexion a la bd para buscar si hay un usuario registrado
            using (var db = new SQLite.SQLiteConnection(_pathToDatabase))
            {
                people = new List <Person> (from p in db.Table <Person> () select p);
            }

            //Establecemos las imagenes de los botones
            setButtonImages();

            //Eventos para los botones de informacion
            this.btnInfo1.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Busca productos por código de barras o nombre", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnInfo2.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Localiza todas las tiendas registradas en FIXBUY", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnInfo3.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Administra tus listas y los productos en ellas", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnInfo4.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Inicia Sesion en FIXBUY para poder acceder a tus listas y más!", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnInfo5.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Establece tu ubicación para una busqueda mas eficaz!", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnInfo6.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Consulta los servicios que ofrece FIXBUY", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnCerrarSesion.TouchUpInside += (sender, e) => {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "Te vas? =(", Message = "Estas seguro que quieres cerrar la sesión?"
                };
                alert.AddButton("Aceptar");
                alert.AddButton("Cancelar");
                alert.Clicked += (s, o) => {
                    if (o.ButtonIndex == 0)
                    {
                        using (var conn = new SQLite.SQLiteConnection(_pathToDatabase))
                        {
                            conn.DropTable <Person>();
                            conn.CreateTable <Person>();
                        }
                        this.NavigationController.PopViewController(true);
                    }
                };
                alert.Show();
            };

            //Boton de buscar productos
            this.btnScan.TouchUpInside += (sender, e) => {
                // Configurar el escaner de codigo de barras.
                picker = new ScanditSDKRotatingBarcodePicker(MainView.appKey);
                picker.OverlayController.Delegate = new overlayControllerDelegate(picker, this);
                picker.OverlayController.ShowToolBar(true);
                picker.OverlayController.ShowSearchBar(true);
                picker.OverlayController.SetToolBarButtonCaption("Cancelar");
                picker.OverlayController.SetSearchBarKeyboardType(UIKeyboardType.Default);
                picker.OverlayController.SetSearchBarPlaceholderText("Búsqueda por nombre de producto");
                picker.OverlayController.SetCameraSwitchVisibility(SICameraSwitchVisibility.OnTablet);
                picker.OverlayController.SetTextForInitializingCamera("Iniciando la camara");
                this.PresentViewController(picker, true, null);

                picker.StartScanning();
            };

            //Boton de tiendas Registradas
            this.btnTiendas.TouchUpInside += (sender, e) => {
                this._loadPop = new LoadingOverlay(UIScreen.MainScreen.Bounds);
                this.Add(this._loadPop);
                mvp = new MapViewController();
                Task.Factory.StartNew(
                    () => {
                    System.Threading.Thread.Sleep(1 * 1000);
                }
                    ).ContinueWith(
                    t => {
                    this._loadPop.Hide();
                    this.NavigationController.PushViewController(mvp, true);
                }, TaskScheduler.FromCurrentSynchronizationContext()
                    );
            };

            //Boton Mis listas
            this.btnListas.TouchUpInside += (sender, e) => {
                if (people.Count == 1)
                {
                    MyListsView myLists = new MyListsView();
                    this.NavigationController.PushViewController(myLists, true);
                }
                else
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Espera!", Message = "Debes iniciar sesión para acceder a tus listas"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };

            //Boton Iniciar Sesion
            this.btnSesion.TouchUpInside += (sender, e) => {
                if (people.Count == 1)
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Espera!", Message = "Ya has iniciado sesión"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
                else
                {
                    LoginView login = new LoginView();
                    this.NavigationController.PushViewController(login, true);
                }
            };

            //Boton Novedades
            this.btnNovedades.TouchUpInside += (sender, e) => {
                StatesView statesView = new StatesView();
                this.NavigationController.PushViewController(statesView, true);
            };

            //Boton Nuestros Servicios
            this.btnServicios.TouchUpInside += (sender, e) => {
                AboutUsView aboutUS = new AboutUsView();
                this.NavigationController.PushViewController(aboutUS, true);
            };

            // creacion de la barra de herramientas
            float toolbarHeight = 44;

            toolbar = new UIToolbar(new CGRect(0
                                               , this.View.Frame.Height - this.NavigationController.NavigationBar.Frame.Height
                                               , this.View.Frame.Width, toolbarHeight));
            toolbar.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleWidth;
            toolbar.TintColor        = UIColor.FromRGB(7, 129, 181);

            // boton acerca de
            UIBarButtonItem btnacercaDe = new UIBarButtonItem(UIBarButtonSystemItem.Bookmarks);

            btnacercaDe.Clicked += (s, e) => {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "Que deseas consultar? "
                };
                alert.AddButton("Terminos y Condiciones");
                alert.AddButton("Aviso de Privacidad");
                alert.Clicked += (sen, o) => {
                    if (o.ButtonIndex == 0)
                    {
                        TermsView termsView = new TermsView();
                        NavigationController.PushViewController(termsView, true);
                    }
                    else
                    {
                        PrivacyNoticeView privacyNoticeView = new PrivacyNoticeView();
                        NavigationController.PushViewController(privacyNoticeView, true);
                    }
                };
                alert.Show();
            };
            // fixed width
            //UIBarButtonItem fixedWidth = new UIBarButtonItem (UIBarButtonSystemItem.FixedSpace);
            //fixedWidth.Width = 35;

            // flexible width space
            UIBarButtonItem flexibleWidth1 = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);

            // boton fixBuy
            UIBarButtonItem btnFixBuy = new UIBarButtonItem(UIBarButtonSystemItem.Search);

            btnFixBuy.Clicked += (s, e) => {
                NSUrl url = new NSUrl(@"http://fixbuy.mx");
                UIApplication.SharedApplication.OpenUrl(url);
            };

            // flexible width space
            UIBarButtonItem flexibleWidth2 = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);

            // boton email
            UIBarButtonItem btnEmail = new UIBarButtonItem(UIBarButtonSystemItem.Compose);

            btnEmail.Clicked += (s, e) => {
                //Añadimos las configuraciones para la vista de email
                mailController = new MFMailComposeViewController();
                mailController.SetToRecipients(new string[] { "*****@*****.**" });
                mailController.SetSubject("Contacto");
                mailController.SetMessageBody("", false);
                mailController.Finished += (object o, MFComposeResultEventArgs args) => {
                    Console.WriteLine(args.Result.ToString());
                    args.Controller.DismissViewController(true, null);
                };

                this.PresentViewController(mailController, true, null);
            };

            // arreglo de botones para toolbar
            UIBarButtonItem[] items = new UIBarButtonItem[] {
                btnacercaDe, flexibleWidth1, btnFixBuy, flexibleWidth2, btnEmail
            };

            // agregar los botones a la toolbar
            toolbar.SetItems(items, false);

            // agregar la vista a la pantalla
            this.View.AddSubview(toolbar);
            try{
                //Leemos el servicio de los banners
                this.bannersService = new BannersService();
                banners             = bannersService.All();
            } catch (System.Net.WebException) {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "UPS :S", Message = "Hubo un error al conectarse a internet la seccion de banners no puede mostrarse, por favor verifica tu conexión a internet"
                };
                alert.AddButton("Aceptar");
                alert.Show();
            }

            button = new UIButton(new CGRect(0, 0, bannerImage.Bounds.Width, bannerImage.Bounds.Height));
            bannerImage.Add(button);
            button.TouchUpInside += (sender, e) => {
                try{
                    if (bannerError == false)
                    {
                        if (element.imagen != "")
                        {
                            NSUrl url = new NSUrl(element.link);
                            UIApplication.SharedApplication.OpenUrl(url);
                        }
                    }
                }catch (Exception) {
                    //solo atrapamos la excepcion, no hacemos nada
                }
            };
        }
        public void Show(ToastView view, object viewModel = null)
        {
            view.Parent         = XF.Application.Current.MainPage;
            view.BindingContext = viewModel;

            var toast = new Android.Widget.Toast(Dialogs.Context);

            var offsetX = (int)Dialogs.Context.ToPixels(view.OffsetX);
            var offsetY = (int)Dialogs.Context.ToPixels(view.OffsetY);

            // HACK: For some reason, the offset direction is reversed when GravityFlags contains Left or Bottom.
            if (view.HorizontalLayoutAlignment == XF.LayoutAlignment.End)
            {
                offsetX *= -1;
            }
            if (view.VerticalLayoutAlignment == XF.LayoutAlignment.End)
            {
                offsetY *= -1;
            }

            toast.SetGravity(Dialogs.GetGravity(view), offsetX, offsetY);
            toast.Duration = Android.Widget.ToastLength.Long;

            var renderer = Dialogs.CreateNativeView(view);

            var measure = Dialogs.Measure(view);

            view.Layout(new XF.Rectangle(new XF.Point(0, 0), measure));

            var realW = (int)Dialogs.Context.ToPixels(measure.Width);
            var realH = (int)Dialogs.Context.ToPixels(measure.Height);

            var layout = new LinearLayout(Dialogs.Context);

            using (var param = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)
            {
                Width = realW,
                Height = realH
            }){
                layout.LayoutParameters = param;
            }

            using (var param = new LinearLayout.LayoutParams(realW, realH)
            {
                Width = realW, Height = realH
            }){
                layout.AddView(renderer.View, param);
            }

            if (view.CornerRadius > 0)
            {
                var border = new GradientDrawable();
                border.SetCornerRadius(Dialogs.Context.ToPixels(view.CornerRadius));
                if (!view.BackgroundColor.IsDefault)
                {
                    border.SetColor(view.BackgroundColor.ToAndroid());
                    border.Alpha = (int)(view.Opacity * 255);
                }
                layout.ClipToOutline = true;
                layout.SetBackground(border);
            }

            toast.View = layout;

            view.RunPresentationAnimation();

            toast.Show();

            var duration = Math.Max(Math.Min(view.Duration - 260, 3500), 0); // give a bit millisecond margin

            var handler = new Handler();

            handler.PostDelayed(new Runnable(view.RunDismissalAnimation), duration);

            handler.PostDelayed(new Runnable(() =>
            {
                //view.RunDismissalAnimation();
                //await Task.Delay(250);
                toast?.Cancel();

                view.Parent = null;

                if (!renderer.View.IsDisposed())
                {
                    renderer.View.RemoveFromParent();
                    renderer.View.Dispose();
                }

                layout.Dispose();

                // I coudn't reproduce https://github.com/muak/AiForms.Dialogs/issues/2.
                // But I let this code disabled because it has no influent even if it is disabled.
                //toast.View = null;

                renderer.Dispose();
                renderer = null;
                toast?.Dispose();
                toast = null;

                view.Destroy();
                view.BindingContext = null;
            }), view.Duration);
        }
Example #25
0
 public static void ShowToast(string content, ToastIconType iconType = ToastIconType.None, string title = null)
 {
     ToastView.ShowToast(content, iconType, title);
 }
Example #26
0
        public ToastView GetToastView(string message, string title)
        {
            var toastView = new ToastView();

            if (StandardImage.HasValue)
            {
                switch (StandardImage)
                {
                case StandardImages.WarningBlack:
                    toastView.IconImageSource = ImageFromBitmap(Resources.warning_black);
                    break;

                case StandardImages.WarningWhite:
                    toastView.IconImageSource = ImageFromBitmap(Resources.warning_white);
                    break;

                case StandardImages.ErrorBlack:
                    toastView.IconImageSource = ImageFromBitmap(Resources.error_black);
                    break;

                case StandardImages.ErrorWhite:
                    toastView.IconImageSource = ImageFromBitmap(Resources.error_white);
                    break;

                case StandardImages.SuccessWhite:
                    toastView.IconImageSource = ImageFromBitmap(Resources.success_white);
                    break;

                case StandardImages.SuccessBlack:
                    toastView.IconImageSource = ImageFromBitmap(Resources.success_black);
                    break;

                case StandardImages.InfoWhite:
                    toastView.IconImageSource = ImageFromBitmap(Resources.info_white);
                    break;

                case StandardImages.InfoBlack:
                    toastView.IconImageSource = ImageFromBitmap(Resources.info_black);
                    break;

                case null:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            else
            {
                toastView.IconImageSource = ImageSource;
            }

            toastView.IconImageSize = ImageSize;

            toastView.ShowCloseButton = ShowCloseButton;

            toastView.CloseButtonFillBrush   = CloseButtonFillBrush;
            toastView.CloseButtonStrokeBrush = CloseButtonStrokeBrush;

            toastView.Height = AutoHeight ? double.NaN : Height;
            toastView.Width  = AutoWidth ? double.NaN : Width;

            toastView.ToastTitle               = title;
            toastView.TitleBackgroundBrush     = TitleBackgroundBrush;
            toastView.TitleForegroundBrush     = TitleForegroundBrush;
            toastView.TitleFontSize            = TitleFontSize;
            toastView.TitleFontWeight          = TitleFontWeight;
            toastView.TitleMargin              = TitleMargin;
            toastView.TitleVerticalAlignment   = TitleVerticalAlignment;
            toastView.TitleHorizontalAlignment = TitleHorizontalAlignment;

            toastView.Message = message;
            toastView.MessageBackgroundBrush     = MessageBackgroundBrush;
            toastView.MessageForegroundBrush     = MessageForegroundBrush;
            toastView.MessageFontSize            = MessageFontSize;
            toastView.MessageFontWeight          = MessageFontWeight;
            toastView.MessageMargin              = MessageMargin;
            toastView.MessageVerticalAlignment   = MessageVerticalAlignment;
            toastView.MessageHorizontalAlignment = MessageHorizontalAlignment;

            toastView.InnerBorderThickness = InnerBorderThickness;
            toastView.InnerBorderBrush     = InnerBorderBrush;
            toastView.CornerRadius         = new CornerRadius(CornerRadius);
            toastView.Opacity = Opacity;

            return(toastView);
        }