android-simple-tooltip icon indicating copy to clipboard operation
android-simple-tooltip copied to clipboard

Custom view height is cut on Android 24

Open egandro opened this issue 8 years ago • 15 comments

Hey,

I have an issue on a Nvidia Shield K1 (Android 7.0). The height of a custom view is cut, when the anchor point is on the very top or very bottom of the screen.

On my phones / 10" tablet I don't have this problem.

egandro avatar May 15 '17 17:05 egandro

I debugged this:

mPopupWindow.showAtLocation(mRootView, Gravity.NO_GRAVITY, mRootView.getWidth(), mRootView.getHeight());

The mRootView of my button is the Toplevel Window.

It is called with height = 1920, width = 1200

Which isn't the center position of the button?

egandro avatar May 15 '17 17:05 egandro

I personally think we need something like this:

    int pos[] = new int[2];
    view.getLocationOnScreen(pos); // or this getLocationInWindow()
    popupWindow.showAtLocation(view.getRootView(), Gravity.NO_GRAVITY, pos[0], pos[1]);

egandro avatar May 15 '17 18:05 egandro

The initial position set to showAtLocation is fake, because the final position is calculated later with the arrow position. See this line.

Can you send a picture or screenshot of this problem?

douglasjunior avatar May 15 '17 20:05 douglasjunior

Thx for pointing me to the calculation function. I'll try hunting the bug ;)

It's somehow strange only on the Nvidia Shield K1 (7" / 2015 / 7.0) there is this problem.

I'll send you a merge request or a sample project if I can't find the issue.

Thx!

egandro avatar May 16 '17 15:05 egandro

@egandro I think I found the problem, but not the solution yet.

On Android 24, apparently, PopupWindow changed behavior when it did not fit the screen. In previous versions the PopupWindow position was adjusted automatically, without changing the size.

See on Android 23 (position adjusted): android-23

But, on Android 24 the size is adjusted automatically: android-24

I will work to find a solution, but suggestions are welcome 😄

douglasjunior avatar May 25 '17 02:05 douglasjunior

Hey!

I got a hint from a friend.

It might be this flag:

https://developer.android.com/reference/android/widget/PopupWindow.html#attr_android:overlapAnchor

Can you give it a try?

Thx.

egandro avatar Jun 01 '17 09:06 egandro

In my tests overlapAnchor did not work. But I found the source for this behavior, it's the property setClippingEnabled.

Setting setClippingEnabled(false) allows PopupWindow to override the screen boundary. See a example:

gravity end

But if the PopupWindow stays outside the screen, it can be hidden.

gravity bottom

Researching a little, I saw that the behavior of PopupWindow was changed on Android 24 and 25, but I'm not sure that this will change in the future.

  • https://stackoverflow.com/questions/39673099/android-nougat-popupwindow-showasdropdown-gravity-not-working
  • https://stackoverflow.com/questions/41973893/android-nougat-7-1-1-showatlocation-gravity-not-working

I've created a test branch (https://github.com/douglasjunior/android-simple-tooltip/commit/632b0289eb3a2943ff3bf49cb0271473186f560a), if you'd like to check it out.

dependencies {
    // ...
    compile ('com.github.douglasjunior:android-simple-tooltip:issue-40-SNAPSHOT') {
        changing = true // Gradle will then check for updates every 24 hours
    }
}

douglasjunior avatar Jun 01 '17 13:06 douglasjunior

Thx man! I'll give it a try. In a view minutes.

egandro avatar Jun 01 '17 15:06 egandro

image

Have a look. It still hast the issue on the K1 :(

egandro avatar Jun 01 '17 15:06 egandro

Yes, the only solution I think is calculating the position manually.

douglasjunior avatar Jun 01 '17 16:06 douglasjunior

I have an idea ;)

You can take the calculation algorithm from <24 and put it in your code.

Check the license if this is ok. But that would fix it 100%

egandro avatar Jun 01 '17 17:06 egandro

It's not that simple, I'll keep thinking about a solution.

One suggestion, your Tooltip has a lot of information, it was not designed to be so big.

Would not it be better to display this layout in a Dialog? Or a tooltip centered on the screen?

douglasjunior avatar Jun 06 '17 11:06 douglasjunior

I experimented with this a lot:

  1. Context Menu
  2. Dialog
  3. Adding more buttons to the Listview Row
  4. Adding multiple checkboxes to the Listview Row

My designer came up with the Popup solution as wie have it in the android simple tooltip.

The user experience is very very cool - it's consumes less space - and despite having the same amount of clicks - the users love the tooltip style as it is fast and integrates fluently in the workflow.

The dialog or the (default) context menu is a lot of slower and the user has to move the finger for a 20% longer distance ;)

You might have a look at the bottom of this page. This is (ugly) Javascript - but it's the algorithm to place a content menu depending on a pivot point:

https://stackoverflow.com/questions/15795253/positioning-context-menu

Check this on jsfiddle:

http://jsfiddle.net/AkshayBandivadekar/zakn7Lwb/14/

egandro avatar Jun 06 '17 12:06 egandro

You can apply code on SimpleToolTip.java

At Line 38x : private final ViewTreeObserver.OnGlobalLayoutListener mLocationLayoutListener

Before call update PopupWindow

mPopupWindow.update((int) location.x, (int) location.y, mPopupWindow.getWidth(), mPopupWindow.getHeight());

Apply this

 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                int popupHeight = mPopupWindow.getContentView().getMeasuredHeight();
                int endOfPopupY = popupHeight + (int) location.y;
                if (endOfPopupY > getScreenHeight()) {
                    location.y = (getScreenHeight() - popupHeight);
                }
            }

@egandro @douglasjunior

ThanawatMas avatar Feb 09 '18 04:02 ThanawatMas

Thanks @ThanawatMas , I'll look soon.

douglasjunior avatar Feb 09 '18 10:02 douglasjunior