コード例 #1
0
        //AI Control. Determines if AI is on or off. AI that will assist the user with any problems
        private void AIFeatures(string title, string message)
        {
            UIAlertController AIController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

            UIAlertAction batteryEnabled = UIAlertAction.Create("Enabled", UIAlertActionStyle.Default, (Action) =>
            {
                //enable the AI (Pass in boolean value that determines if the battery monitor is enabled or not)
                //same thing as the battery monitor
            });

            UIAlertAction batteryDisabled = UIAlertAction.Create("Disabled", UIAlertActionStyle.Cancel, (Action) =>
            {
                AIController.Dispose();
            });


            AIController.AddAction(batteryEnabled);
            AIController.AddAction(batteryDisabled);
            if (this.PresentedViewController == null)
            {
                this.PresentViewController(AIController, true, null);
            }

            else if (this.PresentedViewController != null)
            {
                this.PresentedViewController.DismissViewController(true, () =>
                {
                    AIController.Dispose();
                    this.PresentViewController(AIController, true, null);
                });
            }
        }
コード例 #2
0
        //section 0 alert controllers
        private void batteryMonitorController(string title, string message)
        {
            UIAlertController batteryController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

            UIAlertAction batteryEnabled = UIAlertAction.Create("Enabled", UIAlertActionStyle.Default, (Action) =>
            {
                //enable the battery monitor (Pass in boolean value that determines if the battery monitor is enabled or not)

                //you can try doing this with objects but we will see
            });

            UIAlertAction batteryDisabled = UIAlertAction.Create("Disabled", UIAlertActionStyle.Cancel, (Action) =>
            {
                batteryController.Dispose();
            });

            batteryController.AddAction(batteryEnabled);
            batteryController.AddAction(batteryDisabled);

            if (this.PresentedViewController == null)
            {
                this.PresentViewController(batteryController, true, null);
            }

            else if (this.PresentedViewController != null)
            {
                this.PresentedViewController.DismissViewController(true, () => {
                    batteryController.Dispose();
                    this.PresentViewController(batteryController, true, null);
                });
            }
        }
コード例 #3
0
        private void reportIssue(string title, string message)
        {
            UIAlertController reportIssueController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

            UIAlertAction reportIssueAction = UIAlertAction.Create("Email Tech Support", UIAlertActionStyle.Default, (Action) => {
                MFMailComposeViewController mail = new MFMailComposeViewController();

                if (MFMailComposeViewController.CanSendMail == true)
                {
                    mail.SetToRecipients(new String[] { "*****@*****.**" });
                    this.PresentViewController(mail, true, null);
                }
                else
                {
                    if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                    {
                        AI.AIEnglish("Mail Box is not enabled on your iPad", "en-US", 2.0f, 1.0f, 1.0f);
                    }
                    else if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                    {
                        AI.AIEnglish("Mail Box is not enabled on your iPhone", "en-US", 2.0f, 1.0f, 1.0f);
                    }
                }

                mail.Finished += (sender, e) => {
                    mail.DismissViewController(true, null);
                };
            });

            UIAlertAction denied = UIAlertAction.Create("Never Mind", UIAlertActionStyle.Cancel, (Action) =>
            {
                reportIssueController.Dispose();
            });

            reportIssueController.AddAction(reportIssueAction);
            reportIssueController.AddAction(denied);

            if (this.PresentedViewController == null)
            {
                this.PresentViewController(reportIssueController, true, null);
            }
            else if (this.PresentedViewController != null)
            {
                this.PresentedViewController.DismissViewController(true, () =>
                {
                    reportIssueController.Dispose();
                    this.PresentViewController(reportIssueController, true, null);
                });
            }
        }
コード例 #4
0
        //battery monitoring
        public void BatteryLevel()
        {
            UIDevice.CurrentDevice.BatteryMonitoringEnabled = true;

            if (UIDevice.CurrentDevice.BatteryLevel >= 0.2f && UIDevice.CurrentDevice.BatteryLevel <= 0.4)
            {
                AIEnglish("⚡️ Low battery detected. You should charge your battery", "en-US", 2.5f, 1.0f, 1.0f);

                UIAlertController batteryAlert = UIAlertController.Create("Low Battery", "Battery is currently measured at " + UIDevice.CurrentDevice.BatteryLevel * 100 + "%", UIAlertControllerStyle.Alert);

                UIAlertAction confirmed = UIAlertAction.Create("Thanks for telling me", UIAlertActionStyle.Default, (Action) => {
                    batteryAlert.Dispose();
                });

                batteryAlert.AddAction(confirmed);

                if (navMain.PresentedViewController == null)
                {
                    navMain.PresentViewController(batteryAlert, true, null);
                }
                else if (navMain.PresentedViewController != null)
                {
                    navMain.PresentedViewController.DismissViewController(true, () => {
                        navMain.PresentViewController(batteryAlert, true, null);
                    });
                }
            }
        }
コード例 #5
0
        //handles the event if the user entered the wrong password
        private void passwordIncorrect(string title, string message)
        {
            UIAlertController passwordIncController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

            UIAlertAction confirmed = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (UIAlertAction obj) =>
            {
                this.passwordTextField.Text = "";
                passwordIncController.Dispose();
            });

            passwordIncController.AddAction(confirmed);

            if (this.PresentedViewController == null)
            {
                this.PresentViewController(passwordIncController, true, () =>
                {
                    SystemSound errorSound = new SystemSound(4095);
                    errorSound.PlaySystemSound();
                });
            }
            else
            {
                this.PresentedViewController.DismissViewController(true, () =>
                {
                    this.PresentedViewController.Dispose();
                    this.PresentViewController(passwordIncController, true, () =>
                    {
                        SystemSound errorSound = new SystemSound(4095);
                        errorSound.PlaySystemSound();
                    });
                });
            }
        }
コード例 #6
0
        public override void MotionEnded(UIEventSubtype motion, UIEvent evt)
        {
            if (evt.Type == UIEventType.Motion)
            {
                UIAlertController helpControl = UIAlertController.Create("Need Help?", "On this page you will learn over 500 French phrases. Simply choose a category and have fun", UIAlertControllerStyle.Alert);

                UIAlertAction confirmed = UIAlertAction.Create("Cool", UIAlertActionStyle.Default, (Action) =>
                {
                    helpControl.Dispose();
                });

                helpControl.AddAction(confirmed);

                if (this.PresentedViewController == null)
                {
                    SystemSound sound = new SystemSound(4095);
                    sound.PlaySystemSound();
                    this.PresentViewController(helpControl, true, null);
                }
                else if (this.PresentedViewController != null)
                {
                    this.PresentedViewController.DismissViewController(true, () =>
                    {
                        this.PresentedViewController.Dispose();
                        SystemSound sound = new SystemSound(4095);
                        sound.PlaySystemSound();
                        this.PresentViewController(helpControl, true, null);
                    });
                }
            }
        }
コード例 #7
0
        private void ShowToast(string message, string backgroundHexColor = null, string textHexColor = null, Plugin.Toast.Abstractions.ToastLength toastLength = ToastLength.Short)
        {
            var delay = toastLength == ToastLength.Short ? ShortDelay : LongDelay;

            _alert?.Dispose();
            _alertDelay = NSTimer.CreateScheduledTimer(delay, (obj) =>
            {
                DismissMessage();
            });

            _alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
            var tView = _alert.View;

            if (!string.IsNullOrEmpty(backgroundHexColor))
            {
                var firstSubView     = tView.Subviews?.FirstOrDefault();
                var alertContentView = firstSubView?.Subviews?.FirstOrDefault();
                if (alertContentView != null)
                {
                    foreach (UIView uiView in alertContentView.Subviews)
                    {
                        uiView.BackgroundColor = UIColor.Clear.FromHexString(backgroundHexColor);
                    }
                }
            }
            var attributedString = new NSAttributedString(message, foregroundColor: UIColor.Clear.FromHexString(textHexColor ?? "#000000"));

            _alert.SetValueForKey(attributedString, new NSString("attributedMessage"));
            IosHelper.GetVisibleViewController().PresentViewController(_alert, true, null);
        }
