/** * Modifies keyboards size to fit screen * * @param showKeyboard * @param notificationInfo */ private void adjustViewForKeyboardReveal( boolean showKeyboard, NSDictionary<NSString, ?> notificationInfo) { // notificationInfo:(NSDictionary // *)notificationInfo // the keyboard is showing so resize the table's height CGRect keyboardRect = NSValueExtensions.getRectValue( (NSValue) notificationInfo.get(UIKit.KeyboardFrameEndUserInfoKey())); double animationDuration = ((NSNumber) notificationInfo.get(UIKit.KeyboardAnimationDurationUserInfoKey())) .doubleValue(); CGRect frame = this.textView.getFrame(); // the keyboard rect's width and height are reversed in landscape double adjustDelta = isPortrait(this.getInterfaceOrientation()) ? keyboardRect.getHeight() : keyboardRect.getWidth(); if (showKeyboard) { frame.size().height(frame.size().height() - adjustDelta); } else { frame.size().height(frame.size().height() + adjustDelta); } UIView.beginAnimations("ResizeForKeyboard", null); UIView.setDurationForAnimation(animationDuration); this.textView.setFrame(frame); UIView.commitAnimations(); }
@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"); }
@Override public void layoutSubviews() { super.layoutSubviews(); CGRect bounds = getBounds(); CGRect frame = name.getFrame(); frame.setWidth(bounds.getWidth() - (PRICE_WIDTH + PADDING * 2)); frame.setX(PADDING); frame.setY(PADDING); name.setFrame(frame); frame = price.getFrame(); frame.setY(PADDING + (name.getFrame().getHeight() - frame.getHeight()) / 2); frame.setX(name.getFrame().getX() + name.getFrame().getWidth() + PADDING); frame.setWidth(PRICE_WIDTH); price.setFrame(frame); frame = bounds; frame.setY(name.getFrame().getY() + name.getFrame().getHeight()); frame.setX(PADDING); frame.setWidth(frame.getWidth() - PADDING * 2); frame.setHeight(frame.getHeight() - frame.getY()); descriptionLabel.setFrame(frame); }
@Override public void onValueChanged(UIControl control) { System.out.println( String.format( "The page control changed its current page to %d.", pageControl.getCurrentPage())); colorView.setBackgroundColor(colors[(int) pageControl.getCurrentPage()]); }
private void configureVideoPreviewLayer() { AVCaptureVideoPreviewLayer previewLayer = new AVCaptureVideoPreviewLayer(captureSession); previewLayer.setVideoGravity(AVLayerVideoGravity.ResizeAspectFill); CALayer rootLayer = getView().getLayer(); rootLayer.setMasksToBounds(true); CGRect frame = previewView.getFrame(); previewLayer.setFrame(frame); rootLayer.insertSublayerAt(previewLayer, 0); }
public double getRequiredHeightInView(UIView view) { LayoutMeasureSpec widthMeasureSpec = new LayoutMeasureSpec(view.getBounds().getSize().getWidth(), LayoutMeasureSpecMode.Exactly); LayoutMeasureSpec heightMeasureSpec = new LayoutMeasureSpec(Double.MAX_VALUE, LayoutMeasureSpecMode.AtMost); UIViewLayoutUtil.measure(layoutBridge, widthMeasureSpec, heightMeasureSpec); return UIViewLayoutUtil.getMeasuredSize(layoutBridge).getHeight(); }
private void fillViewController() { ProductDescriptionView productDescriptionView = new ProductDescriptionView(currentProduct); productDescriptionView.setFrame(new CGRect(0, 0, 320, 120)); UIView headerView = new UIView( new CGRect( 0, 0, imageView.getFrame().getWidth(), imageView.getFrame().getY() + imageView.getFrame().getHeight())); headerView.addSubview(imageView); getTableView().setTableHeaderView(headerView); imageView.animate(); List<UITableViewCell> tableItems = new ArrayList<>(); tableItems.add(new CustomViewCell(productDescriptionView)); tableItems.addAll(getOptionCells()); getTableView().setModel(new ProductDetailPageModel(tableItems)); getTableView().reloadData(); }
public MyViewController() { // Get the view of this view controller. UIView view = getView(); // Setup background. view.setBackgroundColor(UIColor.white()); // Setup label. label = new UILabel(new CGRect(20, 250, 280, 44)); label.setFont(UIFont.getSystemFont(24)); label.setTextAlignment(NSTextAlignment.Center); view.addSubview(label); // Setup button. button = UIButton.create(UIButtonType.RoundedRect); button.setFrame(new CGRect(110, 150, 100, 40)); button.setTitle("Click me!", UIControlState.Normal); button.getTitleLabel().setFont(UIFont.getBoldSystemFont(22)); button.addOnTouchUpInsideListener( new UIControl.OnTouchUpInsideListener() { @Override public void onTouchUpInside(UIControl control, UIEvent event) { System.gc(); System.out.println(label.getText()); label.setText("Click Nr. " + (++clickCount)); if (tapjoyConnected) { launchTapjoy(); } else { System.out.println("tapjoy not connected yet"); } } }); view.addSubview(button); }
private void addToBasket() { UINavigationController navigation = getNavigationController(); CGPoint center = bottomView .getButton() .convertPointToView( bottomView.getButton().getImageView().getCenter(), navigation.getView()); UIImageView imageView = new UIImageView(tshirtIcon); imageView.setCenter(center); imageView.setContentMode(UIViewContentMode.ScaleAspectFill); UIImageView backgroundView = new UIImageView(UIImage.getImage("circle")); backgroundView.setCenter(center); navigation.getView().addSubviews(backgroundView, imageView); UIView targetView = (UIView) getNavigationItem().getRightBarButtonItem().getKeyValueCoder().getValue("view"); CGPoint targetPosition = new CGPoint( targetView.getCenter().getX() + targetView.getFrame().getWidth() / 3, targetView.getCenter().getY() + targetView.getFrame().getHeight() / 2); animateView(imageView, targetPosition, null); animateView( backgroundView, targetPosition, () -> { getNavigationItem().setRightBarButtonItem(StoreApp.getInstance().createBasketButton()); }); if (addedToBasket != null) { addedToBasket.invoke(new Order(order)); } }
@Override public void layoutSubviews() { super.layoutSubviews(); layerSizeDidUpdate = true; }
@Override public void setContentScaleFactor(double contentScaleFactor) { super.setContentScaleFactor(contentScaleFactor); layerSizeDidUpdate = true; }