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

Text in prompt on wrong position when activity smaller then screen and not centered #17

Closed
ElineDeMeyer opened this issue Oct 18, 2016 · 11 comments
Milestone

Comments

@ElineDeMeyer
Copy link

When you have an activity like in your DialogActivity but it is not in the center of the screen (eg at the bottom) the prompt is shown ok but the text in it is positioned wrong.

In my example the targetView is on the top right of my activity but my activity is at bottom center of the window. The targetView is still in the bottom right part of the window.
Parameters tell met the text will be shown above/left of the target but that is not in my activity anymore.

I'm searching for a solution in order to help you out :)

@sjwall
Copy link
Owner

sjwall commented Oct 19, 2016

Hi, it sounds like the prompt should be checking if the view has enough height to display the text above (or below) the target and if it doesn't then display the text it to the side. The other option is to add functionality to disable clipping to the activity bounds so that it could draw outside the activity bounds.

Let me know how you get on searching for a solution. I shall look at expanding the dialog functionality in the sample app to cover having the dialog in different positions and sizes.

@ElineDeMeyer
Copy link
Author

ElineDeMeyer commented Oct 19, 2016

Its ok to draw the prompt inside the bounds. I'm perfectly happy with the prompt. It is only shown in the activity bounds. Just the text is not there.

I think if he knew the parent is not full screen parent decorview but is a coordinatorlayout smaller than the screen, it should be fine.

@ElineDeMeyer
Copy link
Author

ElineDeMeyer commented Oct 20, 2016

Changes I did:

  • in getParentView() where you check if the contentView is a drawer layout, I added comparing the size of the contentView with the one of the decorView in that way we pass the contentView when the activity is not full screen:
if (contentView.getClass().getName().equals("android.support.v4.widget.DrawerLayout")
                    || contentView.getHeight() != decorView.getHeight()
                    || contentView.getWidth() != decorView.getWidth())
  • in updateTextPositioning() when calculating mView.mPrimaryTextTop I added in both cases the getParentView().getTop(). This will be 0 for full screen activity and otherwise we get the position of the text relative to the screen boundaries
mView.mPrimaryTextTop = mView.mCentreTop;
        if (mTextPositionAbove)
        {
            mView.mPrimaryTextTop = mView.mPrimaryTextTop - mBaseFocalRadius - mFocalToTextPadding - mView.mPrimaryTextLayout.getHeight() + getParentView().getTop();
        }
        else
        {
            mView.mPrimaryTextTop += mBaseFocalRadius + mFocalToTextPadding + getParentView().getTop();
        }

1 problem left:
after calculating everything and ready to show, I get an onGlobalLayout event and updateFocalCentrePosition is called again but now it sais that my FAB is top right of my screen and my coordinatorLayout is 2272x1672 instead of the dialogActivity coordinatorLayout that should be 800x780
to test I added android:layout_gravity="center_horizontal|bottom" to the CoordinatorLayout and android:layout_gravity="bottom|end" to the FAB in the activity_dialog_style.xml.

Any idea?

@sjwall
Copy link
Owner

sjwall commented Oct 20, 2016

Hey, thanks for your work. I shall have a look at it and see what I can do to fix it

@ElineDeMeyer
Copy link
Author

Debugged a little further and I saw that the mClipToView when having the onGlobalLayout has a different left and top (left: 64 iso 510 and top: 64 iso 1536). It's then used to update everything and the activity is now larger and almost full screen. mClipToView is still the same mClipToView as before (according to my watches in Android Studio). No idea why it changed yet...

@sjwall
Copy link
Owner

sjwall commented Oct 21, 2016

Still need to do some more testing but changing the text positioning at the end of updateFocalCentrePosition() fixes it for me:

mTextPositionAbove = mView.mCentreTop > mView.mClipBoundsTop + ((mView.mClipBoundsBottom - mView.mClipBoundsTop) / 2);
mTextPositionRight = mView.mCentreLeft > mView.mClipBoundsLeft + ((mView.mClipBoundsRight - mView.mClipBoundsLeft) / 2);

I think this can (and should) be improved further so that it can position the text better when there is limited room

@ElineDeMeyer
Copy link
Author

So only this without my changes?

@sjwall
Copy link
Owner

sjwall commented Oct 21, 2016

Currently without, yes

@sjwall
Copy link
Owner

sjwall commented Oct 24, 2016

@ElineDeMeyer did the changes that I suggested work for you?

@ElineDeMeyer
Copy link
Author

Yes, please include these or an improved solution in one of your next releases :)

@sjwall
Copy link
Owner

sjwall commented Oct 25, 2016

Thanks for your help, it is very much appreciated! The fix is released in v1.5.0

@sjwall sjwall closed this as completed Oct 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants