Esempio n. 1
0
        private UIView AddAllMatchesViewExplanatoryViewToContainerView(UIView containerView, List <NSLayoutConstraint> constraints)
        {
            UIView overlayView = AddOverlayViewToContainerView(containerView);

            // Start out hidden
            // This view will become visible once all matches have been viewed
            overlayView.Alpha = 0f;

            UILabel label = StyleUtilities.CreateStandardLabel();

            label.Font = StyleUtilities.LargeFont;
            label.Text = "Stay tuned for more matches!".LocalizedString("Shown when all matches have been viewed");
            overlayView.AddSubview(label);

            // Center the overlay view
            constraints.Add(NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, containerView, NSLayoutAttribute.CenterX, 1f, 0f));
            constraints.Add(NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, containerView, NSLayoutAttribute.CenterY, 1f, 0f));

            // Position the label in the overlay view
            constraints.Add(NSLayoutConstraint.Create(label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Top, 1f, StyleUtilities.ContentVerticalMargin));
            constraints.Add(NSLayoutConstraint.Create(label, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Bottom, 1f, -1 * StyleUtilities.ContentVerticalMargin));
            constraints.Add(NSLayoutConstraint.Create(label, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Leading, 1f, StyleUtilities.ContentHorizontalMargin));
            constraints.Add(NSLayoutConstraint.Create(label, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Trailing, 1f, -1 * StyleUtilities.ContentHorizontalMargin));

            return(overlayView);
        }
Esempio n. 2
0
        private UIView AddSwipeInstructionsToContainerView(UIView containerView, List <NSLayoutConstraint> constraints)
        {
            UIView overlayView = AddOverlayViewToContainerView(containerView);

            UILabel swipeInstructionsLabel = StyleUtilities.CreateStandardLabel();

            swipeInstructionsLabel.Font = StyleUtilities.LargeFont;
            overlayView.AddSubview(swipeInstructionsLabel);
            swipeInstructionsLabel.Text = "Swipe ↑ to say \"Hello!\"\nSwipe ↓ to say \"Goodbye...\"".LocalizedString("Instructions for the Matches page");
            swipeInstructionsLabel.AccessibilityLabel = "Swipe up to say \"Hello!\"\nSwipe down to say \"Goodbye\"".LocalizedString("Accessibility instructions for the Matches page");

            float overlayMargin = StyleUtilities.OverlayMargin;
            NSLayoutConstraint topMarginConstraint = NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1f, overlayMargin);
            float priority = (int)UILayoutPriority.Required - 1;

            topMarginConstraint.Priority = priority;
            constraints.Add(topMarginConstraint);

            // Position the label inside the overlay view
            constraints.Add(NSLayoutConstraint.Create(swipeInstructionsLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Top, 1f, HelloGoodbyeVerticalMargin));
            constraints.Add(NSLayoutConstraint.Create(swipeInstructionsLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.CenterX, 1f, 0f));
            constraints.Add(NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, swipeInstructionsLabel, NSLayoutAttribute.Bottom, 1f, HelloGoodbyeVerticalMargin));

            // Center the overlay view horizontally
            constraints.Add(NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, containerView, NSLayoutAttribute.Left, 1f, overlayMargin));
            constraints.Add(NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, containerView, NSLayoutAttribute.Right, 1f, -overlayMargin));

            return(overlayView);
        }
