Get height of peek card before any are displayed?

故事扮演 提交于 2019-12-11 04:18:21

问题


According the the API docs, all peek cards will only be "a single line tall" when PEEK_MODE_SHORT is set. So this means every peek card will occupy a constant of screen real estate for a particular device.

I plan to leverage this on my watch face by placing the most important info in the area that's guaranteed not to be covered by a card (and the non-critial info in the space which could be covered by a card).

The problem is I don't know how to determine how much space the peek cards take until onPeekCardPositionUpdate(), which is too late, because I want the rest of the layout to take into consideration where the peek cards will go.

TL;DR - Any ideas on how to get the peek card positions before onPeekCardPosition() is called?

EDIT: The reason I need the peek card height is because I'm looking to ensure that something will be fully covered when the peek card is displayed. Like #1 below:


回答1:


No, we didn't provide any API to determine the height of the peek card. You should use onPeekCardPositionUpdate() and make your watch face adjust, when it receives the notification.

I understand that you would like to always put your content above the peek card and be done with it. However, this is not a good idea - you will be wasting real estate available to you on the screen. The user might decide to disable the peeking (there are options available for this) after which you will be left with empty space at the bottom of the screen. Or the user might not have cards in the stream, in which case again, you will be left with empty space at the bottom.

This callback is provided for a reason, so you can dynamically adjust your watch face both when a card is peeking and when it's not and allow users to have best experience in either case.

EDIT:

In your specific case, I would recommend doing this: in your drawing code check the current bounds of the peek card (getPeekCardPosition()). If they are (0-0, 0-0), this means there is no peek card and you can draw the optional piece of content. If the bounds are different, don't draw it. It should be as easy as that. You also want to trigger redraw when the callback about the card bounds comes.



来源:https://stackoverflow.com/questions/28849459/get-height-of-peek-card-before-any-are-displayed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!