@NonNull @Override
  public Object instantiateItem(@NonNull ViewGroup container, int position) {
    View root =
        mLayoutInflater.inflate(R.layout.quick_text_popup_autorowkeyboard_view, container, false);
    ScrollViewWithDisable scrollViewWithDisable =
        root.findViewById(R.id.scroll_root_for_quick_test_keyboard);
    scrollViewWithDisable.setPadding(
        scrollViewWithDisable.getPaddingLeft(),
        scrollViewWithDisable.getPaddingTop(),
        scrollViewWithDisable.getPaddingRight(),
        scrollViewWithDisable.getPaddingBottom() + mBottomPadding);
    container.addView(root);

    final QuickKeysKeyboardView keyboardView = root.findViewById(R.id.keys_container);
    keyboardView.setKeyboardTheme(mKeyboardTheme);
    keyboardView.setOnPopupShownListener(
        new PopupKeyboardShownHandler(mViewPager, scrollViewWithDisable));
    keyboardView.setOnKeyboardActionListener(mKeyboardActionListener);
    QuickTextKey addOn = mAddOns[position];
    AnyPopupKeyboard keyboard = mPopupKeyboards[position];
    if (keyboard == null || position == 0 /*ALWAYS re-create history, in case it has changed*/) {
      if (addOn.isPopupKeyboardUsed()) {
        keyboard =
            new AnyPopupKeyboard(
                addOn,
                mContext,
                addOn.getPopupKeyboardResId(),
                keyboardView.getThemedKeyboardDimens(),
                addOn.getName(),
                mDefaultSkinTonePrefTracker.getDefaultSkinTone(),
                mDefaultGenderPrefTracker.getDefaultGender());
      } else {
        keyboard =
            new PopupListKeyboard(
                mDefaultLocalAddOn,
                mContext,
                keyboardView.getThemedKeyboardDimens(),
                addOn.getPopupListNames(),
                addOn.getPopupListValues(),
                addOn.getName());
      }
      mPopupKeyboards[position] = keyboard;
      final int keyboardViewMaxWidth = keyboardView.getThemedKeyboardDimens().getKeyboardMaxWidth();
      mIsAutoFitKeyboards[position] =
          keyboard.getMinWidth() > keyboardViewMaxWidth || addOn instanceof HistoryQuickTextKey;
      if (mIsAutoFitKeyboards[position]) {
        // fixing up the keyboard, so it will fit nicely in the width
        int currentY = 0;
        int xSub = 0;
        for (Keyboard.Key key : keyboard.getKeys()) {
          key.y = currentY;
          key.x -= xSub;
          if (Keyboard.Key.getEndX(key) > keyboardViewMaxWidth) {
            currentY += key.height;
            xSub += key.x;
            key.y = currentY;
            key.x = 0;
          }
        }
        keyboard.resetDimensions();
      }
    }
    keyboardView.setKeyboard(keyboard);
    return root;
  }
@Test
  @Config(shadows = ShadowAnyKeyboardViewWithMiniKeyboard.class)
  public void testPopupListenerDisable() throws Exception {
    ViewGroup container = new LinearLayout(getApplicationContext());
    Object instance0 = mUnderTest.instantiateItem(container, 0);
    final QuickKeysKeyboardView keyboardView0 =
        ((View) instance0).findViewById(R.id.keys_container);

    ShadowAnyKeyboardViewWithMiniKeyboard shadow = Shadow.extract(keyboardView0);
    Assert.assertNotNull(shadow.mPopupShownListener);

    Mockito.verify(mViewPager, Mockito.never()).setEnabled(Mockito.anyBoolean());

    shadow.mPopupShownListener.onPopupKeyboardShowingChanged(true);

    Mockito.verify(mViewPager).setEnabled(false);
    Mockito.verifyNoMoreInteractions(mViewPager);

    Mockito.reset(mViewPager);

    shadow.mPopupShownListener.onPopupKeyboardShowingChanged(false);

    Mockito.verify(mViewPager).setEnabled(true);
    Mockito.verifyNoMoreInteractions(mViewPager);
  }