WO2019019683A1 - 安卓中弹幕事件自动注册的方法、存储介质、设备及系统 - Google Patents
安卓中弹幕事件自动注册的方法、存储介质、设备及系统 Download PDFInfo
- Publication number
- WO2019019683A1 WO2019019683A1 PCT/CN2018/081311 CN2018081311W WO2019019683A1 WO 2019019683 A1 WO2019019683 A1 WO 2019019683A1 CN 2018081311 W CN2018081311 W CN 2018081311W WO 2019019683 A1 WO2019019683 A1 WO 2019019683A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- mark
- barrage
- event
- registration
- parser
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/37—Compiler construction; Parser generation
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
Definitions
- the invention relates to the technical field of Android (Android) development, in particular to a method, a storage medium, a device and a system for automatically registering an Android bullet event.
- Android Android
- the barrage technology has also been widely used in the field of live broadcasting.
- an Android software system applied to the field of live broadcasting, there will be a lot of places where barrage message reception processing is required.
- the traditional implementation method is that all the places that need to receive the barrage message need to be manually registered by the developer to receive the message.
- the similarity of the code in the registration process is very high, the use of the same code segment in the code will result in redundant code structure, unfavorable maintenance, and low development efficiency.
- the object of the present invention is to overcome the deficiencies of the above background art, and to provide a method, a storage medium, a device and a system for automatically registering an Android bullet event, which can improve a code segment that needs to be manually registered by a developer in the prior art.
- the automatic generation of the registration method not only makes the program structure simple and conducive to maintenance, but also greatly improves the development efficiency.
- the technical solution adopted by the present invention is to provide a method for automatically registering an Android bullet-in event, the method comprising the following steps:
- a custom registration mark Mark is created based on an existing annotation function of the Android system; the registration mark Mark is used to mark a method of a barrage event that needs to be automatically registered;
- step S1 based on the existing annotation function of the Android system, the specific process of creating a customized registration mark Mark is: using the @Target annotation provided by the Android system, the registration mark Mark is defined as being The markup of the method; using the @Retention annotation provided by the Android system, the registration mark Mark is defined to exist only in the class file and does not exist during execution; the name of the registration mark Mark is defined, and a parameter for passing the parsing parameter is defined. The parsing parameters.
- step S3 the specific process of obtaining the barrage event marked by the registered mark Mark in the compiling stage by using the created tag parser is: using the created tag in the compile phase.
- the parser obtains a set of methods for all the barrage events marked by the registered mark by calling the existing tag element obtaining method; and sequentially extracts each element in the current set by the for loop; After an element in the middle, the existing type get function is called to obtain the type corresponding to the element, and it is determined whether the type corresponding to the element is a method type. If yes, the function is obtained by calling an existing method to obtain the corresponding element.
- the present invention also provides a storage medium having stored thereon a computer program, the computer program being executed by the processor to implement the steps of the method for automatically registering the Android bullet-shadow event.
- the present invention also provides an apparatus for automatically registering an Android bullet-in event, comprising a memory, a processor, and a computer program stored on the memory and running on the processor, the processor implementing the computer program to implement the above The steps of the method of automatically registering the Android screen event.
- the invention also provides a system for automatically registering an Android bullet-in event, the system comprising a registration mark creation module, a markup parser creation module, and an automatic registration implementation module;
- the registration mark Mark creation module is configured to: create a customized registration mark Mark based on an existing annotation function of the Android system; the registration mark Mark is used to mark a method of a barrage event that needs to be automatically registered;
- the tag parser creation module is configured to: create a tag parser, and the tag parser is configured to find and save all the barrage events marked by the markup Mark;
- the automatic registration implementation module is configured to: when the method of registering the barrage event is marked with the mark mark, use the created tag parser to parse in the compiling stage, and obtain the method of the barrage event marked by the registered mark Mark. ; Register the methods for all barrage events that are obtained.
- the specific process of the registration mark creation module to create a custom registration mark Mark is: using the @Target annotation provided by the Android system, the registration mark Mark is defined as a mark of the method; using Android
- the @Retention annotation provided by the system defines the registration mark Mark as being present only in the class file and not during execution; defining the name of the registration mark Mark and defining a parsing parameter for passing the parsing parameter information.
- the specific process of the markup parser creation module to create a markup parser is to create a markup parser, such that the markup parser inherits from an existing abstract parser of the operating system;
- the abstract parsing method in the parser causes the created tag parser to find and save all the methods of the barrage event marked by the registered mark.
- the automatic registration implementation module uses the created tag parser to parse in the compiling stage, and the specific process of obtaining the barrage event marked by the registered mark Mark is:
- the existing markup parser by using the created markup parser, by calling the existing markup element acquisition method, a set of methods of the barrage events marked by the registered mark Mark is obtained; and each of the current set is sequentially taken by the for loop.
- the existing type get function is called to obtain the type corresponding to the element, and it is determined whether the type corresponding to the element is a method type, and if so, by calling the existing method
- the obtaining function obtains the method of the barrage event corresponding to the element, and marks the method of the barrage event as the method to be registered; if not, does not do any processing; and marks all the methods of the barrage event marked as the method to be registered Save to a preset collection of methods to be registered.
- the specific process of the automatic registration implementation module for registering all the methods of the barrage event obtained is: sequentially acquiring each barrage event in the set of methods to be registered by using a for loop Method; each time a method of a barrage event in the collection is fetched, the method of the barrage event is registered by calling an existing registration function.
- the method of registering the barrage event is marked by the custom registration mark Mark; then the created mark is utilized in the compile phase.
- the parser parses the registration mark Mark to obtain all the methods of the barrage event marked by the registered mark Mark; finally, the method of all the barrage events obtained is automatically registered, thereby realizing the purpose of automatic registration.
- the present invention improves the automatic generation of the registration of the barrage event, which not only does not need to use the same code segment in the code, but also simplifies the program structure. Conducive to maintenance, and greatly improved development efficiency.
- each type in the set is first type-determined, and only after the method type requirement is met, the corresponding bomb is obtained.
- FIG. 1 is a flowchart of a method for automatically registering an Android bullet-in event in an embodiment of the present invention
- FIG. 2 is a schematic structural diagram of an apparatus for automatically registering an Android bullet-in event in an embodiment of the present invention
- FIG. 3 is a structural block diagram of a system for automatically registering an Android bullet scene event in an embodiment of the present invention.
- an embodiment of the present invention provides a method for automatically registering an Android bullet-in event, the method comprising the following steps:
- Step S1 Creation of the registration mark Mark: Based on the existing Annotation function of the Android system, a custom registration mark Mark is created; the registration mark Mark is used to mark the method of the barrage event that needs to be automatically registered.
- Android provides a set of pre-compiled functions - Annotation (the annotation) function, its main function is to perform some functions in the compilation phase, and do some preliminary work on the compiled code.
- the present invention utilizes the characteristics of the annotation function to design a custom registration mark Mark, which can mark the method of the barrage event that needs to be automatically registered, so that we compile the application. You can do some things with the method of registering the mark Mark (such as auto-complete registration). That is to say, the registration mark Mark we designed will be embedded in the program later, parsed by the compiler during the compilation phase, and then parsed and processed the marked method of the bullet event.
- the native annotations provided by Android have the following types:
- @Target - indicates the scope of the program element that can be annotated for annotations of this type, such as the type of the program element that can indicate the annotation is the method METHOD;
- @Documented - indicates that elements with this annotation can be documented by tools such as javadoc;
- the registration mark Mark is defined as a markup for the method METHOD; using the @Retention annotation provided by the Android system, the registration mark Mark is defined to exist only in the class file and not in the Exists during execution; defines the name of the registration mark Mark, and defines a parsing parameter for passing parsing parameter information, the default value of which can be set to null.
- the implementation code of the created registration mark Mark can be as follows:
- the name of the registration mark Mark is Register; @Target(ElementType.METHOD) indicates that the registration mark Mark is a mark on the method; @Retention(RetentionPolicy.CLASS) indicates that the registration mark Mark exists only in the class file. Will exist during execution; Object params() default null indicates that the registration mark Mark has a parsing parameter for passing parameter information to the parser, and the default value of the parsing parameter is null.
- Step S2 Creation of the markup parser: Create a markup parser for finding and saving all the barrage events marked by the registered mark Mark.
- step S2 specifically includes the following process:
- Step S201 Create a markup parser (such as MyProcessor), so that the markup parser inherits from the abstract parser AbstractProcessor existing in the operating system.
- a markup parser such as MyProcessor
- Step S202 By rewriting the abstract parsing method process in the abstract parser AbstractProcessor, the created token parser is used to find and save all the salvage events marked by the registered mark Mark. Understandably, since the abstract parser AbstractProcessor is a system-provided abstract parser, we need to override the abstract methods in the abstract parser AbstractProcessor, and the most important abstract method is the abstract parsing process. Therefore, we need to override the process method to enable the created tag parser to be used to find and save all the barrage events marked by the mark Mark when parsing.
- Step S3. After the registration mark Mark is applied to the method for registering the barrage event, the method is performed by using the created tag parser in the compiling stage to obtain all the barrage events marked by the registered mark Mark; Register the operation of all the methods of the barrage event to achieve the purpose of automatic registration.
- the specific process of the method for parsing the barrage events marked by the registered mark Mark in the compile stage by using the created tag parser is as follows:
- Each element in the current set is sequentially retrieved by a for loop (the element here corresponds to the above-mentioned method of the marked barrage event); each time an element in the set is fetched, the existing call is made
- the type get function getKind obtains the type corresponding to the element, and determines whether the type corresponding to the element is a method type, and if so, obtains a method of the barrage event corresponding to the element by calling the existing method getMethod, and Mark the method of the barrage event as the method to be registered (such as regFunction); if not, do nothing.
- each element in the set is first type-determined, and only after the method type requirement is met. , will get the corresponding method of the barrage event, and mark the method of the barrage event as the method to be registered and save. This not only ensures the validity of the obtained barrage event method marked by Mark, but also improves the accuracy; and avoids the subsequent registration of the invalid (or wrong) barrage event method, which improves the implementation efficiency.
- the specific process for registering all methods of obtaining a barrage event is as follows:
- the method of retrieving each of the barrage events in the set of methods to be registered (such as listRegFunction) by means of a for loop; each time a method of a barrage event in the set is fetched, the existing registration function register is called by the register.
- the method of the curtain event performs the registration operation, thereby achieving the purpose of automatic registration.
- the method of registering the barrage event is marked by the custom registration mark Mark; then, at the compile stage, the registered markup is performed by using the created markup parser. Parsing, get all the methods of the barrage event marked by the mark Mark; finally, it will automatically register all the methods of the barrage event obtained, thus achieving the purpose of automatic registration.
- the invention can improve the code segment that needs to be manually registered by the developer in the prior art to be automatically generated to register, which not only makes the program structure simple and conducive to maintenance, but also greatly improves the development efficiency.
- the embodiment of the present invention further provides a storage medium, where the computer program is stored, and the computer program is executed by the processor to implement the Android shot in the foregoing embodiments.
- the steps of the method of automatic registration of the event includes a USB flash drive, a mobile hard disk, a ROM (Read-Only Memory), a RAM (Random Access Memory), a magnetic disk, or an optical disk, and the like.
- the medium of the program code includes a USB flash drive, a mobile hard disk, a ROM (Read-Only Memory), a RAM (Random Access Memory), a magnetic disk, or an optical disk, and the like.
- the embodiment of the present invention further provides an apparatus for automatically registering an Android bullet event, including a memory, a processor, and being stored in the memory.
- an apparatus for automatically registering an Android bullet event including a memory, a processor, and being stored in the memory.
- an embodiment of the present invention further provides a system for automatically registering an Android bullet-in event, the system comprising a registration mark creation module, a markup parser creation module, and an automatic registration implementation module.
- the registration mark Mark creation module is configured to: create a customized registration mark Mark based on an existing annotation function of the Android system; the registration mark Mark is used to mark a method of a barrage event that needs to be automatically registered.
- the implementation process is: using the @Target annotation provided by the Android system, the registration mark Mark is defined as a markup of the method; using the @Retention annotation provided by the Android system, the registration mark Mark is defined as only in the class file. Exists but does not exist during execution; defines the name of the registration mark Mark and defines a parsing parameter for passing parsing parameter information.
- the tag parser creation module is used to: create a tag parser that is used to find and save all the barrage events marked by the tag Mark.
- the implementation process is: creating a tag parser, so that the tag parser inherits from the existing abstract parser of the operating system; by rewriting the abstract parsing method in the abstract parser, the created tag parser is used for Find all methods of the barrage event marked with the mark Mark and save it.
- the automatic registration implementation module is used to: when the method of registering the barrage event is marked with the mark Mark, the parsing of the created markup is used in the compiling stage to obtain the method of the barrage event marked by the registered mark Mark; Get all the methods of the barrage event to register.
- the automatic registration implementation module uses the created tag parser to parse in the compiling stage, and the specific process of obtaining the barrage event marked by the registered mark Mark is: using the created tag parser in the compiling stage, By calling an existing tag element acquisition method, a set of methods for all the barrage events marked by the markup mark is obtained; each element in the current set is sequentially fetched by a for loop; each time one of the sets is fetched After the element, the existing type get function is called to obtain the type corresponding to the element, and it is determined whether the type corresponding to the element is a method type, and if so, the corresponding method is obtained by calling an existing method to obtain a corresponding barrage of the element. The method of the event, and mark the method of the barrage event as the method to be registered; if not, do nothing; finally, save all the methods marked as the barrage event of the method to be registered to a preset to be registered Method collection.
- the specific process of the automatic registration implementation module performing a registration operation on all the methods of the barrage event obtained is: sequentially acquiring each barrage event in the method set to be registered by a for loop; After the method of extracting a barrage event in the collection is taken, the method of the barrage event is registered by calling an existing registration function.
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
本发明公开了一种安卓中弹幕事件自动注册的方法、存储介质、设备及系统,涉及安卓开发技术领域。该方法包括:先基于安卓系统已有的注解功能创建自定义的注册标记Mark;再创建标记解析器,该标记解析器用于查找所有被注册标记Mark标记过的弹幕事件的方法;最后,当需要注册的弹幕事件的方法打上注册标记Mark后,在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法;对得到的所有弹幕事件的方法进行注册操作。本发明能将现有技术中需要开发人员手工进行注册的代码段改进为自动生成的方式来进行注册,不但使得程序结构精简利于维护,而且极大地提高了开发效率。
Description
本发明涉及Android(安卓)开发技术领域,具体来讲是一种安卓中弹幕事件自动注册的方法、存储介质、设备及系统。
在Android系统中常常有监听各种各样的事件的要求,比如最常见的按钮事件或者弹幕消息接收事件等。如果开发者想要在弹幕消息到达系统的时候能够知道弹幕信息,那么就需要在系统初始化阶段将相应内容初始化好,然后将监听器注册到事件总线中,这样当事件总线得到弹幕消息的时候才会将消息分发给注册者。
随着弹幕技术的不断发展,弹幕技术在直播领域也得到了广泛使用。然而,在一个应用于直播领域的Android软件系统中,会有非常多的地方需要进行弹幕消息接收处理。传统的实现方法是:在所有需要进行弹幕消息接收的地方全部都需要开发人员进行手动注册的方式来进行消息接收。但由于注册过程的代码的相似度非常高,这样在代码中大量使用相同代码段会导致代码程序结构冗余、后期不利于维护,而且开发效率也低。
发明内容
本发明的目的是为了克服上述背景技术的不足,提供一种安卓中弹幕事件自动注册的方法、存储介质、设备及系统,能将现有技术中需要开发人员手工进行注册的代码段改进为自动生成的方式来进行注册,不但使得程序结构精简利于维护,而且极大地提高了开发效率。
为达到以上目的,本发明采取的技术方案是:提供一种安卓中弹幕事件自动注册的方法,该方法包括以下步骤:
S1、注册标记Mark的创建:基于安卓系统已有的注解功能,创建自定义的注册标记Mark;所述注册标记Mark用于标记需要被自动注册的弹幕事件的方法;
S2、标记解析器的创建:创建标记解析器,所述标记解析器用于查找所有被注册标记Mark标记过的弹幕事件的方法并保存;
S3、自动注册的实现:为需要注册的弹幕事件的方法打上注册标记Mark后,在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法;对得到的所有弹幕事件的方法进行注册操作。
在上述技术方案的基础上,步骤S1中,基于安卓系统已有的注解功能,创建自定义的注册标记Mark的具体流程为:利用安卓系统提供的@Target注解,将注册标记Mark定义为是对方法的标记;利用安卓系统提供的@Retention注解,将注册标记Mark定义为仅在class文件中存在而不会在执行期间存在;定义注册标记Mark的名称,并定义一个用于传递解析用参数信息的解析参数。
在上述技术方案的基础上,步骤S3中,在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法的具体流程为:在编译阶段利用创建的标记解析器,通过调用已有的标记元素获取方法,获取到所有被注册标记Mark标记过的弹幕事件的方法的集合;通过for循环的方式依次取出当前集合中的每个元素;每次取出集合中的一个元素后,通过调用已有的类型获取函数获取到该元素对应的类型,并判断该元素对应的类型是否是方法类型,若是,则通过调用已有的方法获取函数获取到该元素对应的弹幕 事件的方法,并将该弹幕事件的方法标记为待注册方法;若否,则不做任何处理;将所有标记为待注册方法的弹幕事件的方法保存至一个预设的待注册方法集合中。
本发明还提供一种存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现上述安卓中弹幕事件自动注册的方法的步骤。
本发明还提供一种安卓中弹幕事件自动注册的设备,包括存储器、处理器及存储在存储器上并在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现上述安卓中弹幕事件自动注册的方法的步骤。
本发明还提供一种安卓中弹幕事件自动注册的系统,该系统包括注册标记Mark创建模块、标记解析器创建模块、自动注册实现模块;
所述注册标记Mark创建模块用于:基于安卓系统已有的注解功能,创建自定义的注册标记Mark;所述注册标记Mark用于标记需要被自动注册的弹幕事件的方法;
所述标记解析器创建模块用于:创建标记解析器,所述标记解析器用于查找所有被注册标记Mark标记过的弹幕事件的方法并保存;
所述自动注册实现模块用于:当需要注册的弹幕事件的方法打上注册标记Mark后,在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法;对得到的所有弹幕事件的方法进行注册操作。
在上述技术方案的基础上,所述注册标记Mark创建模块创建自定义的注册标记Mark的具体流程为:利用安卓系统提供的@Target注解,将注册标记Mark定义为是对方法的标记;利用安卓系统提供的@Retention注解,将注册标记Mark定义为仅在class文件中存在 而不会在执行期间存在;定义注册标记Mark的名称,并定义一个用于传递解析用参数信息的解析参数。
在上述技术方案的基础上,所述标记解析器创建模块创建标记解析器的具体流程为:创建一个标记解析器,使该标记解析器继承于操作系统已有的抽象解析器;通过重写抽象解析器中的抽象解析方法,使得创建的标记解析器用于查找所有被注册标记Mark标记过的弹幕事件的方法并保存。
在上述技术方案的基础上,所述自动注册实现模块在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法的具体流程为:
在编译阶段利用创建的标记解析器,通过调用已有的标记元素获取方法,获取到所有被注册标记Mark标记过的弹幕事件的方法的集合;通过for循环的方式依次取出当前集合中的每个元素;每次取出集合中的一个元素后,通过调用已有的类型获取函数获取到该元素对应的类型,并判断该元素对应的类型是否是方法类型,若是,则通过调用已有的方法获取函数获取到该元素对应的弹幕事件的方法,并将该弹幕事件的方法标记为待注册方法;若否,则不做任何处理;将所有标记为待注册方法的弹幕事件的方法保存至一个预设的待注册方法集合中。
在上述技术方案的基础上,所述自动注册实现模块对得到的所有弹幕事件的方法进行注册操作的具体流程为:通过for循环的方式依次取出待注册方法集合中的每个弹幕事件的方法;每次取出集合中的一个弹幕事件的方法后,通过调用已有的注册函数对该弹幕事件的方法进行注册操作。
本发明的有益效果在于:
(1)本发明中,利用上述方法实现安卓系统中的弹幕事件注册时,会通过自定义的注册标记Mark为需要注册的弹幕事件的方法打上标记;然后在编译阶段会利用创建的标记解析器对注册标记Mark进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法;最终,会自动对得到的所有弹幕事件的方法进行注册操作,从而实现自动注册的目的。
与现有技术中需要开发人员手工进行弹幕事件注册的方式相比,本发明改进为自动生成的方式来进行弹幕事件的注册,不但无需在代码中大量使用相同代码段,使得程序结构精简利于维护,而且极大地提高了开发效率。
(2)在获取到所有被注册标记Mark标记过的弹幕事件的方法集合后,会对集合中的每个元素先进行类型的判断,只有满足方法类型要求后,才会去获取对应的弹幕事件的方法,并将该弹幕事件的方法标记为待注册方法并保存。这样不但保证了获取到的被注册标记Mark标记过的弹幕事件方法的有效性,提高了准确性;而且避免了后续对无效(或错误)的弹幕事件方法进行注册操作,提高了实现效率。
图1为本发明实施例中的安卓中弹幕事件自动注册的方法的流程图;
图2为本发明实施例中的安卓中弹幕事件自动注册的设备的结构示意图;
图3为本发明实施例中的安卓中弹幕事件自动注册的系统的结构框图。
下面结合附图及具体实施例对本发明作进一步的详细描述。
参见图1所示,本发明实施例提供一种安卓中弹幕事件自动注册的方法,该方法包括以下步骤:
步骤S1、注册标记Mark的创建:基于安卓系统已有的Annotation(注解)功能,创建一个自定义的注册标记Mark;所述注册标记Mark用于标记需要被自动注册的弹幕事件的方法。
可以理解的是,所谓自动化注册其实也就是让程序自己来完成注册的过程,将人工编写代码的部分通过程序的方式来自动完成。
目前,在安卓的开发过程中,安卓系统提供了一套预编译的功能——Annotation(注解)功能,其主要功能是在编译阶段执行一些功能,对编译的代码进行一些前期工作。而本发明则是利用该注解功能的特性设计了一套自定义的注册标记Mark,该注册标记Mark能对需要被自动注册的弹幕事件的方法进行标记,从而使得我们对应用程序进行编译的时候能对打有注册标记Mark的方法进行一些操作(如自动完成注册)。也就是说我们所设计的注册标记Mark后期会嵌入到程序当中,在编译阶段被编译器进行解析,然后对标记过的弹幕事件的方法进行解析和处理操作。
具体来说,安卓系统提供的原生注解有以下几种:
@Target——指明该类型的注解可以注解的程序元素的范围,如可以指明注解的程序元素的类型为方法METHOD;
@Documented——指明拥有这个注解的元素可以被javadoc此类的工具文档化;
@Inherited——指明该注解类型被自动继承;
@Retention——指明了该注解被保留的时间长短。
在此基础上,本实施例中,基于安卓系统已有的Annotation(注解)功能,创建一个自定义的注册标记Mark的具体流程为:
利用安卓系统提供的@Target注解,将注册标记Mark定义为是对方法METHOD的标记;利用安卓系统提供的@Retention注解,将注册标记Mark定义为仅在class(编译)文件中存在而不会在执行期间存在;定义注册标记Mark的名称,并定义一个用于传递解析用参数信息的解析参数,该解析参数的默认值可设置为空。
对应上述创建流程,创建出的注册标记Mark的实现代码可如下:
其中,注册标记Mark的名称为Register;@Target(ElementType.METHOD)表明该注册标记Mark是对方法的标记;@Retention(RetentionPolicy.CLASS)表明该注册标记Mark仅仅在class(编译)文件中存在不会在执行期间存在;Object params()default null表明该注册标记Mark具有一个用于传递参数信息到解析器使用的解析参数,且该解析参数的默认值为空。
通过上述操作,我们就设计了一个自定义的注册标记Mark,该注册标记Mark能用于标记需要被自动注册的弹幕事件的方法,是完成后续自动注册操作的基础,为后续功能奠定了基础。
步骤S2、标记解析器的创建:创建一个标记解析器,该标记解析器用于查找所有被注册标记Mark标记过的弹幕事件的方法并保存。
在一种实施方式中,步骤S2具体包括以下流程:
步骤S201、创建一个标记解析器(如MyProcessor),使该标记解析器继承于操作系统已有的抽象解析器AbstractProcessor。
步骤S202、通过重写抽象解析器AbstractProcessor中的抽象解析方法process,使得创建的标记解析器用于查找所有被注册标记Mark标记过的弹幕事件的方法并保存。可以理解的是,由于抽象解析器AbstractProcessor是一个系统提供的抽象的解析器,所以我们需要重写抽象解析器AbstractProcessor中的抽象方法,而最关键的抽象方法是抽象解析方法process。因此,我们需要重写process方法来使得创建的标记解析器在进行解析时,能用于查找所有被注册标记Mark标记过的弹幕事件的方法并保存。
需要说明的是,上述实施方式仅是一种举例而已,开发人员在实际创建标记解析器时,也可不采用继承操作系统已有的抽象解析器的方式,而自行进行代码的自定义编写。
步骤S3、自动注册的实现:为需要注册的弹幕事件的方法打上注册标记Mark后,在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法;对得到的所有弹幕事件的方法进行注册操作,从而实现自动注册的目的。
在一种实施方式中,在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法的具体流程如下:
1、在编译阶段利用创建的标记解析器,通过调用已有的标记元素获取方法getElementsAnnotatedWith(Register.class),获取到所有被注册标记Mark标记过的弹幕事件的方法的集合(如list)。
2、通过for循环的方式依次取出当前集合中的每个元素(此处的元素即对应上述的被标记过的弹幕事件的方法);每次取出集合中 的一个元素后,通过调用已有的类型获取函数getKind获取到该元素对应的类型,并判断该元素对应的类型是否是方法类型,若是,则通过调用已有的方法获取函数getMethod获取到该元素对应的弹幕事件的方法,并将该弹幕事件的方法标记为待注册方法(如regFunction);若不是,则不做任何处理。
3、将所有标记为待注册方法的弹幕事件的方法保存至一个预设的待注册方法集合(如listRegFunction)中。
可以理解的是,在上述实施方式中,在获取到所有被注册标记Mark标记过的弹幕事件的方法集合后,会对集合中的每个元素先进行类型的判断,只有满足方法类型要求后,才会去获取对应的弹幕事件的方法,并将该弹幕事件的方法标记为待注册方法并保存。这样不但保证了获取到的被注册标记Mark标记过的弹幕事件方法的有效性,提高了准确性;而且避免了后续对无效(或错误)弹幕事件方法的注册,提高了实现效率。
在一种实施方式中,对得到的所有弹幕事件的方法进行注册操作的具体流程如下:
通过for循环的方式依次取出待注册方法集合(如listRegFunction)中的每个弹幕事件的方法;每次取出集合中的一个弹幕事件的方法后,通过调用已有的注册函数register对该弹幕事件的方法进行注册操作,从而实现自动注册的目的。
利用上述方法实现安卓系统中的弹幕事件注册时,会通过自定义的注册标记Mark为需要注册的弹幕事件的方法打上标记;然后在编译阶段会利用创建的标记解析器对注册标记Mark进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法;最终,会自动对得到的所有弹幕事件的方法进行注册操作,从而实现自动注册的目的。本 发明能将现有技术中需要开发人员手工进行注册的代码段改进为自动生成的方式来进行注册,不但使得程序结构精简利于维护,而且极大地提高了开发效率。
对应上述的安卓中弹幕事件自动注册的方法,本发明实施例还提供一种存储介质,其上存储有计算机程序,该计算机程序被处理器执行时可实现上述各实施例中的安卓中弹幕事件自动注册的方法的步骤。需要说明的是,所述存储介质包括U盘、移动硬盘、ROM(Re ad-Only Memory,只读存储器)、RAM(Random Access Memory,随机存取存储器)、磁碟或者光盘等各种可以存储程序代码的介质。
另外,参见图2所示,对应上述的安卓中弹幕事件自动注册的方法,本发明实施例还提供一种安卓中弹幕事件自动注册的设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,该处理器执行计算机程序时可实现上述各实施例中的安卓中弹幕事件自动注册的方法的步骤。
参见图3所示,本发明实施例还提供一种安卓中弹幕事件自动注册的系统,该系统包括注册标记Mark创建模块、标记解析器创建模块、自动注册实现模块。
其中,注册标记Mark创建模块用于:基于安卓系统已有的注解功能,创建自定义的注册标记Mark;所述注册标记Mark用于标记需要被自动注册的弹幕事件的方法。具体来说,其实现流程为:利用安卓系统提供的@Target注解,将注册标记Mark定义为是对方法的标记;利用安卓系统提供的@Retention注解,将注册标记Mark定义为仅在class文件中存在而不会在执行期间存在;定义注册标记Mark的名称,并定义一个用于传递解析用参数信息的解析参数。
标记解析器创建模块用于:创建标记解析器,所述标记解析器用 于查找所有被注册标记Mark标记过的弹幕事件的方法并保存。具体来说,其实现流程为:创建一个标记解析器,使该标记解析器继承于操作系统已有的抽象解析器;通过重写抽象解析器中的抽象解析方法,使得创建的标记解析器用于查找所有被注册标记Mark标记过的弹幕事件的方法并保存。
自动注册实现模块用于:当需要注册的弹幕事件的方法打上注册标记Mark后,在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法;对得到的所有弹幕事件的方法进行注册操作。
进一步地,所述自动注册实现模块在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法的具体流程为:在编译阶段利用创建的标记解析器,通过调用已有的标记元素获取方法,获取到所有被注册标记Mark标记过的弹幕事件的方法的集合;通过for循环的方式依次取出当前集合中的每个元素;每次取出集合中的一个元素后,通过调用已有的类型获取函数获取到该元素对应的类型,并判断该元素对应的类型是否是方法类型,若是,则通过调用已有的方法获取函数获取到该元素对应的弹幕事件的方法,并将该弹幕事件的方法标记为待注册方法;若否,则不做任何处理;最后,将所有标记为待注册方法的弹幕事件的方法保存至一个预设的待注册方法集合中。
更进一步地,所述自动注册实现模块对得到的所有弹幕事件的方法进行注册操作的具体流程为:通过for循环的方式依次取出待注册方法集合中的每个弹幕事件的方法;每次取出集合中的一个弹幕事件的方法后,通过调用已有的注册函数对该弹幕事件的方法进行注册操作。
需要说明的是:上述实施例提供的系统在实现安卓系统中的弹幕事件自动注册时,仅以上述各功能模块的划分进行举例说明,实际应用中,可根据需要而将上述功能分配由不同的功能模块完成,即将系统的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。
本发明不局限于上述实施方式,对于本技术领域的普通技术人员来说,在不脱离本发明原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也视为本发明的保护范围之内。
本说明书中未作详细描述的内容属于本领域专业技术人员公知的现有技术。
Claims (10)
- 一种安卓中弹幕事件自动注册的方法,其特征在于,该方法包括以下步骤:S1、注册标记Mark的创建:基于安卓系统已有的注解功能,创建自定义的注册标记Mark;所述注册标记Mark用于标记需要被自动注册的弹幕事件的方法;S2、标记解析器的创建:创建标记解析器,所述标记解析器用于查找所有被注册标记Mark标记过的弹幕事件的方法并保存;S3、自动注册的实现:为需要注册的弹幕事件的方法打上注册标记Mark后,在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法;对得到的所有弹幕事件的方法进行注册操作。
- 如权利要求1所述的安卓中弹幕事件自动注册的方法,其特征在于:步骤S1中,基于安卓系统已有的注解功能,创建自定义的注册标记Mark的具体流程为:利用安卓系统提供的@Target注解,将注册标记Mark定义为是对方法的标记;利用安卓系统提供的@Retention注解,将注册标记Mark定义为仅在class文件中存在而不会在执行期间存在;定义注册标记Mark的名称,并定义一个用于传递解析用参数信息的解析参数。
- 如权利要求1所述的安卓中弹幕事件自动注册的方法,其特征在于:步骤S3中,在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法的具体流程为:在编译阶段利用创建的标记解析器,通过调用已有的标记元素获取方法,获取到所有被注册标记Mark标记过的弹幕事件的方法的集合;通过for循环的方式依次取出当前集合中的每个元素;每次取出集合中的一个元素后,通过调用已有的类型获取函数获取到该元素对应的类型,并判断该元素对应的类型是否是方法类型,若是,则通过调用已有的方法获取函数获取到该元素对应的弹幕事件的方法,并将该弹幕事件的方法标记为待注册方法;若否,则不做任何处理;将所有标记为待注册方法的弹幕事件的方法保存至一个预设的待注册方法集合中。
- 一种存储介质,其上存储有计算机程序,其特征在于:所述计算机程序被处理器执行时实现上述权利要求1至3中任一项所述方法的步骤。
- 一种安卓中弹幕事件自动注册的设备,包括存储器、处理器及存储在所述存储器上并在所述处理器上运行的计算机程序,其特征在于:所述处理器执行所述计算机程序时实现上述权利要求1至3中任一项所述方法的步骤。
- 一种安卓中弹幕事件自动注册的系统,其特征在于:该系统包括注册标记Mark创建模块、标记解析器创建模块、自动注册实现模块;所述注册标记Mark创建模块用于:基于安卓系统已有的注解功能,创建自定义的注册标记Mark;所述注册标记Mark用于标记需要被自动注册的弹幕事件的方法;所述标记解析器创建模块用于:创建标记解析器,所述标记解析器用于查找所有被注册标记Mark标记过的弹幕事件的方法并保存;所述自动注册实现模块用于:当需要注册的弹幕事件的方法打上注册标记Mark后,在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法;对得到的所有弹 幕事件的方法进行注册操作。
- 如权利要求6所述的安卓中弹幕事件自动注册的系统,其特征在于:所述注册标记Mark创建模块创建自定义的注册标记Mark的具体流程为:利用安卓系统提供的@Target注解,将注册标记Mark定义为是对方法的标记;利用安卓系统提供的@Retention注解,将注册标记Mark定义为仅在class文件中存在而不会在执行期间存在;定义注册标记Mark的名称,并定义一个用于传递解析用参数信息的解析参数。
- 如权利要求6所述的安卓中弹幕事件自动注册的系统,其特征在于:所述标记解析器创建模块创建标记解析器的具体流程为:创建一个标记解析器,使该标记解析器继承于操作系统已有的抽象解析器;通过重写抽象解析器中的抽象解析方法,使得创建的标记解析器用于查找所有被注册标记Mark标记过的弹幕事件的方法并保存。
- 如权利要求6所述的安卓中弹幕事件自动注册的系统,其特征在于,所述自动注册实现模块在编译阶段利用创建的标记解析器进行解析,得到所有被注册标记Mark标记过的弹幕事件的方法的具体流程为:在编译阶段利用创建的标记解析器,通过调用已有的标记元素获取方法,获取到所有被注册标记Mark标记过的弹幕事件的方法的集合;通过for循环的方式依次取出当前集合中的每个元素;每次取出集合中的一个元素后,通过调用已有的类型获取函数获取到该元素对应的类型,并判断该元素对应的类型是否是方法类型,若是,则通过调用已有的方法获取函数获取到该元素对应的弹幕事件的方法,并将 该弹幕事件的方法标记为待注册方法;若否,则不做任何处理;将所有标记为待注册方法的弹幕事件的方法保存至一个预设的待注册方法集合中。
- 如权利要求9所述的安卓中弹幕事件自动注册的系统,其特征在于,所述自动注册实现模块对得到的所有弹幕事件的方法进行注册操作的具体流程为:通过for循环的方式依次取出待注册方法集合中的每个弹幕事件的方法;每次取出集合中的一个弹幕事件的方法后,通过调用已有的注册函数对该弹幕事件的方法进行注册操作。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710624143.3 | 2017-07-27 | ||
| CN201710624143.3A CN107450922B (zh) | 2017-07-27 | 2017-07-27 | 安卓中弹幕事件自动注册的方法、存储介质、设备及系统 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2019019683A1 true WO2019019683A1 (zh) | 2019-01-31 |
Family
ID=60489706
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2018/081311 Ceased WO2019019683A1 (zh) | 2017-07-27 | 2018-03-30 | 安卓中弹幕事件自动注册的方法、存储介质、设备及系统 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN107450922B (zh) |
| WO (1) | WO2019019683A1 (zh) |
Families Citing this family (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107450922B (zh) * | 2017-07-27 | 2020-01-03 | 武汉斗鱼网络科技有限公司 | 安卓中弹幕事件自动注册的方法、存储介质、设备及系统 |
| CN108882053B (zh) * | 2018-06-29 | 2021-04-09 | 武汉斗鱼网络科技有限公司 | 弹幕消息分发方法、装置、设备及存储介质 |
| CN109348303B (zh) * | 2018-09-30 | 2021-02-02 | 武汉斗鱼网络科技有限公司 | 一种弹幕消息的分发方法、装置、终端和存储介质 |
| CN109495782B (zh) * | 2018-10-30 | 2021-04-09 | 武汉斗鱼网络科技有限公司 | 一种弹幕消息的存储方法、系统和存储介质 |
| CN111338659B (zh) * | 2020-02-28 | 2023-06-02 | 广州市百果园信息技术有限公司 | 安装包生成方法、消息管理方法、装置、设备及存储介质 |
| CN113961191A (zh) * | 2021-11-03 | 2022-01-21 | 北京沃东天骏信息技术有限公司 | 一种自动注册楼层化代码方法及装置、存储介质 |
| CN117234500B (zh) * | 2023-10-20 | 2025-01-24 | 浙江常青树信息技术有限责任公司 | 一种使用java语言实现的模型多继承方法、装置及介质 |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20130151463A1 (en) * | 2011-12-08 | 2013-06-13 | Sap Ag | Information Validation |
| CN106528261A (zh) * | 2016-12-02 | 2017-03-22 | 武汉斗鱼网络科技有限公司 | 应用页面初始化的编译控制装置及方法 |
| CN106648569A (zh) * | 2015-11-02 | 2017-05-10 | 腾讯科技(深圳)有限公司 | 目标序列化实现方法和装置 |
| CN107450922A (zh) * | 2017-07-27 | 2017-12-08 | 武汉斗鱼网络科技有限公司 | 安卓中弹幕事件自动注册的方法、存储介质、设备及系统 |
-
2017
- 2017-07-27 CN CN201710624143.3A patent/CN107450922B/zh active Active
-
2018
- 2018-03-30 WO PCT/CN2018/081311 patent/WO2019019683A1/zh not_active Ceased
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20130151463A1 (en) * | 2011-12-08 | 2013-06-13 | Sap Ag | Information Validation |
| CN106648569A (zh) * | 2015-11-02 | 2017-05-10 | 腾讯科技(深圳)有限公司 | 目标序列化实现方法和装置 |
| CN106528261A (zh) * | 2016-12-02 | 2017-03-22 | 武汉斗鱼网络科技有限公司 | 应用页面初始化的编译控制装置及方法 |
| CN107450922A (zh) * | 2017-07-27 | 2017-12-08 | 武汉斗鱼网络科技有限公司 | 安卓中弹幕事件自动注册的方法、存储介质、设备及系统 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN107450922A (zh) | 2017-12-08 |
| CN107450922B (zh) | 2020-01-03 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN107450922B (zh) | 安卓中弹幕事件自动注册的方法、存储介质、设备及系统 | |
| CN111124906A (zh) | 基于动态埋点的跟踪方法、编译方法、装置和电子设备 | |
| US20230315416A1 (en) | Code translation method and apparatus, and device | |
| CN109343836B (zh) | 数据序列化、数据反序列方法、装置及设备 | |
| WO2018196559A1 (zh) | 应用程序异常处理方法、装置及存储介质 | |
| CN104834837A (zh) | 一种基于语义的二进制代码反混淆方法 | |
| CN111966339A (zh) | 埋点参数的录入方法、装置、计算机设备和存储介质 | |
| CN116560642A (zh) | 代码生成方法及其装置、电子设备及存储介质 | |
| WO2018176822A1 (zh) | 一种操作ElasticSearch的方法及装置 | |
| CN107515739A (zh) | 提高代码执行性能的方法及装置 | |
| CN107451045A (zh) | 一种异常信息定位的方法及装置 | |
| CN106814997A (zh) | 数据库操作语言脚本优化方法、装置及系统 | |
| CN106919374B (zh) | 一种脚本生成方法和装置 | |
| CN105138364A (zh) | 一种终端系统升级的方法及装置 | |
| CN108132881A (zh) | 一种自动化测试方法及系统 | |
| CN112800194B (zh) | 一种接口变更识别方法、装置、设备及存储介质 | |
| CN102810062B (zh) | 基于相似度判定的嵌入式操作系统内核版本识别方法 | |
| CN110795915B (zh) | xml文件批量修改方法、系统、设备和计算机可读存储介质 | |
| RU2008139875A (ru) | Устройство обработки для детектирования определенной компьтерной команды | |
| CN115437640A (zh) | 快速编译工程代码的方法 | |
| US11449554B2 (en) | Extensible search solution for asset information | |
| CN111444208B (zh) | 一种数据更新方法及相关设备 | |
| CN108255478A (zh) | 一种标签式模板开发方法 | |
| CN114721657A (zh) | 一种多线程程序实现方法、装置及相关设备 | |
| CN107861779A (zh) | 页面对象定位方法及装置、存储介质、电子设备 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 18837733 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 18837733 Country of ref document: EP Kind code of ref document: A1 |