コード例 #8
0
        private void errorPrinting(string title, string message)
        {
            UIAlertController errorPrintController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

            UIAlertAction onePage = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (UIAlertAction obj) =>
            {
                errorPrintController.Dispose();
            });


            errorPrintController.AddAction(onePage);

            if (this.PresentedViewController == null)
            {
                this.PresentViewController(errorPrintController, true, null);
            }
            else
            {
                this.PresentedViewController.DismissViewController(true, () =>
                {
                    this.PresentedViewController.Dispose();
                    this.PresentViewController(errorPrintController, true, null);
                });
            }
        }
コード例 #9
0
        private void alertInstructions(string title, string message)
        {
            UIAlertController instructionsController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

            UIAlertAction confirmed = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (Action) =>
            {
                instructionsController.Dispose();
            });

            instructionsController.AddAction(confirmed);

            if (this.PresentedViewController == null)
            {
                this.PresentViewController(instructionsController, true, null);
            }

            else if (this.PresentedViewController != null)
            {
                this.PresentedViewController.DismissViewController(true, () =>
                {
                    this.PresentedViewController.Dispose();
                    this.PresentViewController(instructionsController, true, null);
                });
            }
        }
コード例 #10
0
 void DismissMessage(UIAlertController alert, NSTimer alertDelay, Action complete)
 {
     alert?.DismissViewController(true, complete);
     alert?.Dispose();
     alertDelay?.Dispose();
     _lastAlertDelay = null;
     _lastAlert      = null;
 }
コード例 #11
0
 public void Dispose()
 {
     alertController?.Dispose();
     alertView?.DismissWithClickedButtonIndex(alertView.CancelButtonIndex, true);
     alertView?.Dispose();
     tcs?.TrySetCanceled();
     tcs = null;
 }
コード例 #12
0
        private void rateOnAppStore(string title, string message)
        {
            UIAlertController rateAppStore = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

            UIAlertAction rateAction = UIAlertAction.Create("Rate on the App Store", UIAlertActionStyle.Default, (Action) =>
            {
                NSUrl appStoreURL = NSUrl.FromString("");                 //URL of this application on the app store
                if (UIApplication.SharedApplication.CanOpenUrl(appStoreURL) == true)
                {
                    UIApplication.SharedApplication.OpenUrl(appStoreURL);
                }
                else
                {
                    if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                    {
                        AI.AIEnglish("No internet connection detected. Cannot connect to the App Store", "en-US", 2.5f, 1.0f, 1.0f);
                    }
                    else if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                    {
                        AI.AIEnglish("No internet connection detected. Cannot connect to the App Store", "en-US", 2.5f, 1.0f, 1.0f);
                    }
                }
            });

            UIAlertAction denied = UIAlertAction.Create("Maybe Later", UIAlertActionStyle.Destructive, (Action) =>
            {
                rateAppStore.Dispose();
            });

            rateAppStore.AddAction(rateAction);
            rateAppStore.AddAction(denied);


            if (this.PresentedViewController == null)
            {
                this.PresentViewController(rateAppStore, true, null);
            }
            else if (this.PresentedViewController != null)
            {
                this.PresentedViewController.DismissViewController(true, () =>
                {
                    rateAppStore.Dispose();
                    this.PresentViewController(rateAppStore, true, null);
                });
            }
        }
コード例 #13
0
        public void HideLoading()
        {
            if (_progressAlert == null)
            {
                return;
            }

            _progressAlert.DismissViewController(true, () => { });
            _progressAlert.Dispose();
            _progressAlert = null;
        }
コード例 #14
0
        private void corruptController(int index)
        {
            var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var directory = Directory.GetFiles(documents, "*.pdf");

            UIAlertController corruptAlert = UIAlertController.Create("Corrupt file cannot be opened!", "'" + Path.GetFileName(directory[index]) + "'" + " cannot be opened because it appears to be corrupt. Would you like to delete this file?", UIAlertControllerStyle.Alert);

            UIAlertAction confirmed = UIAlertAction.Create("No", UIAlertActionStyle.Destructive, (UIAlertAction obj) => {
                corruptAlert.Dispose();
            });

            UIAlertAction deleteFile = UIAlertAction.Create("Delete file", UIAlertActionStyle.Cancel, (UIAlertAction obj) => {
                File.Delete(directory[index]);
                this.pdfList.RemoveAt(index);
                this.creationDate.RemoveAt(index);
                this.thumbnailImage.RemoveAt(index);

                int indexCorrupt  = this.pdfList.IndexOf(this.pdfList[index]);
                int indexOfficial = this.corruptIndex.IndexOf(indexCorrupt);

                this.corruptIndex.RemoveAt(indexOfficial);
                this.TableView.ReloadData();

                //	this.corruptIndex.Clear();


                //why do i need to call on view didload again in order to proces any other corrupt files with broken packets
                //	this.ViewDidLoad();
            });

            corruptAlert.AddAction(confirmed);
            corruptAlert.AddAction(deleteFile);

            if (this.PresentedViewController == null)
            {
                this.PresentViewController(corruptAlert, true, () =>
                {
                    SystemSound sound = new SystemSound(4095);
                    sound.PlaySystemSound();
                });
            }
            else
            {
                this.PresentedViewController.DismissViewController(true, () =>
                {
                    this.PresentedViewController.Dispose();
                    this.PresentViewController(corruptAlert, true, () => {
                        SystemSound sound = new SystemSound(4095);
                        sound.PlaySystemSound();
                    });
                });
            }
        }
コード例 #15
0
ファイル: DeviceActionService.cs プロジェクト: phaufe/mobile
        public Task HideLoadingAsync()
        {
            var result = new TaskCompletionSource <int>();

            if (_progressAlert == null)
            {
                result.TrySetResult(0);
            }
            _progressAlert.DismissViewController(false, () => result.TrySetResult(0));
            _progressAlert.Dispose();
            _progressAlert = null;
            return(result.Task);
        }
コード例 #16
0
        void ShowAlert(string message, double seconds)
        {
            alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null);

            NSTimer.CreateScheduledTimer(seconds, (obj) =>
            {
                if (alert != null)
                {
                    UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, () =>
                    {
                        alert.DismissViewController(true, null);
                        alert.Dispose();

                        obj?.Dispose();
                    });
                }
            });
        }
コード例 #17
0
        private void emailMessage()
        {
            UIAlertController promptEmail = UIAlertController.Create("Password recovery", "", UIAlertControllerStyle.Alert);

            promptEmail.AddTextField((UITextField obj) =>
            {
                obj.Placeholder            = "Email address";
                obj.SpellCheckingType      = UITextSpellCheckingType.No;
                obj.AutocorrectionType     = UITextAutocorrectionType.No;
                obj.AutocapitalizationType = UITextAutocapitalizationType.None;
                obj.BorderStyle            = UITextBorderStyle.RoundedRect;
                obj.KeyboardType           = UIKeyboardType.EmailAddress;
                obj.KeyboardAppearance     = UIKeyboardAppearance.Alert;
            });

            UIAlertAction confirmed = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (UIAlertAction obj) =>
            {
                var emailAddress = Environment.GetFolderPath(Environment.SpecialFolder.System);
                var filePath     = System.IO.Path.Combine(emailAddress, "emailAddress");
                System.IO.File.WriteAllText(filePath, promptEmail.TextFields[0].Text);
            });

            UIAlertAction denied = UIAlertAction.Create("Maybe Later", UIAlertActionStyle.Destructive, (UIAlertAction obj) =>
            {
                promptEmail.Dispose();
            });

            promptEmail.AddAction(confirmed);
            promptEmail.AddAction(denied);

            if (this.PresentedViewController == null)
            {
                this.PresentViewController(promptEmail, true, null);
            }
            else
            {
                this.PresentedViewController.DismissViewController(true, () =>
                {
                    this.PresentedViewController.Dispose();
                    this.PresentViewController(promptEmail, true, null);
                });
            }
        }
コード例 #18
0
        void DismissDialog(UIAlertAction obj)
        {
            alertController.DismissViewController(true, null);

            okButton.Dispose();
            alertController.Dispose();

            title           = null;
            message         = null;
            okButton        = null;
            alertController = null;

            if (_callBack != null)
            {
                _callBack.Invoke();
            }

            _callBack = null;
        }
