Base class for all elements in MonoTouch.Dialog
Inheritance: IDisposable
		public void ShowPopup(Element element){
			InvokeOnMainThread(()=>{
				using (var popup = new UIAlertView("Hello", "This is a popup created from the action.", null, "OK")){
					popup.Show();
				}
			});
		}
        void OnElementDeleted(Element element, NSIndexPath path)
        {
            var handler = ElementDeleted;

            if (handler != null)
                handler (this, new ElementEventArgs (element, path));
        }
		public override void Execute (FormDialogViewController controller, Element element,  Action completed)
		{
			try {
				controller.GetType().InvokeMember(this.ActionName,
				    BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,
				    null, controller, Parameter == null ? new object[]{element} : new object[]{Parameter});
				
			} catch (Exception e){
				Console.WriteLine("Could not invoke action '{0}' on dialog '{1}'. {2}", ActionName, controller.GetType().Name, e.ToString());
			}
		}
        private void Delete(Element element)
        {
            var accountElement = element as AccountElement;
            if (accountElement == null)
                return;

            //Remove the designated username
            var account = accountElement.Account;
            Application.Accounts.Remove(account);

            if (Application.Account != null && Application.Account.Equals(account))
            {
                NavigationItem.LeftBarButtonItem.Enabled = false;
                Application.Account = null;
            }
        }
		public override void Execute (FormDialogViewController controller, Element element, Action completed)
		{
			Console.WriteLine("ShowValuesInConsole");
			ThreadPool.QueueUserWorkItem( delegate { 
				
				System.Threading.Thread.Sleep(2000);
				var values = controller.GetAllValues();
				foreach (var v in values){
					Console.WriteLine("Value => {0} - {1}", v.Key, v.Value);	
				}
				
				element.Caption = "Action completed!";
				completed();
			} );
			
		}	
示例#6
0
		public override void Execute (Element element, Action completed)
		{
			try {
				if (element==null)
					Controller.GetType().InvokeMember(this.ActionName,
					    BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,
					    null, Controller, null);
				
				else
					Controller.GetType().InvokeMember(this.ActionName,
					    BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,
					    null, Controller, new object[]{element});
				
			} catch (Exception e){
				Console.WriteLine("Could not invoke action '{0}' on dialog '{1}'. {2}", ActionName, Controller.GetType().Name, e.ToString());
			}
		}
示例#7
0
        private void Delete(Element element, Section section)
        {
            var e = element as Gistacular.Elements.NameTimeStringElement;
            if (e == null || e.Tag == null)
                return;

            var gist = e.Tag as GistModel;
            if (gist == null)
                return;

            this.DoWork(() => {
                Application.Client.API.DeleteGist(gist.Id);

                InvokeOnMainThread(() => {
                    section.Remove(element);
                });
            });
        }
		public override void Execute (FormDialogViewController controller, Element element, Action completed)
		{
			controller.SetValue("temperature", "");
			controller.SetValue("humidity", "");
			controller.SetValue("windspeed", "");
			
			var request = new NSMutableUrlRequest(new NSUrl("http://ws.geonames.org/weatherIcaoJSON?ICAO=KORD"), NSUrlRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, 10);
			
			new UrlConnection("weather", request, (result)=>{
				var json = JsonObject.Parse(result);
				var weather = json["weatherObservation"];
				
				controller.SetValue("temperature", weather["temperature"].CleanString()+ " celsius");
				controller.SetValue("humidity", weather["humidity"].CleanString() + "%");
				controller.SetValue("windspeed", weather["windSpeed"].CleanString()+" km/h");
				
				controller.Reload();
				completed();
				
			}, (error)=>{
				controller.NetworkFailed(error);
				completed();
			});
		}
示例#9
0
		void AddMapping (string id, Element element)
		{
			if (jsonParent != null){
				jsonParent.AddMapping (id, element);
				return;
			}
			if (map == null)
				map = new Dictionary<string, Element> ();
			map.Add (id, element);
		}
示例#10
0
 private void Delete(Element element)
 {
     _model.Files.Remove(element.Caption);
 }
