Relative Content

Tag Archive for javaandroiddrag-and-dropborderlimit

Drag and drop within grid’s boundaries

I know that this topic has been discussed many times but I really need a bit of help as I couldn’t find any solution to my issue.
I will try to brief, android studio project, java.
I have a grid, a shape which takes 5 grid cells made out of 5 images.
The shape it’s grid’s child, it’s defined as a list based on a formula which inlcudes offset rows & columns relative to one image ( so all the other 4 images are aligned in a certain patern relative to the 1st image ).
Please see the image attached ( initial position, no rotation applied ).
All the images have DragAndDropListener so they would behave as a single object.
I have applied drag and drop & snap to the shape, it’s limited within grid’s boundaries.
Here comes my issue, I want to apply rotations by 90 degree to shape.
As the initial size takes 2×4 ( rows x cols ) the 1st rotation would change its size to 4×2 ( rows x cols ).
Bassically the rules that I’ve applied in the ACTION_MOVE ( drag ) won’t apply if the shape it’s rotated.
If I place the shape in a container it would simplify the rules as I would have two sizes: 2×4 or 4×2.
But if I place it in a container the other 3 cells around shape will be available for drag as well and I don’t want that.
Having 4 positions/rotations ( 0/90/180/270 degree ) that means that I would have to define rules for each of them and that it’s kind of static, not exactly optimizing ( so far I have managed to define only 2 of them ).
I have tried to define the grid’s top/left/bottom/right boundaries based on cell IDs ( as general rule that could be applied to any shape & position ) but not successful.
My question it is: How can I limit shape’s movement inside grid’s boundaries based on the imaged cells/shape, no matter it’s rotated or not, a more dynamic rule.
Any suggestion would help me a lot as I’ve been stuck at this issue for a few weeks now.
Thank you in advance!