Android Question DraggableView Class Issue

mjtaryan

Active Member
Licensed User
Longtime User
I am creating a puzzle with moveable pieces (Panels I've called "Tiles"). The setup for this is complete and I'm working on being able to drag the pieces. However, the puzzle has certain rules. These are:
  1. A piece can only be moved to an adjacent grid location.
  2. The grid location must be open (blank or free).
  3. The piece can only be moved horizontally (x) or vertically (y). It cannot be moved diagonally.
Because of these constraints, the code needs to have access to various data that is not contained in the Tile (panel) being moved. I cannot find a way to share this data with the DraggableView class module. (The only solution I've come up with that appears to have the potential of working is to not use the DraggableView, but use the touch event code from the class module - with modifications - in the activity itself. I've tested part of this and the dragging works). Does anyone have other viable suggestions where the DraggableView class can be used?? Thanks.
 

mjtaryan

Active Member
Licensed User
Longtime User
You can pass an array of panels to the class and save it as a global variable. You will then be able to use it whenever needed.

Thanks Erel,

Although I didn't try defining the whole array of panels as DraggableView, I did define each element individually. Each of the individual elements moved. However, given the restraints listed in my original post, I also need to access the "grid" and the current grid location of the free space. The Grid is an integer array (MaxElements, 3). MaxElements depends on the puzzle"s cocmplexity level. The other dimension is: 0 = occupied/not occupied (1/0), 1 = Left edge of grid cell, 2 = Top edge of grid cell. The free space (Free) is a pointer (integer) that holds the Grid element number of the free space.

As the "Tiles" are moved, the location of the free space will change (will be swapped with the Tile being moved). It is the entire Grid array and Free to which I need access and to be able to change as needed. I would add the necessary procedures/functions to the DraggableView class module but I don't know how and when to declare pass these variables. If the entire array of panels could be defined and initialized (not element by element), I suppose I could add the grid array to the class module's Sub Initialize. But I will need Free as well, which dynamically changes with each moved piece. How/Where do I define these and where do I pass them? I hope I am being clear in my description and questions. Thanks.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
You can pass any object you like to the classes. The object is not copied. Only its reference is copied.

Thanks Erel. I worked with the test project I created some more and got it to work the way I want/need. I don't know if what I did is what you meant in the above quote. For my particular version of the DraggableView class I declared the variables to which I need read/write access in the actual Activity's "Sub Process_Global" (I tried declaring them in "Sub Globals" but got a 'used before declaration' error). Then, in the class module, I referenced these variables in the usual manner (i.e. "<activity name>.<variable name>). And the DraggableView class works perfectly. But, is this what you meant above? Thanks again.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
This is one option. The other option is to pass the variables to the class as sub parameters and store it in the class globals. However both options are good.

Thanks Erel. In my test I tried what you suggest here - at least that is what I think I did. I copied the passed variable (v) to one declared in Sub Class Global (innerView). However, when I did that, when innerView.Left and innerView.Top changed, the corresponding properties of v did not. That's why I opted to use the method described in my previous post. Since that method is working, even if it may be less elegant, I think I'll stick with it at least for now, particularly because my needs are rather specific to the one app in which I will be using this modified/epanded version of the DraggableView class. Thanks again.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Oh, oh! I now have a few more related questions. Should I start a new thread?
 
Upvote 0
Top