示例#11
0
        void DownloadTweets(int insertPoint, long? since, long? max_id, Element removeOnInsert)
        {
            Account.ReloadTimeline (kind, since, max_id, count => {
                CancelMenu ();
                mainSection.Remove (removeOnInsert);
                if (count == -1){
                    var msg = Locale.Format ("Net failure on {0}", DateTime.Now);
                    Element insertElement;

                    if (mainSection.Count > 0 && (insertElement = mainSection [insertPoint] as StyledStringElement) != null)
                        insertElement.Caption = msg;
                    else
                        mainSection.Insert (insertPoint, new StyledStringElement (msg){
                            Font = UIFont.SystemFontOfSize (14)
                        });
                    count = 1;
                } else {
                    // If we find an overlapping value, the timeline is continous, otherwise, we offer to load more

                    // If insertPoint == 0, this is a top load, otherwise it is a "Load more tweets" load, so we
                    // need to fetch insertPoint-1 to get the actual last tweet, instead of the message.
                    long lastId = GetTableTweetId (insertPoint == 0 ? 0 : insertPoint-1) ?? 0;

                    continuous = false;
                    int nParsed;

                    Util.ReportTime ("Before Loading tweet from DB");
                    lock (Database.Main)
                        nParsed = mainSection.Insert (insertPoint, UITableViewRowAnimation.None, UnlockedFetchTweets (count, lastId, insertPoint));
                    Util.ReportTime ("Time spent loading tweets");

                    NSTimer.CreateScheduledTimer (TimeSpan.FromSeconds (0.3), delegate {
                        NavigationController.TabBarItem.BadgeValue = (nParsed > 0) ? nParsed.ToString () : null;
                    });

                    if (!continuous && nParsed > 0){
                        LoadMoreElement more = null;

                        more = new LoadMoreElement (Locale.GetText ("Load more tweets"), Locale.GetText ("Loading"), delegate {
                            more.Animating = true;
                            DownloadTweets (insertPoint + nParsed, null, GetTableTweetId (insertPoint + count-1)-1, more);
                        });
                        more.Height = 60;

                        try {
                            mainSection.Insert (insertPoint+nParsed, UITableViewRowAnimation.None, more);
                        } catch {
                            Console.WriteLine ("on {0} inserting at {1}+{2} section has {3}", kind, insertPoint, count, mainSection.Count);
                        }
                    }
                    count = nParsed;
                }
                ReloadComplete ();

                // Only scroll to last unread if this was not an intermediate "Load more tweets"
                if (insertPoint == 0 && count > 0)
                    TableView.ScrollToRow (NSIndexPath.FromRowSection (count-1, 0), UITableViewScrollPosition.Middle, false);
            });
        }
		public override bool FetchElementValue(Element element, out object Value)
		{
			if (element.GetType() == typeof(CustomElement)) {
				Value = ((CustomElement)element).Value;
				return true;
			}

			return base.FetchElementValue(element, out Value);
		}
示例#13
0
		/// <summary>
		/// Fetch the value of an element that was returned by <see cref="CreateElement"/>.
		/// </summary>
		/// <returns>
		/// The value that is held by given element. 
		/// </returns>
		/// <param name='element'>
		/// Element to fetch the value for. This element was previously created with <see cref="CreateElement"/>.
		/// </param>
		/// <param name='resultType'>
		/// Type of the object to return. Even tough the return type of this method is <see cref="object"/>, 
		/// it is the responsibility of this method to make sure the return value can be
		/// directly cast to the specified resultType (i.e., it should not need extra conversion through,
		/// for example, the <see cref="Convert"/> class).
		/// </param>
		public abstract object GetValue(Element element, Type resultType);
