Exemple #1
0
        // Need HUD display here
        void ShrinkUrls(string [] words)
        {
            var hud = new LoadingHUDView(Locale.GetText("Shrinking"));

            this.AddSubview(hud);
            hud.StartAnimating();

            var wc = new WebClient();

            for (int i = 0; i < words.Length; i++)
            {
                if (!words [i].StartsWith("http://"))
                {
                    continue;
                }

                try {
                    words [i] = wc.DownloadString(new Uri("http://is.gd/api.php?longurl=" + HttpUtility.UrlEncode(words [i])));
                } catch {
                }
            }
            hud.StopAnimating();
            hud.RemoveFromSuperview();
            hud = null;
        }
Exemple #2
0
        void PictureSelected(NSDictionary pictureDict)
        {
            int level = Util.Defaults.IntForKey("sizeCompression");

            if ((pictureDict [UIImagePickerController.MediaType] as NSString) == "public.image")
            {
                Picture = pictureDict [UIImagePickerController.EditedImage] as UIImage;
                if (Picture == null)
                {
                    Picture = pictureDict [UIImagePickerController.OriginalImage] as UIImage;
                }

                // Save a copy of the original picture
                if (!FromLibrary)
                {
                    Picture.SaveToPhotosAlbum(delegate {
                        // ignore errors
                    });
                }

                var   size = Picture.Size;
                float maxWidth;
                switch (level)
                {
                case 0:
                    maxWidth = 640;
                    break;

                case 1:
                    maxWidth = 1024;
                    break;

                default:
                    maxWidth = size.Width;
                    break;
                }

                var hud = new LoadingHUDView(Locale.GetText("Image"), Locale.GetText("Compressing"));
                View.AddSubview(hud);
                hud.StartAnimating();

                // Show the UI, and on a callback, do the scaling, so the user gets an animation
                NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(0), delegate {
                    if (size.Width > maxWidth || size.Height > maxWidth)
                    {
                        Picture = Scale(Picture, new SizeF(maxWidth, maxWidth * size.Height / size.Width));
                    }
                    hud.StopAnimating();
                    hud.RemoveFromSuperview();
                    hud = null;
                });
            }
            else
            {
                //NSUrl movieUrl = pictureDict [UIImagePickerController.MediaURL] as NSUrl;

                // Future use, when we find a video host that does not require your Twitter login/password
            }

            pictureDict.Dispose();
        }
Exemple #3
0
        // Need HUD display here
        void ShrinkUrls(string [] words)
        {
            var hud = new LoadingHUDView (Locale.GetText ("Shrinking"));
            this.AddSubview (hud);
            hud.StartAnimating ();

            var wc = new WebClient ();
            for (int i = 0; i < words.Length; i++){
                if (!words [i].StartsWith ("http://"))
                    continue;

                try {
                    words [i] = wc.DownloadString (new Uri ("http://is.gd/api.php?longurl=" + HttpUtility.UrlEncode (words [i])));
                } catch {
                }
            }
            hud.StopAnimating ();
            hud.RemoveFromSuperview ();
            hud = null;
        }
Exemple #4
0
        void PictureSelected(NSDictionary pictureDict)
        {
            int level = Util.Defaults.IntForKey ("sizeCompression");

            if ((pictureDict [UIImagePickerController.MediaType] as NSString) == "public.image"){
                Picture = pictureDict [UIImagePickerController.EditedImage] as UIImage;
                if (Picture == null)
                    Picture = pictureDict [UIImagePickerController.OriginalImage] as UIImage;

                // Save a copy of the original picture
                if (!FromLibrary){
                    Picture.SaveToPhotosAlbum (delegate {
                        // ignore errors
                    });
                }

                var size = Picture.Size;
                float maxWidth;
                switch (level){
                case 0:
                    maxWidth = 640;
                    break;
                case 1:
                    maxWidth = 1024;
                    break;
                default:
                    maxWidth = size.Width;
                    break;
                }

                var hud = new LoadingHUDView (Locale.GetText ("Image"), Locale.GetText ("Compressing"));
                View.AddSubview (hud);
                hud.StartAnimating ();

                // Show the UI, and on a callback, do the scaling, so the user gets an animation
                NSTimer.CreateScheduledTimer (TimeSpan.FromSeconds (0), delegate {
                    if (size.Width > maxWidth || size.Height > maxWidth)
                        Picture = Scale (Picture, new SizeF (maxWidth, maxWidth*size.Height/size.Width));
                    hud.StopAnimating ();
                    hud.RemoveFromSuperview ();
                    hud = null;
                });
            } else {
                //NSUrl movieUrl = pictureDict [UIImagePickerController.MediaURL] as NSUrl;

                // Future use, when we find a video host that does not require your Twitter login/password
            }

            pictureDict.Dispose ();
        }
