The road to Android reconstruction and design starts from the pop-up window in the prompt dialog box.

Source: Internet
Author: User

The road to Android reconstruction and design starts from the pop-up window in the prompt dialog box.

Encapsulate an independent pop-up window Module. the pop-up window here includes the normal Dialog mode pop-up box and WindowManager mode pop-up window. Provides a solution for managing project pop-up windows, which facilitates later modification and maintenance.

First, describe a common phenomenon in large projects: due to the many functions of the project, different persons in charge of the functions, when the function requires a normal confirm cancel dialog box, most people choose to write one on their own, and new is an independent pop-up window on their own. The following benefits are provided:

However, this practice leads to a large amount of code redundancy in the project, and a large number of scattered pop-up windows will not cause any problems in the short term. If the project needs to be restructured at this time, to modify the style of all the pop-up windows, we will face several problems:

This article is a project with the above pop-up window features. It provides a dialog box management method and a better maintenance implementation method (not necessarily the best ). Due to the large amount of code, this article only describes the implementation design ideas and implementation methods. The specific source code can be downloaded and viewed directly from github. The address will be provided later.

 

This article provides an animated demonstration of the pop-up window effect.

In this article, a total of 12 Dialog pop-up window styles are implemented, but this cannot be used as a standard. You need to classify the style based on your project's actual situation, of course, most simple projects can be directly used using the Module provided in this Article.

 

Implementation of Common pop-up windows

 

Analysis of common pop-up window implementation methods

This implementation method is generally designed in this way when the project is just started. It is no problem if the pop-up window style is small and the layout of the pop-up window is relatively standard. But in fact, these two conditions are generally not met in large projects. First of all, there must be a lot of pop-up window styles. In fact, in order to meet various product requirements, the pop-up window layout will also be different. The pop-up window layout of a dialog box needs to accommodate the pop-up window style, that is, a CommonDialog contains all the pop-up window logic, which maintains the singularity principle. In addition, the more difficult it will be to maintain it in the future, and everyone will change to the same class and layout. It is estimated that it is a little difficult for the first person who handles the change. To solve this problem, we can use the following method.

 

Easy to maintain and expand dialog box pop-up window implementation

The WindowManager pop-up window is designed in the same way as the Dialog pop-up window, except that the underlying layer is used to display the View. This article does not specifically describe the source code.

  

Easy to maintain and expand dialog box pop-up window implementation analysis

The preceding implementation methods have the following benefits:

1. In the factory mode, a Type parameter is input externally. You do not need to implement the relationship details, but only need to know the layout style corresponding to the Type.

2. Each Type corresponds to a pop-up window layout. You only need to implement the interface of your own relationship.

3. Various pop-up window logics are completely independent, independently modified, and maintained

The user needs to pay attention to the Type and the method for calling the corresponding Type pop-up window. The Type here must let the user know what style it corresponds to. This is more difficult, the code can only be annotated to clarify that a more orthodox company may have a document record. However, this will not cause much trouble. Users can easily test whether they want their own styles, so users can easily use them.

 

Easy to maintain and expand some dialog box pop-up display

The pop-up window achieves rounded corners of different shapes, and the button supports water ripple

 

 

 

 

 

 

 

 

Easy to maintain and expand dialog box pop-up source code implementation and use

1. To implement this pop-up window, you need to define the TypeType should be reasonably classified according to the actual situation of your project. The following is the Type definition in this article.

  

 

2. the Dialog pop-up window user calls are as follows:

final ICommonDialog dialog = CommonDialogFactory.createDialogByType(this, DialogUtil.DIALOG_TYPE_1);dialog.setTitleText("DIALOG_TYPE_1");dialog.setCancelBtn(R.string.cancel, new View.OnClickListener() {    @Override    public void onClick(View v) {    }});dialog.setOkBtn(R.string.ok, new View.OnClickListener() {    @Override    public void onClick(View v) {        dialog.dismiss();    }});dialog.setCanceledOnTouchOutside(true);dialog.show();

 

3. WindowManager pop-up window Type definition

 

4. The WindowManager pop-up window user calls are as follows:

final ICommonWindowPop windowPop = CommonWindowPopFactory.createWindowPopByType(this, WindowPopUtil.WINDOW_POP_TYPE_2);windowPop.setTitleBgType(WindowPopUtil.TITLE_SAFE_BLUE);windowPop.setTitleText("WINDOW_POP_TYPE_2");windowPop.setContentView(R.layout.dialog_custom_content_test_layout);windowPop.setCanceledOnTouchOutside(true);windowPop.setCancelBtn(R.string.cancel, new View.OnClickListener() {    @Override    public void onClick(View v) {    }});windowPop.setOkBtn(R.string.ok, new View.OnClickListener() {    @Override    public void onClick(View v) {        windowPop.dismiss();    }});windowPop.show();

 

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

 

Summary

This project only provides a basic framework. The dialog box style can be changed based on the needs of your project. You can add, delete, or modify a type at will, the main purpose is to uniformly manage the pop-up windows in the project for convenient maintenance and management.

 

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.