FBReaderJ Study Notes (2): PopWindow enables custom reading page menu, fbreaderjpopwindow

Source: Internet
Author: User

FBReaderJ Study Notes (2): PopWindow enables custom reading page menu, fbreaderjpopwindow

Few technical blogs are written. The most common blog is Lofter: chacpm. Non-technical blog.

In addition, I developed a reader based on FBReaderJ: yueda. If you are interested, you can install it.

The menu is as follows.

 

MainMenuPopup

  Note: This article does not involve the specific interface design, but focuses only on ideas.

 

1. Structure

  Before officially changing the code, we 'd better first figure out the structure and inheritance relationships of several popwindows, because FBReaderJ is tightly encapsulated and easily leads to a dead end.

The entire class structure related to popup is like this, where the red class is an abstract class. The name is clear, so I won't explain what every one is doing.

To customize the popwindow menu, we can imitate the NavigationPopup practice and write a MainMenuPopup inherited from PopupPanel.

  2. Principles

  Open the assets Directory and find that tapzones is defined in the following directory.

  

Open down. xml and find that the content is like this. Now I understand what the click events on the reading page are. In fact, the whole area is divided into nine grids, and each grid responds to different events. To display menus, you only need to change all menus here to navigate, and then implement the navigate RESPONSE event in the code to display our custom menus. In fact, we can see that the () region is missing here. I don't know why the original author made it so. For a better experience, we need to add () to respond to navigate.

3. Solutions for simultaneous display of two popwindows

In our menu, the top menu and the bottom menu are included at the same time. How can this problem be solved?

One intuitive way is to get two menus, of course. BottomMenuPopup and TopMenuPopup both inherit from PopupPanel. I thought so at first, but the problem is that the PopupPanel display is an Application. showPopup (ID ). The Code is as follows. We found that hideActivePopup () will be called before show, so that when we show the second Popup, we will first hide the first Popup.

    public final void showPopup(String id) {        hideActivePopup();        myActivePopup = myPopups.get(id);        if (myActivePopup != null) {            myActivePopup.show_();        }    }

Of course we can remove this line, but this will cause us to call hideActivePopup every time we display other Popup. For the purpose of less code modification, I gave up this method.

The second method is to create a TopMenuPopup without inheriting PopupPanel. However, after I try it, I find it will be more troublesome and will show when it will disappear.

Finally, I thought of adding a myWindowTop in PopupPanel. In this way, we have two popupwindows, but both are displayed in a PopupPanel subclass. We name them MainMenuPopup.

    protected volatile PopupWindow myWindow;    protected volatile PopupWindow myWindowTop;

  4. Switch PopupPanel

The above solves the MainMenuPopup display, but we actually include multiple PopupPanel, which involves switching. Take MainMenuPopup and NavigationPopup as examples.

The following code is used to display NavigationPopup. As mentioned above, hideActivePopup () is called in the showPopup (ID) method, so the switchover here is not a problem.

((NavigationPopup)Application.getPopupById(NavigationPopup.ID)).runNavigation();

Another problem is to show and hide Popup. Because clicking books corresponds to the navigate () method, we need to determine whether to display or hide Popup. Fortunately, FBReaderJ already has a method Application. getActivePopup () to obtain the currently displayed Popup. You only need to judge whether it is null. So the showBottomMenu () method in MainMenuPopup is like this.

    public void showBottomMenu(){        if (myWindow == null || myWindow.getVisibility() == View.GONE){            if(Application.getActivePopup()==null){                Application.showPopup(ID);            }else{                Application.hideActivePopup();            }        }else{            Application.hideActivePopup();        }    }

  5. Conclusion

  

  The current structure is like this, And a MainMenuPopup is added.

The general process isChange tapzones-> Create MainMenuPopup-> Add myPopWindowTop-> show/hide popup.

  This idea has basically been clarified. As I said at the beginning, this article does not involve specific interface development. It only serves as a demonstration at the beginning, so do not feel cheated.

There are many ways to implement custom menus. For example, the menu at the top can be implemented using Actionbar, And the ics version of FBReaderJ does this; or the menu at the bottom and top can be directly put out of ZLViewWidget in XML. The method in this article is only one. You are welcome to discuss with me what I do not understand and what I do not understand.

 

In addition, I developed a reader based on FBReaderJ: yueda. If you are interested, you can install it.

 

Next, let's talk about customizing the status bar at the bottom.

Related Article

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.