コード例 #19
0
        public bool batteryLevel(bool allowed)
        {
            if (allowed == true)
            {
                if (UIDevice.CurrentDevice.BatteryLevel < 0.5 && UIDevice.CurrentDevice.BatteryLevel >= 0.3)
                {
                    UIDevice.CurrentDevice.BatteryMonitoringEnabled = true;
                    UIAlertController levelController = UIAlertController.Create("⚡️ Low Battery", "Battery is measured at " + UIDevice.CurrentDevice.BatteryLevel * 100 + "%", UIAlertControllerStyle.Alert);

                    UIAlertAction confirmed = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (Action) =>
                    {
                        levelController.Dispose();
                    });

                    levelController.AddAction(confirmed);

                    if (master.PresentedViewController == null)
                    {
                        master.PresentViewController(levelController, true, null);
                    }

                    else if (master.PresentedViewController != null)
                    {
                        master.PresentedViewController.DismissViewController(true, () =>
                        {
                            master.PresentedViewController.Dispose();
                            master.PresentViewController(levelController, true, null);
                        });
                    }
                    return(true);
                }
            }
            else
            {
                Console.WriteLine("Battery monitor is disabled");
                return(false);
            }
            return(false);
        }
コード例 #20
0
        private void errorCamera(string title, string message)
        {
            UIAlertController errorController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

            UIAlertAction confirmed = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (Action) =>
            {
                errorController.Dispose();
            });

            errorController.AddAction(confirmed);

            if (navController.PresentedViewController == null)
            {
                navController.PresentViewController(errorController, true, null);
            }
            else if (navController.PresentedViewController != null)
            {
                navController.PresentedViewController.DismissViewController(true, () =>
                {
                    navController.PresentedViewController.Dispose();
                    navController.PresentViewController(errorController, true, null);
                });
            }
        }
コード例 #21
0
        public override void ViewDidLoad()
        {
            this.NavigationController.NavigationBar.BackgroundColor = UIColor.White;
            this.NavigationItem.Title         = "My PDFs";
            this.TableView.RowHeight          = 70.0f;
            this.appDelegate.library          = this;
            this.appDelegate.resultsStringPDF = this.pdfList;
            UIStoryboard story = UIStoryboard.FromName("Main", NSBundle.MainBundle);

            this.appDelegate.PDF = story.InstantiateViewController("PDFReader") as PDFReader;

            this.searchController = new UISearchController(new resultsController());
            this.searchController.SearchResultsUpdater                 = new searchUpdator(this);
            this.searchController.DimsBackgroundDuringPresentation     = true;
            this.searchController.HidesNavigationBarDuringPresentation = true;

            this.search = this.searchController.SearchBar;
            this.EdgesForExtendedLayout = UIRectEdge.None;

            this.search.Frame             = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width - 5.0f, 50.0f);
            this.search.SpellCheckingType = UITextSpellCheckingType.No;
            this.search.BarStyle          = UIBarStyle.Default;
            this.search.SearchBarStyle    = UISearchBarStyle.Prominent;
            this.search.Placeholder       = "Search...";

            this.search.CancelButtonClicked += (object sender, EventArgs e) =>
            {
                this.search.ResignFirstResponder();
            };
            this.search.TextChanged += (object sender, UISearchBarTextChangedEventArgs e) =>
            {
                SystemSound keyboardClick = new SystemSound(1105);
                keyboardClick.PlaySystemSound();
            };

            this.search.SearchButtonClicked += (object sender, EventArgs e) =>
            {
                search.ResignFirstResponder();
            };

            this.TableView.TableHeaderView = search;

            var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var directory = Directory.GetFiles(documents, "*.pdf");

            var fileName = Path.Combine(documents, "*.pdf");

            this.appDelegate.directories = directory;


            NSError error = new NSError();

            try
            {
                if (NSFileManager.DefaultManager.GetDirectoryContent(documents, out error).Length == 0)
                {
                    throw new FileNotFoundException();
                }
                else
                {
                    for (int i = 0; i <= directory.Length - 1; i++)
                    {
                        try
                        {
                            if (directory[i] == null)
                            {
                                throw new ArgumentOutOfRangeException();
                            }
                            else
                            {
                                this.pdfList.Add(Path.GetFileName(directory[i]));
                                this.creationDate.Add(Convert.ToString(Directory.GetCreationTime(directory[i])));
                                addImageContext(directory, i);
                            }
                        }
                        catch (ArgumentOutOfRangeException) {
                            Console.WriteLine("File does not exist");
                        }
                    }
                }
            }
            catch (FileNotFoundException) {
                Console.WriteLine("Cannot find the specified pdf file in the library");
            }

            if (this.pdfList.Count == 0)
            {
                emptyPDF = new UIView();

                emptyImage = new UIImageView();

                this.description      = new UILabel();
                this.description.Text = "This page contains no PDFs. To get started adding your ";
                this.description.Font = UIFont.FromName("Georgia-Italic", 26.0f);
                this.description.AdjustsFontSizeToFitWidth = true;

                this.description_2      = new UILabel();
                this.description_2.Text = "own PDFs drag your files through iTunes file sharing";
                this.description_2.Font = UIFont.FromName("Georgia-Italic", 26.0f);
                this.description_2.AdjustsFontSizeToFitWidth = true;


                this.titleDescription      = new UILabel();
                this.titleDescription.Text = "No PDFs";
                this.titleDescription.Font = UIFont.SystemFontOfSize(26.0f);
                this.titleDescription.Font = UIFont.FromName("AmericanTypewriter-Bold", 26.0f);

                if (UIApplication.SharedApplication.StatusBarHidden == true)
                {
                    emptyPDF.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);

                    emptyImage.Frame = new CGRect(emptyPDF.Center.X - 100.0f, emptyPDF.Center.Y - 200.0f, 200, 200);

                    this.description.Frame      = new CGRect(this.View.Bounds.Left + 35.0f, this.View.Center.Y + 10.0f, UIScreen.MainScreen.Bounds.Width - 5.0f, 50.0f);
                    this.description_2.Frame    = new CGRect(this.View.Bounds.Left + 35.0f, this.View.Center.Y + 70.0f, UIScreen.MainScreen.Bounds.Width - 5.0f, 50.0f);
                    this.titleDescription.Frame = new CGRect(this.View.Center.X - 60.0f, this.View.Center.Y - 180.0f, UIScreen.MainScreen.Bounds.Width - 50.0f, 300.0f);
                }
                else
                {
                    emptyPDF.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);

                    emptyImage.Frame = new CGRect(emptyPDF.Center.X - 100.0f, emptyPDF.Center.X - 95.0f, 200, 200);

                    this.description.Frame      = new CGRect(this.View.Bounds.Left + 5.0f, this.View.Center.Y, UIScreen.MainScreen.Bounds.Width - 5.0f, 50.0f);
                    this.description_2.Frame    = new CGRect(this.View.Bounds.Left + 5.0f, this.View.Center.Y + 50.0f, UIScreen.MainScreen.Bounds.Width - 5.0f, 50.0f);
                    this.titleDescription.Frame = new CGRect(this.View.Center.X - 60.0f, this.View.Center.Y - 240.0f, UIScreen.MainScreen.Bounds.Width - 50.0f, 300.0f);
                }

                emptyImage.Image = new UIImage("EmptyScreen.png");

                emptyPDF.AddSubview(emptyImage);
                emptyPDF.AddSubview(this.description);
                emptyPDF.AddSubview(this.description_2);
                emptyPDF.AddSubview(this.titleDescription);

                this.TableView.SeparatorColor  = UIColor.GroupTableViewBackgroundColor;
                this.TableView.TintColor       = UIColor.GroupTableViewBackgroundColor;
                this.TableView.TableHeaderView = null;

                this.Add(emptyPDF);
                this.View.BringSubviewToFront(emptyPDF);
            }
            else
            {
                this.TableView.SeparatorColor = UIColor.LightGray;
                this.TableView.TintColor      = UIColor.LightGray;

                //this.TableView.TableHeaderView = this.search;
                emptyPDF = new UIView();

                emptyImage = new UIImageView();

                emptyPDF.RemoveFromSuperview();
                emptyImage.RemoveFromSuperview();
            }
            this.emptyPDF.BackgroundColor = UIColor.GroupTableViewBackgroundColor;


            UIBarButtonItem cancelEditing = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, e) =>
            {
                this.selectedCellsToRemove.Clear();
                this.TableView.SetEditing(false, true);
                this.NavigationItem.SetRightBarButtonItem(this.appDelegate.editPassword, true);
            });

            //nav bar items
            UIBarButtonItem edit = new UIBarButtonItem(UIBarButtonSystemItem.Edit, (object sender, EventArgs e) =>
            {
                //pushes the password reader controller which allows the user to enter
                var documents_2         = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var passwordDirectory_2 = Path.Combine(documents, "*.pdf");


                NSError error_2 = new NSError();
                if (NSFileManager.DefaultManager.GetDirectoryContent(passwordDirectory_2, out error_2).Length == 0)
                {
                    UIAlertController emptyPasswords = UIAlertController.Create("Nothing to delete", "You have no passwords listed here to delete", UIAlertControllerStyle.Alert);

                    UIAlertAction confirmed = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        emptyPasswords.Dispose();
                    });

                    emptyPasswords.AddAction(confirmed);

                    if (this.PresentedViewController == null)
                    {
                        this.PresentViewController(emptyPasswords, true, () =>
                        {
                            SystemSound soundError = new SystemSound(4095);
                            soundError.PlaySystemSound();
                        });
                    }
                    else
                    {
                        this.PresentedViewController.DismissViewController(true, () =>
                        {
                            this.PresentedViewController.Dispose();
                            this.PresentViewController(emptyPasswords, true, () =>
                            {
                                SystemSound soundError = new SystemSound(4095);
                                soundError.PlaySystemSound();
                            });
                        });
                    }
                }
                else
                {
                    this.TableView.SetEditing(true, true);
                    this.NavigationItem.SetRightBarButtonItem(cancelEditing, true);
                }
            });

            this.appDelegate.editPassword = edit;
        }
