Android refactoring and Design path, starting with the pop-up popup dialog box

Source: Internet
Author: User

Encapsulates a standalone pop-up module, where the pop-up window includes a regular dialog-mode bullet frame and a windowmanager-style pop-up window. Provide a scheme to manage the window of the project, facilitate the late modification and maintenance.

First of all, describe a common phenomenon in large projects: because of the function of the project, the person responsible for the function is different, when the function needs a normal OK Cancel dialog box, most people choose to write their own, their new a separate pop-up window. The benefits of doing this are as follows:

    1. Code logic Independent, self-written code can control
    2. Fast and convenient, easy to modify, easy to meet a variety of strange needs

However, this practice resulted in a large number of code redundancy in the project, a large number of scattered pop-up windows, in the short term will generally not have any problems, if this time the project to restructure, to modify the style of all pop-up windows, the next face several problems:

    1. I don't know how many pop-up windows.
    2. I don't know where there's a pop-up window in the code.
    3. Do not know what to do with the pop-up window (style does not know, the way to pop is dialog or WindowManager)
    4. Large number of changes, heavy workload, high risk

This article is the needle exists above the window features of the project, provide a dialog box management, provide a better way to maintain the implementation (not necessarily the best way to achieve). Because of the large amount of code, this article only talk about the implementation of design ideas and implementation methods, the specific source code can be downloaded directly from GitHub to view, the following will provide the address.

This paper realizes the animation of the popup effect.

In this article, the dialog pop-up style total 12, but this can not be a standard, according to the actual situation of their own projects, do the classification, of course, most of the simple project with the module provided in this article can be used directly.

How to implement common pop-up windows

Analysis of the realization mode of common pop-up window

This way of implementation is generally the beginning of the project, the people who write the pop-up window will generally be such a design, itself is not a problem, if the pop-up window style is less and the layout of the window is more standard can be maintained. But in fact, these two conditions in large projects are generally not satisfied, the first window style certainly a lot of, in fact, in order to meet the needs of the product, the window layout will be different. Phenomenon, just a dialog box pop-up layout to accommodate the pop-up window style, that is, a CommonDialog contains all the window logic, which in itself maintains the principle of singleness. And the more difficult it is to maintain, everyone changes the same class, the same layout, the first person to handle the estimate is a bit difficult to modify. In order to solve this phenomenon, it can be replaced by the following way.

Easy-to-maintain and easy-to-expand dialog box Popup implementation method

WindowManager mode of the design of the window and dialog the same way, only the bottom to show the view of the place is not the same, this article is not specific, the source part is included.

An easy-to-maintain and easy-to-expand dialog box Pop-up realization mode analysis

There are several benefits to the above implementation approach

1. Through the Factory mode, the external pass in a type parameter, the user does not need the relationship implementation details, only need to know the type corresponding layout style

2. Each type corresponds to a pop-up layout that only needs to implement its own relationship interface

3. All kinds of window logic completely independent, independent modification, independent maintenance

The user needs to be concerned about type types and what methods are required to invoke the corresponding type pop-up, where type types must let the user know what style it corresponds to, which is difficult, and the code can only be explained in comments, if the more orthodox company may have documented it. However, there will not be a lot of trouble, users can easily test out is not their own style, so users are very convenient to use.

Easy to maintain easy to expand part of the dialog box pop-up display

Easy to maintain easy to expand the dialog box pop-up window source implementation

To implement this kind of pop-up window, we need to define the type, and to classify the type reasonably according to the actual situation of the project.

The pop-up effect achieves a variety of rounded corners, and the buttons support the water ripple

Source: Https://github.com/PopFisher/SmartAlertPop

Summarize

This project is just to provide a basic framework, the specific dialog box style can be changed according to the needs of their own projects, can be arbitrarily added delete modify a type, mainly for the unified management of the Project window, convenient maintenance and management.

Android refactoring and Design path, starting with the pop-up popup dialog box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.