1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-06 03:50:19 +02:00

popup windows refactoring

This commit is contained in:
Nikolay Pultsin 2011-06-10 04:56:59 +02:00
parent 14c0b2c101
commit 8b73346089
7 changed files with 230 additions and 265 deletions

View file

@ -1,150 +0,0 @@
/*
* Copyright (C) 2010-2011 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.android.fbreader;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.zlibrary.text.view.ZLTextWordCursor;
import org.geometerplus.fbreader.fbreader.FBReaderApp;
abstract class ControlButtonPanel implements ZLApplication.ButtonPanel {
public final FBReaderApp Reader;
public ZLTextWordCursor StartPosition;
private boolean myVisible;
protected ControlPanel myControlPanel;
ControlButtonPanel(FBReaderApp fbReader) {
Reader = fbReader;
fbReader.registerButtonPanel(this);
}
public final void hide() {
hide(false);
}
public void updateStates() {
}
public final boolean hasControlPanel() {
return myControlPanel != null;
}
private final void removeControlPanel() {
if (myControlPanel != null) {
ViewGroup root = (ViewGroup)myControlPanel.getParent();
myControlPanel.hide(false);
root.removeView(myControlPanel);
myControlPanel = null;
}
}
public static void removeControlPanels(ZLApplication application) {
for (ZLApplication.ButtonPanel panel : application.buttonPanels()) {
((ControlButtonPanel)panel).removeControlPanel();
}
}
public static void restoreVisibilities(ZLApplication application) {
for (ZLApplication.ButtonPanel panel : application.buttonPanels()) {
final ControlButtonPanel p = (ControlButtonPanel)panel;
p.setVisibility(p.myVisible);
}
}
public static void saveVisibilities(ZLApplication application) {
for (ZLApplication.ButtonPanel panel : application.buttonPanels()) {
final ControlButtonPanel p = (ControlButtonPanel)panel;
p.myVisible = p.getVisibility();
}
}
public static void hideAllPendingNotify(ZLApplication application) {
for (ZLApplication.ButtonPanel panel : application.buttonPanels()) {
final ControlButtonPanel p = (ControlButtonPanel)panel;
if (p.myControlPanel != null && p.getVisibility()) {
p.myControlPanel.hide(false);
}
}
}
public final boolean getVisibility() {
if (myControlPanel != null) {
return myControlPanel.getVisibility() == View.VISIBLE;
}
return false;
}
private void setVisibility(boolean visible) {
if (visible) {
show(false);
} else {
hide(false);
}
}
private void hideOthers() {
for (ZLApplication.ButtonPanel panel : Reader.buttonPanels()) {
if (panel != this) {
((ControlButtonPanel)panel).hide(false);
}
}
}
public final void show(boolean animate) {
if (myControlPanel != null && !getVisibility()) {
hideOthers();
onShow();
myControlPanel.show(animate);
}
}
public final void initPosition() {
if (StartPosition == null) {
StartPosition = new ZLTextWordCursor(Reader.getTextView().getStartCursor());
}
}
public final void storePosition() {
if (StartPosition != null &&
!StartPosition.equals(Reader.getTextView().getStartCursor())) {
Reader.addInvisibleBookmark(StartPosition);
}
}
public final void hide(boolean animate) {
if (myControlPanel != null && getVisibility()) {
onHide();
myControlPanel.hide(animate);
}
}
public abstract void createControlPanel(FBReader activity, RelativeLayout root, ControlPanel.Location location);
// callback methods
public void onShow() {}
public void onHide() {}
}

View file

@ -53,9 +53,6 @@ public final class FBReader extends ZLAndroidActivity {
private int myFullScreenFlag; private int myFullScreenFlag;
private static TextSearchButtonPanel ourTextSearchPanel;
private static NavigationButtonPanel ourNavigatePanel;
@Override @Override
protected ZLFile fileFromIntent(Intent intent) { protected ZLFile fileFromIntent(Intent intent) {
String filePath = intent.getStringExtra(BOOK_PATH_KEY); String filePath = intent.getStringExtra(BOOK_PATH_KEY);
@ -79,11 +76,11 @@ public final class FBReader extends ZLAndroidActivity {
); );
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance(); final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
if (ourTextSearchPanel == null) { if (fbReader.getPopupById(TextSearchPopup.ID) == null) {
ourTextSearchPanel = new TextSearchButtonPanel(fbReader); new TextSearchPopup(fbReader);
} }
if (ourNavigatePanel == null) { if (fbReader.getPopupById(NavigationPopup.ID) == null) {
ourNavigatePanel = new NavigationButtonPanel(fbReader); new NavigationPopup(fbReader);
} }
fbReader.addAction(ActionCode.SHOW_LIBRARY, new ShowLibraryAction(this, fbReader)); fbReader.addAction(ActionCode.SHOW_LIBRARY, new ShowLibraryAction(this, fbReader));
@ -135,20 +132,21 @@ public final class FBReader extends ZLAndroidActivity {
final String pattern = intent.getStringExtra(SearchManager.QUERY); final String pattern = intent.getStringExtra(SearchManager.QUERY);
final Runnable runnable = new Runnable() { final Runnable runnable = new Runnable() {
public void run() { public void run() {
ourTextSearchPanel.initPosition();
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance(); final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
final TextSearchPopup popup = (TextSearchPopup)fbReader.getPopupById(TextSearchPopup.ID);
popup.initPosition();
fbReader.TextSearchPatternOption.setValue(pattern); fbReader.TextSearchPatternOption.setValue(pattern);
if (fbReader.getTextView().search(pattern, true, false, false, false) != 0) { if (fbReader.getTextView().search(pattern, true, false, false, false) != 0) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
ourTextSearchPanel.show(true); fbReader.showPopup(popup.getId());
} }
}); });
} else { } else {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
UIUtil.showErrorMessage(FBReader.this, "textNotFound"); UIUtil.showErrorMessage(FBReader.this, "textNotFound");
ourTextSearchPanel.StartPosition = null; popup.StartPosition = null;
} }
}); });
} }
@ -173,13 +171,10 @@ public final class FBReader extends ZLAndroidActivity {
startActivity(new Intent(this, this.getClass())); startActivity(new Intent(this, this.getClass()));
} }
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
final RelativeLayout root = (RelativeLayout)findViewById(R.id.root_view); final RelativeLayout root = (RelativeLayout)findViewById(R.id.root_view);
if (!ourTextSearchPanel.hasControlPanel()) { ((PopupPanel)fbReader.getPopupById(TextSearchPopup.ID)).createControlPanel(this, root, PopupWindow.Location.Bottom);
ourTextSearchPanel.createControlPanel(this, root, ControlPanel.Location.Bottom); ((PopupPanel)fbReader.getPopupById(NavigationPopup.ID)).createControlPanel(this, root, PopupWindow.Location.Bottom);
}
if (!ourNavigatePanel.hasControlPanel()) {
ourNavigatePanel.createControlPanel(this, root, ControlPanel.Location.Bottom);
}
} }
@Override @Override
@ -189,18 +184,12 @@ public final class FBReader extends ZLAndroidActivity {
sendBroadcast(new Intent(getApplicationContext(), KillerCallback.class)); sendBroadcast(new Intent(getApplicationContext(), KillerCallback.class));
} catch (Throwable t) { } catch (Throwable t) {
} }
ControlButtonPanel.restoreVisibilities(FBReaderApp.Instance()); PopupPanel.restoreVisibilities(FBReaderApp.Instance());
}
@Override
public void onPause() {
ControlButtonPanel.saveVisibilities(FBReaderApp.Instance());
super.onPause();
} }
@Override @Override
public void onStop() { public void onStop() {
ControlButtonPanel.removeControlPanels(FBReaderApp.Instance()); PopupPanel.removeAllWindows(FBReaderApp.Instance());
super.onStop(); super.onStop();
} }
@ -215,12 +204,14 @@ public final class FBReader extends ZLAndroidActivity {
@Override @Override
public boolean onSearchRequested() { public boolean onSearchRequested() {
final FBReaderApp fbreader = (FBReaderApp)FBReaderApp.Instance(); final FBReaderApp fbreader = (FBReaderApp)FBReaderApp.Instance();
ControlButtonPanel.saveVisibilities(fbreader); final FBReaderApp.PopupPanel popup = fbreader.getActivePopup();
ControlButtonPanel.hideAllPendingNotify(fbreader); fbreader.hideActivePopup();
final SearchManager manager = (SearchManager)getSystemService(SEARCH_SERVICE); final SearchManager manager = (SearchManager)getSystemService(SEARCH_SERVICE);
manager.setOnCancelListener(new SearchManager.OnCancelListener() { manager.setOnCancelListener(new SearchManager.OnCancelListener() {
public void onCancel() { public void onCancel() {
ControlButtonPanel.restoreVisibilities(fbreader); if (popup != null) {
fbreader.showPopup(popup.getId());
}
manager.setOnCancelListener(null); manager.setOnCancelListener(null);
} }
}); });
@ -263,7 +254,7 @@ public final class FBReader extends ZLAndroidActivity {
} }
public void navigate() { public void navigate() {
ourNavigatePanel.runNavigation(); ((NavigationPopup)FBReaderApp.Instance().getPopupById(NavigationPopup.ID)).runNavigation();
} }
private void addMenuItem(Menu menu, String actionId, int iconId) { private void addMenuItem(Menu menu, String actionId, int iconId) {

View file

@ -34,55 +34,66 @@ import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.fbreader.fbreader.FBReaderApp; import org.geometerplus.fbreader.fbreader.FBReaderApp;
final class NavigationButtonPanel extends ControlButtonPanel { final class NavigationPopup extends PopupPanel {
final static String ID = "NavigationPopup";
private volatile boolean myIsInProgress; private volatile boolean myIsInProgress;
NavigationButtonPanel(FBReaderApp fbReader) { NavigationPopup(FBReaderApp fbReader) {
super(fbReader); super(fbReader);
} }
public void runNavigation() { public void runNavigation() {
if (!getVisibility()) { if (myWindow.getVisibility() == View.GONE) {
myIsInProgress = false; myIsInProgress = false;
initPosition(); initPosition();
show(true); Application.showPopup(ID);
} }
} }
@Override @Override
public void onShow() { public String getId() {
if (myControlPanel != null) { return ID;
setupNavigation(myControlPanel); }
@Override
protected void show_() {
super.show_();
if (myWindow != null) {
setupNavigation(myWindow);
} }
} }
@Override @Override
public void updateStates() { protected void update() {
super.updateStates(); if (!myIsInProgress && myWindow != null) {
if (!myIsInProgress && myControlPanel != null) { setupNavigation(myWindow);
setupNavigation(myControlPanel);
} }
} }
@Override @Override
public void createControlPanel(FBReader activity, RelativeLayout root, ControlPanel.Location location) { public void createControlPanel(FBReader activity, RelativeLayout root, PopupWindow.Location location) {
myControlPanel = new ControlPanel(activity, root, location, true); if (myWindow != null) {
return;
}
final View layout = activity.getLayoutInflater().inflate(R.layout.navigate, myControlPanel, false); myWindow = new PopupWindow(activity, root, location, true);
final View layout = activity.getLayoutInflater().inflate(R.layout.navigate, myWindow, false);
final SeekBar slider = (SeekBar)layout.findViewById(R.id.book_position_slider); final SeekBar slider = (SeekBar)layout.findViewById(R.id.book_position_slider);
final TextView text = (TextView)layout.findViewById(R.id.book_position_text); final TextView text = (TextView)layout.findViewById(R.id.book_position_text);
slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
private void gotoPage(int page) { private void gotoPage(int page) {
final ZLTextView view = Reader.getTextView(); final ZLTextView view = getReader().getTextView();
if (page == 1) { if (page == 1) {
view.gotoHome(); view.gotoHome();
} else { } else {
view.gotoPage(page); view.gotoPage(page);
} }
Reader.getViewWidget().reset(); getReader().getViewWidget().reset();
Reader.getViewWidget().repaint(); getReader().getViewWidget().repaint();
} }
public void onStopTrackingTouch(SeekBar seekBar) { public void onStopTrackingTouch(SeekBar seekBar) {
@ -109,12 +120,12 @@ final class NavigationButtonPanel extends ControlButtonPanel {
public void onClick(View v) { public void onClick(View v) {
final ZLTextWordCursor position = StartPosition; final ZLTextWordCursor position = StartPosition;
if (v == btnCancel && position != null) { if (v == btnCancel && position != null) {
Reader.getTextView().gotoPosition(position); getReader().getTextView().gotoPosition(position);
} else if (v == btnOk) { } else if (v == btnOk) {
storePosition(); storePosition();
} }
StartPosition = null; StartPosition = null;
hide(true); Application.hideActivePopup();
} }
}; };
btnOk.setOnClickListener(listener); btnOk.setOnClickListener(listener);
@ -123,14 +134,14 @@ final class NavigationButtonPanel extends ControlButtonPanel {
btnOk.setText(buttonResource.getResource("ok").getValue()); btnOk.setText(buttonResource.getResource("ok").getValue());
btnCancel.setText(buttonResource.getResource("cancel").getValue()); btnCancel.setText(buttonResource.getResource("cancel").getValue());
myControlPanel.addView(layout); myWindow.addView(layout);
} }
private void setupNavigation(ControlPanel panel) { private void setupNavigation(PopupWindow panel) {
final SeekBar slider = (SeekBar)panel.findViewById(R.id.book_position_slider); final SeekBar slider = (SeekBar)panel.findViewById(R.id.book_position_slider);
final TextView text = (TextView)panel.findViewById(R.id.book_position_text); final TextView text = (TextView)panel.findViewById(R.id.book_position_text);
final ZLTextView textView = Reader.getTextView(); final ZLTextView textView = getReader().getTextView();
final int page = textView.computeCurrentPage(); final int page = textView.computeCurrentPage();
final int pagesNumber = textView.computePageNumber(); final int pagesNumber = textView.computePageNumber();

View file

@ -0,0 +1,95 @@
/*
* Copyright (C) 2010-2011 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.android.fbreader;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.zlibrary.text.view.ZLTextWordCursor;
import org.geometerplus.fbreader.fbreader.FBReaderApp;
abstract class PopupPanel extends ZLApplication.PopupPanel {
public ZLTextWordCursor StartPosition;
protected PopupWindow myWindow;
PopupPanel(FBReaderApp fbReader) {
super(fbReader);
}
protected final FBReaderApp getReader() {
return (FBReaderApp)Application;
}
@Override
protected void show_() {
if (myWindow != null) {
myWindow.show();
}
}
@Override
protected void hide_() {
if (myWindow != null) {
myWindow.hide();
}
}
private final void removeWindow() {
if (myWindow != null) {
ViewGroup root = (ViewGroup)myWindow.getParent();
myWindow.hide();
root.removeView(myWindow);
myWindow = null;
}
}
public static void removeAllWindows(ZLApplication application) {
for (ZLApplication.PopupPanel popup : application.popupPanels()) {
((PopupPanel)popup).removeWindow();
}
}
public static void restoreVisibilities(ZLApplication application) {
final PopupPanel popup = (PopupPanel)application.getActivePopup();
if (popup != null) {
popup.show_();
}
}
public final void initPosition() {
if (StartPosition == null) {
StartPosition = new ZLTextWordCursor(getReader().getTextView().getStartCursor());
}
}
public final void storePosition() {
if (StartPosition != null &&
!StartPosition.equals(getReader().getTextView().getStartCursor())) {
getReader().addInvisibleBookmark(StartPosition);
}
}
public abstract void createControlPanel(FBReader activity, RelativeLayout root, PopupWindow.Location location);
}

View file

@ -19,6 +19,7 @@
package org.geometerplus.android.fbreader; package org.geometerplus.android.fbreader;
import android.app.Activity;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.content.Context; import android.content.Context;
@ -28,19 +29,22 @@ import android.widget.*;
import org.geometerplus.zlibrary.ui.android.R; import org.geometerplus.zlibrary.ui.android.R;
public class ControlPanel extends LinearLayout { public class PopupWindow extends LinearLayout {
public static enum Location { public static enum Location {
Bottom, Bottom,
Floating Floating
} }
public ControlPanel(Context context, RelativeLayout root, Location location, boolean fillWidth) { private final Activity myActivity;
super(context);
public PopupWindow(Activity activity, RelativeLayout root, Location location, boolean fillWidth) {
super(activity);
myActivity = activity;
setFocusable(false); setFocusable(false);
final LayoutInflater inflater = final LayoutInflater inflater =
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate( inflater.inflate(
location == Location.Bottom location == Location.Bottom
? R.layout.control_panel_bottom : R.layout.control_panel_floating, ? R.layout.control_panel_bottom : R.layout.control_panel_floating,
@ -64,47 +68,22 @@ public class ControlPanel extends LinearLayout {
return true; return true;
} }
private interface VisibilityAction { public void show() {
int SHOW_ANIMATED = 0; myActivity.runOnUiThread(new Runnable() {
int SHOW_INSTANTLY = 1; public void run() {
int HIDE_ANIMATED = 2; setVisibility(View.VISIBLE);
int HIDE_INSTANTLY = 3;
}
private Handler myVisibilityHandler = new Handler() {
public void handleMessage(Message message) {
switch (message.what) {
case VisibilityAction.SHOW_ANIMATED:
fade(View.VISIBLE, 0.0f, 1.0f);
break;
case VisibilityAction.SHOW_INSTANTLY:
setVisibility(View.VISIBLE);
break;
case VisibilityAction.HIDE_ANIMATED:
fade(View.GONE, 1.0f, 0.0f);
break;
case VisibilityAction.HIDE_INSTANTLY:
setVisibility(View.GONE);
break;
} }
} });
};
public void show(boolean animate) {
myVisibilityHandler.sendEmptyMessage(animate ? VisibilityAction.SHOW_ANIMATED : VisibilityAction.SHOW_INSTANTLY);
} }
public void hide(boolean animate) { public void hide() {
myVisibilityHandler.sendEmptyMessage(animate ? VisibilityAction.HIDE_ANIMATED : VisibilityAction.HIDE_INSTANTLY); myActivity.runOnUiThread(new Runnable() {
public void run() {
setVisibility(View.GONE);
}
});
} }
private void fade(int visibility, float startAlpha, float endAlpha) {
final AlphaAnimation animation = new AlphaAnimation(startAlpha, endAlpha);
animation.setDuration(500);
startAnimation(animation);
setVisibility(visibility);
}
public void addView(View view) { public void addView(View view) {
((LinearLayout)findViewById(R.id.tools_plate)).addView(view); ((LinearLayout)findViewById(R.id.tools_plate)).addView(view);
} }

View file

@ -42,21 +42,33 @@ class ActionButton extends ZoomButton {
} }
} }
final class TextSearchButtonPanel extends ControlButtonPanel implements View.OnClickListener { final class TextSearchPopup extends PopupPanel implements View.OnClickListener {
final static String ID = "TextSearchPopup";
private final ArrayList<ActionButton> myButtons = new ArrayList<ActionButton>(); private final ArrayList<ActionButton> myButtons = new ArrayList<ActionButton>();
TextSearchButtonPanel(FBReaderApp fbReader) { TextSearchPopup(FBReaderApp fbReader) {
super(fbReader); super(fbReader);
} }
@Override @Override
public void onHide() { public String getId() {
Reader.getTextView().clearFindResults(); return ID;
} }
@Override @Override
public void createControlPanel(FBReader activity, RelativeLayout root, ControlPanel.Location location) { protected void hide_() {
myControlPanel = new ControlPanel(activity, root, location, false); getReader().getTextView().clearFindResults();
super.hide_();
}
@Override
public void createControlPanel(FBReader activity, RelativeLayout root, PopupWindow.Location location) {
if (myWindow != null) {
return;
}
myWindow = new PopupWindow(activity, root, location, false);
addButton(ActionCode.FIND_PREVIOUS, false, R.drawable.text_search_previous); addButton(ActionCode.FIND_PREVIOUS, false, R.drawable.text_search_previous);
addButton(ActionCode.CLEAR_FIND_RESULTS, true, R.drawable.text_search_close); addButton(ActionCode.CLEAR_FIND_RESULTS, true, R.drawable.text_search_close);
@ -64,27 +76,27 @@ final class TextSearchButtonPanel extends ControlButtonPanel implements View.OnC
} }
private void addButton(String actionId, boolean isCloseButton, int imageId) { private void addButton(String actionId, boolean isCloseButton, int imageId) {
final ActionButton button = new ActionButton(myControlPanel.getContext(), actionId, isCloseButton); final ActionButton button = new ActionButton(myWindow.getContext(), actionId, isCloseButton);
button.setImageResource(imageId); button.setImageResource(imageId);
myControlPanel.addView(button); myWindow.addView(button);
button.setOnClickListener(this); button.setOnClickListener(this);
myButtons.add(button); myButtons.add(button);
} }
@Override @Override
public void updateStates() { protected void update() {
for (ActionButton button : myButtons) { for (ActionButton button : myButtons) {
button.setEnabled(Reader.isActionEnabled(button.ActionId)); button.setEnabled(Application.isActionEnabled(button.ActionId));
} }
} }
public void onClick(View view) { public void onClick(View view) {
final ActionButton button = (ActionButton)view; final ActionButton button = (ActionButton)view;
Reader.doAction(button.ActionId); Application.doAction(button.ActionId);
if (button.IsCloseButton && myControlPanel != null) { if (button.IsCloseButton) {
storePosition(); storePosition();
StartPosition = null; StartPosition = null;
myControlPanel.hide(true); Application.hideActivePopup();
} }
} }
} }

View file

@ -75,14 +75,27 @@ public abstract class ZLApplication {
if (myWindow != null) { if (myWindow != null) {
myWindow.refreshMenu(); myWindow.refreshMenu();
} }
for (ButtonPanel panel : myPanels) { for (PopupPanel popup : popupPanels()) {
panel.updateStates(); popup.update();
} }
} }
public final void onViewChanged() { public final void onViewChanged() {
for (ButtonPanel panel : myPanels) { hideActivePopup();
panel.hide(); }
public final void hideActivePopup() {
if (myActivePopup != null) {
myActivePopup.hide_();
myActivePopup = null;
}
}
public final void showPopup(String id) {
hideActivePopup();
myActivePopup = myPopups.get(id);
if (myActivePopup != null) {
myActivePopup.show_();
} }
} }
@ -182,16 +195,30 @@ public abstract class ZLApplication {
} }
} }
static public interface ButtonPanel { public static abstract class PopupPanel {
void updateStates(); protected final ZLApplication Application;
void hide();
protected PopupPanel(ZLApplication application) {
application.myPopups.put(getId(), this);
Application = application;
}
abstract public String getId();
abstract protected void update();
abstract protected void hide_();
abstract protected void show_();
} }
private final List<ButtonPanel> myPanels = new LinkedList<ButtonPanel>();
public final List<ButtonPanel> buttonPanels() { private final HashMap<String,PopupPanel> myPopups = new HashMap<String,PopupPanel>();
return Collections.unmodifiableList(myPanels); private PopupPanel myActivePopup;
public final Collection<PopupPanel> popupPanels() {
return myPopups.values();
} }
public final void registerButtonPanel(ButtonPanel panel) { public final PopupPanel getActivePopup() {
myPanels.add(panel); return myActivePopup;
}
public final PopupPanel getPopupById(String id) {
return myPopups.get(id);
} }
public int getBatteryLevel() { public int getBatteryLevel() {