コード例 #22
0
        public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
        {
            if (editingStyle == UITableViewCellEditingStyle.Insert)
            {
                //user clicks the bar button item whateevr he has already favourit as in whaterver exists withint the applications delegate list if the strin already exist the editing saccessory style becomes delete

                if (this.application.localizedTextFamily.Count((string arg) => arg.ToString() == this.familyDict[indexPath.Row]) >= 1)
                {
                    UIAlertController alreadyFavourited = UIAlertController.Create("Already favourited!", "You have already favourited this phrase!", UIAlertControllerStyle.Alert);

                    UIAlertAction confirmed = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (Action) =>
                    {
                        alreadyFavourited.Dispose();
                    });

                    alreadyFavourited.AddAction(confirmed);


                    if (this.PresentedViewController == null)
                    {
                        this.PresentViewController(alreadyFavourited, true, () =>
                        {
                            AudioToolbox.SystemSound sound = new AudioToolbox.SystemSound(4095);
                            sound.PlaySystemSound();
                        });
                    }
                    else
                    {
                        this.PresentedViewController.DismissViewController(true, () =>
                        {
                            this.PresentedViewController.Dispose();
                            this.PresentViewController(alreadyFavourited, true, () =>
                            {
                                AudioToolbox.SystemSound sound = new AudioToolbox.SystemSound(4095);
                                sound.PlaySystemSound();
                            });
                        });
                    }

                    Console.WriteLine("The object already exists inside the list");
                }

                else if (this.application.localizedTextFamily.Count((string arg) => arg.ToString() == this.familyDict[indexPath.Row]) == 0)
                {
                    this.application.localizedTextFamily.Add(this.familyDict[indexPath.Row]);
                    this.application.frenchTextFamily.Add(this.familyTranslatedDict[indexPath.Row]);
                    this.application.indexPathsRegister.Add(indexPath);
                    this.application.indexPathsInt.Add(indexPath.Row);
                    this.favouritesIndicator = new UILabel();

                    this.favouritesIndicator.Text                      = this.favouritesButton.Title;
                    this.favouritesIndicator.MinimumFontSize           = 20.0f;
                    this.favouritesIndicator.AdjustsFontSizeToFitWidth = true;
                    this.favouritesIndicator.Frame                     = new CoreGraphics.CGRect(0, 20, 40, 40);


                    NSIndexPath        index       = indexPath;
                    List <NSIndexPath> indexChosen = new List <NSIndexPath>()
                    {
                    };
                    indexChosen.Add(index);

                    List <int> indexInt = new List <int>()
                    {
                    };
                    indexInt.Add(indexPath.Row);

                    this.application.indexIntFamily.Add(indexPath.Row);

                    this.application.indexTableFamily = index;

                    this.TableView.ReloadData();
                }
            }
            else if (editingStyle == UITableViewCellEditingStyle.Delete)
            {
                if (this.application.indexIntFamily.Contains(indexPath.Row) == true)
                {
                    this.application.localizedTextFamily.RemoveAll((string obj) => obj == this.familyDict[indexPath.Row]);
                    this.application.indexIntFamily.RemoveAll((int obj) => obj == indexPath.Row);

                    this.application.favourites.RemoveAll((string obj) => obj == this.familyDict[indexPath.Row]);
                    this.application.favouritesFrench.RemoveAll((string obj) => obj == this.familyTranslatedDict[indexPath.Row]);

                    if (this.application.indexTableFamily.Row == indexPath.Row || this.application.indexTableFamily.Row != indexPath.Row)
                    {
                        this.application.cellFamily.AccessoryView        = null;
                        this.application.cellFamily.EditingAccessoryView = null;
                        this.TableView.ReloadData();
                    }

                    if (this.application.localizedTextFamily.Count == 1)
                    {
                        this.TableView.ReloadData();
                    }

                    if (this.application.cellFamily.EditingStyle == UITableViewCellEditingStyle.Insert)
                    {
                        this.application.cellFamily.AccessoryView        = null;
                        this.application.cellFamily.EditingAccessoryView = null;
                        this.TableView.ReloadData();
                    }

                    /*if (this.application.localizedText.Count == 0)
                     * {
                     *      if (this.application.cellBusiness.AccessoryView != null)
                     *      {
                     *              this.application.cellBusiness.AccessoryView = null;
                     *              this.application.cellBusiness.EditingAccessoryView = null;
                     *              this.TableView.ReloadData();
                     *      }
                     * }*/
                }
                else
                {
                    this.application.cellFamily.AccessoryView        = null;
                    this.application.cellFamily.EditingAccessoryView = null;
                    this.TableView.ReloadData();
                }
                //this.application.localizedText.RemoveAt(this.companyDict.IndexOf(this.companyDict[indexPath.Row]));
                //this.application.indexInt.RemoveAt(this.companyDict.IndexOf(this.companyDict[indexPath.Row]));
                //tableView.ReloadData();
                this.TableView.ReloadData();
            }
        }
コード例 #23
0
        private void chooseApp(string title, string message)
        {
            UIAlertController chooseAppController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

            //user chooses to look at the other apps
            UIAlertAction confirmed = UIAlertAction.Create("Yes", UIAlertActionStyle.Default, (Action) =>
            {
                NSUrl linkToPhraseBook = NSUrl.FromString("");
                if (UIApplication.SharedApplication.CanOpenUrl(linkToPhraseBook) == true)
                {
                    UIApplication.SharedApplication.OpenUrl(linkToPhraseBook);
                    chooseAppController.Dispose();
                }
                else if (UIApplication.SharedApplication.CanOpenUrl(linkToPhraseBook) == false)
                {
                    if (chooseAppController.IsBeingDismissed == true)
                    {
                        chooseAppController.Dispose();

                        UIAlertController noInternetController = UIAlertController.Create("No Internet", "Seems we could not connect you to the App Store. Check your internet connection and try again", UIAlertControllerStyle.Alert);

                        UIAlertAction confirmedInternet = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (Action_2) =>
                        {
                            noInternetController.Dispose();
                        });

                        noInternetController.AddAction(confirmedInternet);

                        if (this.PresentedViewController == null)
                        {
                            this.PresentViewController(noInternetController, true, null);
                        }
                        else if (this.PresentedViewController != null)
                        {
                            this.PresentedViewController.DismissViewController(true, () =>
                            {
                                this.PresentedViewController.Dispose();
                                this.PresentViewController(noInternetController, true, null);
                            });
                        }
                    }
                    else if (chooseAppController.IsBeingDismissed == false)
                    {
                        Console.WriteLine("App Controller is not being dismissed");
                    }
                }
            });

            UIAlertAction denied = UIAlertAction.Create("Maybe Later", UIAlertActionStyle.Destructive, (Action) =>
            {
                chooseAppController.Dispose();
            });

            chooseAppController.AddAction(confirmed);
            chooseAppController.AddAction(denied);

            if (this.PresentedViewController == null)
            {
                this.PresentViewController(chooseAppController, true, null);
            }
            else if (this.PresentedViewController != null)
            {
                this.PresentedViewController.DismissViewController(true, () =>
                {
                    this.PresentedViewController.Dispose();
                    this.PresentViewController(chooseAppController, true, null);
                });
            }
        }
