@Override
  public void showPreviewForKey(Keyboard.Key key, CharSequence label, Point previewPosition) {
    mPreviewIcon.setVisibility(View.GONE);
    mPreviewText.setVisibility(View.VISIBLE);
    mPreviewIcon.setImageDrawable(null);
    mPreviewText.setTextColor(mPreviewPopupTheme.getPreviewKeyTextColor());

    mPreviewText.setText(label);
    if (label.length() > 1 && key.getCodesCount() < 2) {
      mPreviewText.setTextSize(
          TypedValue.COMPLEX_UNIT_PX, mPreviewPopupTheme.getPreviewLabelTextSize());
    } else {
      mPreviewText.setTextSize(
          TypedValue.COMPLEX_UNIT_PX, mPreviewPopupTheme.getPreviewKeyTextSize());
    }

    mPreviewText.measure(
        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

    showPopup(
        key, mPreviewText.getMeasuredWidth(), mPreviewText.getMeasuredHeight(), previewPosition);
  }
@Test
  public void testPreviewLayoutCorrectlyForNoneLabel() {
    PreviewPopupTheme theme = new PreviewPopupTheme();
    theme.setPreviewKeyBackground(
        ContextCompat.getDrawable(getApplicationContext(), blacktheme_preview_background));
    theme.setPreviewKeyTextSize(1);
    final KeyPreviewPopupWindow underTest =
        new KeyPreviewPopupWindow(
            getApplicationContext(), new View(getApplicationContext()), theme);

    PopupWindow createdPopupWindow =
        Shadows.shadowOf((Application) ApplicationProvider.getApplicationContext())
            .getLatestPopupWindow();
    Assert.assertNull(createdPopupWindow);

    Keyboard.Key key = Mockito.mock(Keyboard.Key.class);
    Mockito.doReturn((int) 'y').when(key).getPrimaryCode();
    Mockito.doReturn(1).when(key).getCodesCount();
    key.width = 10;
    key.height = 20;
    underTest.showPreviewForKey(key, "y", new Point(1, 1));

    createdPopupWindow =
        Shadows.shadowOf((Application) ApplicationProvider.getApplicationContext())
            .getLatestPopupWindow();
    Assert.assertNotNull(createdPopupWindow);
  }