/**
   * 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 viewDidDisappear(boolean animated) {
    super.viewDidDisappear(animated);

    NSNotificationCenter.getDefaultCenter().removeObserver(UIKit.KeyboardWillShowNotification());
    NSNotificationCenter.getDefaultCenter().removeObserver(UIKit.KeyboardWillHideNotification());
  }
 @Override
 public void viewWillAppear(boolean animated) {
   super.viewWillAppear(animated);
   Selector willShow = Selector.register("keyboardWillShow:");
   Selector willHide = Selector.register("keyboardWillHide:");
   NSNotificationCenter center = NSNotificationCenter.getDefaultCenter();
   center.addObserver(this, willShow, UIKit.KeyboardWillShowNotification(), null);
   center.addObserver(this, willHide, UIKit.KeyboardWillHideNotification(), null);
 }
  /** setup components and load to UI */
  private void setupTextView() {
    getView().setFrame(new CGRect(0, 0, 320, 460));
    textView = new UITextView(getView().getFrame());
    textView.setTextColor(UIColor.colorBlack());
    textView.setFont(UIFont.getFont("Arial", 18.0));
    textView.setDelegate(
        new UITextViewDelegateAdapter() {
          @Override
          public void didBeginEditing(UITextView textView) {
            Selector saveAction = Selector.register("saveAction");
            UIBarButtonItem saveItem =
                new UIBarButtonItem(UIBarButtonSystemItem.Done, null, saveAction);
            saveItem.setTarget(TextViewController.this);
            getNavigationItem().setRightBarButtonItem(saveItem);
          }
        });
    textView.setBackgroundColor(UIColor.colorWhite());
    textView.setAutoresizingMask(
        UIViewAutoresizing.FlexibleWidth.set(UIViewAutoresizing.FlexibleHeight));

    String textToAdd =
        "Now is the time for all good developers to come to serve their country.\n\nNow is the time for all good developers to come to serve their country.\r\rThis text view can also use attributed strings.";
    NSMutableAttributedString attrString = new NSMutableAttributedString(textToAdd);
    attrString.addAttribute(
        UIKit.ForegroundColorAttributeName(),
        UIColor.colorRed(),
        new NSRange(textToAdd.length() - 19, 19));
    attrString.addAttribute(
        UIKit.ForegroundColorAttributeName(),
        UIColor.colorBlue(),
        new NSRange(textToAdd.length() - 23, 3));
    attrString.addAttribute(
        UIKit.UnderlineStyleAttributeName(),
        NSNumber.valueOf(1l),
        new NSRange(textToAdd.length() - 23, 3));
    this.textView.setAttributedText(attrString);

    textView.setReturnKeyType(UIReturnKeyType.Default);
    textView.setKeyboardType(UIKeyboardType.Default);
    textView.setScrollEnabled(true);
    textView.setAutocorrectionType(UITextAutocorrectionType.No);

    getView().addSubview(textView);
  }