コード例 #24
0
ファイル: AlertView.cs プロジェクト: xcodeuuuuu66699/gMusic
 public void Dispose()
 {
     dict = null;
     sheet?.Dispose();
     controller?.Dispose();
 }
コード例 #25
0
        public override void ViewDidAppear(bool animated)
        {
            this.appDelegate.tablePDFSearch = 0;
            UIBarButtonItem searchText = new UIBarButtonItem(UIBarButtonSystemItem.Search, (object sender, EventArgs e) =>
            {
                //searches for matching text inside pdf
                this.searchForText.Placeholder       = "Search...";
                this.searchForText.SpellCheckingType = UITextSpellCheckingType.No;
                this.searchForText.SearchBarStyle    = UISearchBarStyle.Prominent;
                this.searchForText.BarStyle          = UIBarStyle.Default;
                this.searchForText.ShowsCancelButton = true;
                this.NavigationItem.TitleView        = this.searchForText;

                this.searchForText.BecomeFirstResponder();
                this.searchForText.CancelButtonClicked += (object sender_2, EventArgs e_2) => {
                    //replaces the navigation item with the title text
                    this.searchForText.ResignFirstResponder();
                    this.NavigationItem.TitleView = null;
                    this.NavigationItem.Title     = "Viewer";
                };
            });

            UIBarButtonItem pageMode = new UIBarButtonItem("Page Mode", UIBarButtonItemStyle.Done, (object sender, EventArgs e) => {
                //page count is adjusted
                //creates a small table which adjusts the number of pages to render

                //an alert controller is best for this
                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                {
                    UIAlertController pageModeController = UIAlertController.Create("", "", UIAlertControllerStyle.ActionSheet);

                    UIAlertAction onePage = UIAlertAction.Create("Single Page", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        this.pdfWebReader.PaginationMode = UIWebPaginationMode.TopToBottom;
                        pageModeController.Dispose();
                    });

                    UIAlertAction continousPages = UIAlertAction.Create("Continuous", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        this.pdfWebReader.PaginationMode = UIWebPaginationMode.Unpaginated;
                        pageModeController.Dispose();
                    });

                    UIAlertAction denied = UIAlertAction.Create("Never Mind", UIAlertActionStyle.Cancel, (UIAlertAction obj) =>
                    {
                        pageModeController.Dispose();
                    });

                    pageModeController.AddAction(onePage);
                    pageModeController.AddAction(continousPages);
                    pageModeController.AddAction(denied);

                    if (this.PresentedViewController == null)
                    {
                        this.PresentViewController(pageModeController, true, null);
                    }
                    else
                    {
                        this.PresentedViewController.DismissViewController(true, () =>
                        {
                            this.PresentedViewController.Dispose();
                            this.PresentViewController(pageModeController, true, null);
                        });
                    }
                }
                else
                {
                    UIAlertController pageModeController = UIAlertController.Create("", "", UIAlertControllerStyle.Alert);

                    UIAlertAction onePage = UIAlertAction.Create("Single Page", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        this.pdfWebReader.PaginationMode = UIWebPaginationMode.TopToBottom;
                        pageModeController.Dispose();
                    });

                    UIAlertAction continousPages = UIAlertAction.Create("Full Screen", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        this.pdfWebReader.PaginationMode = UIWebPaginationMode.Unpaginated;
                        pageModeController.Dispose();
                    });

                    UIAlertAction denied = UIAlertAction.Create("Never Mind", UIAlertActionStyle.Cancel, (UIAlertAction obj) =>
                    {
                        pageModeController.Dispose();
                    });

                    pageModeController.AddAction(onePage);
                    pageModeController.AddAction(continousPages);
                    pageModeController.AddAction(denied);

                    if (this.PresentedViewController == null)
                    {
                        this.PresentViewController(pageModeController, true, null);
                    }
                    else
                    {
                        this.PresentedViewController.DismissViewController(true, () =>
                        {
                            this.PresentedViewController.Dispose();
                            this.PresentViewController(pageModeController, true, null);
                        });
                    }
                }
            });
            UIBarButtonItem share = new UIBarButtonItem(UIBarButtonSystemItem.Action, (sender, e) => {
                //introduces an action sheet. with the following options:

                /*
                 * allows the user to share file (which creates an activity controller where the user can choose how to share the file)
                 * allows updating to the cloud
                 * allows an option to open the document in another application of choice (UIDocumentInterationController)
                 * Print the document (In a nearby printer via AirPrint)
                 *
                 */
                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                {
                    UIAlertController shareModeController = UIAlertController.Create("", "", UIAlertControllerStyle.ActionSheet);

                    UIAlertAction shareFile = UIAlertAction.Create("Share File", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        var directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        var filePath  = Path.Combine(directory, this.appDelegate.pdfString);

                        NSUrl pdfURL   = NSUrl.FromFilename(filePath);
                        NSData pdfData = NSData.FromUrl(pdfURL);

                        NSObject[] dataToShare            = new NSObject[] { pdfURL };
                        UIActivityViewController activity = new UIActivityViewController(dataToShare, null);

                        //UIActivityType[] activityTypes = new UIActivityType[] { UIActivityType.Print, UIActivityType.SaveToCameraRoll };


                        if (this.PresentedViewController == null)
                        {
                            this.PresentViewController(activity, true, null);
                        }
                        else
                        {
                            this.PresentedViewController.DismissViewController(true, () => {
                                this.PresentedViewController.Dispose();
                                this.PresentViewController(activity, true, null);
                            });
                        }
                        shareModeController.Dispose();
                    });

                    UIAlertAction printDocument = UIAlertAction.Create("Print Document", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        var directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        var filePath  = Path.Combine(directory, this.appDelegate.pdfString);

                        NSUrl pdfURL                = NSUrl.FromFilename(filePath);
                        var printInformation        = UIPrintInfo.PrintInfo;
                        printInformation.OutputType = UIPrintInfoOutputType.General;
                        printInformation.JobName    = "Print Job";

                        var print            = UIPrintInteractionController.SharedPrintController;
                        print.PrintInfo      = printInformation;
                        print.PrintFormatter = this.pdfWebReader.ViewPrintFormatter;
                        print.PrintingItem   = pdfURL;
                        print.ShowsPageRange = true;

                        if (UIPrintInteractionController.CanPrint(pdfURL) == true)
                        {
                            print.Present(true, (UIPrintInteractionController printInteractionController, bool completed, NSError error) =>
                            {
                                if (error != null)
                                {
                                    print.Dismiss(true);
                                    errorPrinting("Print Error!", "Cannot print your document. Check if your printer is connected");
                                }
                                else
                                {
                                    Console.WriteLine("Printer success");
                                }
                            });
                        }
                        else
                        {
                            errorPrinting("Print Error!", "Cannot print your document. Check if your printer is connected");
                        }
                        shareModeController.Dispose();
                    });

                    UIAlertAction denied = UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, (UIAlertAction obj) =>
                    {
                        shareModeController.Dispose();
                    });

                    shareModeController.AddAction(shareFile);
                    shareModeController.AddAction(printDocument);
                    shareModeController.AddAction(denied);

                    if (this.PresentedViewController == null)
                    {
                        this.PresentViewController(shareModeController, true, null);
                    }
                    else
                    {
                        this.PresentedViewController.DismissViewController(true, () =>
                        {
                            this.PresentedViewController.Dispose();
                            this.PresentViewController(shareModeController, true, null);
                        });
                    }
                }
                else
                {
                    UIAlertController shareModeController = UIAlertController.Create("", "", UIAlertControllerStyle.Alert);

                    UIAlertAction shareFile = UIAlertAction.Create("Share File", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        var directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        var filePath  = Path.Combine(directory, this.appDelegate.pdfString);

                        NSUrl pdfURL   = NSUrl.FromFilename(filePath);
                        NSData pdfData = NSData.FromUrl(pdfURL);

                        NSObject[] dataToShare            = new NSObject[] { pdfURL };
                        UIActivityViewController activity = new UIActivityViewController(dataToShare, null);

                        //UIActivityType[] activityTypes = new UIActivityType[] { UIActivityType.Print, UIActivityType.SaveToCameraRoll };


                        if (this.PresentedViewController == null)
                        {
                            this.PresentViewController(activity, true, null);
                        }
                        else
                        {
                            this.PresentedViewController.DismissViewController(true, () =>
                            {
                                this.PresentedViewController.Dispose();
                                this.PresentViewController(activity, true, null);
                            });
                        }
                        shareModeController.Dispose();
                    });

                    UIAlertAction printDocument = UIAlertAction.Create("Print Document", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        var directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        var filePath  = Path.Combine(directory, this.appDelegate.pdfString);

                        NSUrl pdfURL = NSUrl.FromFilename(filePath);

                        var printInformation        = UIPrintInfo.PrintInfo;
                        printInformation.OutputType = UIPrintInfoOutputType.General;
                        printInformation.JobName    = "Print Job";

                        var print            = UIPrintInteractionController.SharedPrintController;
                        print.PrintInfo      = printInformation;
                        print.PrintFormatter = this.pdfWebReader.ViewPrintFormatter;
                        print.PrintingItem   = pdfURL;

                        print.ShowsPageRange = true;
                        print.Present(true, (UIPrintInteractionController printInteractionController, bool completed, NSError error) =>
                        {
                            if (error != null)
                            {
                                print.Dismiss(true);
                                errorPrinting("Print Error!", "Cannot print your document. Check if your printer is connected");
                            }
                            else
                            {
                                Console.WriteLine("Printer success");
                            }
                        });

                        shareModeController.Dispose();
                    });

                    UIAlertAction denied = UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, (UIAlertAction obj) =>
                    {
                        shareModeController.Dispose();
                    });

                    shareModeController.AddAction(shareFile);
                    shareModeController.AddAction(printDocument);
                    shareModeController.AddAction(denied);

                    if (this.PresentedViewController == null)
                    {
                        this.PresentViewController(shareModeController, true, null);
                    }
                    else
                    {
                        this.PresentedViewController.DismissViewController(true, () =>
                        {
                            this.PresentedViewController.Dispose();
                            this.PresentViewController(shareModeController, true, null);
                        });
                    }
                }
            });
            UIBarButtonItem writeComment = new UIBarButtonItem("Comment", UIBarButtonItemStyle.Done, (sender, e) => {
                //adjusts the toolbar items with drawing items used for drawing items on the PDF view controller
            });

            this.NavigationController.SetToolbarHidden(false, true);
            UIBarButtonItem space_1 = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace, null);
            UIBarButtonItem space_2 = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace, null);

            this.NavigationController.Toolbar.Items = new UIBarButtonItem[] { searchText, space_1, space_2, share };
        }
