void AddCodeWordToView(Secret s)
 {
     s.WatchEvent += UpdateSecretDeviceCount;
                 var secret = new SecretItem {
                         Secret = s.Phrase,
                         Devices = s.ListenersCount
                 };
                 var view = _inflater.Inflate (Resource.Layout.SecretItemView, _mainLayout, false);
                 var tv = view.FindViewById<TextView> (Resource.Id.textViewSecrets);
                 tv.Text = secret.Secret;
                 tv = view.FindViewById<TextView> (Resource.Id.textViewDevices);
                 tv.Text = secret.Devices.ToString ();
                 _secretItems [view] = secret;
                 view.Click += OnShowSecret;
                 _mainLayout.AddView (view, 4);
 }
 /// <summary>
 /// Updates the shared devices count display.
 /// </summary>
 /// <param name='secret'>
 /// Secret.
 /// </param>
 void UpdateSharedDevicesCount(Secret secret)
 {
     RunOnUiThread (() => {
                         _tvShareCount.Text = secret.ListenersCount == 1
                                 ? GetString (Resource.String.ShareWithNoDevices)
                                         : string.Format (GetString (Resource.String.ShareWithNDevices), secret.ListenersCount);
                 });
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);
                        SetContentView (Resource.Layout.SessionView);

                        _textToSend = FindViewById<EditText> (Resource.Id.textViewUpload);
                        _tvShareCount = FindViewById<TextView> (Resource.Id.tvShareCount);
                        _tvCodeWord = FindViewById<TextView> (Resource.Id.tvCodeWord);
                        _chooseContent = FindViewById<Button> (Resource.Id.btnChooseContent);
                        _mainLayout = FindViewById<LinearLayout> (Resource.Id.shareLayout);

                        var btnSend = FindViewById<Button> (Resource.Id.buttonSend);
                        btnSend.Click += (object sender, EventArgs e) => {
                                SendText ();
                        };

                        _textToSend.KeyPress += (object sender, View.KeyEventArgs e) => {
                                if (e.KeyCode == Keycode.Enter && e.Event.Action == KeyEventActions.Down) {
                                        SendText ();
                                } else
                                        e.Handled = false;
                        };
                        _chooseContent.Click += ChooseFile;

                        var phrase = Intent.GetStringExtra ("Secret");
                        _secret = CrossCopyApp.HistoryData.Secrets.Where (s => s.Phrase == phrase).SingleOrDefault ();
                        if (_secret == null)
                                Finish ();

                        _secret.WatchEvent += UpdateSharedDevicesCount;
                        CrossCopyApp.Srv.CurrentSecret = _secret;

                        GetString (Resource.String.SessionTitle);

                        _tvCodeWord.Text = _secret.Phrase;
                        _tvShareCount.Text = GetString (Resource.String.ShareWithNoDevices);

                        _inflater = (LayoutInflater)GetSystemService (Context.LayoutInflaterService);
                        _inputMethodManager = (InputMethodManager)GetSystemService (InputMethodService);
                        HandlePossibleSharedContent ();
        }
Exemple #4
0
        private void ShowSecretsView()
        {
            var secret = currentSecret;
            RootElement root = CreateRootElement ();
            rootDVC = new StyledDialogViewController (root, null, backgroundColor)
            {
                Autorotate = true,
                HidesBottomBarWhenPushed = true
            };
            rootDVC.ViewAppearing += (sender, e) => {
                server.Abort ();
                currentSecret = null;
                NSError err;
                Analytics.SharedTracker.TrackPageView ("/secrets", out err);
                ReOrderSecrets ();
            };

            var aboutButton = UIHelper.CreateInfoButton(40f, 60f);
            aboutButton.TouchDown += (sender, e) => {
                ShowAboutView();
            };
            rootDVC.View.AddSubview(aboutButton);

            navigation = new UINavigationController ();
            Flurry.LogAllPageViews(navigation);
            navigation.SetNavigationBarHidden (true, false);
            navigation.PushViewController (rootDVC, false);

            window.RootViewController = navigation;

            if (ResharedItem != null)
            {
                var sbounds = UIScreen.MainScreen.Bounds;
                var btnCancel = UIButton.FromType (UIButtonType.RoundedRect);
                btnCancel.Tag = CANCEL_BUTTON_TAG;
                btnCancel.Frame = new RectangleF (
                    10,
                    sbounds.Height - 60f,
                    100,
                    30
                    );
                btnCancel.SetTitle ("Cancel", UIControlState.Normal);
                btnCancel.SetTitleColor (UIColor.Black, UIControlState.Normal);
                btnCancel.TouchDown += delegate {
                    ResharedItem = null;
                    if (rootDVC.View.ViewWithTag(CANCEL_BUTTON_TAG) != null) {
                        rootDVC.View.ViewWithTag(CANCEL_BUTTON_TAG).RemoveFromSuperview();
                    }
                    UpdateSecretsViewLabel(WELCOME_LABEL_TEXT);
                    DisplaySecretDetail(secret);
                };
                rootDVC.View.AddSubview (btnCancel);

                UpdateSecretsViewLabel(String.Format(SHARE_LABEL_TEXT, UrlHelper.GetFileName(ResharedItem.ItemPath)));
            }
        }