Esempio n. 3
0
        UIView[] AddAgeControlsToView(UIView overlayView, List <NSLayoutConstraint> constraints)
        {
            UILabel ageTitleLabel = StyleUtilities.CreateStandardLabel();

            ageTitleLabel.Text = "Your age".LocalizedString("The user's age");
            overlayView.AddSubview(ageTitleLabel);

            AgeSlider ageSlider = new AgeSlider {
                Value = person.Age,
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            ageSlider.ValueChanged += OnAgeUpdate;
            overlayView.AddSubview(ageSlider);

            // Display the current age next to the slider
            ageValueLabel = AddAgeValueLabelToView(overlayView);
            UpdateAgeValueLabelFromSlider(ageSlider);

//			// Position the age title and value side by side, within the overlay view
            constraints.Add(NSLayoutConstraint.Create(ageTitleLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Top, 1f, StyleUtilities.ContentVerticalMargin));
            constraints.Add(NSLayoutConstraint.Create(ageTitleLabel, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Leading, 1f, StyleUtilities.ContentHorizontalMargin));
            constraints.Add(NSLayoutConstraint.Create(ageSlider, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ageTitleLabel, NSLayoutAttribute.Trailing, 1f, LabelControlMinimumSpacing));
            constraints.Add(NSLayoutConstraint.Create(ageSlider, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, ageTitleLabel, NSLayoutAttribute.CenterY, 1f, 0f));
            constraints.Add(NSLayoutConstraint.Create(ageValueLabel, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ageSlider, NSLayoutAttribute.Trailing, 1f, LabelControlMinimumSpacing));
            constraints.Add(NSLayoutConstraint.Create(ageValueLabel, NSLayoutAttribute.FirstBaseline, NSLayoutRelation.Equal, ageTitleLabel, NSLayoutAttribute.FirstBaseline, 1f, 0f));
            constraints.Add(NSLayoutConstraint.Create(ageValueLabel, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Trailing, 1f, -1 * StyleUtilities.ContentHorizontalMargin));

            return(new UIView[] { ageTitleLabel, ageSlider, ageValueLabel });
        }
Esempio n. 4
0
        UILabel AddAgeValueLabelToView(UIView overlayView)
        {
            UILabel ageValueLabel = StyleUtilities.CreateStandardLabel();

            ageValueLabel.IsAccessibilityElement = false;
            overlayView.AddSubview(ageValueLabel);

            return(ageValueLabel);
        }
Esempio n. 5
0
        private void AddProfileViews()
        {
            _photo = new UIImageView {
                IsAccessibilityElement = true,
                AccessibilityLabel     = "Profile photo".LocalizedString("Accessibility label for profile photo"),
                TranslatesAutoresizingMaskIntoConstraints = false,
            };
            AddSubview(_photo);

            _ageTitleLabel      = StyleUtilities.CreateStandardLabel();
            _ageTitleLabel.Text = "Age".LocalizedString("Age of the user");
            AddSubview(_ageTitleLabel);

            _ageValueLabel = StyleUtilities.CreateDetailLabel();
            AddSubview(_ageValueLabel);

            _hobbiesTitleLabel      = StyleUtilities.CreateStandardLabel();
            _hobbiesTitleLabel.Text = "Hobbies".LocalizedString("The user's hobbies");
            AddSubview(_hobbiesTitleLabel);

            _hobbiesValueLabel = StyleUtilities.CreateDetailLabel();
            AddSubview(_hobbiesValueLabel);

            _elevatorPitchTitleLabel      = StyleUtilities.CreateStandardLabel();
            _elevatorPitchTitleLabel.Text = "Elevator Pitch".LocalizedString("The user's elevator pitch for finding a partner");
            AddSubview(_elevatorPitchTitleLabel);

            _elevatorPitchValueLabel = StyleUtilities.CreateDetailLabel();
            AddSubview(_elevatorPitchValueLabel);

            this.SetAccessibilityElements(NSArray.FromNSObjects(
                                              _photo,
                                              _ageTitleLabel,
                                              _ageValueLabel,
                                              _hobbiesTitleLabel,
                                              _hobbiesValueLabel,
                                              _elevatorPitchTitleLabel,
                                              _elevatorPitchValueLabel
                                              ));
        }
Esempio n. 6
0
        UITextField AddTextFieldWithName(string name, string text, UIView overlayView, IEnumerable <UIView> previousRowItems, List <NSLayoutConstraint> constraints)
        {
            UILabel titleLabel = StyleUtilities.CreateStandardLabel();

            titleLabel.Text = name;
            overlayView.AddSubview(titleLabel);

            var attributes = new CTStringAttributes();

            attributes.ForegroundColor = StyleUtilities.DetailOnOverlayPlaceholderColor.CGColor;

            UITextField valueField = new UITextField {
                WeakDelegate          = this,
                Font                  = StyleUtilities.StandardFont,
                TextColor             = StyleUtilities.DetailOnOverlayColor,
                Text                  = text,
                AttributedPlaceholder = new NSAttributedString("Type here...".LocalizedString("Placeholder for profile text fields"), attributes),
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            overlayView.AddSubview(valueField);

            // Ensure sufficient spacing from the row above this one
            foreach (UIView previousRowItem in previousRowItems)
            {
                constraints.Add(NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Top, NSLayoutRelation.GreaterThanOrEqual, previousRowItem, NSLayoutAttribute.Bottom, 1f, MinimumVerticalSpacingBetweenRows));
            }

            // Place the title directly above the value
            constraints.Add(NSLayoutConstraint.Create(valueField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, titleLabel, NSLayoutAttribute.Bottom, 1f, 0f));

            // Position the title and value within the overlay view
            constraints.Add(NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Leading, 1f, StyleUtilities.ContentHorizontalMargin));
            constraints.Add(NSLayoutConstraint.Create(valueField, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, titleLabel, NSLayoutAttribute.Leading, 1f, 0f));
            constraints.Add(NSLayoutConstraint.Create(valueField, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Trailing, 1f, -1 * StyleUtilities.ContentHorizontalMargin));

            return(valueField);
        }
        CardView AddCardViewToView(UIView containerView)
        {
            CardView cv = new CardView();

            cv.Update(CurrentMatch);
            cv.TranslatesAutoresizingMaskIntoConstraints = false;
            this.cardView = cv;
            containerView.AddSubview(cv);

            UISwipeGestureRecognizer swipeUpRecognizer = new UISwipeGestureRecognizer(HandleSwipeUp);

            swipeUpRecognizer.Direction = UISwipeGestureRecognizerDirection.Up;
            cv.AddGestureRecognizer(swipeUpRecognizer);

            UISwipeGestureRecognizer swipeDownRecognizer = new UISwipeGestureRecognizer(HandleSwipeDown);

            swipeDownRecognizer.Direction = UISwipeGestureRecognizerDirection.Down;
            cv.AddGestureRecognizer(swipeDownRecognizer);

            string sayHelloName = "Say hello".LocalizedString(@"Accessibility action to say hello");

            helloAction = new UIAccessibilityCustomAction(sayHelloName, SayHello);

            string sayGoodbyeName = "Say goodbye".LocalizedString("Accessibility action to say goodbye");

            goodbyeAction = new UIAccessibilityCustomAction(sayGoodbyeName, SayGoodbye);

            UIView[] elements = NSArray.FromArray <UIView> ((NSArray)cv.GetAccessibilityElements());
            foreach (UIView element in elements)
            {
                element.AccessibilityCustomActions = new UIAccessibilityCustomAction[] { helloAction, goodbyeAction }
            }
            ;

            return(cv);
        }

        void HandleSwipeUp(UISwipeGestureRecognizer gestureRecognizer)
        {
            if (gestureRecognizer.State == UIGestureRecognizerState.Recognized)
            {
                SayHello(helloAction);
            }
        }

        void HandleSwipeDown(UISwipeGestureRecognizer gestureRecognizer)
        {
            if (gestureRecognizer.State == UIGestureRecognizerState.Recognized)
            {
                SayGoodbye(goodbyeAction);
            }
        }

        UIView AddAllMatchesViewExplanatoryViewToContainerView(UIView containerView, List <NSLayoutConstraint> constraints)
        {
            UIView overlayView = AddOverlayViewToContainerView(containerView);

            // Start out hidden
            // This view will become visible once all matches have been viewed
            overlayView.Alpha = 0f;

            UILabel label = StyleUtilities.CreateStandardLabel();

            label.Font = StyleUtilities.LargeFont;
            label.Text = "Stay tuned for more matches!".LocalizedString("Shown when all matches have been viewed");
            overlayView.AddSubview(label);

            // Center the overlay view
            constraints.Add(NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, containerView, NSLayoutAttribute.CenterX, 1f, 0f));
            constraints.Add(NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, containerView, NSLayoutAttribute.CenterY, 1f, 0f));

            // Position the label in the overlay view
            constraints.Add(NSLayoutConstraint.Create(label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Top, 1f, StyleUtilities.ContentVerticalMargin));
            constraints.Add(NSLayoutConstraint.Create(label, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Bottom, 1f, -1 * StyleUtilities.ContentVerticalMargin));
            constraints.Add(NSLayoutConstraint.Create(label, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Leading, 1f, StyleUtilities.ContentHorizontalMargin));
            constraints.Add(NSLayoutConstraint.Create(label, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Trailing, 1f, -1 * StyleUtilities.ContentHorizontalMargin));

            return(overlayView);
        }

        bool SayHello(UIAccessibilityCustomAction customAction)
        {
            AnimateCardsForHello(true);
            return(true);
        }

        bool SayGoodbye(UIAccessibilityCustomAction customAction)
        {
            AnimateCardsForHello(false);
            return(true);
        }

        void AnimateCardsForHello(bool forHello)
        {
            AnimateCardOffScreenToTop(forHello, () => {
                currentMatchIndex++;
                Person nextMatch = CurrentMatch;
                if (nextMatch != null)
                {
                    // Show the next match's profile in the card
                    cardView.Update(nextMatch);

                    // Ensure that the view's layout is up to date before we animate it
                    View.LayoutIfNeeded();

                    if (UIAccessibility.IsReduceMotionEnabled)
                    {
                        // Fade the card into view
                        FadeCardIntoView();
                    }
                    else
                    {
                        // Zoom the new card from a tiny point into full view
                        ZoomCardIntoView();
                    }
                }
                else
                {
                    // Hide the card
                    cardView.Hidden = true;

                    // Fade in the "Stay tuned for more matches" blurb
                    UIView.Animate(FadeAnimationDuration, () => {
                        swipeInstructionsView.Alpha           = 0f;
                        allMatchesViewedExplanatoryView.Alpha = 1f;
                    });
                }

                UIAccessibility.PostNotification(UIAccessibilityPostNotification.LayoutChanged, null);
            });
        }

        void FadeCardIntoView()
        {
            cardView.Alpha = 0f;
            UIView.Animate(FadeAnimationDuration, () => {
                cardView.Alpha = 1f;
            });
        }

        void ZoomCardIntoView()
        {
            cardView.Transform = CGAffineTransform.MakeScale(0f, 0f);
            UIView.Animate(ZoomAnimationDuration, () => {
                cardView.Transform = CGAffineTransform.MakeIdentity();
            });
        }

        void AnimateCardOffScreenToTop(bool toTop, Action completion)
        {
            NSLayoutConstraint offScreenConstraint = null;

            if (toTop)
            {
                offScreenConstraint = NSLayoutConstraint.Create(cardView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1f, 0f);
            }
            else
            {
                offScreenConstraint = NSLayoutConstraint.Create(cardView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1f, 0f);
            }

            View.LayoutIfNeeded();

            UIView.Animate(SwipeAnimationDuration, () => {
                // Slide the card off screen
                View.RemoveConstraints(cardViewVerticalConstraints);
                View.AddConstraint(offScreenConstraint);
                View.LayoutIfNeeded();
            }, () => {
                // Bring the card back into view
                View.RemoveConstraint(offScreenConstraint);
                View.AddConstraints(cardViewVerticalConstraints);

                if (completion != null)
                {
                    completion();
                }
            });
        }

        UIView AddSwipeInstructionsToContainerView(UIView containerView, List <NSLayoutConstraint> constraints)
        {
            UIView overlayView = AddOverlayViewToContainerView(containerView);

            UILabel swipeInstructionsLabel = StyleUtilities.CreateStandardLabel();

            swipeInstructionsLabel.Font = StyleUtilities.LargeFont;
            overlayView.AddSubview(swipeInstructionsLabel);
            swipeInstructionsLabel.Text = "Swipe ↑ to say \"Hello!\"\nSwipe ↓ to say \"Goodbye...\"".LocalizedString("Instructions for the Matches page");
            swipeInstructionsLabel.AccessibilityLabel = "Swipe up to say \"Hello!\"\nSwipe down to say \"Goodbye\"".LocalizedString("Accessibility instructions for the Matches page");

            float overlayMargin = StyleUtilities.OverlayMargin;
            NSLayoutConstraint topMarginConstraint = NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1f, overlayMargin);
            float priority = (int)UILayoutPriority.Required - 1;

            topMarginConstraint.Priority = priority;
            constraints.Add(topMarginConstraint);

            // Position the label inside the overlay view
            constraints.Add(NSLayoutConstraint.Create(swipeInstructionsLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Top, 1f, HelloGoodbyeVerticalMargin));
            constraints.Add(NSLayoutConstraint.Create(swipeInstructionsLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.CenterX, 1f, 0f));
            constraints.Add(NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, swipeInstructionsLabel, NSLayoutAttribute.Bottom, 1f, HelloGoodbyeVerticalMargin));

            // Center the overlay view horizontally
            constraints.Add(NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, containerView, NSLayoutAttribute.Left, 1f, overlayMargin));
            constraints.Add(NSLayoutConstraint.Create(overlayView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, containerView, NSLayoutAttribute.Right, 1f, -overlayMargin));

            return(overlayView);
        }

        UIView AddOverlayViewToContainerView(UIView containerView)
        {
            UIView overlayView = new UIView {
                BackgroundColor = StyleUtilities.OverlayColor,
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            overlayView.Layer.CornerRadius = StyleUtilities.OverlayCornerRadius;
            containerView.AddSubview(overlayView);

            return(overlayView);
        }
    }