コード例 #26
0
        //sharing options
        private void shareAlert(string title, string message)
        {
            UIAlertController shareController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);


            //facebook servers
            UIAlertAction facebookAction = UIAlertAction.Create("Facebook", UIAlertActionStyle.Default, (Action) => {
                NSUrl facebookURL = NSUrl.FromString("");

                if (UIApplication.SharedApplication.CanOpenUrl(facebookURL) == true)
                {
                    UIApplication.SharedApplication.OpenUrl(facebookURL);
                    shareController.Dispose();
                }
                else if (UIApplication.SharedApplication.CanOpenUrl(facebookURL) == false)
                {
                    AI.AIEnglish("Cannot connect you to the facebook servers. Check your internet connection", "en-US", 2.0f, 1.0f, 1.0f);
                    shareController.Dispose();
                }
            });

            //twitter servers
            UIAlertAction twitterAction = UIAlertAction.Create("Twitter", UIAlertActionStyle.Default, (Action) =>
            {
                NSUrl twitterURL = NSUrl.FromString("");

                if (UIApplication.SharedApplication.CanOpenUrl(twitterURL) == true)
                {
                    UIApplication.SharedApplication.OpenUrl(twitterURL);
                    shareController.Dispose();
                }
                else if (UIApplication.SharedApplication.CanOpenUrl(twitterURL) == false)
                {
                    AI.AIEnglish("Cannot connect you to the twitter servers. Check your internet connection", "en-US", 2.0f, 1.0f, 1.0f);
                    shareController.Dispose();
                }
            });

            //email a friend option
            UIAlertAction emailFriend = UIAlertAction.Create("\ud83d\udc8c Email a Friend", UIAlertActionStyle.Default, (Action) =>
            {
                MFMailComposeViewController mailEmail = new MessageUI.MFMailComposeViewController();

                if (MFMailComposeViewController.CanSendMail == true)
                {
                    this.PresentViewController(mailEmail, true, null);
                }

                else
                {
                    if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                    {
                        AI.AIEnglish("Error cannot open mail box. Check if the mail box is enabled on your iPad", "en-US", 2.0f, 1.0f, 1.0f);
                    }
                    else if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                    {
                        AI.AIEnglish("Error cannot open mail box. Check if the mail box is enabled on your iPhone", "en-US", 2.0f, 1.0f, 1.0f);
                    }
                }

                mailEmail.Finished += (sender, e) =>
                {
                    //mail closes
                    mailEmail.DismissViewController(true, null);
                };
            });

            //text a friend option
            UIAlertAction textFriend = UIAlertAction.Create("\ud83d\udcf2 Text a friend", UIAlertActionStyle.Default, (Action) => {
                NSUrl textFriendURL = NSUrl.FromString("sms:");

                if (UIApplication.SharedApplication.CanOpenUrl(textFriendURL) == true)
                {
                    UIApplication.SharedApplication.OpenUrl(textFriendURL);
                }
                else if (UIApplication.SharedApplication.CanOpenUrl(textFriendURL) == false)
                {
                    if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                    {
                        AI.AIEnglish("Error cannot open text message box. Check if the text messages are enabled on your iPad", "en-US", 2.0f, 1.0f, 1.0f);
                    }
                    else if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                    {
                        AI.AIEnglish("Error cannot open text message box. Check if the text messages are enabled on your iPhone", "en-US", 2.0f, 1.0f, 1.0f);
                    }
                }
            });

            UIAlertAction rateOnAppStore = UIAlertAction.Create("\ud83d\udc4d Rate on App Store", UIAlertActionStyle.Default, (Action) =>
            {
                NSUrl urlRateAppURL = NSUrl.FromString("");                 //url of application on app store

                if (UIApplication.SharedApplication.CanOpenUrl(urlRateAppURL) == true)
                {
                    UIApplication.SharedApplication.OpenUrl(urlRateAppURL);
                }

                else
                {
                    if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                    {
                        AI.AIEnglish("No internet connection detected. Cannot connect to the App Store", "en-US", 2.5f, 1.0f, 1.0f);
                    }
                    else if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                    {
                        AI.AIEnglish("No internet connection detected.  Cannot connect to the App Store", "en-US", 2.5f, 1.0f, 1.0f);
                    }
                    shareController.Dispose();
                }
            });

            UIAlertAction denied = UIAlertAction.Create("Maybe Later", UIAlertActionStyle.Destructive, (Action) =>
            {
                shareController.Dispose();
            });

            shareController.AddAction(facebookAction);
            shareController.AddAction(twitterAction);
            shareController.AddAction(emailFriend);
            shareController.AddAction(textFriend);
            shareController.AddAction(rateOnAppStore);
            shareController.AddAction(denied);

            if (this.PresentedViewController == null)
            {
                this.PresentViewController(shareController, true, null);
            }

            else if (this.PresentedViewController != null)
            {
                this.PresentedViewController.DismissViewController(true, () =>
                {
                    this.PresentedViewController.Dispose();
                    this.PresentViewController(shareController, true, null);
                });
            }
        }
