Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System; using System.Collections.Generic; using System.Linq; using System.Drawing; using FlyoutNavigation; using MonoTouch.Foundation; using MonoTouch.UIKit; using MonoTouch.Dialog; using System.Threading; namespace DigitalRelativityCBC13Kiosk { public partial class WebViewHtmlViewController : DialogViewController { FlyoutNavigationController navigation; //IEnumerable<ABWEvent> abwEvents; //IEnumerable<SocialItem> abwSocialItems; UIBarButtonItem flyoutButton; UIButton imageButton; UIWebView webView; UIToolbar topBar; UIToolbar toolbar; UIBarButtonItem backButton, forwardButton, stopButton, refreshButton, shareButton; UILabel title; protected UIWebView WebView; private string ViewTitle; private string startUrl; private string html; private bool displayShareButton; UIView theWebView; UIBarButtonItem closebutton; UIBarButtonItem newButton; public WebViewHtmlViewController (FlyoutNavigationController Navigation, string html, string Title, bool DisplayShareButton) : base (UITableViewStyle.Plain, null) { displayShareButton = DisplayShareButton; ViewTitle = Title; this.html = html; theWebView = getWebView(); Root = new RootElement (ViewTitle){ new Section(""){ new UIViewElement("",theWebView,true){Flags = UIViewElement.CellFlags.DisableSelection} } } ; this.TableView.ScrollEnabled = false; } public WebViewHtmlViewController (FlyoutNavigationController Navigation, string html, string Title) : base (UITableViewStyle.Plain, null) { ViewTitle = Title; this.html = html; theWebView = getWebView(); Root = new RootElement (ViewTitle){ new Section(""){ new UIViewElement("",theWebView,true){Flags = UIViewElement.CellFlags.DisableSelection} } } ; this.TableView.ScrollEnabled = false; } public WebViewHtmlViewController (string html, string Title) : base (UITableViewStyle.Plain, null,true) { ViewTitle = Title; this.html = html; navigation = null; displayShareButton = true; theWebView = getWebView(); Root = new RootElement (ViewTitle){ new Section(""){ new UIViewElement("",theWebView,true){Flags = UIViewElement.CellFlags.DisableSelection & UIViewElement.CellFlags.Transparent} } } ; this.TableView.ScrollEnabled = false; } public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) { //return toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown; return toInterfaceOrientation == UIInterfaceOrientation.Portrait; } public override void WillRotate (UIInterfaceOrientation toInterfaceOrientation, double duration) { base.WillRotate (toInterfaceOrientation, duration); } public override void DidRotate (UIInterfaceOrientation fromInterfaceOrientation) { base.DidRotate (fromInterfaceOrientation); theWebView.Frame = Util.CurrentOrientation() == "Portrait"? new RectangleF(0f, 0f, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height - 20f) : new RectangleF(0f, 0f, UIScreen.MainScreen.Bounds.Height, UIScreen.MainScreen.Bounds.Width - 20f); webView.Frame = Util.CurrentOrientation() == "Portrait" ? new RectangleF(0f, 0f, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height - 20f) : new RectangleF(0f, 0f, UIScreen.MainScreen.Bounds.Height, UIScreen.MainScreen.Bounds.Width - 20f); theWebView.SetNeedsDisplay(); theWebView.SetNeedsDisplay(); this.ReloadData(); } public UIView getWebView(){ //UIView view = new UIView(new RectangleF(0f, 0f, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height - 20f)); //var webRect = new RectangleF(0f, 0f,UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height - 60f); Console.WriteLine(UIDevice.CurrentDevice.Orientation.ToString()); UIView view = new UIView( Util.CurrentOrientation() == "Portrait"? new RectangleF(0f, 0f, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height - 20f) : new RectangleF(0f, 0f, UIScreen.MainScreen.Bounds.Height, UIScreen.MainScreen.Bounds.Width - 20f)); var webRect = Util.CurrentOrientation() == "Portrait" ? new RectangleF(0f, 0f, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height - 20f) : new RectangleF(0f, 0f, UIScreen.MainScreen.Bounds.Height, UIScreen.MainScreen.Bounds.Width - 20f); webView = new UIWebView(webRect); webView.BackgroundColor = UIColor.White; webView.LoadHtmlString(html.ToString(),new NSUrl (Util.BaseDir, true)); webView.ScalesPageToFit = true; view.AddSubview(webView); /* toolbar = new UIToolbar(); var fixedSpace = new UIBarButtonItem (UIBarButtonSystemItem.FixedSpace, null) { Width = 26 } ; var flexibleSpace = new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace, null); backButton = new UIBarButtonItem (UIImage.FromBundle ("Images/back.png"), UIBarButtonItemStyle.Plain, (o, e) => { webView.GoBack (); }); forwardButton = new UIBarButtonItem (UIImage.FromBundle ("Images/forward.png"), UIBarButtonItemStyle.Plain, (o, e) => { webView.GoForward (); }); refreshButton = new UIBarButtonItem (UIBarButtonSystemItem.Refresh, (o, e) => { webView.Reload (); }); stopButton = new UIBarButtonItem (UIBarButtonSystemItem.Stop, (o, e) => { webView.StopLoading (); }); //toolbar.Items = new UIBarButtonItem [] { backButton, fixedSpace, forwardButton, flexibleSpace, stopButton, fixedSpace, refreshButton }; //toolbar.Frame = Util.CurrentOrientation() == "Portrait" ? new RectangleF (0, UIScreen.MainScreen.Bounds.Height - 100f, UIScreen.MainScreen.Bounds.Width, 44) : new RectangleF (0, UIScreen.MainScreen.Bounds.Width- 100f,UIScreen.MainScreen.Bounds.Height , 44); toolbar.TintColor = UIColor.Black; view.Add(toolbar); webView.LoadStarted += (sender, e) => { stopButton.Enabled = true; refreshButton.Enabled = false; UpdateNavButtons (); } ; webView.LoadFinished += (sender, e) => { stopButton.Enabled = false; refreshButton.Enabled = true; //Util.PopNetworkActive (); UpdateNavButtons (); } ; webView.LoadStarted += delegate { stopButton.Enabled = true; refreshButton.Enabled = false; UpdateNavButtons (); //Util.PushNetworkActive (); } ; webView.LoadFinished += delegate { stopButton.Enabled = false; refreshButton.Enabled = true; //Util.PopNetworkActive (); UpdateNavButtons (); //title.Text = UpdateTitle (); } ; */ return view; } void UpdateNavButtons () { if (webView == null) return; backButton.Enabled = webView.CanGoBack; forwardButton.Enabled = webView.CanGoForward; } public override void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); //UIImageView iv = new UIImageView(UIImage.FromBundle("Images/Content.png")); //this.TableView.BackgroundView = Util.backgroundImageView; this.TableView.SeparatorColor = UIColor.Clear; /* imageButton = new UIButton(new System.Drawing.RectangleF(0,0,Util.normal.Size.Width,Util.normal.Size.Height)); imageButton.SetImage(Util.normal, UIControlState.Normal); imageButton.SetImage(Util.selected, UIControlState.Selected); imageButton.SetImage(Util.selected,UIControlState.Highlighted); imageButton.AddTarget((sender, e) => {navigation.ToggleMenu ();},UIControlEvent.TouchUpInside); flyoutButton = new UIBarButtonItem(imageButton); */ if(navigation != null){ flyoutButton = new UIBarButtonItem(UIImage.FromBundle("Images/flyoutButton.png"),UIBarButtonItemStyle.Plain,(sender, e) => {Util.navigation.ToggleMenu ();}); this.NavigationItem.SetLeftBarButtonItem(flyoutButton,true); } // //newButton = new UIBarButtonItem(newImageButton); //flyoutButton.SetBackgroundImage(UIImage.FromBundle("Images/flyoutButton.png"),UIControlState.Normal,UIBarMetrics.Default); //flyoutButton.SetBackgroundImage(UIImage.FromBundle("Images/flyoutButtonPressed.png"),UIControlState.Selected, UIBarMetrics.Default); //flyoutButton.SetBackButtonBackgroundImage(UIImage.FromBundle("Images/flyoutButtonPressed.png"),UIControlState.Highlighted, UIBarMetrics.Default); webView.SetNeedsDisplay(); } public override void DidReceiveMemoryWarning () { base.DidReceiveMemoryWarning (); GC.Collect(); } public override void ViewDidAppear (bool animated) { base.ViewDidAppear (animated); //navigation.ToggleMenu(); /* ThreadPool.QueueUserWorkItem((state)=>{ Thread.Sleep(1000); this.InvokeOnMainThread(()=>{WebViewController.OpenUrl(this,"http://www.digitalrelativity.com");}); } ); */ } public class UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate { UIView viewC; public UIDocumentInteractionControllerDelegateClass(UIView controller) { viewC = controller; } public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller) { return null; } public override UIView ViewForPreview (UIDocumentInteractionController controller) { return viewC; } public override RectangleF RectangleForPreview (UIDocumentInteractionController controller) { return viewC.Frame; } } } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement