14

I am making a Keyboard which shows a popupWindow of languages. In all device, I get perfect popupWindow outside of keyboard but in only Android Pie, I can not show popupWindow outside of the keyboard.

I want to show popup outside of keyboard's candidateView when Bluetooth keyboard is connected.

I am using this code

setClippingEnabled(false);
showAtLocation(anchor, Gravity.NO_GRAVITY, x, y);

Does someone have any idea, what is the issue?

here is demo app - https://github.com/priyankagb/andoidpiepopupwindowdemo

see screenshots,

In Android Pie in which you can see a small line at the bottom which is popupWindow for languages

Left is Below Pie, Right is Pie

Blundell
  • 75,855
  • 30
  • 208
  • 233
Priyanka
  • 3,369
  • 1
  • 10
  • 33
  • Have your tried manually setting the width and height of the popup window using `setWidth()` and `setHeight()` methods – Syed Ahmed Jamil Jul 07 '19 at 14:04
  • yes, I tried this, but no result. – Priyanka Jul 08 '19 at 04:19
  • From how it looks it seems that the popup window is not inflating at the first place. Because if it were behind the keyboard we could still see some of it right ? – Syed Ahmed Jamil Jul 08 '19 at 05:09
  • you can see the popup window in Pie below flag(small white line), but in below pie, popup window automatically set its position on the upper side, but this is not happening in Android Pie. – Priyanka Jul 08 '19 at 05:34
  • Yes I can see the white line but where is the rest of its body if it actually inflated. My guess is it is not inflating at all in Pie. Try creating an empty project targeting only Pie and just display a simple popup window using similar code you wrote before and see if that works. – Syed Ahmed Jamil Jul 08 '19 at 05:38
  • its layout is inflating, I have checked by making keyboard hight more than popup windows layout hight than I can see full popup window below the flag – Priyanka Jul 08 '19 at 05:41
  • take a note that the view is showing for prediction is a candidate view of keyboard – Priyanka Jul 08 '19 at 05:49
  • I remember I face a problem with `Gravity.NO_GRAVITY` before but I can not remember exactly. In your case I think you can try to use `Gravity.TOP`, hope it help – Linh Jul 08 '19 at 07:13
  • @PhanVanLinh, I tried this, but not working – Priyanka Jul 08 '19 at 07:26
  • do you have any simple demo project for this issue, if you have, you can share the demo to question and we can try to find – Linh Jul 08 '19 at 07:27
  • No, I don't have – Priyanka Jul 08 '19 at 07:29
  • 2
    @PhanVanLinh, I have created a demo app, please see this link. https://github.com/priyankagb/andoidpiepopupwindowdemo – Priyanka Jul 08 '19 at 08:08
  • @Priyankagb, in your example, why you need this `if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) popupWindowAbove.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);`. if you remove this check your popup will display correct – Linh Jul 08 '19 at 08:48
  • yes, it'll display correctly but only in the demo, still in my application, I'm facing an issue. By removing that line, now popup window is showing upside, but not showing full popup, it's only small line above the flag. see this screenshot - https://ibb.co/MD14SPg – Priyanka Jul 08 '19 at 10:39
  • @PhanVanLinh see what happen when I change the height of `candidateView` https://ibb.co/VNjTJv4 – Priyanka Jul 08 '19 at 11:00
  • @Priyankagb, can you reproduce it in your demo again. I can help you fix it – Linh Jul 08 '19 at 11:08
  • ok. let me try. – Priyanka Jul 08 '19 at 11:08
  • @PhanVanLinh I have pushed code on Github. Please checkout latest code. The same issue is there on the keyboard. I have made a custom keyboard. Please select `andoidpiepopupwindowdemo` keyboard for testing. Popup will open on click of setting icon of candidate view – Priyanka Jul 08 '19 at 12:43
  • @PhanVanLinh are you got any solution? – Priyanka Jul 09 '19 at 11:26
  • Not yet. I see the problem but still not find a solution for it. – Linh Jul 09 '19 at 12:10
  • @PhanVanLinh see that `TextView`s are clickable in the demo, but they are not showing to us. Strange!!!! – Priyanka Jul 10 '19 at 09:32
  • Yes. Dont know what wrong with android Pie. I see we can not show popupwindow out of keyboard view. I think you can make the demo project more simple (remove all unnecesary thing) and send issue to Google issue tracker – Linh Jul 10 '19 at 09:38

2 Answers2

3

Yes, I have solved my issue by changing my keyboard's layout file

I have added one dummy view above candidate view

like...

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <View
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toTopOf="@+id/rlPredictionView" />

    <RelativeLayout
        android:id="@+id/rlPredictionView"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@drawable/background_with_shadow_prediction_bar"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent">

        ...

    </RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

than override this method in InputMethodService class

 @Override
    public void onComputeInsets(InputMethodService.Insets outInsets) {
        super.onComputeInsets(outInsets);
        outInsets.visibleTopInsets = candidateView.getRelativeView().getTop();
        outInsets.contentTopInsets = candidateView.getRelativeView().getTop();
    }

dummy view above rlPredictionView will set visibleTopInsets of the keyboard and in this area, the popup will show

this dummy view will allow accessing background view on touch so this will not visible to the user

Reference - https://stackoverflow.com/a/53326786/10989990

Priyanka
  • 3,369
  • 1
  • 10
  • 33
0

Add following code where your popupWindow will show

[view].getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
            public void onGlobalLayout(){
                int screenHeight = [view].getRootView().getHeight();
                Rect r = new Rect();
                View view = getWindow().getDecorView();
                view.getWindowVisibleDisplayFrame(r);
                int keyBoardHeight = screenHeight - r.bottom;
                if ( keyBoardHeight > 150 ){
                    // keyboard is showing, set popup window above keyboard height
                } else {
                    // keyboard gone, restore popup window location to center screen
                }
            }
        });

Replace [view] with your views

BahmanWorld
  • 23
  • 2
  • 10
  • Tx for answer, but its not useful for me, I am already showing popup above & below properly, but the question is that why in Android Pie I can not show popup out of the keyboard. – Priyanka Jul 15 '19 at 06:10