コード例 #27
0
        public override void ViewDidLoad()
        {
            this.NavigationController.NavigationBar.BackgroundColor = UIColor.White;
            this.NavigationItem.Title           = "My Photos & Videos";
            this.TableView.RowHeight            = 70.0f;
            this.appDelegate.photo              = this;
            this.appDelegate.resultsStringPhoto = this.pdfList;
            UIStoryboard story = UIStoryboard.FromName("Main", NSBundle.MainBundle);

            this.appDelegate.photoReader = story.InstantiateViewController("PhotosReader") as PhotosReader;

            this.searchController = new UISearchController(new resultsControllerPhoto());
            this.searchController.SearchResultsUpdater                 = new searchUpdatorPhoto(this);
            this.searchController.DimsBackgroundDuringPresentation     = true;
            this.searchController.HidesNavigationBarDuringPresentation = true;

            this.search = this.searchController.SearchBar;
            this.EdgesForExtendedLayout = UIRectEdge.None;

            this.search.Frame             = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width - 5.0f, 50.0f);
            this.search.SpellCheckingType = UITextSpellCheckingType.No;
            this.search.BarStyle          = UIBarStyle.Default;
            this.search.SearchBarStyle    = UISearchBarStyle.Prominent;
            this.search.Placeholder       = "Search...";

            this.search.CancelButtonClicked += (object sender, EventArgs e) =>
            {
                this.search.ResignFirstResponder();
            };
            this.search.TextChanged += (object sender, UISearchBarTextChangedEventArgs e) =>
            {
                SystemSound keyboardClick = new SystemSound(1105);
                keyboardClick.PlaySystemSound();
            };

            this.search.SearchButtonClicked += (object sender, EventArgs e) =>
            {
                search.ResignFirstResponder();
            };

            this.TableView.TableHeaderView = search;

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

            var directoryJPG = Directory.GetFiles(documents, "*.jpg");
            var directoryPNG = Directory.GetFiles(documents, "*.png");
            var directoryGIF = Directory.GetFiles(documents, "*.gif");
            var directorySVG = Directory.GetFiles(documents, "*.svg");
            var directoryICO = Directory.GetFiles(documents, "*.ico");


            this.appDelegate.directories = directoryJPG;

            NSError error = new NSError();

            try
            {
                if (NSFileManager.DefaultManager.GetDirectoryContent(documents, out error).Length == 0)
                {
                    throw new FileNotFoundException();
                }
                else
                {
                    //Photo formats
                    //.jpg
                    for (int i = 0; i <= directoryJPG.Length - 1; i++)
                    {
                        try
                        {
                            if (directoryJPG[i] == null)
                            {
                                throw new ArgumentOutOfRangeException();
                            }
                            else
                            {
                                this.pdfList.Add(Path.GetFileName(directoryJPG[i]));
                                this.creationDate.Add(Convert.ToString(Directory.GetCreationTime(directoryJPG[i])));
                                addImageContext(directoryJPG, i);
                            }
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            Console.WriteLine("File does not exist");
                        }
                    }

                    //.png
                    for (int i = 0; i <= directoryPNG.Length - 1; i++)
                    {
                        try
                        {
                            if (directoryPNG[i] == null)
                            {
                                throw new ArgumentOutOfRangeException();
                            }
                            else
                            {
                                this.pdfList.Add(Path.GetFileName(directoryPNG[i]));
                                this.creationDate.Add(Convert.ToString(Directory.GetCreationTime(directoryPNG[i])));
                                addImageContext(directoryPNG, i);
                            }
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            Console.WriteLine("File does not exist");
                        }
                    }

                    //gif
                    for (int i = 0; i <= directoryGIF.Length - 1; i++)
                    {
                        try
                        {
                            if (directoryGIF[i] == null)
                            {
                                throw new ArgumentOutOfRangeException();
                            }
                            else
                            {
                                this.pdfList.Add(Path.GetFileName(directoryGIF[i]));
                                this.creationDate.Add(Convert.ToString(Directory.GetCreationTime(directoryGIF[i])));
                                addImageContext(directoryGIF, i);
                            }
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            Console.WriteLine("File does not exist");
                        }
                    }

                    //.svg
                    for (int i = 0; i <= directorySVG.Length - 1; i++)
                    {
                        try
                        {
                            if (directorySVG[i] == null)
                            {
                                throw new ArgumentOutOfRangeException();
                            }
                            else
                            {
                                this.pdfList.Add(Path.GetFileName(directorySVG[i]));
                                this.creationDate.Add(Convert.ToString(Directory.GetCreationTime(directorySVG[i])));
                                addImageContext(directorySVG, i);
                            }
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            Console.WriteLine("File does not exist");
                        }
                    }

                    //.ico
                    for (int i = 0; i <= directoryICO.Length - 1; i++)
                    {
                        try
                        {
                            if (directoryICO[i] == null)
                            {
                                throw new ArgumentOutOfRangeException();
                            }
                            else
                            {
                                this.pdfList.Add(Path.GetFileName(directoryICO[i]));
                                this.creationDate.Add(Convert.ToString(Directory.GetCreationTime(directoryICO[i])));
                                addImageContext(directoryICO, i);
                            }
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            Console.WriteLine("File does not exist");
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Cannot find the specified pdf file in the library");
            }

            if (this.pdfList.Count == 0)
            {
                emptyPDF = new UIView();

                emptyImage = new UIImageView();

                this.description      = new UILabel();
                this.description.Text = "This page contains no passwords. To get started adding";
                this.description.Font = UIFont.FromName("Georgia-Italic", 26.0f);

                this.description_2      = new UILabel();
                this.description_2.Text = "your own passwords click \ud83d\udcdd";
                this.description_2.Font = UIFont.FromName("Georgia-Italic", 26.0f);

                this.description_2.AdjustsFontSizeToFitWidth = true;
                this.description.AdjustsFontSizeToFitWidth   = true;

                this.titleDescription      = new UILabel();
                this.titleDescription.Text = "No Photos";
                this.titleDescription.Font = UIFont.SystemFontOfSize(26.0f);
                this.titleDescription.Font = UIFont.FromName("AmericanTypewriter-Bold", 26.0f);

                if (UIApplication.SharedApplication.StatusBarHidden == true)
                {
                    emptyPDF.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);

                    emptyImage.Frame = new CGRect(emptyPDF.Center.X - 100.0f, emptyPDF.Center.Y - 200.0f, 200, 200);

                    this.description.Frame   = new CGRect(this.View.Center.X - 315.0f, this.View.Center.Y, UIScreen.MainScreen.Bounds.Width - 50.0f, 50.0f);
                    this.description_2.Frame = new CGRect(this.View.Center.X - 155.0f, this.View.Center.Y + 50.0f, UIScreen.MainScreen.Bounds.Width - 210.0f, 50.0f);

                    this.titleDescription.Frame = new CGRect(this.View.Center.X - 70.0f, this.View.Center.Y - 180.0f, UIScreen.MainScreen.Bounds.Width - 50.0f, 300.0f);
                }
                else
                {
                    emptyPDF.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);

                    emptyImage.Frame = new CGRect(emptyPDF.Center.X - 100.0f, emptyPDF.Center.X - 95.0f, 200, 200);

                    this.description.Frame      = new CGRect(this.View.Center.X - 190.0f, this.View.Center.Y, UIScreen.MainScreen.Bounds.Width - 50.0f, 50.0f);
                    this.description_2.Frame    = new CGRect(this.View.Center.X - 95.0f, this.View.Center.Y + 50.0f, UIScreen.MainScreen.Bounds.Width - 210.0f, 50.0f);
                    this.titleDescription.Frame = new CGRect(this.View.Center.X - 70.0f, this.View.Center.Y - 240.0f, UIScreen.MainScreen.Bounds.Width - 50.0f, 300.0f);
                }

                emptyImage.Image = new UIImage("EmptyScreen.png");

                emptyPDF.AddSubview(emptyImage);
                emptyPDF.AddSubview(this.description);
                emptyPDF.AddSubview(this.description_2);
                emptyPDF.AddSubview(this.titleDescription);

                this.TableView.SeparatorColor  = UIColor.GroupTableViewBackgroundColor;
                this.TableView.TintColor       = UIColor.GroupTableViewBackgroundColor;
                this.TableView.TableHeaderView = null;

                this.Add(emptyPDF);
                this.View.BringSubviewToFront(emptyPDF);
            }
            else
            {
                this.TableView.SeparatorColor = UIColor.LightGray;
                this.TableView.TintColor      = UIColor.LightGray;

                //this.TableView.TableHeaderView = this.search;
                emptyPDF = new UIView();

                emptyImage = new UIImageView();

                emptyPDF.RemoveFromSuperview();
                emptyImage.RemoveFromSuperview();
            }
            this.emptyPDF.BackgroundColor = UIColor.GroupTableViewBackgroundColor;

            this.NavigationController.SetToolbarHidden(false, true);
            this.NavigationController.Toolbar.BarTintColor    = UIColor.White;
            this.NavigationController.Toolbar.BackgroundColor = UIColor.White;
            this.NavigationController.Toolbar.TintColor       = UIColor.Blue;

            UIBarButtonItem bin = new UIBarButtonItem(UIBarButtonSystemItem.Trash, (sender, e) =>
            {
                //pushes the password reader controller which allows the user to enter
                var documents_2 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                //var passwordDirectory_2 = Path.Combine(documents, "Passwords");

                var directoryJPG_2 = Directory.GetFiles(documents, "*.jpg");
                var directoryPNG_2 = Directory.GetFiles(documents, "*.png");
                var directoryGIF_2 = Directory.GetFiles(documents, "*.gif");
                var directorySVG_2 = Directory.GetFiles(documents, "*.svg");
                var directoryICO_2 = Directory.GetFiles(documents, "*.ico");


                NSError error_2 = new NSError();
                if (this.pdfList.Count == 0)
                {
                    UIAlertController emptyPasswords = UIAlertController.Create("Nothing to delete", "You have no passwords listed here to delete", UIAlertControllerStyle.Alert);

                    UIAlertAction confirmed = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        emptyPasswords.Dispose();
                    });

                    emptyPasswords.AddAction(confirmed);

                    if (this.PresentedViewController == null)
                    {
                        this.PresentViewController(emptyPasswords, true, () =>
                        {
                            SystemSound soundError = new SystemSound(4095);
                            soundError.PlaySystemSound();
                        });
                    }
                    else
                    {
                        this.PresentedViewController.DismissViewController(true, () =>
                        {
                            this.PresentedViewController.Dispose();
                            this.PresentViewController(emptyPasswords, true, () =>
                            {
                                SystemSound soundError = new SystemSound(4095);
                                soundError.PlaySystemSound();
                            });
                        });
                    }
                }

                //files do exist in the directory
                else
                {
                    if (this.TableView.Editing == false)
                    {
                        UIAlertController emptyPasswords = UIAlertController.Create("Clear your photos?", "Are you sure you want to clear the whole list of your photos?", UIAlertControllerStyle.Alert);

                        UIAlertAction confirmed = UIAlertAction.Create("Yes", UIAlertActionStyle.Destructive, (UIAlertAction obj) =>
                        {
                            //delete list for the table
                            //delete files contained inside the directory
                            this.pdfList.Clear();
                            this.creationDate.Clear();

                            Console.WriteLine("Number of files: " + NSFileManager.DefaultManager.GetDirectoryContent(documents_2, out error_2).Length);

                            //.jpg
                            for (int j = 0; j <= directoryJPG_2.Length - 1; j++)
                            {
                                File.Delete(directoryJPG_2[j]);
                            }

                            /*try
                             * {
                             *      if (String.IsNullOrEmpty(directoryJPG_2[NSFileManager.DefaultManager.GetDirectoryContent(documents_2, out error_2).Length - 1]) == true)
                             *      {
                             *              throw new IndexOutOfRangeException();
                             *      }
                             *      else {
                             *              File.Delete(directoryJPG_2[NSFileManager.DefaultManager.GetDirectoryContent(documents_2, out error_2).Length - 1]);
                             *      }
                             * }
                             * catch (IndexOutOfRangeException)
                             * {
                             *      Console.WriteLine("File does not exist inside this directory");
                             * }*/

                            //.png
                            for (int j = 0; j <= directoryPNG_2.Length - 1; j++)
                            {
                                File.Delete(directoryPNG_2[j]);
                            }

                            //.gif
                            for (int j = 0; j <= directoryGIF_2.Length - 1; j++)
                            {
                                File.Delete(directoryGIF_2[j]);
                            }

                            //.svg
                            for (int j = 0; j <= directorySVG_2.Length - 1; j++)
                            {
                                File.Delete(directorySVG_2[j]);
                            }

                            //.ico
                            for (int j = 0; j <= directoryICO_2.Length - 1; j++)
                            {
                                File.Delete(directoryICO_2[j]);
                            }

                            this.NavigationController.PopViewController(true);
                            emptyPasswords.Dispose();
                        });

                        UIAlertAction denied = UIAlertAction.Create("No", UIAlertActionStyle.Cancel, (UIAlertAction obj) =>
                        {
                            emptyPasswords.Dispose();
                        });

                        emptyPasswords.AddAction(confirmed);
                        emptyPasswords.AddAction(denied);

                        if (this.PresentedViewController == null)
                        {
                            this.PresentViewController(emptyPasswords, true, () =>
                            {
                                SystemSound soundError = new SystemSound(4095);
                                soundError.PlaySystemSound();
                            });
                        }
                        else
                        {
                            this.PresentedViewController.DismissViewController(true, () =>
                            {
                                this.PresentedViewController.Dispose();
                                this.PresentViewController(emptyPasswords, true, () =>
                                {
                                    SystemSound soundError = new SystemSound(4095);
                                    soundError.PlaySystemSound();
                                });
                            });
                        }
                    }
                    //table view is in editing mode
                    else
                    {
                        //bar button item will clear only the values that match the index chosen
                        for (int i = 0; i <= this.selectedCellsToRemove.Count - 1; i++)
                        {
                            this.pdfList.RemoveAt(i);
                            this.creationDate.RemoveAt(i);

                            Console.WriteLine("Contents: " + Directory.GetFiles(documents_2)[i]);
                            File.Delete(Directory.GetFiles(documents_2)[i]);
                            this.NavigationController.PopViewController(true);
                        }
                    }
                }
            });

            this.SetToolbarItems(new UIBarButtonItem[] { bin }, true);

            UIBarButtonItem cancelEditing = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, e) =>
            {
                this.selectedCellsToRemove.Clear();
                this.TableView.SetEditing(false, true);
                this.NavigationItem.SetRightBarButtonItem(this.appDelegate.editPassword, true);
            });

            //nav bar items
            UIBarButtonItem edit = new UIBarButtonItem(UIBarButtonSystemItem.Edit, (object sender, EventArgs e) =>
            {
                //pushes the password reader controller which allows the user to enter
                var documents_2 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                var directoryJPG_3 = Directory.GetFiles(documents_2, "*.jpg");
                var directoryPNG_3 = Directory.GetFiles(documents_2, "*.png");
                var directoryGIF_3 = Directory.GetFiles(documents_2, "*.gif");
                var directorySVG_3 = Directory.GetFiles(documents_2, "*.svg");
                var directoryICO_3 = Directory.GetFiles(documents_2, "*.ico");

                NSError error_2 = new NSError();
                if (this.pdfList.Count == 0)
                {
                    UIAlertController emptyPasswords = UIAlertController.Create("Nothing to delete", "You have no passwords listed here to delete", UIAlertControllerStyle.Alert);

                    UIAlertAction confirmed = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (UIAlertAction obj) =>
                    {
                        emptyPasswords.Dispose();
                    });

                    emptyPasswords.AddAction(confirmed);

                    if (this.PresentedViewController == null)
                    {
                        this.PresentViewController(emptyPasswords, true, () =>
                        {
                            SystemSound soundError = new SystemSound(4095);
                            soundError.PlaySystemSound();
                        });
                    }
                    else
                    {
                        this.PresentedViewController.DismissViewController(true, () =>
                        {
                            this.PresentedViewController.Dispose();
                            this.PresentViewController(emptyPasswords, true, () =>
                            {
                                SystemSound soundError = new SystemSound(4095);
                                soundError.PlaySystemSound();
                            });
                        });
                    }
                }
                else
                {
                    this.TableView.SetEditing(true, true);
                    this.NavigationItem.SetRightBarButtonItem(cancelEditing, true);
                }
            });

            this.appDelegate.editPassword = edit;
            this.NavigationItem.SetRightBarButtonItem(edit, false);

            this.TableView.AllowsSelection = true;
            this.TableView.AllowsSelectionDuringEditing         = true;
            this.TableView.AllowsMultipleSelectionDuringEditing = true;
            this.TableView.AllowsMultipleSelection = true;
        }