Exemple #5
0
        private void DisplaySecretDetail(Secret s)
        {
            NSError error;
            Analytics.SharedTracker.TrackPageView ("/session", out error);

            var subRoot = new RootElement (s.Phrase)
            {
                (shareSection = new Section ("Keep on server (1 min)") {
                    (pickPhoto = new StyledStringElement ("Photo", delegate { ShowImagePicker(); })),
                    (dataEntry = new AdvancedEntryElement ("Text", "your message", null))}),
                (entriesSection = new Section ("History"))
            };

            pickPhoto.Accessory = UITableViewCellAccessory.DisclosureIndicator;
            dataEntry.ShouldReturn += delegate {
                UIApplication.SharedApplication.InvokeOnMainThread (delegate {
                    dataEntry.GetContainerTableView ().EndEditing (true);
                }
                );

                server.Send (dataEntry.Value.Trim ());

                return true;
            };
            dataEntry.ReturnKeyType = UIReturnKeyType.Send;

            entriesSection.Elements.AddRange (
                from d in s.DataItems
                select ((Element)CreateDataItemElement (d))
                );

            subRoot.UnevenRows = true;

            sectionDVC = new StyledDialogViewController (
                subRoot,
                true,
                null,
                backgroundColor
                );
            sectionDVC.HidesBottomBarWhenPushed = false;
            navigation.SetNavigationBarHidden (false, true);
            navigation.PushViewController (sectionDVC, true);

            server.CurrentSecret = s;
            currentSecret = s;
            server.Listen ();

            currentSecret.WatchEvent += (secret) => {
                int count = secret.ListenersCount - 1;
                string pattern = "Keep on server (1 min)";
                if (count > 0) {
                    pattern = (count) > 1 ? "Share with {0} devices" : "Share with {0} device";
                }
                UIApplication.SharedApplication.InvokeOnMainThread (delegate {
                    shareSection.Caption = string.Format (pattern, count);
                    if (sectionDVC != null) {
                        sectionDVC.ReloadData ();
                    }
                }
                );
            };

            sectionDVC.ViewAppearing += delegate {
                if (navigation.View.ViewWithTag(SHARE_BUTTON_TAG) != null) {
                    navigation.View.ViewWithTag(SHARE_BUTTON_TAG).RemoveFromSuperview();
                }
            };

            if (ResharedItem != null) {
                ReshareData();
            }
        }
Exemple #6
0
        private RootElement CreateRootElement()
        {
            var captionLabel = UIHelper.CreateLabel (
                "cross copy",
                true,
                32,
                32,
                UITextAlignment.Center,
                UIColor.Black
                );
            UILabel subcaptionLabel = UIHelper.CreateLabel (
                WELCOME_LABEL_TEXT,
                false,
                14,
                85,
                UITextAlignment.Center,
                lightTextColor
                );
            subcaptionLabel.Tag = 3;

            captionLabel.Frame = new Rectangle (0, 10, 320, 40);
            subcaptionLabel.Frame = new Rectangle (20, 55, 280, 100);
            UIView header = new UIView (new Rectangle (0, 0, 300, 145));
            header.AddSubviews (captionLabel, subcaptionLabel);

            var root = new RootElement ("Secrets")
            {
                new Section (header),
                (secretsSection = new Section ("Secrets")),
                new Section ()
                {
                    (secretEntry = new AdvancedEntryElement ("Secret", "enter new phrase", "", null))
                }
            };

            secretsSection.AddAll (from s in AppDelegate.HistoryData.Secrets select (Element)CreateImageButtonStringElement (s));

            secretEntry.AutocapitalizationType = UITextAutocapitalizationType.None;
            secretEntry.ShouldReturn += delegate {

                if (String.IsNullOrEmpty (secretEntry.Value))
                    return false;

                var newSecret = new Secret (secretEntry.Value);
                AppDelegate.HistoryData.Secrets.Add (newSecret);

                if (root.Count == 2)
                    root.Insert (1, secretsSection);

                secretsSection.Insert (
                    secretsSection.Elements.Count,
                    UITableViewRowAnimation.Fade,
                    CreateImageButtonStringElement (newSecret)
                    );
                secretEntry.Value = "";
                secretEntry.ResignFirstResponder (false);
                DisplaySecretDetail (newSecret);

                return true;
            };
            secretEntry.ReturnKeyType = UIReturnKeyType.Go;
            if (secretsSection.Count == 0) {
                secretEntry.BecomeFirstResponder (true);
                root.RemoveAt (1);
            }
            return root;
        }
