Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom view height is cut on Android 24 #40

Closed
egandro opened this issue May 15, 2017 · 15 comments
Closed

Custom view height is cut on Android 24 #40

egandro opened this issue May 15, 2017 · 15 comments

Comments

@egandro
Copy link

egandro commented May 15, 2017

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
Copy link
Author

egandro commented May 15, 2017

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
Copy link
Author

egandro commented May 15, 2017

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]);
@douglasjunior
Copy link
Owner

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?

@egandro
Copy link
Author

egandro commented May 16, 2017

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!

@douglasjunior
Copy link
Owner

@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 douglasjunior changed the title Custom view height is cut May 25, 2017
@egandro
Copy link
Author

egandro commented Jun 1, 2017

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.

@douglasjunior
Copy link
Owner

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.

I've created a test branch (632b028), 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
    }
}
@egandro
Copy link
Author

egandro commented Jun 1, 2017

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

@egandro
Copy link
Author

egandro commented Jun 1, 2017

image

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

@douglasjunior
Copy link
Owner

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

@egandro
Copy link
Author

egandro commented Jun 1, 2017

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%

@douglasjunior
Copy link
Owner

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?

@egandro
Copy link
Author

egandro commented Jun 6, 2017

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/

@ThanawatMas
Copy link

ThanawatMas commented Feb 9, 2018

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

@douglasjunior
Copy link
Owner

Thanks @ThanawatMas , I'll look soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants