public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;
            float width = View.Frame.Width;

            float height = View.Frame.Height;

            if (orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight)
            {
                width  = View.Frame.Height;
                height = View.Frame.Width;
            }

            recognizedTextLabel      = new UILabel(new RectangleF(button_gap, 30, width, 20));
            recognizedTextLabel.Text = "Recognized Text:";
            View.Add(recognizedTextLabel);
            recognizedText                 = new UITextView(new RectangleF(button_gap, header_height, width - button_gap * 2, height / 4));
            recognizedText.Editable        = false;
            recognizedText.Font            = UIFont.FromName("Courier", 18);
            recognizedText.Text            = "";
            recognizedText.BackgroundColor = UIColor.Gray;
            recognizedText.TextColor       = UIColor.White;
            View.Add(recognizedText);
            inkView             = new InkView();
            inkView.Frame       = new RectangleF(button_gap, header_height + height / 4 + button_gap, width - button_gap * 2, height - bottom_gap - (height / 4) - header_height - button_gap);
            inkView.ContentMode = UIViewContentMode.Redraw;
            View.Add(inkView);

            inkView.OnReturnGesture += () => recognizedText.Text = inkView.Recognize(true);
            inkView.OnReturnGesture += () => inkView.cleanView(true);
            inkView.OnCutGesture    += () => inkView.cleanView(true);

            float x = (width - (button_width * 4 + button_gap * 3)) / 2;

            recognizeAllButton       = new UIButton(UIButtonType.Custom);
            recognizeAllButton.Frame = new RectangleF(x, height - bottom_gap, button_width, button_height);
            recognizeAllButton.SetTitle("Recognize", UIControlState.Normal);
            recognizeAllButton.Font = UIFont.SystemFontOfSize(button_font_size);
            recognizeAllButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            recognizeAllButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            recognizeAllButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                recognizedText.Text = inkView.Recognize(false);
            };
            View.Add(recognizeAllButton);
            x                += (button_gap + button_width);
            clearButton       = new UIButton(UIButtonType.Custom);
            clearButton.Frame = new RectangleF(x, height - bottom_gap, button_width, button_height);
            clearButton.SetTitle("Clear", UIControlState.Normal);
            clearButton.Font = UIFont.SystemFontOfSize(button_font_size);
            clearButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            clearButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            clearButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                inkView.cleanView(true);
            };
            View.Add(clearButton);

            x += (button_gap + button_width);
            languageButton       = new UIButton(UIButtonType.Custom);
            languageButton.Frame = new RectangleF(x, height - bottom_gap, button_width, button_height);
            languageButton.SetTitle("Language", UIControlState.Normal);
            languageButton.Font = UIFont.SystemFontOfSize(button_font_size);
            languageButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            languageButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            languageButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                var actionSheet = new UIActionSheet("Select Language:", null, "Cancel", null,
                                                    new [] { "English", "English UK", "German", "French", "Spanish", "Portuguese", "Brazilian", "Dutch", "Italian", "Finnish", "Swedish", "Norwegian", "Danish", "Indonesian" });
                actionSheet.Clicked += delegate(object a, UIButtonEventArgs b) {
                    switch (b.ButtonIndex)
                    {
                    case 0:
                        WritePadAPI.language = WritePadAPI.LanguageType.en;
                        break;

                    case 1:
                        WritePadAPI.language = WritePadAPI.LanguageType.en_uk;
                        break;

                    case 2:
                        WritePadAPI.language = WritePadAPI.LanguageType.de;
                        break;

                    case 3:
                        WritePadAPI.language = WritePadAPI.LanguageType.fr;
                        break;

                    case 4:
                        WritePadAPI.language = WritePadAPI.LanguageType.es;
                        break;

                    case 5:
                        WritePadAPI.language = WritePadAPI.LanguageType.pt_PT;
                        break;

                    case 6:
                        WritePadAPI.language = WritePadAPI.LanguageType.pt_BR;
                        break;

                    case 7:
                        WritePadAPI.language = WritePadAPI.LanguageType.nl;
                        break;

                    case 8:
                        WritePadAPI.language = WritePadAPI.LanguageType.it;
                        break;

                    case 9:
                        WritePadAPI.language = WritePadAPI.LanguageType.fi;
                        break;

                    case 10:
                        WritePadAPI.language = WritePadAPI.LanguageType.sv;
                        break;

                    case 11:
                        WritePadAPI.language = WritePadAPI.LanguageType.nb;
                        break;

                    case 12:
                        WritePadAPI.language = WritePadAPI.LanguageType.da;
                        break;

                    case 13:
                        WritePadAPI.language = WritePadAPI.LanguageType.id;
                        break;
                    }
                    WritePadAPI.recoFree();
                    WritePadAPI.recoInit();
                    WritePadAPI.initializeFlags();
                    inkView.cleanView(true);
                    recognizedTextLabel.Text = "Language: " + " (" + WritePadAPI.getLanguageName() + ")";
                };
                actionSheet.ShowInView(View);
            };
            View.Add(languageButton);

            x                  += (button_gap + button_width);
            optionsButton       = new UIButton(UIButtonType.Custom);
            optionsButton.Frame = new RectangleF(x, height - bottom_gap, button_width, button_height);
            optionsButton.SetTitle("Options", UIControlState.Normal);
            optionsButton.Font = UIFont.SystemFontOfSize(button_font_size);
            optionsButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            optionsButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            optionsButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                OptionsViewControllerController optionsController = new OptionsViewControllerController();
                UINavigationController          navController     = new UINavigationController(optionsController);
                navController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
                PresentViewController(navController, true, null);
            };
            View.Add(optionsButton);

            recognizedTextLabel.Text = "Language: " + " (" + WritePadAPI.getLanguageName() + ")";
        }
