void Init(Context context) { _richTextEditor = new Abstractions.TEditor(); this.SetWebViewClient(new TEditorWebViewClient(_richTextEditor)); this.SetWebChromeClient(new TEditorChromeWebClient()); _richTextEditor.SetJavaScriptEvaluatingFunction((input) => { this.EvaluateJavascript(input, null); }); _richTextEditor.SetJavaScriptEvaluatingWithResultFunction((input) => { var activity = context as Activity; JavaScriptResult result = new JavaScriptResult(); this.EvaluateJavascript(input, result); if (activity != null) { activity.RunOnUiThread(() => { }); } return(result.GetResultAsync()); }); _colorPickerDialog = new ColorPickerDialog(context, Color.Red); _colorPickerDialog.ColorChanged += (o, args) => { _richTextEditor.SetTextColor((int)args.Color.R, (int)args.Color.G, (int)args.Color.B); }; _richTextEditor.LaunchColorPicker = () => { _colorPickerDialog.Show(); }; this.LoadResource(); }
void AddColorPickerControl() { _colorPickerViewController = new PopColorPickerViewController(); _colorPickerViewController.CancelButton.Clicked += (object sender, EventArgs e) => { if (!IsIpad()) { _colorPickerViewController.NavigationController.PopViewController(true); } else { _popoverController.Dismiss(true); } }; _colorPickerViewController.DoneButton.Clicked += (object sender, EventArgs e) => { if (!IsIpad()) { _colorPickerViewController.NavigationController.PopViewController(true); } else { _popoverController.Dismiss(true); } nfloat r, g, b, a; _colorPickerViewController.SelectedColor.GetRGBA(out r, out g, out b, out a); _richTextEditor.SetTextColor((int)(r * 255), (int)(g * 255), (int)(b * 255)); }; _richTextEditor.LaunchColorPicker = () => { if (!IsIpad()) { this.NavigationController.PushViewController(_colorPickerViewController, true); } else { var navController = new UINavigationController(_colorPickerViewController); _popoverController = new UIPopoverController(navController); _popoverController.PresentFromRect(_toolbarHolder.Frame, View, UIPopoverArrowDirection.Down, true); } }; }
void KeyboardWillShow(NSNotification notification) { if (contentView != null) { InputAssistantItem.LeadingBarButtonGroups = new[] { new UIBarButtonItemGroup(_uiToolbarItems.ToArray(), null) } } ; } void StyleScrollView() { var width = this.View.Frame.Width - 44; if (IsIpad()) { width = this.View.Frame.Width; } _toolbarScroll = new UIScrollView() { Frame = new CGRect(0, 0, width, 44) }; _toolbarScroll.BackgroundColor = UIColor.Clear; _toolbarScroll.ShowsVerticalScrollIndicator = false; } void StyleToolbar() { _toolbar = new UIToolbar(_toolbarScroll.Frame); _toolbar.BackgroundColor = UIColor.Clear; _toolbarScroll.AddSubview(_toolbar); _toolbarScroll.AutoresizingMask = _toolbar.AutoresizingMask; } void AddColorPickerControl() { _colorPickerViewController = new PopColorPickerViewController(); _colorPickerViewController.CancelButton.Clicked += (object sender, EventArgs e) => { if (IsIpad()) { _popoverController.Dismiss(true); } else { _colorPickerViewController.NavigationController.PopViewController(true); } }; _colorPickerViewController.DoneButton.Clicked += (object sender, EventArgs e) => { if (IsIpad()) { _popoverController.Dismiss(true); } else { _colorPickerViewController.NavigationController.PopViewController(true); } nfloat r, g, b, a; _colorPickerViewController.SelectedColor.GetRGBA(out r, out g, out b, out a); _richTextEditor.SetTextColor((int)(r * 255), (int)(g * 255), (int)(b * 255)); }; _richTextEditor.LaunchColorPicker = () => { if (IsIpad()) { var navController = new UINavigationController(_colorPickerViewController); _popoverController = new UIPopoverController(navController); _popoverController.PresentFromRect(_toolbarHolder.Frame, View, UIPopoverArrowDirection.Down, true); } else { this.NavigationController.PushViewController(_colorPickerViewController, true); } }; } void LayoutToolBarHolder() { float toolbarHeight = _uiToolbarItems.Count > 0 ? 44f : 0f; UIToolbar backgroundToolbar = new UIToolbar() { Frame = new CGRect(0, 0, this.View.Frame.Width, toolbarHeight) }; backgroundToolbar.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; _toolbarHolder = new UIView(new CGRect(0, this.View.Frame.Height, this.View.Frame.Width, toolbarHeight)); _toolbarHolder.AutoresizingMask = _toolbar.AutoresizingMask; _toolbarHolder.AddSubview(_toolbarScroll); _toolbarHolder.InsertSubview(backgroundToolbar, 0); // Hide Keyboard if (!IsIpad()) { // Toolbar holder used to crop and position toolbar UIView toolbarCropper = new UIView(new CGRect(this.View.Frame.Width - toolbarHeight, 0, 44, toolbarHeight)); toolbarCropper.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin; toolbarCropper.ClipsToBounds = true; // Use a toolbar so that we can tint UIToolbar keyboardToolbar = new UIToolbar(new CGRect(-7, -1, 44, toolbarHeight)); toolbarCropper.AddSubview(keyboardToolbar); _keyboardItem = new UIBarButtonItem(UIImage.FromFile("ZSSkeyboard.png"), UIBarButtonItemStyle.Plain, delegate(object sender, EventArgs e) { this.View.EndEditing(true); }); keyboardToolbar.Items = new[] { _keyboardItem }; _toolbarHolder.AddSubview(toolbarCropper); UIView line = new UIView(new CGRect(0, 0, 0.6, 44)); line.BackgroundColor = UIColor.LightGray; line.Alpha = (nfloat)0.7; toolbarCropper.AddSubview(line); } float toolbarWidth = _uiToolbarItems.Count == 0 ? 0.0f : ((_uiToolbarItems.Count * 39) + 50); _toolbar.Items = _uiToolbarItems.ToArray(); _toolbar.Frame = new CGRect(0, 0, toolbarWidth, toolbarHeight); _toolbarScroll.ContentSize = new CGSize(_toolbar.Frame.Width, _toolbar.Frame.Height); if (!IsIpad()) { this.View.AddSubview(_toolbarHolder); } } bool IsIpad() { return(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad); }