Android: programmatically get position of the widget on desktop relative to other widgets -


On Android, a user can place a widget on the desktop and then touch it for long and keep the fingers moving forward. Could.

Is it possible to get the position on the screen on the screen, where the widget was touched for a long time?

I need my desktop widget to have it near the edge of the screen, depending on the device's desktop or at the bottom of the widget, depending on what will happen.

I hope this situation has not been given in pixels, but as a pair of 0-based indexes. As if the device can display 4x7 cells on the desktop, the widgets in the lower-right corner should have cores (3, 6).

Or am I doing some misunderstanding?

With Android 2.1 and later, with some select home screens, you can find out that the app Where the widget is located, when clicked through getSourceBounds () - this value is associated with any intent that you pending via setOnClickPendingIntent () .

However:

  • It only works on Android 2.1 and newer
  • Not all Home screens can do this, because this launcher code is part of IIRC
  • Coordinate pixels are in IIRC
  • there is no way to inquire from the Home screen because this information is any Also, it is also known in other ways, because there is no API to interact with the Home screen

    Therefore, I Its stated goal ( "it decided depending on the different layouts below the top of the desktop or widget") is impossible, I think.

Comments