Dragging movement collision method and device, computer equipment and storage medium
By recording and comparing the positions of buttons in the grid, the problem of dragging and dropping across the grid is solved, and the smooth drag and placement of buttons is achieved, improving the operating experience and smoothness of the on-board system.
Patent Information
- Application Number
- CN202410922044.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-11-15
AI Technical Summary
In existing on-board systems, buttons cannot be dragged from the left grid to the right grid, and dragging will affect the layout of all button positions in the current grid.
By obtaining the set of button positions in the current grid, we judge the button type and the lattice position occupied, record and compare positions in the drag event, judge whether a collision occurs, and move the button as a whole to open the position according to the direction, realize the cross-border button Drag and place the grid.
It realizes smooth drag and placement between buttons, improves the smoothness and ease of use of quick operation buttons, and meets the layout display of 1×1, 2×2, and 4×1 types of buttons.
Smart Images

Figure CN118963633A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of vehicle-mounted technology, and in particular to a dragging movement collision method, device, computer equipment and storage medium. Background Art
[0002] In the current in-vehicle system, the quick operation page is a common interface that allows users to control some quick operations while driving. This page will display some function buttons related to vehicle quick operations, and the page will be divided into two grid layouts on the left and right. The rows and columns of the left and right grids are 4×4 respectively. These buttons are of 1×1, 2×2 and 4×1 types. 1×1 refers to a grid display occupying 1 column and 1 row, 2×2 refers to a 4-grid display occupying 2 rows, 2 columns and 2 rows, and 4×1 refers to a 4-grid display occupying 4 rows, 1 column and 1 row. Users are supported to manually add and delete and drag these buttons to the page grid.
[0003] In the existing method, the layout buttons of the vehicle quick operation page are realized by dragging, moving and colliding, and the RecyclerView and ItemTouchHelper solutions are generally used. The left and right 4×4 areas use two RecyclerViews to realize the grid layout, and the dragging, moving and colliding are assisted by ItemTouchHelper. The ItemHelpCallback listens to the onMove method, and the reordering of the grid buttons after the dragging, moving and colliding is realized in onMove.
[0004] The two RecyclerView grid layouts divided by the existing solution cannot drag and move buttons from the left grid to the right grid. It can only perform movement and collision logic in the current RecyclerView grid, and the drag and move collision of this solution will affect the position arrangement of all buttons in the current grid. Summary of the invention
[0005] The purpose of the embodiments of the present invention is to propose a drag-and-move collision method, device, computer equipment and storage medium to solve the problem that in the existing layout button drag-and-move collision, the button cannot be dragged from the left grid to the right grid, and the drag-and-move collision will affect the position arrangement of all buttons in the current grid.
[0006] In order to solve the above technical problems, the present invention provides a drag movement collision method, which adopts the following technical solution, including the steps of:
[0007] S1. Obtain the button position set CurrentExitList that records the button positions placed in the current grid;
[0008] S2. Get the position coordinates (x, y) of the current button in the GridLayout grid in the drag event;
[0009] S3, loop through the GridLayout grid, determine the current button type and which grids the current button occupies after moving, and record the position of the occupied grid into the current grid set CurrentList;
[0010] S4, determine whether the elements in CurrentList are in CurrentExitList, otherwise it is determined that the current button movement has not collided, and the button can be placed at this position after releasing the button, and the position position is removed from the current grid set CurrentList and put into the button position set CurrentExitList, if yes, it is determined that the current button movement has collided, and enter step S5;
[0011] S5. Determine the direction in which the current button moves, determine the buttons that can be moved to the collision position, move them one grid as a whole, and leave the current position for the dragged button, determine whether it can be placed according to the button type, and if it can be placed, place it according to the direction in which the current button moves.
[0012] Preferably, the step of S1, obtaining a button position set CurrentExitList recording the button positions position placed in the current grid, specifically further comprises:
[0013] S11, read the button configuration table;
[0014] S12, looping through the button configuration table, and putting the valid button positions position recorded in the button configuration table into the button position set CurrentExitList. Preferably, the step of S2, obtaining the position coordinates (x, y) of the current button moved to the GridLayout grid in the drag event, specifically comprises:
[0015] S21. Set a drag event listener for the grid;
[0016] S22. When the dragged button enters the grid area, an entry event notification is issued, and the position coordinates (x, y) of the current button moving to the grid area are provided.
[0017] Preferably, the step of looping through the GridLayout grid, determining the current button type and the grids occupied by the current button after it moves, and recording the position of the occupied grid into the current grid set CurrentList specifically includes:
[0018] S31, in the grid drag event monitoring, after receiving the entry event notification sent by the front end, loop through each grid of the grid and compare the coordinates sent in the drag event with the position of the grid;
[0019] S32, if the horizontal coordinate x is greater than the position of the left side of the grid from the screen, that is, the left value of the grid, and less than the position of the right side of the grid from the screen, that is, the right value of the grid, then it is determined that the button is within the horizontal axis of the grid;
[0020] S33, if the vertical coordinate y is greater than the position of the top of the grid from the screen, that is, the top value of the grid, and less than the position of the bottom of the grid from the screen, that is, the bottom value of the grid, then it is determined that the button is within the vertical axis of the grid;
[0021] S34, if the button is within the horizontal axis of the grid and within the vertical axis of the grid, it is determined that the current button movement occupies the current grid, and the position position of the occupied grid is recorded in the current grid set CurrentList. Preferably, the S4, determines whether the elements in CurrentList are in CurrentExitList, otherwise it is determined that the current button movement has not collided, and the button can be placed at this position after releasing the button, and the position position is removed from the current grid set CurrentList and put into the button position set CurrentExitList. If yes, it is determined that the current button movement has collided, and the step of entering step S5 specifically includes:
[0022] S41, traverse CurrentList, obtain the position information in CurrentList, traverse CurrentExitList, determine whether the position information in CurrentList is the same as the position information in CurrentExitList, if they are the same, determine that a button collision occurs, otherwise, no button collision occurs;
[0023] S42. If no button collision occurs, the button is added to the grid, the addView method of the grid container is used to add the button to the grid container, and the button is drawn and displayed on the device screen. Then the position is removed from the CurrentList and placed in the CurrentExitList to indicate that a button has been placed at this position.
[0024] Preferably, the step of S5, determining the direction of movement of the current button, determining the buttons at the collision position that can be moved, moving them as a whole by one grid, leaving the current position for the dragged button, determining whether the button can be placed according to the button type, and if the button can be placed, placing the buttons according to the direction of movement of the current button specifically includes:
[0025] S51, determining the direction in which the current button moves;
[0026] S52. According to the direction of movement of the current button, determine the button that can be moved to the collision position, then move the buttons that can be squeezed away by one grid as a whole, leaving the current position for the dragged button, and determine whether it can be placed according to the button type. If it can be placed, place it according to the direction of movement of the current button.
[0027] In order to solve the above technical problems, the present invention further provides a dragging movement collision device, which adopts the following technical solution, including:
[0028] The first acquisition module is used to acquire a button position set CurrentExitList recording the button positions placed in the current grid;
[0029] The second acquisition module is used to obtain the position coordinates (x, y) of the current button moved to the GridLayout grid in a drag event;
[0030] The recording module is used to loop through the GridLayout grid, determine the current button type and which grids the current button occupies after moving, and record the position of the occupied grid into the current grid set CurrentList;
[0031] The judgment module is used to judge whether the elements in CurrentList are in CurrentExitList. If not, it is judged that the current button movement has not collided. After releasing the button, the button can be placed at this position, and the position position is removed from the current grid set CurrentList and put into the button position set CurrentExitList. If yes, it is judged that the current button movement has collided.
[0032] The placement module is used to determine the direction in which the current button is moving. If the buttons at the collision position can be moved, they will be moved one grid as a whole to make room for the dragged button. It is also used to determine whether the buttons can be placed based on the button type. If they can be placed, they will be placed in the direction in which the current button is moving.
[0033] Preferably, the placement module comprises:
[0034] The direction determination module is used to determine the direction in which the current button moves;
[0035] The processing module is used to determine the buttons that can be moved to the collision position according to the direction of the current button movement, and then move the buttons that can be squeezed away by one grid as a whole to vacate the current position for the dragged button. It is also used to determine whether the buttons can be placed according to the button type. If they can be placed, they are placed according to the direction of the current button movement.
[0036] In order to solve the above technical problems, the present invention also provides a computer device, which adopts the technical solution described below, including a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the above-mentioned drag-move collision method when executing the computer-readable instructions.
[0037] In order to solve the above technical problems, the present invention also provides a computer-readable storage medium, which adopts the technical solution described below, and stores computer-readable instructions on the computer-readable storage medium. When the computer-readable instructions are executed by the processor, the steps of the above-mentioned drag-move collision method are implemented.
[0038] Compared with the prior art, the present invention has the following beneficial effects: when dragging 1×1, 2×2, and 4×1 type buttons, the buttons at the position can be bumped apart, and there is no need to delete the existing buttons at the position and then place them again. This can meet the layout display of 1×1, 2×2, and 4×1 types of in-vehicle quick operation buttons, and can improve the smoothness and ease of dragging the quick operation buttons. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the scheme in the present invention, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0040] Figure 1 is a flow chart of an embodiment of the drag-move collision method of the present invention;
[0041] Figure 2 It is a schematic diagram of buttons of 1×1, 2×2, and 4×1 types used in the drag-move collision method of the present invention;
[0042] Figure 3 It is a structural schematic diagram of an embodiment of the drag-and-move collision device of the present invention;
[0043] Figure 4 It is a schematic structural diagram of an embodiment of a computer device of the present invention. DETAILED DESCRIPTION
[0044] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present invention; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention; the terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present invention or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0045] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0046] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings.
[0047] It should be noted that the drag-and-move collision method provided in the embodiment of the present invention is generally executed by a server / terminal device, and accordingly, the drag-and-move collision device is generally disposed in the server / terminal device.
[0048] It should be understood that the number of terminal devices, networks and servers is only illustrative. Depending on the implementation requirements, there can be any number of terminal devices, networks and servers.
[0049] Embodiment 1
[0050] Please refer to Figure 1 , shows a flow chart of an embodiment of the drag-and-move collision method of the present invention. The drag-and-move collision method comprises the following steps:
[0051] Step S1, obtaining a button position set CurrentExitList recording the button positions placed in the current grid.
[0052] In this embodiment, the electronic device (e.g., server / terminal device) on which the drag-move collision method is executed can receive the drag-move collision request via a wired connection or a wireless connection. It should be noted that the wireless connection method may include but is not limited to 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAXX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.
[0053] Figure 2 1×1, 2×2, 4×1 buttons used in the drag-and-drop collision method of the present invention. Figure 2 As shown, the button types involved in this embodiment include 1×1 type, 2×2 type and 4×1 type.
[0054] In this embodiment, step S1, obtaining a button position set CurrentExitList recording the button positions position placed in the current grid may specifically include the following steps:
[0055] S11, read the button configuration table.
[0056] Each time an electronic device is turned on, the button configuration table is read. This step mainly loads the current button information configuration.
[0057] In GUI application development, reading the button configuration table is a key step, which ensures that the behavior and appearance of the button are consistent with the predefined specifications. The configuration table is usually a structured file containing information about the button, such as XML or JSON format. This information may include the button's text, size, color, font, and click event handler functions.
[0058] S12, looping through the button configuration table, and putting the valid button positions position recorded in the button configuration table into the button position set CurrentExitList.
[0059] For configuration tables in XML format, you can use an XML parsing library (such as DOM or SAX) to parse the file and extract the button configuration information. For configuration tables in JSON format, you can use a JSON parsing library (such as Jackson or Gson) to parse the JSON string and convert it into a data structure that the program can process.
[0060] During the parsing process, it is necessary to locate the specific button configuration information based on the structure of the configuration table. This involves traversing XML elements or JSON objects and extracting corresponding values based on tag names or key names.
[0061] Once the button configuration information is successfully read, it can be applied to the button control in the GUI application, ensuring that the button's behavior and appearance are consistent with the predefined specifications.
[0062] The button configuration table records the subscript position of the button. Loop through the button configuration table collection. If the subscript position of the button is not -1, it means that the button is placed in the grid. This step is mainly to identify which buttons' subscript position is valid, and then put the valid button's subscript position into the button position collection CurrentExitList.
[0063] Step S2, obtaining the position coordinates (x, y) of the current button moved to the GridLayout grid in the drag event.
[0064] A drag event means that after a user presses and holds a button in a certain area on the device screen, the user can drag the button to another location.
[0065] In this embodiment, step S2, obtaining the position coordinates (x, y) of the current button moved to the GridLayout grid in the drag event, may specifically include the following steps:
[0066] S21, setting a drag event listener for the grid.
[0067] Setting up drag event listeners for a grid is an interactive requirement that allows users to reorder or perform other actions by long-pressing and dragging grid items.
[0068] Register a drag listener on each grid item. This can be achieved by setting OnLongC lickListener in ViewHolder. When the user long presses a grid item, a drag operation will be triggered. During the drag process, the system will pass the drag event through the DragEvent class. Developers can override the methods in View.OnDragListener to handle these events.
[0069] The main purpose of the drag event listener is to provide intuitive interaction between users and grid items. By dragging, users can easily reorder grid items. Drag event listeners can also be used in conjunction with other interaction methods (such as click, double-click, etc.) to provide users with a richer operating experience.
[0070] S22, when the dragged button enters the grid area, an entry event notification is issued, and the position coordinates (x, y) of the current button moving to the grid area are provided.
[0071] When implementing the function of dragging a button into a grid area and sending an entry event notification, you can combine front-end event monitoring, drag libraries (such as jQuery UI, Vue.Draggab le, etc.) and back-end communication mechanisms.
[0072] In specific implementation, the front end will bind a drag event to the button, and when the button is dragged, the button's position is calculated in real time. When the button is dragged and dropped into the grid area, the front end will determine whether the button's coordinates fall within the valid range of the grid. Once it is confirmed to enter the grid area, the front end can send an entry event notification to the back end through Ajax requests or WebSocket, etc., and carry the current button's position coordinates (x, y) in the grid.
[0073] This feature is useful in many scenarios. For example, in a visual layout editor, users can quickly arrange page elements by dragging buttons to specified grid positions; in map applications, the drag function can be used to mark locations or place annotations; in game development, it can be used to move and place characters or items. By sending entry event notifications and location coordinates, the backend can process the user's drag operation in real time, realizing rich interactive logic and business functions.
[0074] Step S3, looping through the GridLayout grid, determining the current button type and which grids the current button occupies after moving, and recording the position of the occupied grid into the current grid set CurrentList.
[0075] In this embodiment, step S3, looping through the GridLayout grid, determining the current button type and which grids the current button occupies after moving, and recording the position of the occupied grid into the current grid set CurrentList, may specifically include the following steps:
[0076] S31, in the grid drag event monitoring, after receiving the entry event notification sent by the front end, loop through each grid of the grid and compare the coordinates sent in the drag event with the position of the grid.
[0077] S32, if the horizontal coordinate x is greater than the position of the left side of the grid from the screen, that is, the left value of the grid, and less than the position of the right side of the grid from the screen, that is, the right value of the grid, then it is determined that the button is within the horizontal axis of the grid.
[0078] S33, if the vertical coordinate y is greater than the position of the top of the grid from the screen, that is, the top value of the grid, and less than the position of the bottom of the grid from the screen, that is, the bottom value of the grid, then it is determined that the button is within the vertical axis of the grid.
[0079] S34, if the button is within the horizontal axis of the grid and within the vertical axis of the grid, it is determined that the current button moves to occupy the current grid, and the position position of the occupied grid is recorded in the current grid set CurrentList.
[0080] Because it is a loop traversal, the current grid position can be known, and the position of the grid occupied is recorded in CurrentList. If the current button type is 1×1, the drag and move of the 1×1 type button only needs to record the current position in the grid. For example, if the current selection is 1, then 1 is put into CurrentList.
[0081] If the current button type is 2×2, the dragging and moving of the 2×2 button needs to record the 4 positions currently occupied in the grid. For example, if the currently selected position is 1, then (1, 2, 5, 6) is put into CurrentList.
[0082] If the current button type is 4×1, the dragging and moving of the 4×1 button needs to record the 4 positions currently occupied in the grid. For example, if the currently selected position is 1, then (1, 2, 3, 4) is put into CurrentList.
[0083] Step S4, determine whether the elements in CurrentList are in CurrentExitList, otherwise it is determined that no collision occurs in the current button movement. After releasing the button, the button can be placed at this position, and the position is removed from the current grid set CurrentList and placed in the button position set CurrentExitList. If so, it is determined that a collision occurs in the current button movement, and proceed to step S5.
[0084] The placement process means: the button itself is a control view, the grid is a control container, and you can use addView to add some control views to the device. The addView process is that the machine sends a drawing signal to notify the system to draw and layout the controls.
[0085] CurrentList stores the position information of the grid occupied by the current button during dragging, and CurrentExitList stores the position information of the buttons already placed in the current grid.
[0086] In this embodiment, step S4 may further include the following steps:
[0087] S41, traverse CurrentList, obtain the position information in CurrentList, traverse CurrentExitList, and determine whether the position information in CurrentList is the same as the position information in CurrentExitList. If they are the same, it is determined that a button collision occurs, otherwise, no button collision occurs.
[0088] S42, if no button collision occurs, the button is added to the grid, the addView method of the grid container is used to add the button to the grid container, and it is drawn and displayed on the device screen, and then the position is removed from the CurrentList and put into the CurrentExitList to indicate that a button has been placed at this position.
[0089] Step S5, determine the direction of movement of the current button, determine the button that can be moved to the collision position, then move the buttons that can be squeezed away by one grid as a whole, leaving the current position for the dragged button, and determine whether it can be placed according to the button type. If it can be placed, place it according to the direction of movement of the current button.
[0090] A button that can move the collision position refers to a button that can be pushed aside to make room during the collision process.
[0091] The DragEvent.ACTION_DRAG_LOCATION event refers to the button position change event sent by the front end after the grid sets the drag event and the button is dragged to the grid area.
[0092] In this embodiment, step S5 may further include the following steps:
[0093] S51, determining the direction in which the current button moves.
[0094] Get the button position coordinates (x1, y1) and (x2, y2) of the two DragEvent.ACTION_DRAG_LOCATION events. If the absolute value of the second x-axis coordinate value minus the first x-axis coordinate value is greater than the absolute value of the second y-axis coordinate value minus the first y-axis coordinate value, that is, |x2-x1|>|y2-y1|, then it is determined that the button is moving in the up and down direction, otherwise it is moving in the left and right direction.
[0095] It should be noted that there is no requirement for the time interval between the two events. As long as one event is received, it will be triggered, because the DragEvent.ACTION_DRAG_LOCATION event is only issued when the button is dragged and moved to change the coordinate position.
[0096] If it is moving in the left or right direction, compare the x-axis coordinate values of the two coordinates. If the second x-axis coordinate value is larger than the first, that is, x2>x1, then it is determined that the button is moving to the right.
[0097] If it is in the up and down direction, compare the y-axis coordinate values of the two coordinates. If the second y-axis coordinate value is larger than the first, that is, y2>y1, it is judged to move downward.
[0098] S52, according to the direction of the current button movement, determine the button that can be moved to the collision position, then move the buttons that can be squeezed away by one grid as a whole, leaving the current position for the dragged button, and determine whether it can be placed according to the button type. If it can be placed, place it according to the direction of the current button movement.
[0099] A collision 1×1 type button is a button that occupies a grid-sized position in the grid.
[0100] The process of colliding a 1×1 type button includes:
[0101] If the button moves to the left: take out the current collision position, and then determine whether there is an element at position - 1 in the CurrenExitList. If it is determined that it cannot be moved, recursively determine whether there is an element at position - 1 - 1 until the boundary of the grid is reached.
[0102] If the button moves to the right: take out the current collision position, and then determine whether there is an element at position+1 in CurrenExitList. If it is determined that it cannot be moved, recursively determine whether there is an element at position+1+1 until the boundary of the grid is reached.
[0103] If the button moves upward: take out the current collision position, and then determine whether there is an element at position - 4 in the CurrenExitList. If it is determined that it cannot be moved, recursively determine whether there is an element at position - 4 - 4, until the boundary of the grid is reached.
[0104] If the button moves downward: take out the current collision position, and then determine whether there is an element at position+4 in CurrenExitList. If it is determined that it cannot be moved, recursively determine whether there is an element at position+4+4 until the boundary of the grid is reached.
[0105] Here, we mainly use recursive judgment to find the button that can make the collision position squeeze in the moving direction, leaving a position for the dragged button to be placed. The collision 2×2 type button means that it occupies 4 grids in the grid, that is, it is connected to 2 grids horizontally and 2 grids vertically.
[0106] The process of colliding a 2×2 type button includes:
[0107] If the button moves to the left: take out the current colliding position, and then determine whether there are elements at position - 1 and position + 3 in the CurrenExitList. If it is determined that it cannot be moved, recursively determine whether there are elements at position - 1 - 1 and position + 3 - 1 until the boundary of the grid is reached.
[0108] If the button moves to the right: take out the current collision position, and then determine whether there are elements at position+2 and position+6 in CurrenExitList. If it is determined that it cannot be moved, recursively determine whether there are elements at position+2+1 and position+6+1 until the boundary of the grid is reached.
[0109] If the button moves upward: take out the current colliding position, and then determine whether there are elements at position - 4 and position - 3 in the CurrenExitList. If it is determined that it cannot be moved, recursively determine whether there are elements at position - 4 - 4 and position - 3 - 4, until the boundary of the grid is reached.
[0110] If the button moves downward: take out the current collision position, and then determine whether there are elements at position+8 and position+9 in CurrenExitList. If it is determined that it cannot be moved, recursively determine whether there are elements at position+8+4 and position+9+4 until the boundary of the grid is reached.
[0111] Here, we mainly use recursive judgment to find the buttons at the collision position that can be squeezed in the moving direction, leaving 4 positions for the dragged buttons to be placed.
[0112] A collision 4×1 type button means that it occupies 4 grids in the grid, that is, 4 grids connected horizontally.
[0113] The process of colliding with a 4×1 type button includes:
[0114] If the button moves upward: take out the current colliding position, and then determine whether there are elements at position - 4, position - 3, position - 2, position - 1 in CurrenExitList. If it is determined that it cannot be moved, recursively determine whether there are elements at position - 4 - 4, position - 3 - 4, position - 2 - 4, position - 1 - 4, until the boundary of the grid is reached.
[0115] If the button moves downward: take out the current colliding position, and determine whether there are elements at position+4, position+5, position+6, and position+7 in CurrenExitList. If it is determined that the button cannot be moved, recursively determine whether there are elements at position+4+4, position+5+4, position+6+4, and position+7+4, until the boundary of the grid is reached.
[0116] Through recursive judgment, find the buttons at the collision position that can be squeezed in the moving direction, leaving 4 positions for the dragged buttons to be placed.
[0117] It can be seen that by adopting steps S1-S5, the quick operation page uses a GridLayout layout on the left and right to display a 4×4 grid. The button drag uses the View's startDragAndDrop method, and the GridLayout uses setOnDragListener to listen to the drag event, and listens to the DragEvent.ACTION_DRAG_LOCATION event to handle the collision of the button dragging and moving. The buttons can be dragged and moved to place, and not only placed in blank positions, but also existing buttons can be moved and collided according to the collision method to make room. This is practical in the vehicle environment, has operational convenience, and is convenient to improve the user's operating experience.
[0118] The beneficial effect of implementing this embodiment is that when dragging 1×1, 2×2, and 4×1 type buttons, the buttons at the position can be bumped apart, and there is no need to delete the existing buttons at the position and then place them again. This can meet the layout display of 1×1, 2×2, and 4×1 types of in-vehicle quick operation buttons, and can improve the smoothness and ease of use of dragging the quick operation buttons.
[0119] The present invention can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present invention can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present invention can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0120] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0121] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0122] Embodiment 2
[0123] Further references Figure 3 , as a response to the above Figure 1 The present invention provides an embodiment of a drag-and-drop collision device, and the embodiment of the device is similar to Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0124] like Figure 3 As shown, the dragging and moving collision device 60 of this embodiment includes: a first acquisition module 61, a second acquisition module 62, a recording module 63, a judgment module 64 and a placement module 65. Among them:
[0125] The first acquisition module 61 is used to acquire a button position set CurrentExitList recording the button positions position placed in the current grid;
[0126] The second acquisition module 62 is used to obtain the position coordinates (x, y) of the current button moved to the GridLayout grid in the drag event;
[0127] The recording module 63 is used to loop through the GridLayout grid, determine the current button type and which grids the current button occupies after moving, and record the position of the occupied grid into the current grid set CurrentList;
[0128] The judging module 64 is used to judge whether the elements in CurrentList are in CurrentExitList. If not, it is judged that the current button movement has not caused a collision. After releasing the button, the button can be placed at the position, and the position position is removed from the current grid set CurrentList and put into the button position set CurrentExitList. If yes, it is judged that the current button movement has caused a collision.
[0129] The placement module 65 is used to determine the direction in which the current button is moving, and to determine the buttons that can be moved to the collision position, and then move them one grid as a whole to vacate the current position for the dragged button, and to determine whether it can be placed according to the button type. If it can be placed, it will be placed in the direction in which the current button is moving.
[0130] In some optional implementations of this embodiment, the first acquisition module 61 further includes:
[0131] A reading module 611 is used to read a button configuration table;
[0132] The traversal module 612 is used to traverse the button configuration table in a loop, and put the valid button positions position recorded in the button configuration table into the button position set CurrentExitList.
[0133] In some optional implementations of this embodiment, the second acquisition module 62 further includes:
[0134] The monitoring module 621 is used to set a drag event monitoring for the grid;
[0135] The event module 622 is used to send an entry event notification when the dragged button enters the grid area, and provide the position coordinates (x, y) of the current button moving to the grid area.
[0136] In some optional implementations of this embodiment, the recording module 63 further includes:
[0137] The comparison module 631 is used to loop through each grid of the grid after receiving the entry event notification sent by the front end during the grid drag event monitoring, and compare the coordinates sent in the drag event with the position of the grid;
[0138] The first judging module 632 is used to judge that if the horizontal coordinate x is greater than the position of the left side of the grid from the screen, that is, the left value of the grid, and less than the position of the right side of the grid from the screen, that is, the right value of the grid, then it is judged that the button is within the horizontal axis of the grid;
[0139] The second judging module 633 is used to judge that if the vertical coordinate y is greater than the position of the top of the grid from the screen, that is, the top value of the grid, and less than the position of the bottom of the grid from the screen, that is, the bottom value of the grid, then it is judged that the button is within the vertical axis of the grid;
[0140] The third judgment module 634 is used to judge if the button is within the horizontal axis of the grid and the vertical axis of the grid, then judge that the current button moves to occupy the current grid, and record the position position of the occupied grid into the current grid set CurrentList.
[0141] In some optional implementations of this embodiment, the determination module 64 further includes:
[0142] The collision judgment module 641 is used to traverse CurrentList, obtain the position information in CurrentList, traverse CurrentExitList, and judge whether the position information in CurrentList is the same as the position information in CurrentExitList. If they are the same, it is judged that a button collision occurs, otherwise, no button collision occurs;
[0143] The non-collision processing module 642 is used to add the button to the grid if no button collision occurs, add the button to the grid container using the addView method of the grid container, draw and display it on the device screen, and then remove the position position from CurrentList and put it into CurrentExitList to indicate that a button has been placed at this position.
[0144] In some optional implementations of this embodiment, the placement module 65 further includes:
[0145] A direction determination module 651 is used to determine the direction in which the current button moves;
[0146] Processing module 652 is used to determine the buttons that can be moved to the collision position according to the direction of the current button movement, and then move the buttons that can be squeezed away by one grid as a whole to vacate the current position for the dragged button, and determine whether it can be placed according to the button type. If it can be placed, it will be placed according to the direction of the current button movement.
[0147] The beneficial effect of implementing this embodiment is that when dragging 1×1, 2×2, and 4×1 type buttons, the buttons at the position can be bumped apart, and there is no need to delete the existing buttons at the position and then place them again. This can meet the layout display of 1×1, 2×2, and 4×1 types of in-vehicle quick operation buttons, and can improve the smoothness and ease of use of dragging the quick operation buttons.
[0148] Embodiment 3
[0149] To solve the above technical problems, the embodiment of the present invention also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0150] The computer device 7 includes a memory 71, a processor 72, and a network interface 73 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 7 having components of a memory 71, a processor 72, and a network interface 73, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to a microprocessor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a digital processor (DSP), an embedded device, etc.
[0151] The computer device may be a desktop computer, a notebook computer, a PDA, a cloud server, etc. The computer device may interact with the user through a keyboard, a mouse, a remote control, a touch pad, or a voice control device.
[0152] The memory 71 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 71 may be an internal storage unit of the computer device 7, such as a hard disk or memory of the computer device 7. In other embodiments, the memory 71 may also be an external storage device of the computer device 7, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. equipped on the computer device 7. Of course, the memory 71 may also include both the internal storage unit of the computer device 7 and its external storage device. In this embodiment, the memory 71 is generally used to store the operating system and various application software installed on the computer device 7, such as computer-readable instructions of the drag-move collision method, etc. In addition, the memory 71 can also be used to temporarily store various types of data that have been output or are to be output.
[0153] The processor 72 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 72 is generally used to control the overall operation of the computer device 7. In this embodiment, the processor 72 is used to run the computer-readable instructions stored in the memory 71 or process data, such as running the computer-readable instructions of the drag-move-collision method.
[0154] The network interface 73 may include a wireless network interface or a wired network interface. The network interface 73 is generally used to establish a communication connection between the computer device 7 and other electronic devices.
[0155] The beneficial effect of implementing this embodiment is that when dragging 1×1, 2×2, and 4×1 type buttons, the buttons at the position can be bumped apart, and there is no need to delete the existing buttons at the position and then place them again. This can meet the layout display of 1×1, 2×2, and 4×1 types of in-vehicle quick operation buttons, and can improve the smoothness and ease of use of dragging the quick operation buttons.
[0156] Embodiment 4
[0157] The present invention also provides another embodiment, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the drag-move collision method as described above.
[0158] The beneficial effect of implementing this embodiment is that when dragging 1×1, 2×2, and 4×1 type buttons, the buttons at the position can be bumped apart, and there is no need to delete the existing buttons at the position and then place them again. This can meet the layout display of 1×1, 2×2, and 4×1 types of in-vehicle quick operation buttons, and can improve the smoothness and ease of use of dragging the quick operation buttons.
[0159] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the various embodiment methods of the present invention.
[0160] Obviously, the embodiments described above are only some embodiments of the present invention, rather than all embodiments. The preferred embodiments of the present invention are given in the accompanying drawings, but they do not limit the patent scope of the present invention. The present invention can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present invention more thorough and comprehensive. Although the present invention has been described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific embodiments, or to perform equivalent replacements for some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of the present invention, directly or indirectly used in other related technical fields, is also within the scope of patent protection of the present invention.
Claims
1. A drag-and-drop collision method, characterized in that: The steps include: S1. Obtain the button position set CurrentExitList that records the button positions placed in the current grid; S2. Get the position coordinates (x, y) of the current button in the GridLayout grid in the drag event; S3, loop through the GridLayout grid, determine the current button type and which grids the current button occupies after moving, and record the position of the occupied grid into the current grid set CurrentList; S4, determine whether the elements in CurrentList are in CurrentExitList, otherwise it is determined that the current button movement has not collided, and the button can be placed at this position after releasing the button, and the position position is removed from the current grid set CurrentList and put into the button position set CurrentExitList, if yes, it is determined that the current button movement has collided, and enter step S5; S5. Determine the direction in which the current button moves, determine the buttons that can be moved to the collision position, move them one grid as a whole, and leave the current position for the dragged button, determine whether it can be placed according to the button type, and if it can be placed, place it according to the direction in which the current button moves.
2. The drag-and-move collision method according to claim 1, characterized in that: The step of S1, obtaining a button position set CurrentExitList recording the button positions position placed in the current grid, specifically includes: S11, read the button configuration table; S12, looping through the button configuration table, and putting the valid button positions position recorded in the button configuration table into the button position set CurrentExitList.
3. The drag-and-move collision method according to claim 1, characterized in that: The step S2 of obtaining the position coordinates (x, y) of the current button moved to the GridLayout grid in the drag event specifically includes: S21. Set a drag event listener for the grid; S22. When the dragged button enters the grid area, an entry event notification is issued, and the position coordinates (x, y) of the current button moving to the grid area are provided.
4. The drag-and-move collision method according to claim 1, characterized in that: The step S3 of looping through the GridLayout grid, determining the current button type and which grids the current button occupies after moving, and recording the position of the occupied grid into the current grid set CurrentList specifically includes: S31, in the grid drag event monitoring, after receiving the entry event notification sent by the front end, loop through each grid of the grid and compare the coordinates sent in the drag event with the position of the grid; S32, if the horizontal coordinate x is greater than the position of the left side of the grid from the screen, that is, the left value of the grid, and less than the position of the right side of the grid from the screen, that is, the right value of the grid, then it is determined that the button is within the horizontal axis of the grid; S33, if the vertical coordinate y is greater than the position of the top of the grid from the screen, that is, the top value of the grid, and less than the position of the bottom of the grid from the screen, that is, the bottom value of the grid, then it is determined that the button is within the vertical axis of the grid; S34. If the button is within the horizontal axis of the grid and within the vertical axis of the grid, it is determined that the current button moves to occupy the current grid, and the position position of the occupied grid is recorded in the current grid set CurrentList.
5. The drag-and-move collision method according to claim 1, characterized in that: The above S4, determines whether the elements in CurrentList are in CurrentExitList, otherwise, it is determined that the current button movement has not collided, and the button can be placed at this position after releasing the button, and the position position is removed from the current grid set CurrentList and put into the button position set CurrentExitList. If yes, it is determined that the current button movement has collided, and the step of entering step S5 specifically includes: S41, traverse CurrentList, obtain the position information in CurrentList, traverse CurrentExitList, determine whether the position information in CurrentList is the same as the position information in CurrentExitList, if they are the same, determine that a button collision occurs, otherwise, no button collision occurs; S42. If no button collision occurs, the button is added to the grid, the addView method of the grid container is used to add the button to the grid container, and the button is drawn and displayed on the device screen. Then, the position is removed from the CurrentList and placed in the CurrentExitList to indicate that a button has been placed at this position.
6. The drag-and-move collision method according to claim 1, characterized in that: The step of S5, determining the direction of movement of the current button, determining the buttons at the collision position that can be moved, moving them as a whole by one grid, leaving the current position for the dragged button, determining whether the buttons can be placed according to the button type, and if they can be placed, placing them according to the direction of movement of the current button specifically includes: S51, determining the direction in which the current button moves; S52. According to the direction of movement of the current button, determine the button that can be moved to the collision position, then move the buttons that can be squeezed away by one grid as a whole, leaving the current position for the dragged button, and determine whether it can be placed according to the button type. If it can be placed, place it according to the direction of movement of the current button.
7. A drag-and-drop collision device, characterized in that: include: The first acquisition module is used to acquire a button position set CurrentExitList recording the button positions placed in the current grid; The second acquisition module is used to obtain the position coordinates (x, y) of the current button moved to the GridLayout grid in a drag event; The recording module is used to loop through the GridLayout grid, determine the current button type and which grids the current button occupies after moving, and record the position of the occupied grid into the current grid set CurrentList; The judgment module is used to judge whether the elements in CurrentList are in CurrentExitList. If not, it is judged that the current button movement has not collided. After releasing the button, the button can be placed at this position, and the position position is removed from the current grid set CurrentList and put into the button position set CurrentExitList. If yes, it is judged that the current button movement has collided. The placement module is used to determine the direction in which the current button is moving. If the buttons at the collision position can be moved, they will be moved one grid as a whole to make room for the dragged button. It is also used to determine whether the buttons can be placed based on the button type. If they can be placed, they will be placed in the direction in which the current button is moving.
8. The dragging movement collision device according to claim 7, characterized in that: The placement module comprises: The direction determination module is used to determine the direction in which the current button moves; The processing module is used to determine the buttons that can be moved to the collision position according to the direction of the current button movement, and then move the buttons that can be squeezed away by one grid as a whole to vacate the current position for the dragged button. It is also used to determine whether the buttons can be placed according to the button type. If they can be placed, they are placed according to the direction of the current button movement.
9. A computer device, comprising a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the drag-and-move collision method according to any one of claims 1 to 6 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the drag-and-move collision method according to any one of claims 1 to 6 are implemented.
