Focus control method and device, medium and equipment
By obtaining focus movement instructions and combining them with layout parameters and a recursive search algorithm, the focus index is calculated and corrected, achieving precise control of focus, solving problems such as focus loss, abnormal crashes, and focus confusion, and improving the user experience.
Patent Information
- Application Number
- CN202510894057.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-09-09
AI Technical Summary
The focus control in the existing technology has problems such as focus loss, abnormal crash, focus confusion and discontinuous focus response, resulting in a poor user operation experience.
By obtaining the focus movement instruction, combining the preset layout parameters and recursive search algorithm, the focus index is calculated and corrected to ensure that the focus moves within the valid range and accurately locate the view element for control.
It solves the problems of focus loss and abnormal crash, avoids focus confusion, ensures the continuity of focus response, and significantly improves the user interaction experience.
Smart Images

Figure CN120614489A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of focus control, and in particular to a focus control method, device, medium and equipment. Background Art
[0002] In devices like smart conference systems and all-in-one electronic whiteboards, users often browse files using a remote control to operate a file manager. These devices typically feature a file list interface, where users can use the remote's arrow keys (such as up / down / left / right) to move the focus and select different file items for operation. However, existing technologies for handling focus movement have the following problems:
[0003] Focus loss: When a user quickly and long-presses the arrow keys on the remote control to browse a large number of files, the system needs to continuously scroll the file list and update the focus position. However, with existing technologies, the focus may not jump to the new view item in time, resulting in focus loss and the user being unable to determine the current object of the operation.
[0004] Abnormal crash issue: If the target file item has not been rendered, directly setting the focus on the item may cause an exception, resulting in a system crash or an error prompt, affecting the user experience.
[0005] Focus confusion problem: In the existing technology, the focus movement logic is relatively simple. When the focus is on a subview (such as a button, text box, etc.), directly setting the focus may cause a type conversion error, making it impossible to focus correctly on the target item, resulting in focus confusion.
[0006] Intermittent focus response: When the remote control triggers focus movement commands frequently, existing technologies cannot guarantee continuous focus response. The focus may jump or freeze, failing to smoothly follow the user's operation commands, affecting the consistency of file browsing.
[0007] These problems result in the existing technology being unable to accurately and efficiently control the remote control focus. Summary of the Invention
[0008] The present invention provides a focus control method, device, medium and equipment to solve the problem in the prior art that the remote control focus cannot be controlled accurately and efficiently.
[0009] In a first aspect, the present application provides a focus control method, comprising:
[0010] Get the focus movement instruction and determine the focus movement direction;
[0011] Calculating a first target focus index based on the movement direction and preset layout parameters; wherein the layout parameters include the number of display items per row or column;
[0012] According to the relationship between the first target focus index and the index range of the currently displayed file list item, the first target focus index is modified to obtain a second target focus index;
[0013] Based on the second target focus index, in combination with a preset recursive search algorithm, locate and obtain a view element associated with the second target focus index;
[0014] Focus is controlled according to the view element.
[0015] This application obtains the focus movement instruction and determines the movement direction, and can calculate the first target focus index according to the movement direction and preset layout parameters (such as the number of display items per row or column). Then, by checking the relationship between the first target focus index and the index range of the currently displayed file list item, the index is corrected to obtain the second target focus index, ensuring that the focus always moves within the valid range. Finally, the preset recursive search algorithm is used to locate the view element associated with the second target focus index, and the focus is set on the view element, thereby achieving precise control of the focus. This series of steps not only solves the problems of focus loss and abnormal crashes, but also avoids focus confusion, ensures the continuity of focus response, significantly improves the user's interactive experience when using the remote control to operate the file list, and effectively solves the problem of the inability to accurately and efficiently control the remote control focus in the prior art.
[0016] Furthermore, the first target focus index is calculated based on the moving direction and the preset layout parameters, specifically:
[0017] When the movement direction is downward, the current focus index is added to the number of display items per row to obtain the first target focus index;
[0018] When the moving direction is upward, the current focus index is subtracted from the number of display items per row to obtain the first target focus index;
[0019] When the moving direction is leftward or rightward, a first target focus index is obtained according to preset layout parameters and a preset formula.
[0020] More specifically, when the moving direction is leftward or rightward, the first target focus index is obtained according to the preset layout parameters and the preset formula, specifically:
[0021] According to the preset formula, calculate the column index of the current focus index in the current row;
[0022] When the moving direction is leftward, if the column index is not a preset first threshold, the first target focus index is set to the current focus index minus a preset second threshold;
[0023] When the moving direction is rightward, if the column index is less than the number of items displayed in each row minus a preset second threshold, the first target focus index is set to the current focus index plus the preset second threshold;
[0024] The preset formula is the remainder of dividing the current focus index by the number of display items per row.
[0025] The present application calculates a first target focus index based on the movement direction and preset layout parameters, thereby accurately predicting the target position after the focus moves. Specifically, when the movement direction is downward, the current focus index is added to the number of display items per row to obtain the first target focus index, which enables the focus to be accurately moved to the corresponding position of the next row. Conversely, when the movement direction is upward, the number of display items per row is subtracted from the current focus index to achieve the function of moving the focus upward. For movement to the left or right, the column index of the current focus index in the current row is calculated using a preset formula (the remainder of the current focus index divided by the number of display items per row). If the movement direction is left and the column index is not the preset first threshold, the first target focus index is set to the current focus index minus the preset second threshold, thereby achieving the operation of moving the focus to the left. Similarly, if the movement direction is right and the column index is less than the number of display items per row minus the preset second threshold, the first target focus index is set to the current focus index plus the preset second threshold to complete the operation of moving the focus to the right. This calculation method not only improves the accuracy of focus movement, but also ensures that the movement of focus in the grid layout is more natural and intuitive, thereby significantly improving the user's interactive experience when browsing file lists.
[0026] Furthermore, the first target focus index is modified according to the relationship between the first target focus index and the index range of the currently displayed file list item to obtain the second target focus index, specifically:
[0027] If the first target focus index is less than a preset first threshold, setting the second target focus index to the preset first threshold;
[0028] If the first target focus index is greater than or equal to the total number of file list items, setting the second target focus index to the total number of file list items minus a preset second threshold;
[0029] If the first target focus index is less than the total number of file list items, the second target focus index is set to the first target focus index.
[0030] The present application ensures that the focus always moves within the valid range by making corrections based on the relationship between the first target focus index and the index range of the currently displayed file list item. Specifically, if the first target focus index is less than the preset first threshold, it means that the focus may have moved before the starting position of the list. At this time, the second target focus index is set to the preset first threshold to prevent the focus from exceeding the list range. If the first target focus index is greater than or equal to the total number of file list items, it means that the focus may have moved after the end position of the list. At this time, the second target focus index is set to the total number of file list items minus the preset second threshold to ensure that the focus stays on the last valid item. Only when the first target focus index is within the total number of file list items is the second target focus index set to the first target focus index, thereby ensuring the accuracy of focus movement. This correction mechanism effectively avoids the problem of focus loss or out-of-bounds, ensures that the focus always points to a valid file list item, and improves the stability of the system and user experience.
[0031] Furthermore, based on the second target focus index, in combination with a preset recursive search algorithm, the view element associated with the second target focus index is located, specifically:
[0032] Starting from the view element where the current focus is located, search upwards level by level for the second view element of the current view element;
[0033] Search for the list item view of each second view element. If a focusable list item view is found, use the focusable view element as the target view element.
[0034] This application locates the view element associated with the index based on the second target focus index and combined with a preset recursive search algorithm, and can accurately determine where the focus should be set. Specifically, starting from the view element where the current focus is located, its parent view element is searched upward step by step. This process ensures a comprehensive check of the entire view hierarchy. For each parent view element, it is further checked whether it is a focusable list item view. If a qualified focusable view element is found, it is determined as the target view element, thereby ensuring that the focus can be correctly set to a valid interactive object. This recursive search mechanism effectively avoids focus setting errors caused by the complexity of the view hierarchy, and at the same time solves the type conversion exception problem caused by factor views in the prior art, significantly improving the accuracy of focus control and the stability of the system, and optimizing the user interaction experience.
[0035] In a second aspect, the present application provides a focus control device. The focus control device includes:
[0036] An acquisition module is used to obtain the focus movement instruction and determine the focus movement direction;
[0037] a calculation module, configured to calculate a first target focus index based on the movement direction and preset layout parameters; wherein the layout parameters include the number of display items per row or column;
[0038] a correction module, configured to correct the first target focus index according to a relationship between the first target focus index and an index range of a currently displayed file list item to obtain a second target focus index;
[0039] a positioning module, configured to locate a view element associated with the second target focus index based on the second target focus index and in combination with a preset recursive search algorithm;
[0040] The control module is used to control the focus according to the view element.
[0041] The focus control device of the present application realizes efficient and accurate focus control through the synergy of its various modules. First, the acquisition module can timely capture the focus movement instruction and clarify the movement direction, providing a basis for subsequent calculations. The calculation module accurately calculates the first target focus index based on the movement direction and layout parameters (such as the number of display items per row or column), and preliminarily determines the moving target of the focus. The correction module further ensures the rationality of the focus movement. By comparing the first target focus index with the index range of the currently displayed file list item, the necessary correction is made to the index to obtain a more accurate second target focus index. The positioning module uses a recursive search algorithm to accurately locate the view element associated with it based on the corrected index, avoiding focus setting errors caused by the complexity of the view hierarchy. Finally, the control module accurately controls the focus according to the located view element to ensure that the focus can be accurately moved to the position desired by the user. This series of modular designs not only improves the accuracy and efficiency of focus control, but also enhances the stability of the system and the user's operating experience.
[0042] Furthermore, the calculation module is used to calculate a first target focus index based on the moving direction and preset layout parameters, specifically:
[0043] When the moving direction is downward, the calculation module adds the current focus index to the number of display items per row to obtain a first target focus index;
[0044] When the moving direction is upward, the current focus index is subtracted from the number of display items per row to obtain the first target focus index;
[0045] When the moving direction is leftward or rightward, a first target focus index is obtained according to preset layout parameters and a preset formula.
[0046] The calculation module of the present application realizes efficient calculation of the first target focus index based on the focus movement direction and preset layout parameters (such as the number of display items per row or column) through accurate algorithm design. Specifically, when the focus needs to move downward, the calculation module adds the current focus index to the number of display items per row to obtain the first target focus index. This operation ensures that the focus can accurately jump to the corresponding position of the next row. On the contrary, when the focus moves upward, the calculation module subtracts the number of display items per row from the current focus index to achieve accurate movement of the focus to the upper row. For movement to the left or right, the calculation module calculates according to the preset layout parameters and formulas to determine the moving target of the focus within the same row. This calculation method based on direction and layout parameters not only improves the accuracy and efficiency of focus movement, but also makes the movement of focus in the grid layout more natural and intuitive, effectively avoids the problem of focus confusion or loss, and significantly improves the user's interactive experience when browsing the file list.
[0047] Furthermore, the correction module corrects the first target focus index according to the relationship between the first target focus index and the index range of the currently displayed file list item to obtain a second target focus index, specifically:
[0048] If the first target focus index is less than a preset first threshold, the correction module sets the second target focus index to the preset first threshold;
[0049] If the first target focus index is greater than or equal to the total number of file list items, setting the second target focus index to the total number of file list items minus a preset second threshold;
[0050] If the first target focus index is less than the total number of file list items, the second target focus index is set to the first target focus index.
[0051] The correction module of the present application ensures that the focus index is always within the valid range through an accurate boundary checking mechanism. Specifically, when the first target focus index is less than the preset first threshold, the correction module adjusts it to the preset first threshold, thereby preventing the focus from moving before the starting position of the list. When the first target focus index is greater than or equal to the total number of file list items, the correction module adjusts it to the total number of file list items minus the preset second threshold, ensuring that the focus does not exceed the end of the list. Only when the first target focus index is within the total number of file list items will the correction module directly use it as the second target focus index. This correction mechanism effectively avoids the problem of focus index out of bounds, ensures that the focus always points to a valid file list item, and improves system stability and user experience.
[0052] In a third aspect, the present application provides a computer-readable storage medium, the computer-readable storage medium including a stored computer program. When the computer program is executed, the computer-readable storage medium controls a device containing the computer-readable storage medium to execute a focus control method as described above. The beneficial effects of the focus control method provided in the first aspect of the present application are the same as those of the focus control method provided in the first aspect of the present application.
[0053] In a fourth aspect, the present application provides a terminal device comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, it implements any one of the focus control methods described in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 : A flow chart of an embodiment of the focus control method provided by the present application;
[0055] Figure 2 : A flowchart of an embodiment of focus control logic judgment provided by this application;
[0056] Figure 3 : A structural diagram of an embodiment of the focus control device provided in this application. DETAILED DESCRIPTION
[0057] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0058] Example 1
[0059] Please refer to Figure 1 In order to solve the problem that the prior art cannot accurately and efficiently control the remote control focus, an embodiment of the present invention provides a focus control method, including steps S01-S05.
[0060] S01: Obtain the focus movement instruction and determine the focus movement direction.
[0061] As a preferred implementation of this embodiment, the focus movement instruction is specifically as follows: when a user triggers a focus movement operation via a remote control, the system receives the operation instruction and parses the instruction to determine the focus movement direction. The movement direction can be up, down, left, or right, depending on the direction key pressed by the user on the remote control.
[0062] More specifically, get the fromPos of the current focus view (that is, the position of the item where the focus is).
[0063] Calculate the target focus position target according to the sliding direction (up / down / left / right).
[0064] S02: Calculate a first target focus index based on the moving direction and preset layout parameters; wherein the layout parameters include the number of display items per row or column.
[0065] As a preferred implementation of this embodiment, the first target focus index is calculated based on the moving direction and the preset layout parameters, specifically:
[0066] Based on the index of the currently focused item (currentIndex) and the movement direction, combined with the preset layout parameters (such as the number of items displayed per row or column, spanCount), the first target focus index (targetIndex) is calculated using the following formula:
[0067] When the moving direction is downward: targetIndex = currentIndex + spanCount;
[0068] When the moving direction is upward: targetIndex = currentIndex - spanCount;
[0069] When the movement direction is left or right, the column index of the current focus index in the current row is calculated according to a preset formula (col_index=currentIndex%spanCount), and the first target focus index is adjusted according to the movement direction:
[0070] Move to the left and col_index is not 0: targetIndex = currentIndex - 1;
[0071] When moving right and col_index is less than spanCount-1: targetIndex=currentIndex+1.
[0072] This application can accurately predict the target position after the focus moves by calculating the first target focus index based on the moving direction and preset layout parameters. Specifically, when the moving direction is downward, the current focus index is added to the number of display items per row to obtain the first target focus index, which enables the focus to accurately move to the corresponding position in the next row. On the contrary, when the moving direction is upward, the number of display items per row is subtracted from the current focus index to implement the function of moving the focus upward. For left or right movement, the column index of the current focus index in the current row is calculated through a preset formula (the remainder of the current focus index divided by the number of display items per row). If the moving direction is left and the column index is not the preset first threshold (the first threshold is 0), the first target focus index is set to the current focus index minus the preset second threshold (the second threshold is 1) to achieve moving the focus to the left. Similarly, if the moving direction is right and the column index is less than the number of display items per row minus the preset second threshold, the first target focus index is set to the current focus index plus the preset second threshold to complete the operation of moving the focus to the right. This calculation method not only improves the accuracy of focus movement but also ensures that the focus moves more naturally and intuitively in the grid layout, thus significantly enhancing the user's interaction experience when browsing the file list.
[0073] S03: Modify the first target focus index according to the relationship between the first target focus index and the index range of the currently displayed file list items to obtain a second target focus index.
[0074] As a preferred implementation manner of this embodiment, the modification of the first target focus index is specifically as follows:
[0075] Check whether the first target focus index is within the index range of the currently displayed file list items. If the first target focus index is less than 0, modify it to 0; if the first target focus index is greater than or equal to the total number (count) of file list items, modify it to count - 1. Otherwise, keep the first target focus index unchanged and use it as the second target focus index.
[0076] More specifically, if target exceeds the range of the total number of Items (target < 0 or target >= count), modify it to the boundary value and mark returnSystemProcess.
[0077] If target exceeds the current visible range (target > lastVisibleItemPos or target < firstVisibleItemPosition), call scrollToPosition to slide to the target position.
[0078] S04: Based on the second target focus index, combined with a preset recursive search algorithm, locate and obtain the view element associated with the second target focus index.
[0079] As a preferred implementation of this embodiment, the preset recursive search algorithm is combined to locate the view element associated with the second target focus index, specifically:
[0080] Starting with the currently focused view element, the program searches upwards through its parent view elements. For each parent view element, it checks whether it is a focusable list item view. If a focusable list item view is found, it is used as the target view element. This recursive search algorithm ensures that the list item view associated with the target focus index is correctly located, even if the focus is in a child view.
[0081] Starting from the view element where the current focus is located, its parent view element is searched upwards step by step. This process ensures a comprehensive check of the entire view hierarchy. For each parent view element, it is further checked whether it is a focusable list item view. If a focusable view element that meets the conditions is found, it is determined as the target view element, thereby ensuring that the focus can be correctly set to a valid interactive object. This recursive search mechanism effectively avoids focus setting errors caused by the complexity of the view hierarchy, and at the same time solves the type conversion anomaly problem caused by factor views in the existing technology, significantly improving the accuracy of focus control and the stability of the system, and optimizing the user interaction experience.
[0082] S05: Control the focus according to the view element.
[0083] As a preferred implementation of this embodiment, the focus is controlled as follows:
[0084] After the target view element is loaded, the focus is set to the view element and the view element is highlighted so that the user can clearly see the object of the current operation. If the target view element has not yet been loaded, wait until it is loaded before performing the focus setting operation.
[0085] As a preferred implementation of this embodiment, the focus control method also includes an exception handling mechanism. During the execution of the above steps, a try-catch statement is used to catch any exceptions that may occur, such as IndexOutOfBoundsException or NullPointerException. If an exception is caught, a detailed debug log is recorded, allowing developers to quickly locate and resolve the issue, thereby ensuring stable system operation.
[0086] Furthermore, if Figure 2 As shown, Figure 2This is a flowchart of the focus control logic judgment of this application. The specific control logic is as follows:
[0087] 1) Focus index calculation:
[0088] Core formula:
[0089] target=fromPos+direction_offset;
[0090] Down / Up Direction:
[0091] Downward: direction_offset = spanCount (for example, 3 items per row, jump to the next row when moving downward).
[0092] Upward: direction_offset = -spanCount.
[0093] Left / right direction:
[0094] Current column index: col_index = fromPos% spanCount.
[0095] Left: target = fromPos - 1 (if col_index != 0).
[0096] Right: target = fromPos + 1 (if col_index ! = spanCount - 1).
[0097] Boundary correction logic:
[0098]
[0099] (2) Dynamic adjustment of visible range:
[0100] Judgment logic:
[0101]
[0102] Function: When the target position exceeds the current visible range, it automatically slides to the target position to ensure that the focus can be obtained.
[0103] (3) Recursively search for the ItemView associated with the focus;
[0104] Implementation logic:
[0105]
[0106] Purpose: To resolve the issue where getPosition calls fail due to type conversion exceptions when the focus is on a subview.
[0107] (4)Exception handling mechanism:
[0108] Logic description:
[0109] In onInterceptFocusSearch, exceptions (such as type conversion exceptions) are captured through try-catch. If an exception occurs, returnSystemProcess = true is marked and the system default logic is used for processing.
[0110] Through the above steps S01-S05, this embodiment describes in detail the process of the focus control method in the present application. This method can effectively solve the problems of focus loss, abnormal crash, focus confusion and discontinuous focus response in the prior art, and significantly improve the user's interactive experience when using the remote control to operate the file list.
[0111] This application obtains the focus movement instruction and determines the movement direction, and can calculate the first target focus index according to the movement direction and preset layout parameters (such as the number of display items per row or column). Then, by checking the relationship between the first target focus index and the index range of the currently displayed file list item, the index is corrected to obtain the second target focus index, ensuring that the focus always moves within the valid range. Finally, the preset recursive search algorithm is used to locate the view element associated with the second target focus index, and the focus is set on the view element, thereby achieving precise control of the focus. This series of steps not only solves the problems of focus loss and abnormal crashes, but also avoids focus confusion, ensures the continuity of focus response, significantly improves the user's interactive experience when using the remote control to operate the file list, and effectively solves the problem of the inability to accurately and efficiently control the remote control focus in the prior art.
[0112] Example 2
[0113] Please refer to Figure 3 , which is a focus control device provided in an embodiment of the present application.
[0114] In this embodiment, the focus control device includes an acquisition module 10 , a calculation module 20 , a correction module 30 , a positioning module 40 and a control module 50 .
[0115] The acquisition module 10 is used to acquire a focus movement instruction and determine a focus movement direction.
[0116] As a preferred implementation of this embodiment, the focus movement instruction is specifically as follows: when a user triggers a focus movement operation via a remote control, the system receives the operation instruction and parses the instruction to determine the focus movement direction. The movement direction can be up, down, left, or right, depending on the direction key pressed by the user on the remote control.
[0117] More specifically, get the fromPos of the current focus view (that is, the position of the item where the focus is).
[0118] Calculate the target focus position target according to the sliding direction (up / down / left / right).
[0119] The calculation module 20 is used to calculate a first target focus index based on the moving direction and preset layout parameters; wherein the layout parameters include the number of display items per row or per column.
[0120] As a preferred implementation of this embodiment, the first target focus index is calculated based on the moving direction and the preset layout parameters, specifically:
[0121] Based on the index of the currently focused item (currentIndex) and the movement direction, combined with the preset layout parameters (such as the number of items displayed per row or column, spanCount), the first target focus index (targetIndex) is calculated using the following formula:
[0122] When the moving direction is downward: targetIndex = currentIndex + spanCount;
[0123] When the moving direction is upward: targetIndex = currentIndex - spanCount;
[0124] When the movement direction is left or right, the column index of the current focus index in the current row is calculated according to a preset formula (col_index=currentIndex%spanCount), and the first target focus index is adjusted according to the movement direction:
[0125] Move to the left and col_index is not 0: targetIndex = currentIndex - 1;
[0126] When moving right and col_index is less than spanCount-1: targetIndex=currentIndex+1.
[0127] This application can accurately predict the target position after focus movement by calculating the first target focus index based on the movement direction and preset layout parameters. Specifically, when the movement direction is downward, the current focus index is added to the number of display items per row to obtain the first target focus index, which enables the focus to accurately move to the corresponding position in the next row. Conversely, when the movement direction is upward, the number of display items per row is subtracted from the current focus index to achieve the function of moving the focus upward. For left or right movement, the column index of the current focus index in the current row is calculated through a preset formula (the remainder of the current focus index divided by the number of display items per row). If the movement direction is left and the column index is not the preset first threshold (the first threshold is 0), the first target focus index is set to the current focus index minus the preset second threshold (the second threshold is 1) to achieve left focus movement. Similarly, if the movement direction is right and the column index is less than the number of display items per row minus the preset second threshold, the first target focus index is set to the current focus index plus the preset second threshold to complete the right focus movement operation. This calculation method not only improves the accuracy of focus movement but also ensures that the focus moves more naturally and intuitively in the grid layout, thus significantly enhancing the user's interaction experience when browsing the file list.
[0128] The correction module 30 is used to correct the first target focus index according to the relationship between the first target focus index and the index range of the currently displayed file list items, and obtain the second target focus index.
[0129] As a preferred implementation manner of this embodiment, the correction of the first target focus index is specifically:
[0130] Check whether the first target focus index is within the index range of the currently displayed file list items. If the first target focus index is less than 0, it is corrected to 0; if the first target focus index is greater than or equal to the total number (count) of file list items, it is corrected to count - 1. Otherwise, the first target focus index remains unchanged and is used as the second target focus index.
[0131] More specifically, if the target exceeds the range of the total number of Items (target < 0 or target >= count), it is corrected to the boundary value and the returnSystemProcess is marked.
[0132] If the target exceeds the current visible range (target > lastVisibleItemPos or target < firstVisibleItemPosition), call scrollToPosition to slide to the target position.
[0133] The positioning module 40 is configured to locate the view element associated with the second target focus index based on the second target focus index in combination with a preset recursive search algorithm.
[0134] As a preferred implementation of this embodiment, the preset recursive search algorithm is combined to locate the view element associated with the second target focus index, specifically:
[0135] Starting with the currently focused view element, the program searches upwards through its parent view elements. For each parent view element, it checks whether it is a focusable list item view. If a focusable list item view is found, it is used as the target view element. This recursive search algorithm ensures that the list item view associated with the target focus index is correctly located, even if the focus is in a child view.
[0136] Starting from the view element where the current focus is located, its parent view element is searched upwards step by step. This process ensures a comprehensive check of the entire view hierarchy. For each parent view element, it is further checked whether it is a focusable list item view. If a focusable view element that meets the conditions is found, it is determined as the target view element, thereby ensuring that the focus can be correctly set to a valid interactive object. This recursive search mechanism effectively avoids focus setting errors caused by the complexity of the view hierarchy, and at the same time solves the type conversion anomaly problem caused by factor views in the existing technology, significantly improving the accuracy of focus control and the stability of the system, and optimizing the user interaction experience.
[0137] The control module 50 is used to control the focus according to the view element.
[0138] As a preferred implementation of this embodiment, the focus is controlled as follows:
[0139] After the target view element is loaded, the focus is set to the view element and the view element is highlighted so that the user can clearly see the object of the current operation. If the target view element has not yet been loaded, wait until it is loaded before performing the focus setting operation.
[0140] As a preferred implementation of this embodiment, the focus control device also includes an exception handling mechanism. During the execution of the above steps, a try-catch statement is used to catch any exceptions that may occur, such as IndexOutOfBoundsException or NullPointerException. If an exception is caught, a detailed debug log is recorded, allowing developers to quickly locate and resolve the issue, thereby ensuring stable system operation.
[0141] Furthermore, if Figure 2 As shown, Figure 2 This is a flowchart of the focus control logic judgment of this application. The specific control logic is as follows:
[0142] 1) Focus index calculation:
[0143] Core formula:
[0144] target=fromPos+direction_offset;
[0145] Down / Up Direction:
[0146] Downward: direction_offset = spanCount (for example, 3 items per row, jump to the next row when moving downward).
[0147] Upward: direction_offset = -spanCount.
[0148] Left / right direction:
[0149] Current column index: col_index = fromPos% spanCount.
[0150] Left: target = fromPos - 1 (if col_index != 0).
[0151] Right: target = fromPos + 1 (if col_index ! = spanCount - 1).
[0152] Boundary correction logic:
[0153]
[0154]
[0155] (2) Dynamic adjustment of visible range:
[0156] Judgment logic:
[0157]
[0158] Function: When the target position exceeds the current visible range, it automatically slides to the target position to ensure that the focus can be obtained.
[0159] (3) Recursively search for the ItemView associated with the focus;
[0160] Implementation logic:
[0161]
[0162] Purpose: To resolve the issue where getPosition calls fail due to type conversion exceptions when the focus is on a subview.
[0163] (4)Exception handling mechanism:
[0164] Logic description:
[0165] In onInterceptFocusSearch, exceptions (such as type conversion exceptions) are captured through try-catch. If an exception occurs, returnSystemProcess = true is marked and the system default logic is used for processing.
[0166] Through the above modules, this embodiment describes in detail the process of the focus control device in this application. This method can effectively solve the problems of focus loss, abnormal crash, focus confusion and discontinuous focus response in the prior art, and significantly improves the user's interactive experience when using the remote control to operate the file list.
[0167] The focus control device of the present application realizes efficient and accurate focus control through the synergy of its various modules. First, the acquisition module can timely capture the focus movement instruction and clarify the movement direction, providing a basis for subsequent calculations. The calculation module accurately calculates the first target focus index based on the movement direction and layout parameters (such as the number of display items per row or column), and preliminarily determines the moving target of the focus. The correction module further ensures the rationality of the focus movement. By comparing the first target focus index with the index range of the currently displayed file list item, the necessary correction is made to the index to obtain a more accurate second target focus index. The positioning module uses a recursive search algorithm to accurately locate the view element associated with it based on the corrected index, avoiding focus setting errors caused by the complexity of the view hierarchy. Finally, the control module accurately controls the focus according to the located view element to ensure that the focus can be accurately moved to the position desired by the user. This series of modular designs not only improves the accuracy and efficiency of focus control, but also enhances the stability of the system and the user's operating experience.
[0168] Example 3:
[0169] An embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the focus control method described above;
[0170] Wherein, if the focus control method is implemented in the form of a software functional unit and used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing related hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device that can carry the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0171] Example 4
[0172] The present application provides a terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, any one of the focus control methods described in Example 1 is implemented.
[0173] The specific embodiments described above further illustrate the objectives, technical solutions, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. In particular, it should be noted that any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included within the scope of protection of the present invention for those skilled in the art.
Claims
1. A focus control method, characterized in that: include: Get the focus movement instruction and determine the focus movement direction; Calculating a first target focus index based on the movement direction and preset layout parameters; wherein the layout parameters include the number of display items per row or column; According to the relationship between the first target focus index and the index range of the currently displayed file list item, the first target focus index is modified to obtain a second target focus index; Based on the second target focus index, in combination with a preset recursive search algorithm, locate and obtain a view element associated with the second target focus index; Focus is controlled according to the view element.
2. The focus control method according to claim 1, wherein: The first target focus index is calculated based on the moving direction and the preset layout parameters, specifically: When the movement direction is downward, the current focus index is added to the number of display items per row to obtain the first target focus index; When the moving direction is upward, the current focus index is subtracted from the number of display items per row to obtain the first target focus index; When the moving direction is leftward or rightward, a first target focus index is obtained according to preset layout parameters and a preset formula.
3. The focus control method according to claim 2, wherein: When the moving direction is left or right, the first target focus index is obtained according to the preset layout parameters and the preset formula, specifically: According to the preset formula, calculate the column index of the current focus index in the current row; When the moving direction is leftward, if the column index is not a preset first threshold, the first target focus index is set to the current focus index minus a preset second threshold; When the moving direction is rightward, if the column index is less than the number of items displayed in each row minus a preset second threshold, the first target focus index is set to the current focus index plus the preset second threshold; The preset formula is the remainder of dividing the current focus index by the number of display items per row.
4. The focus control method according to claim 1, wherein: The first target focus index is modified according to the relationship between the first target focus index and the index range of the currently displayed file list item to obtain the second target focus index, specifically: If the first target focus index is less than a preset first threshold, setting the second target focus index to the preset first threshold; If the first target focus index is greater than or equal to the total number of file list items, setting the second target focus index to the total number of file list items minus a preset second threshold; If the first target focus index is less than the total number of file list items, the second target focus index is set to the first target focus index.
5. The focus control method according to claim 1, wherein: The method of locating the view element associated with the second target focus index based on the second target focus index and in combination with a preset recursive search algorithm is as follows: Starting from the view element where the current focus is located, search upwards level by level for the second view element of the current view element; Search for the list item view of each second view element. If a focusable list item view is found, use the focusable view element as the target view element.
6. A focus control device, characterized in that: include: An acquisition module is used to obtain the focus movement instruction and determine the focus movement direction; a calculation module, configured to calculate a first target focus index based on the movement direction and preset layout parameters; wherein the layout parameters include the number of display items per row or column; a correction module, configured to correct the first target focus index according to a relationship between the first target focus index and an index range of a currently displayed file list item to obtain a second target focus index; a positioning module, configured to locate a view element associated with the second target focus index based on the second target focus index and in combination with a preset recursive search algorithm; The control module is used to control the focus according to the view element.
7. The focus control device according to claim 6, wherein: The calculation module is used to calculate the first target focus index based on the moving direction and the preset layout parameters, specifically: When the moving direction is downward, the calculation module adds the current focus index to the number of display items per row to obtain a first target focus index; When the moving direction is upward, the current focus index is subtracted from the number of display items per row to obtain the first target focus index; When the moving direction is leftward or rightward, a first target focus index is obtained according to preset layout parameters and a preset formula.
8. The focus control device according to claim 6, wherein: The correction module corrects the first target focus index according to the relationship between the first target focus index and the index range of the currently displayed file list item to obtain a second target focus index, specifically: If the first target focus index is less than a preset first threshold, the correction module sets the second target focus index to the preset first threshold; If the first target focus index is greater than or equal to the total number of file list items, setting the second target focus index to the total number of file list items minus a preset second threshold; If the first target focus index is less than the total number of file list items, the second target focus index is set to the first target focus index.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the focus control method according to any one of claims 1 to 5.
10. A terminal device, characterized in that: The apparatus comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the focus control method according to any one of claims 1 to 5 when executing the computer program.