Exemple #2
0
 public override void WillTerminate(UIApplication app)
 {
     WritePadAPI.recoFree();
 }
Exemple #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;
            float width = (float)View.Frame.Width;

            float height = (float)View.Frame.Height;

            if (orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight)
            {
                width  = (float)View.Frame.Height;
                height = (float)View.Frame.Width;
            }

            WritePadAPI.setRecoFlag(WritePadAPI.recoGetFlags(), true, WritePadAPI.FLAG_USERDICT);
            WritePadAPI.setRecoFlag(WritePadAPI.recoGetFlags(), true, WritePadAPI.FLAG_ANALYZER);
            WritePadAPI.setRecoFlag(WritePadAPI.recoGetFlags(), true, WritePadAPI.FLAG_CORRECTOR);

            inkView                  = new InkView();
            inkView.Frame            = new CGRect(button_gap, header_height + button_gap, width - button_gap * 2, height);
            inkView.ContentMode      = UIViewContentMode.Redraw;
            inkView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            View.Add(inkView);

            formattedText           = new UITextView();
            formattedText.Frame     = new CGRect(0, UIScreen.MainScreen.Bounds.Height * 0.02, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
            formattedText.TextColor = UIColor.Black;
            formattedText.Font      = UIFont.FromName("Baskerville", 28f);
            formattedText.Hidden    = true;
            View.Add(formattedText);

            inkView.OnReturnGesture += () => recognized_text = inkView.Recognize(true);
            inkView.OnReturnGesture += () => inkView.cleanView(true);
            inkView.OnCutGesture    += () => inkView.cleanView(true);
            inkView.OnUndoGesture   += () => inkView.cleanView(true);

            float x = (width - (button_width * 5 + button_gap * 5)) / 2;

            switchViewButton       = new UIButton(UIButtonType.Custom);
            switchViewButton.Frame = new CGRect(x, height - bottom_gap, button_width, button_height);
            switchViewButton.SetTitle("Switch View", UIControlState.Normal);
            switchViewButton.Font = UIFont.SystemFontOfSize(button_font_size);
            switchViewButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            switchViewButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            switchViewButton.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
            switchViewButton.TouchUpInside   += (object sender, EventArgs e) => {
                if (inkView.getNumPaths() > 0)
                {
                    recognized_text = inkView.Recognize(false);
                }
                if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                {
                    formattedText.Text   = recognized_text;
                    formattedText.Text   = FormatLatex(recognized_text);
                    formattedText.Hidden = false;
                    inkView.Hidden       = true;
                    displayingFormatted  = true;
                    printButton.SetTitle("Print", UIControlState.Normal);
                }
                else if (displayingFormatted)
                {
                    formattedText.Hidden = true;
                    inkView.Hidden       = false;
                    displayingFormatted  = false;
                    printButton.SetTitle("Save", UIControlState.Normal);
                }
            };
            View.Add(switchViewButton);
            x                += (button_gap + button_width);
            clearButton       = new UIButton(UIButtonType.Custom);
            clearButton.Frame = new CGRect(x, height - bottom_gap, button_width, button_height);
            clearButton.SetTitle("Clear", UIControlState.Normal);
            clearButton.Font = UIFont.SystemFontOfSize(button_font_size);
            clearButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            clearButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            clearButton.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
            clearButton.TouchUpInside   += (object sender, EventArgs e) => {
                inkView.cleanView(true);
            };
            View.Add(clearButton);

            x += (button_gap + button_width);
            languageButton       = new UIButton(UIButtonType.Custom);
            languageButton.Frame = new CGRect(x, height - bottom_gap, button_width, button_height);
            languageButton.SetTitle("Language", UIControlState.Normal);
            languageButton.Font = UIFont.SystemFontOfSize(button_font_size);
            languageButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            languageButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            languageButton.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
            languageButton.TouchUpInside   += (object sender, EventArgs e) => {
                var actionSheet = new UIActionSheet("Select Language:", (IUIActionSheetDelegate)null, "Cancel", null,
                                                    new [] { "English", "English UK", "German", "French", "Spanish", "Portuguese", "Brazilian", "Dutch", "Italian", "Finnish", "Swedish", "Norwegian", "Danish", "Indonesian" });
                actionSheet.Clicked += delegate(object a, UIButtonEventArgs b) {
                    switch (b.ButtonIndex)
                    {
                    case 0:
                        WritePadAPI.language = WritePadAPI.LanguageType.en;
                        from_language        = "en";
                        break;

                    case 1:
                        WritePadAPI.language = WritePadAPI.LanguageType.en_uk;
                        from_language        = "en";
                        break;

                    case 2:
                        WritePadAPI.language = WritePadAPI.LanguageType.de;
                        from_language        = "de";
                        break;

                    case 3:
                        WritePadAPI.language = WritePadAPI.LanguageType.fr;
                        from_language        = "fr";
                        break;

                    case 4:
                        WritePadAPI.language = WritePadAPI.LanguageType.es;
                        from_language        = "es";
                        break;

                    case 5:
                        WritePadAPI.language = WritePadAPI.LanguageType.pt_PT;
                        from_language        = "pt";
                        break;

                    case 6:
                        WritePadAPI.language = WritePadAPI.LanguageType.pt_BR;
                        from_language        = "pt";
                        break;

                    case 7:
                        WritePadAPI.language = WritePadAPI.LanguageType.nl;
                        from_language        = "nl";
                        break;

                    case 8:
                        WritePadAPI.language = WritePadAPI.LanguageType.it;
                        from_language        = "it";
                        break;

                    case 9:
                        WritePadAPI.language = WritePadAPI.LanguageType.fi;
                        from_language        = "fi";
                        break;

                    case 10:
                        WritePadAPI.language = WritePadAPI.LanguageType.sv;
                        from_language        = "sv";
                        break;

                    case 11:
                        WritePadAPI.language = WritePadAPI.LanguageType.nb;
                        from_language        = "nb";
                        break;

                    case 12:
                        WritePadAPI.language = WritePadAPI.LanguageType.da;
                        from_language        = "da";
                        break;

                    case 13:
                        WritePadAPI.language = WritePadAPI.LanguageType.id;
                        from_language        = "id";
                        break;
                    }
                    WritePadAPI.recoFree();
                    WritePadAPI.recoInit();
                    WritePadAPI.initializeFlags();
                };
                actionSheet.ShowInView(View);
            };
            View.Add(languageButton);

            x += (button_gap + button_width);
            translateButton       = new UIButton(UIButtonType.Custom);
            translateButton.Frame = new CGRect(x, height - bottom_gap, button_width, button_height);
            translateButton.SetTitle("Translate", UIControlState.Normal);
            translateButton.Font = UIFont.SystemFontOfSize(button_font_size);
            translateButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            translateButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            translateButton.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
            translateButton.TouchUpInside   += (object sender, EventArgs e) => {
                var translateActionSheet = new UIActionSheet("Select Language:", (IUIActionSheetDelegate)null, "Cancel", null,
                                                             new [] { "English", "English UK", "German", "French", "Spanish", "Portuguese", "Brazilian", "Dutch", "Italian", "Finnish", "Swedish", "Norwegian", "Danish", "Indonesian" });
                translateActionSheet.Clicked += delegate(object a, UIButtonEventArgs b) {
                    switch (b.ButtonIndex)
                    {
                    case 0:
                        to_language     = "en";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 1:
                        to_language     = "en";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 2:
                        to_language     = "de";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 3:
                        to_language     = "fr";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 4:
                        to_language     = "es";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 5:
                        to_language     = "pt";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 6:
                        to_language     = "pt";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 7:
                        to_language     = "nl";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 8:
                        to_language     = "it";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 9:
                        to_language     = "fi";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 10:
                        to_language     = "sv";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 11:
                        to_language     = "nb";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 12:
                        to_language     = "da";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;

                    case 13:
                        to_language     = "id";
                        recognized_text = inkView.Recognize(false);
                        if (!displayingFormatted && recognized_text != "" && recognized_text != "*Error*")
                        {
                            Translate(FormatLatex(recognized_text));
                        }
                        break;
                    }
                    WritePadAPI.recoFree();
                    WritePadAPI.recoInit();
                    WritePadAPI.initializeFlags();
                };
                translateActionSheet.ShowInView(View);
            };
            View.Add(translateButton);

            x                += (button_gap + button_width);
            printButton       = new UIButton(UIButtonType.Custom);
            printButton.Frame = new CGRect(x, height - bottom_gap, button_width, button_height);
            printButton.SetTitle("Save", UIControlState.Normal);
            printButton.Font = UIFont.SystemFontOfSize(button_font_size);
            printButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            printButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            printButton.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
            printButton.TouchUpInside   += (object sender, EventArgs e) => {
                if (displayingFormatted && formattedText.Text != "")
                {
                    var printInfo = UIPrintInfo.PrintInfo;

                    printInfo.OutputType = UIPrintInfoOutputType.General;
                    printInfo.JobName    = "Printing Tidied-Up Text";

                    UIPrintInteractionController printer = UIPrintInteractionController.SharedPrintController;

                    printer.PrintInfo      = printInfo;
                    printer.PrintingItem   = new NSString(formattedText.Text);
                    printer.ShowsPageRange = true;

                    printer.Present(true, PrintingCompleted);
                }
                else if (!displayingFormatted)
                {
                    switchViewButton.Hidden = true;
                    clearButton.Hidden      = true;
                    languageButton.Hidden   = true;
                    translateButton.Hidden  = true;
                    printButton.Hidden      = true;
                    UIImage data = UIScreen.MainScreen.Capture();
                    data.SaveToPhotosAlbum(null);
                    switchViewButton.Hidden = false;
                    clearButton.Hidden      = false;
                    languageButton.Hidden   = false;
                    translateButton.Hidden  = false;
                    printButton.Hidden      = false;
                }
            };
            View.Add(printButton);

            /*x += (button_gap + button_width);
             * rewriteButton = new UIButton (UIButtonType.Custom);
             * rewriteButton.Frame = new CGRect (x, height - bottom_gap, button_width, button_height);
             * rewriteButton.SetTitle ("Rewrite", UIControlState.Normal);
             * rewriteButton.Font = UIFont.SystemFontOfSize (button_font_size);
             * rewriteButton.SetTitleColor (UIColor.Blue, UIControlState.Normal);
             * rewriteButton.SetTitleColor (UIColor.White, UIControlState.Highlighted);
             * rewriteButton.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
             * rewriteButton.TouchUpInside += (object sender, EventArgs e) => {
             *      inkView.cleanView (true);
             *      if (translated_text != "")
             *      {
             *              formattedText.Hidden = true;
             *              inkView.Hidden = false;
             *              displayingFormatted = false;
             *              inkView.writeText (translated_text, (int)(width - button_gap * 2), (int)height);
             *      }
             * };
             * View.Add (rewriteButton);*/
        }