Method for Android system to simulate and support remote multi-point control instruction
Technical Field
The invention relates to an Android system remote control technology, in particular to a method for simulating and supporting remote multipoint control instructions by an Android system.
Background
The Android system is provided with a touch control instruction of the Android system, and when the Android system needs to be remotely controlled, a set of control instruction needs to be packaged on the upper layer of the system so as to control the remote Android system.
When we only need one touch click, we can do this:
firstly, acquiring a click simulation object newly introduced by Java, utilizing a motionevent object function by a method of sendPointerSync (), and then inputting corresponding parameters (click start time, click end time, click type (pressing, lifting and touching), x-axis coordinate position of a screen and y-axis coordinate position of the screen). If a touch click event needs to have a pressing and lifting action, the pressing action needs to be implemented once, and then the lifting action needs to be invoked once, so that the touch click event is completed.
When we only need two or three touch points, we can do this:
similarly, an object of simulation click of Instrumentation newly introduced by Java needs to be acquired, a motionevent. But only need here with the motion event.pointerproperties [ ] array and the motion event.pointercodes [ ] array, then encapsulate each touch click event, then fill the data into these two arrays, from the code level, we need to copy the code that writes a touch click event, modify the parameter and just can use, so we can support the click event of two points.
This is also possible when one or two touch click events are performed, but if more than ten touch click events are required, the code is inconvenient to expand and manage, and the code amount is undoubtedly heavy and redundant, which is not beneficial to reading and expanding.
Disclosure of Invention
The invention aims at the technical problem of the reference, and provides a method for simulating and supporting remote multipoint control instructions by an Android system.
In order to achieve the purpose, the specific technical scheme of the invention is as follows:
a method for supporting remote multipoint control instructions in Android system simulation comprises the following steps:
defining an object on the upper layer of the system, wherein the object comprises three attributes of coordinates x/y and touch point assignment action, and performing a layer of list array packaging on the object;
traversing the list array to obtain a current corresponding value and endowing the current corresponding value to the list array, marking the position of the simulated touch point at this time through a temporary variable targetIndex, and performing displacement calculation to obtain a click type;
and calling a sendPointerSync method to trigger the multi-point touch instruction.
Preferably, the specific assignment method of action is as follows: when there is only one touch point, the action value is 0, when there are two touch points, the action value is 1, when there are three touch points, the action value is 2, and so on.
Preferably, the sendPointerSync method is:
sendPointerSync (motionevent. object (click start time, click end time, type of click (press, lift, touch), number of arrays of this touch point, number of arrays of PointerProperties, number of arrays of pointerCoords, 0,0,1,1,0,0, inputdevice.
By adopting the technical scheme, the invention reduces the redundancy of codes, can flexibly support multi-point touch control, can accurately know the current specific active touch point, and improves the code readability and expansibility.
Detailed Description
In order that those skilled in the art will be able to understand and practice the present invention, further description will be given below of embodiments of the present invention.
The invention provides a method for supporting remote multipoint control instructions by Android system simulation, which comprises the following steps:
(1) defining an object on the upper layer of the system, wherein the object comprises three attributes of coordinates x/y and touch point assignment action, and performing a layer of list array packaging on the object.
Specifically, such a layer of packaging can be performed on the upper layer, by defining an object, where the object includes three attributes of x, y, and action, where the x and y attributes are values serving as coordinate axes of a mobile phone screen, and the action attribute is a behavior judgment value of a touch point, and then performing a layer of packaging of a list array on the object, when there is only one touch point, our action value is 0, when there are two touch points, the action value is 1, when there are three touch points, the action value is 2, and the action value is incremented by analogy, so we can implement remote multi-point touch.
(2) And traversing the list array to obtain a current corresponding value and endowing the current corresponding value to the list array, marking the position of the simulated touch point at this time through a temporary variable targetIndex, and performing displacement calculation to obtain a click type.
Specifically, the following are included:
a. firstly, PointProperties and PointCoords are instantiated, and the size of the touch point list at the time is filled, so that the sets corresponding to the PointProperties and the PointCoords do not need to be set in advance, and only the value is directly assigned through the size acquired from the far end;
b. traversing the size of the packaged finger List array through an enhanced for loop (the enhanced for loop can improve the processing time), acquiring the current corresponding value and setting;
c. marking the position of the touch Point of the simulation by a temporary variable (targetIndex), calculating displacement (< <) to obtain a difference value (the difference value between the click starting time and the click ending time), and according to the difference value, judging whether the click type action Point is move, down or up;
(3) and calling a sendPointerSync method to trigger the multi-point touch instruction.
Specifically, after the data information value is obtained, the sendPointerSync method can be executed very simply:
corresponding parameter values, motionevent.object function, are sequentially filled in, and then corresponding parameters (click start time, click end time, click type (press, lift, touch), array size of touch point, array of PointerProperties, array of pointerCoords, 0,0,1,1,0,0, input device.source _ touch, 0) are input. Namely, the following steps can be called:
inst.sendPointerSync(MotionEvent.obtain(when,when,actionPoint,jsonArray.size(),pointerProperties,pointerCoords,0,0,1,1,0,0,InputDevice.SOURCE_TOUCHSCREEN,0))。
the above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.