示例#14
0
        private RootElement InitializeAccountSettings()
        {
            user = App.ViewModel.User;
            ThemedRootElement accountRootElement = null;

            // initialize the Account element based on whether connected or disconnected
            if (IsConnected)
            {
                // initialize account controls
                Email = new StringElement("Email", user.Email);
                // create unicode bullet characters for every character in the password
                var sb = new StringBuilder();
                if (user != null && user.Password != null)
                    foreach (var c in user.Password)
                        sb.Append("\u25CF"); // \u2022
                Password = new StringElement("Password", sb.ToString());

                // create buttons
                var button = new ButtonListElement()
                {
                    new Button() { Caption = "Disconnect",  Background = "Images/darkgreybutton.png", Clicked = DisconnectUserButton_Click },
                };
                button.Margin = 0f;

                // create the account root element
                accountRootElement = new ThemedRootElement("Account")
                {
                    new Section()
                    {
                        Email,
                        Password,
                    },
                    new Section()
                    {
                        button
                    }
                };
            }
            else
            {
                // initialize account controls
                Email = new EntryElement("Email", "Enter email", user != null ? user.Email : null);
                Password = new EntryElement("Password", "Enter password", user != null ? user.Password : null, true);

                var createButton = new ButtonListElement()
                {
                    new Button() { Caption = "Create a new account",  Background = "Images/darkgreybutton.png", Clicked = CreateUserButton_Click },
                };
                createButton.Margin = 0f;
                var connectButton = new ButtonListElement()
                {
                    new Button() { Caption = "Connect to an existing account", Background = "Images/darkgreybutton.png", Clicked = ConnectUserButton_Click },
                };
                connectButton.Margin = 0f;

                // create the account root element
                accountRootElement = new ThemedRootElement("Account")
                {
                    new Section()
                    {
                        Email,
                        Password,
                    },
                    new Section()
                    {
                        createButton,
                    },
                    new Section()
                    {
                        connectButton
                    }
                };
            }

            return accountRootElement;
        }
示例#15
0
        /// <summary>
        /// Adds a new child Element to the Section
        /// </summary>
        /// <param name="element">
        /// An element to add to the section.
        /// </param>
        public void Add(Element element)
        {
            if (element == null)
                return;

            Elements.Add (element);
            element.Parent = this;

            if (Parent != null)
                InsertVisual (Elements.Count-1, UITableViewRowAnimation.None, 1);
        }
        void DBChooserComplete(DBChooserResult[] results)
        {
            if (results != null && results.Length > 0) {
                var result = results [0];

                var metadata = root [1];
                metadata.Clear ();

                var values = new Element[] {
                    new StringElement("Name",result.Name),
                    new StringElement("Size in bytes: ",result.Size.ToString()),
                    new ImageStringElement("Icon", UIImage.LoadFromData(NSData.FromUrl(result.IconURL)))
                };

                foreach (var item in values) {
                    metadata.Add (item);
                }

                var linkSection = root [2];
                linkSection.Clear ();

                linkSection.Add (
                    new StringElement (result.Link.ToString (), delegate {
                    OpenLink (result.Link);
                }));

                foreach (var thumb in result.Thumbnails) {
                    string key = thumb.Key.ToString ();
                    string value = thumb.Value.ToString ();
                    linkSection.Add (new StringElement (key, delegate {
                        OpenLink (NSUrl.FromString (value));
                    }));
                }

            } else {
                UIAlertView error = new UIAlertView ("Error", "No values", null, "OK", null);
                error.Show ();
            }
        }
		public void Reload(Element el){
			PrepareRoot(new RootElement(Title));
			ReloadData();
			_processFile(Url, null);
		}
		public void DismissModal(Element el){
			this.DismissModalViewControllerAnimated(true);	
		}
		private void _invokeAction(string action, Element element){
			this.GetType().InvokeMember(action,
				    BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public,
				    null, this, new object[]{element});
		}
		public void InvokeAction(string action, Element element){
			_invokeAction(action, element);
		}
示例#21
0
 public void Reload(Element element, UITableViewRowAnimation animation)
 {
     if (element == null)
         throw new ArgumentNullException ("element");
     var section = element.Parent as Section;
     if (section == null)
         throw new ArgumentException ("Element is not attached to this root");
     var root = section.Parent as RootElement;
     if (root == null)
         throw new ArgumentException ("Element is not attached to this root");
     var path = element.IndexPath;
     if (path == null)
         return;
     TableView.ReloadRows (new NSIndexPath [] { path }, animation);
 }
		public override object GetValue (Element element, Type resultType)
		{
			return Convert.ChangeType(((BooleanImageElement) element).Value, resultType);
		}		