Exemple #5
0
        void PostCallback(object sender, EventArgs a)
        {
            sendItem.Enabled = false;

            if (Picture == null){
                Post ();
                return;
            }

            hud = new LoadingHUDView (Locale.GetText ("Image"), Locale.GetText ("Uploading"));
            View.AddSubview (hud);
            hud.StartAnimating ();

            var jpeg = Picture.AsJPEG ();
            Stream stream;
            unsafe { stream = new UnmanagedMemoryStream ((byte*) jpeg.Bytes, jpeg.Length); }

            ThreadPool.QueueUserWorkItem (delegate {
                TwitterAccount.CurrentAccount.UploadPicture (stream, PicUploadComplete);

                // This captures the variable and handle of jpeg, and then we clear it
                // to release it
                jpeg = null;
            });
        }
Exemple #6
0
        void PicUploadComplete(string name)
        {
            hud.StopAnimating ();
            hud.RemoveFromSuperview ();
            hud = null;

            if (name == null){
                alert = new UIAlertView (Locale.GetText ("Error"),
                    Locale.GetText ("There was an error uploading the media, do you want to post without it?"), null,
                    Locale.GetText ("Cancel Post"), Locale.GetText ("Post"));

                alert.Clicked += delegate(object sender, UIButtonEventArgs e) {
                    if (e.ButtonIndex == 1)
                        Post ();
                };
                alert.Show ();
            } else {
                var text = composerView.Text.Trim ();
                if (text.Length + name.Length > 140){
                    alert = new UIAlertView ("Error",
                        Locale.GetText ("Message is too long"), null, null, "Ok");
                    alert.Show ();
                } else {
                    text = text + " " + name;
                    if (text.Length > 140)
                        text = text.Trim ();
                    composerView.Text = text;
                    Post ();
                }
            }
        }
Exemple #7
0
        void PostCallback(object sender, EventArgs a)
        {
            sendItem.Enabled = false;

            var pictureDict = composerView.PictureDict;
            if (pictureDict == null){
                Post ();
                return;
            }

            int level = Util.Defaults.IntForKey ("sizeCompression");

            if ((pictureDict [UIImagePickerController.MediaType] as NSString) == "public.image"){
                var img = pictureDict [UIImagePickerController.EditedImage] as UIImage;
                if (img == null)
                    img = pictureDict [UIImagePickerController.OriginalImage] as UIImage;

                // Save a copy of the original picture
                if (!composerView.FromLibrary){
                    img.SaveToPhotosAlbum (delegate {
                        // Ignore
                    });
                }

                var size = img.Size;
                float maxWidth;
                switch (level){
                case 0:
                    maxWidth = 640;
                    break;
                case 1:
                    maxWidth = 1024;
                    break;
                default:
                    maxWidth = size.Width;
                    break;
                }

                if (size.Width > maxWidth || size.Height > maxWidth)
                    img = img.Scale (new SizeF (maxWidth, maxWidth*size.Height/size.Width));

                var jpeg = img.AsJPEG ();
                Stream stream;
                unsafe { stream = new UnmanagedMemoryStream ((byte*) jpeg.Bytes, jpeg.Length); }

                hud = new LoadingHUDView (Locale.GetText ("Uploading\nImage"), "");
                View.AddSubview (hud);
                hud.StartAnimating ();

                TwitterAccount.CurrentAccount.UploadPicture (stream, PicUploadComplete);
            } else {
                //NSUrl movieUrl = pictureDict [UIImagePickerController.MediaURL] as NSUrl;

                // Future use, when we find a video host that does not require your Twitter login/password
            }
        }