Rarely write technical blog, the most commonly used blog or lofter this: chacepm. Non-technical blogs.
In addition, based on FBREADERJ I developed a reader: Yue read. Interested friends can go to install to see, support a bit.
The following is the menu of the implementation.
Mainmenupopup
Configpopup
This article uses the FBReaderJ-2.2.2.1.
Note: This article does not involve specific interface design, only talk about ideas.
1. Structure
Before we formally change the code, we'd better figure out the structure and inheritance of several Popwindow, because Fbreaderj's encapsulation is tight and it's easy to walk into a dead end.
This is probably the whole class structure associated with the popup, where the red is an abstract class. The name is clear and I don't explain what each one is.
We want to implement custom Popwindow menu, can imitate Navigationpopup practice, write a mainmenupopup inherit from Popuppanel.
2. Principle
We opened the assets directory and found that Tapzones was defined in the following directory.
Open the Down.xml and find the content is like this. This understanding of the Reading page of the Click event is how it is, in fact, the whole area is divided into nine Gongge, each grid response to different events. In order for our menu to be displayed, simply change here the menu to navigate, and then implement the navigate response event in the code to display our custom menu. In fact, we see here is less than the region, do not know why the original author made this, in order to better experience, we need to add (navigate) also respond to the.
3. Two x Popwindow simultaneous display Solutions
In our menu, it contains both the top menu and the bottom menu, how to solve this problem?
An intuitive way of course is to get two menus, bottommenupopup and Topmenupopup are inherited from Popuppanel, and I thought so at the beginning, but the problem came, The display of the Popuppanel is the Application.showpopup (ID) used. The code below shows 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 (); = mypopups.get (ID); if NULL ) { myactivepopup.show_ (); } }
Of course we can get rid of this line, but it will cause us to call hideactivepopup every time we show the other popup, and I give up this method for the sake of less code change.
The second way is to get a topmenupopup instead of inheriting Popuppanel, but I've tried it for a bit and found it more troublesome and when it shows what's going to disappear.
The last way I think about it is to add a mywindowtop inside the popuppanel. So we have two popupwindow, but it's all shown in a Popuppanel subclass, and we're named Mainmenupopup.
protected volatile Popupwindow Mywindow; protected volatile Popupwindow Mywindowtop;
4. Switch Popuppanel
The above solves the Mainmenupopup display, but in fact we contain multiple popuppanel, which involves switching problems. Let's take the switch of Mainmenupopup and Navigationpopup as an example.
The following code is used to display the Navigationpopup, said above, in the ShowPopup (ID) method will first call Hideactivepopup (), so the switch here is not a problem.
((Navigationpopup) Application.getpopupbyid (navigationpopup.id)). Runnavigation ();
Another problem is to show and hide the popup, because clicking on the book corresponds to the Navigate () method, so we need to determine when the click is displayed or hidden. Fortunately Fbreaderj already has a method application.getactivepopup () to get the currently displayed popup, as long as the decision is empty. So the Showbottommenu () method inside the Mainmenupopup is like this.
Public void Showbottommenu () { ifnull | | mywindow.getvisibility () = = View.gone) { if (Application.getactivepopup () ==null) { application.showpopup (ID); } Else { application.hideactivepopup (); } } Else { application.hideactivepopup (); } }
5. Conclusion
Now the structure is like this, adding a mainmenupopup.
The general process is to change tapzones-> new mainmenupopup-> new mypopwindowtop-> judging Show/Hide Popup.
To this idea has been basically cleared, the beginning said that this article does not involve the specific interface development, the beginning of only for demonstration, do not have the feeling of being cheated.
There are a number of ways to implement a custom menu. For example, the top menu can be implemented with Actionbar, which is done with the ICS version of FBREADERJ, or in XML directly on the bottom and top menu in Zlviewwidget. The method of this article is just one. I do not understand the place, as well as the shortcomings, welcome to discuss the exchange with me.
In addition, based on the FBREADERJ I developed a reader: Yue read. Interested friends can go to install to see, support a bit.
The next section is about customizing the status bar at the bottom.
FBREADERJ Learning Note (ii): Popwindow Implementing a custom Reading page menu