示例#23
0
 public void Remove(Element e)
 {
     if (e == null)
         return;
     for (int i = Elements.Count; i > 0;){
         i--;
         if (Elements [i] == e){
             RemoveRange (i, 1);
             return;
         }
     }
 }
		public void Execute(ControllerAction action, Element el, Action completed){
			action.Execute(this, (ActivityElement)el, completed);	
		}
示例#25
0
 public override void ViewDidUnload()
 {
     TraceHelper.AddMessage("Settings: ViewDidLoad");
     if (dvc != null)
         this.ViewControllers = new UIViewController[0];
     Email = null;
     Password = null;
     dvc = null;
     base.ViewDidUnload();
 }
示例#26
0
        private void Delete(Element element)
        {
            var accountElement = element as AccountElement;
            if (accountElement == null)
                return;

            //Remove the designated username
            AccountDeleted(accountElement.Account);
        }
示例#27
0
		internal virtual void OnSwipe (NSIndexPath path, UITableViewCell cell)
		{
			MenuHostElement = TweetElementFromPath (path);
			if (MenuHostElement != null){
				var frame = cell.ContentView.Frame;				
				TableView.ScrollEnabled = false;
				
				if (swipeMenuImages == null){
					swipeMenuImages = new UIImage [] {
						UIImage.FromBundle ("Images/swipe-reply.png"),
						UIImage.FromBundle ("Images/swipe-retweet.png"),
						UIImage.FromBundle ("Images/swipe-profile.png"),
						UIImage.FromBundle ("Images/swipe-star-off.png"),
						UIImage.FromBundle ("Images/swipe-star-on.png"),
						UIImage.FromBundle ("Images/swipe-clip.png"),
						UIImage.FromBundle ("Images/swipe-clipdark.png"),
					};

					onImages = new UIImage [] {
						swipeMenuImages [0], swipeMenuImages [1], swipeMenuImages [2], swipeMenuImages [4], swipeMenuImages [5]
					};
					offImages = new UIImage [] {
						swipeMenuImages [0], swipeMenuImages [1], swipeMenuImages [2], swipeMenuImages [3], swipeMenuImages [5]
					};
				}
				var imageSet = true ? onImages : offImages;
				
				var menu = new SwipeMenuView (this, imageSet, frame);
				menu.Selected += idx => {
					switch (idx){
					case 0:
						//AppDelegate.MainAppDelegate.Reply (this, MenuHostElement.Tweet);
						break;
						
					case 1:
						//AppDelegate.MainAppDelegate.Retweet (this, MenuHostElement.Tweet);
						break;
						
					case 2:
						//ActivateController (new FullProfileView (MenuHostElement.Tweet.UserId));
						break;
						
					case 3:
						//AppDelegate.MainAppDelegate.ToggleFavorite (MenuHostElement.Tweet);
						break;
						
					case 4:
						// Instapaper
						//var bookmarkTweet = MenuHostElement.Tweet;		
						break;
					}
				};
				ShowMenu (menu, cell);
			}
		}
示例#28
0
	    public abstract void Execute(Element el, Action completed);
		public void Reload(Element el){
			Reload();
		}
示例#30
0
		bool HideMenu ()
		{
			if (menuCell == null)
				return false;
			
			float offset = menuCell.ContentView.Frame.Width;
			

			UIView.BeginAnimations ("Foo");
			UIView.SetAnimationDuration (hideDelay);
			UIView.SetAnimationCurve (UIViewAnimationCurve.EaseInOut);			

			var animation = MakeBounceAnimation (Math.Abs (offset), "position.x");
			
			foreach (var view in menuCell.ContentView.Subviews){
				if (view == currentMenuView)
					continue;

				view.SetNeedsDisplay ();
				AnimateBack (view, animation);
			}
			AnimateBack (menuCell.SelectedBackgroundView, animation);

			UIView.CommitAnimations ();
			
			// Pass the currentMenuView as the view to remove, as it is a global that can be overwritten by
			// another menu showing up.
			var copy = currentMenuView;
			NSTimer.CreateScheduledTimer (hideDelay + 0.1, delegate {
				copy.RemoveFromSuperview ();
				copy.Dispose ();
			});
	
			menuCell = null;
			MenuHostElement = null;
			currentMenuView = null;
			return true;
		}