Exemple #7
0
        private ImageButtonStringElement CreateImageButtonStringElement(Secret secret)
        {
            var secretElement = new ImageButtonStringElement (secret.Phrase, secret, "Images/remove.png",
                                                              delegate {
                DisplaySecretDetail (secret);
            },
            delegate {
                AppDelegate.HistoryData.Secrets.Remove (secret);
                Element found = null;
                foreach (var element in secretsSection.Elements) {
                    if (element.Caption == secret.Phrase) {
                        found = element;
                        break;
                    }
                }

                if (found != null) {
                    secretsSection.Remove (found);
                    if (secretsSection.Count == 0)
                        (secretsSection.Parent as RootElement).RemoveAt (1);
                }
            }
            );
            secretElement.Value = " ";
            secret.WatchEvent += (s) => {
                InvokeOnMainThread (() => {
                    int peers = s.ListenersCount;
                    secretElement.Value = peers > 0 ? peers + " device" + (peers > 1 ? "s" : "") : " ";
                    rootDVC.ReloadData ();
                }
                );
            };

            return secretElement;
        }
Exemple #8
0
 public void Abort()
 {
     receiveClient.CancelAsync ();
                 CurrentSecret = null;
 }
 void UpdateSecretDeviceCount(Secret secret)
 {
     RunOnUiThread (() => {
                         var item = _secretItems.Where (s => s.Value.Secret == secret.Phrase).SingleOrDefault ();
                         item.Value.Devices = secret.ListenersCount;
                         var tv = item.Key.FindViewById<TextView> (Resource.Id.textViewDevices);
                         tv.Text = item.Value.Devices.ToString ();
                 });
 }
        protected override void OnResume()
        {
            base.OnResume ();

            CrossCopyApp.Srv.Abort ();

            FindViewById<Button>(Resource.Id.buttonGo).Click +=(sender, e) => {
                string phrase = FindViewById<EditText>(Resource.Id.editTextSecret).Text;
                if (String.IsNullOrEmpty (phrase))
                    return;

                Secret newSecret = new Secret (phrase);
                CrossCopyApp.HistoryData.Secrets.Add (newSecret);

                DisplaySecretDetail (phrase);
            };

            //			foreach (Secret s in CrossCopyApp.HistoryData.Secrets) {
            //				secretsSection.Add((Element)new StringElement (s.Phrase));
            //			}
            //			if (secretsSection.Count == 0) {
            //                ((RootElement) secretsSection.Parent).RemoveAt (0);
            //            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.Share);

            List<HistoryList> hl = new List<HistoryList> () {
            new HistoryList() { Left="History1", Right="" },
             new HistoryList() { Left="", Right="History2" },
                new HistoryList() { Left="History3", Right="" },
             new HistoryList() { Left="", Right="History4" },
                new HistoryList() { Left="History5", Right="" },
             new HistoryList() { Left="", Right="History6" }
            };
            historyListAdap = new HistoryListAdapter (this, hl);
            var listView = FindViewById<ListView> (Resource.Id.listViewHistory);
            listView.Adapter = historyListAdap;
            listView.ItemClick += listView_ItemClick;

            listData = "";
            var btnSend = FindViewById<Button> (Resource.Id.buttonGo);
            var txtMsg = FindViewById<EditText> (Resource.Id.textViewUpload);
            btnSend.Click += (sender, args) => {
                if (!String.IsNullOrEmpty (txtMsg.Text)) {
                    CrossCopyApp.Srv.Send (txtMsg.Text.Trim ());
                    //Paste (new DataItem (txtMsg.Text.Trim (), DataItemDirection.Out, DateTime.Now));
                }
            };

            string phrase = Intent.GetStringExtra ("Secret");
            secret = new Secret (phrase);
            CrossCopyApp.Srv.CurrentSecret = secret;
        }