Detailed Description
In the operating systems of many intelligent devices, a picture loading library is required to be adopted to load and display pictures. Taking the android system as an example, the current open-source picture loading library includes but is not limited to: a Glide picture load library by Google, a Fresco picture load library by Facebook, and a picaso picture load library by Square. In the development process of various APPs, a proper picture loading library is selected to realize picture display, and the picture display effect and performance generally determine the user experience of the APP, so that how to select the proper picture loading library is one of the important points concerned by APP developers. Currently, with the development of technologies, many image loading libraries with stronger functions and better performance are emerging, so expanding or migrating existing image loading library codes into service codes has become a demand of many APP developers. However, since each APP uses a different picture loading library, the code cannot be multiplexed basically. Since different image loading libraries at present have great difference in implementation codes (such as difference of API), it increases learning cost, Bug occurrence probability and Bug repair cost. When a picture loading library which a certain APP depends on needs to be switched or a code of the picture loading library needs to be migrated, a service code of the APP needs to be modified greatly, so that the switching process of the picture loading library is inefficient. For example, assuming that a certain APP originally uses a Fresco picture loading library, at this time, the code of the picaso picture loading library needs to be migrated to the APP (i.e., the original Fresco picture loading library code is replaced by the picaso picture loading library code), in this process, a developer needs to delete the implementation code file of the Fresco picture loading library, add the implementation code file of the picaso picture loading library, and also needs to modify all places of the APP service code that call the API of the Fresco picture loading library, which greatly increases the difficulty of code migration. In view of the above, a solution is proposed herein for facilitating the migration of a picture loading library.
Fig. 1 is a flowchart of a method for implementing a picture loading library according to an exemplary embodiment of the present application. As shown in FIG. 1, in the embodiment of the present application, the method includes the following steps 101-102, wherein:
in step 101, an API common to a plurality of picture loading libraries is defined, wherein the API is used for being called in a service code.
The picture loading library generally provides some APIs (application programming interfaces) for the APP service layer (service code) to call, and these APIs may be used to implement some functions (e.g., picture downloading, loading, displaying, etc.) through some logic or method.
Referring to fig. 2, a new APP code architecture proposed in the embodiment of the present application includes: a business layer (business layer), a Framework layer (Framework layer) and a plug-in layer (plug layer). The method comprises the steps that business layer codes are separated from concrete implementation codes of picture loading libraries through a framework layer, and the API functions of the picture loading libraries are specifically implemented in a plug-in mode through a plug-in implementation layer by defining a universal API of each picture loading library. In this embodiment, the general APIs may be defined by java files at the architecture layer, so that the service layer may determine, through the java files at the architecture layer, which general APIs of the picture loading library may be called.
Before defining the general API, the picture drawing behavior (ImageViewAction) and some extended functions of each picture loading library to be selected can be abstracted, and the general API is respectively defined according to the abstracted picture drawing behavior (ImageViewAction) and some extended functions. Referring to fig. 3, for example, the general API corresponding to the picture drawing action (ImageViewAction) may include: "render", "setloadlingListener", "setProresesListener", and the like. The general API corresponding to the extended function may include: "setImageURI", "setBOarder", "setPlaseleholederImage", and the like.
In step 102, the function of the API is implemented by a code in the function implementation file of each picture loading library.
As shown in fig. 2, in the plug-in implementation layer, each picture loading library may implement the function of the general API defined by the framework layer through a corresponding function implementation file. In the embodiment of the present application, the picture loading library implemented in the form of a plug-in may include, but is not limited to: picaso picture loading library, Fresco picture loading library, Glide picture loading library, Phenix picture loading library, and the like. Taking picaso picture loading library as an example, after defining the general API, exemplary implementation code is as follows:
taking the Fresco picture load library as an example, after defining the generic API, exemplary implementation code is as follows:
as can be seen from the above example code, the picaso picture loading library and the Fresco picture loading library respectively implement the above defined general API through the code: "render", "setloadlingListener", "setProcessListener", and the like.
In this embodiment of the present application, an Image control attribute common to multiple picture loading libraries may be further defined, where the common Image control attribute is used when implementing a function of the API. For example, the generic Image control properties may include: "anyFailureImage", "anyRoundTomLeft", "anyProgressBarImage", and the like. In the implementation code of the plug-in implementation layer, the general Image control attributes can be assigned. In addition, the Image control attribute required to be defined can be expanded according to actual needs.
In the embodiment of the application, a common application programming interface API is defined in a plurality of picture loading libraries, the common application programming interface API is called in a service code, and in a function implementation file of each picture loading library, the functions of the application programming interface API are implemented through codes respectively. By defining a general API, the service code and the picture loading library can realize code separation. When the picture loading library depended by the application APP needs to be switched, a user only needs to modify the picture loading library depended by the service code by modifying the configuration file, and does not need to modify the service code, so that the efficient picture loading library switching process is realized.
Fig. 4 is a flowchart of a method for implementing a picture loading library according to another embodiment of the present application. As shown in fig. 4, in the embodiment of the present application, the method is used for implementing a fast switching process of a picture loading library, and includes the following steps 201 to 203, where:
in step 201, after receiving a code compiling instruction, determining a target picture loading library on which a service code depends according to a configuration file.
Wherein, the configuration file (such as a Gradle file) is used for describing the picture loading library on which the APP business code depends. For example, the dependencies in the configuration file are as follows:
dependencies{
compile'com.alibaba.android.anyimageview-fresco:1.0.0'
}
wherein, the "anyimageview-fresco: 1.0.0" is the target picture loading library which is depended by the service code.
In step 202, a function implementation file corresponding to the target picture loading library is selected from function implementation files of a plurality of to-be-selected picture loading libraries, wherein each function implementation file is respectively used for implementing a function of an application programming interface API called in a service code, and the application programming interface API is common to the plurality of picture loading libraries.
In step 203, the selected function implementation file is compiled.
As in the above embodiment, after the general API is defined, the function of the general API may be respectively implemented by the function implementation file of each to-be-selected picture loading library. For example, the plug-in form respectively implements a picaso picture loading library and a Fresco picture loading library, and when function implementation files corresponding to the picaso picture loading library and the Fresco picture loading library are packed, the function implementation files are named as: "com, alibaba, android, and exists under different directories. Thus, according to the target picture loading library determined in step 201 above: "andyimageview-Fresco: 1.0.0", and can choose the function realization file named "com.
It can be seen that when a user needs to switch a picture loading library used by an APP, the user only needs to modify a line of codes used for describing a dependent object in a configuration file and recompile the codes, for example: the method has the advantages that the 'complex' com.albaba.android.anyimageview-freq 1.0 'is modified into the' complex 'com.albaba.android.anyimageview-picaso 1.0.0', so that the process of greatly modifying the API (application programming interface) which is dependent in the service code is avoided, the efficient switching process of the picture loading library is realized, the APP development efficiency is improved, and the code reusability and the migratability of the picture loading library are better.
By the aid of the method, the problems of expansion, switching or migration of the APP-dependent image loading library on the electronic equipment can be solved. One application scenario is for example: according to actual business requirements, the business of the APP2 needs to be integrated in the APP1, but the APP1 and the APP2 use different picture loading libraries to realize a picture display function, so that the development cost of the business of integrating the APP2 in the APP1 is very high. By using the method provided by the embodiment of the application, the unified and general APIs and the image control attributes of each image loading library are defined, and the general APIs are realized in the image loading library realization codes in APP1 and APP2, so that when the service of APP2 needs to be integrated in APP1, the service of APP1 and APP2 can depend on the respective image loading libraries by modifying the configuration file, and the APP integration cost is greatly reduced.
Fig. 5 is a block diagram of an apparatus for implementing a picture loading library according to an exemplary embodiment of the present application. On the hardware level, the apparatus may be applied to an electronic device including a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs the computer program, thereby forming the device shown in fig. 5 on the logic level. Of course, besides the software implementation, the present application does not exclude other implementations, such as logic devices or a combination of software and hardware, and the like, that is, the execution subject of the following processing flow is not limited to each logic unit, and may also be hardware or logic devices. Based on the implementation logic of the method, the device comprises:
an API defining unit 301, configured to define an application programming interface API that is common to the plurality of picture loading libraries, where the application programming interface API is used to be called in the service code.
A function implementing unit 302, configured to implement, through a code, a function of the API in the function implementing file of each picture loading library.
Taking java as an example, the API definition unit 301 and the function implementation unit 302 may implement the API definition and the API implementation process through corresponding java files, respectively.
In an optional embodiment of the present application, the apparatus further includes:
the control attribute definition unit is used for defining the Image control attribute which is commonly used in the plurality of picture loading libraries;
and the function implementation unit uses the universal Image control attribute when implementing the function of the application programming interface API.
Fig. 6 is a block diagram of another apparatus for implementing a picture loading library according to an exemplary embodiment of the present application. On the hardware level, the apparatus may be applied to an electronic device including a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs the computer program, thereby forming the device shown in fig. 6 on the logic level. Of course, besides the software implementation, the present application does not exclude other implementations, such as logic devices or a combination of software and hardware, and the like, that is, the execution subject of the following processing flow is not limited to each logic unit, and may also be hardware or logic devices. Based on the implementation logic of the method, the device comprises:
a loading library determining unit 401, configured to determine, according to the configuration file, a target picture loading library on which the service code depends after receiving the code compiling instruction;
a selecting unit 402, configured to select a function implementation file corresponding to the target picture loading library from function implementation files of multiple to-be-selected picture loading libraries, where each function implementation file is used to implement a function of an application programming interface API called in a service code, and the application programming interface API is common to multiple picture loading libraries.
And a compiling unit 403, configured to compile using the selected function implementation file.
In an optional embodiment of the present application, each function implementation file uses an Image control attribute common to a plurality of picture loading libraries when implementing the function common to the plurality of picture loading libraries.
It should be noted that the above-mentioned apparatus embodiments and the above-mentioned method embodiments can be mutually complementary without violating the present invention.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer, which may take the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email messaging device, game console, tablet computer, wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the units may be implemented in one or more software and/or hardware when implementing the present application.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.