@Override
  public void viewDidLoad() {
    super.viewDidLoad();

    getTableView().setSeparatorStyle(UITableViewCellSeparatorStyle.None);
    getTableView().setBackgroundColor(UIColor.black());

    getNavigationItem().setTitleView(new UIImageView(UIImage.getImage("TitleFindFriends")));

    if (getNavigationController().getViewControllers().first() == this) {
      UIBarButtonItem dismissLeftBarButtonItem =
          new UIBarButtonItem(
              "Back",
              UIBarButtonItemStyle.Plain,
              new UIBarButtonItem.OnClickListener() {
                @Override
                public void onClick(UIBarButtonItem barButtonItem) {
                  getNavigationController().dismissViewController(true, null);
                }
              });
      getNavigationItem().setLeftBarButtonItem(dismissLeftBarButtonItem);
    } else {
      getNavigationItem().setLeftBarButtonItem(null);
    }

    if (MFMailComposeViewController.canSendMail() || MFMessageComposeViewController.canSendText()) {
      headerView = new UIView(new CGRect(0, 0, 320, 67));
      headerView.setBackgroundColor(UIColor.black());
      UIButton clearButton = new UIButton(UIButtonType.Custom);
      clearButton.setBackgroundColor(UIColor.clear());
      clearButton.addOnTouchUpInsideListener(inviteFriendsButtonAction);
      clearButton.setFrame(headerView.getFrame());
      headerView.addSubview(clearButton);
      String inviteString = "Invite friends";
      CGRect boundingRect =
          NSString.getBoundingRect(
              inviteString,
              new CGSize(310, Float.MAX_VALUE),
              NSStringDrawingOptions.with(
                  NSStringDrawingOptions.TruncatesLastVisibleLine,
                  NSStringDrawingOptions.UsesLineFragmentOrigin),
              new NSAttributedStringAttributes().setFont(UIFont.getBoldSystemFont(18)),
              null);
      CGSize inviteStringSize = boundingRect.getSize();

      UILabel inviteLabel =
          new UILabel(
              new CGRect(
                  10,
                  (headerView.getFrame().getSize().getHeight() - inviteStringSize.getHeight()) / 2,
                  inviteStringSize.getWidth(),
                  inviteStringSize.getHeight()));
      inviteLabel.setText(inviteString);
      inviteLabel.setFont(UIFont.getBoldSystemFont(18));
      inviteLabel.setTextColor(UIColor.white());
      inviteLabel.setBackgroundColor(UIColor.clear());
      headerView.addSubview(inviteLabel);
      getTableView().setTableHeaderView(headerView);
    }
  }
  private void animateView(UIView view, CGPoint targetPosition, Runnable completion) {
    CGSize size = view.getFrame().getSize();
    CGSize grow = new CGSize(size.getWidth() * 1.7, size.getHeight() * 1.7);
    CGSize shrink = new CGSize(size.getWidth() * .4, size.getHeight() * .4);

    CAKeyframeAnimation pathAnimation = new CAKeyframeAnimation("position");
    pathAnimation.setCalculationMode(CAAnimationCalculationMode.Paced);
    pathAnimation.setFillMode(CAFillMode.Forwards);
    pathAnimation.setRemovedOnCompletion(false);
    pathAnimation.setDuration(.5);

    UIBezierPath path = new UIBezierPath();
    path.move(view.getCenter());
    path.addQuadCurve(
        targetPosition, new CGPoint(view.getCenter().getX(), view.getCenter().getY()));
    pathAnimation.setPath(path.getCGPath());

    CABasicAnimation growAnimation = new CABasicAnimation("bounds.size");
    growAnimation.setToValue(NSValue.valueOf(grow));
    growAnimation.setFillMode(CAFillMode.Forwards);
    growAnimation.setRemovedOnCompletion(false);
    growAnimation.setDuration(.1);

    CABasicAnimation shrinkAnimation = new CABasicAnimation("bounds.size");
    shrinkAnimation.setToValue(NSValue.valueOf(shrink));
    shrinkAnimation.setFillMode(CAFillMode.Forwards);
    shrinkAnimation.setRemovedOnCompletion(false);
    shrinkAnimation.setDuration(.4);
    shrinkAnimation.setBeginTime(.1);

    CAAnimationGroup animations = new CAAnimationGroup();
    animations.setAnimations(new NSArray<>(pathAnimation, growAnimation, shrinkAnimation));
    animations.setFillMode(CAFillMode.Forwards);
    animations.setRemovedOnCompletion(false);
    animations.setDuration(.5);
    animations.setDelegate(
        new CAAnimationDelegateAdapter() {
          @Override
          public void didStop(CAAnimation anim, boolean flag) {
            view.removeFromSuperview();

            if (completion != null) {
              completion.run();
            }
          }
        });
    view.getLayer().addAnimation(animations, "movetocart");
  }
Ejemplo n.º 3
0
  public void display() {
    // Create autorelease pool per frame to avoid possible deadlock
    // situations
    // because there are 3 CAMetalDrawables sitting in an autorelease pool.

    try (NSAutoreleasePool pool = new NSAutoreleasePool()) {
      // handle display changes here
      if (layerSizeDidUpdate) {
        // set the metal layer to the drawable size in case orientation
        // or size changes
        CGSize drawableSize = getBounds().getSize();
        drawableSize.setWidth(drawableSize.getWidth() * this.getContentScaleFactor());
        drawableSize.setHeight(drawableSize.getHeight() * this.getContentScaleFactor());

        metalLayer.setDrawableSize(drawableSize);

        // renderer delegate method so renderer can resize anything if
        // needed
        delegate.reshape(this);

        layerSizeDidUpdate = false;
      }

      // rendering delegate method to ask renderer to draw this frame's
      // content
      delegate.render(this);

      // do not retain current drawable beyond the frame.
      // There should be no strong references to this object outside of
      // this view class
      ((NSObject) currentDrawable).dispose();
      currentDrawable = null;
    }
  }
  public void computeConstantSize() {
    CGSize minSize = CGSize.Zero();
    CGSize intrinsicSize = CGSize.Zero();

    for (Drawable drawable : drawables) {
      CGSize min = drawable.getMinimumSize();
      CGSize intrinsic = drawable.getIntrinsicSize();

      if (min.getWidth() > minSize.getWidth()) minSize.setWidth(min.getWidth());
      if (min.getHeight() > minSize.getHeight()) minSize.setHeight(min.getHeight());

      if (intrinsic.getWidth() > intrinsicSize.getWidth())
        intrinsicSize.setWidth(intrinsic.getWidth());
      if (intrinsic.getHeight() > intrinsicSize.getHeight())
        intrinsicSize.setHeight(intrinsic.getHeight());
    }

    this.constantIntrinsicSize = intrinsicSize;
    this.constantMinimumSize = minSize;
    this.constantSizeComputed = true;
  }