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:
parent
14c0b2c101
commit
8b73346089
7 changed files with 230 additions and 265 deletions
|
@ -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() {}
|
||||
}
|
|
@ -53,9 +53,6 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
|
||||
private int myFullScreenFlag;
|
||||
|
||||
private static TextSearchButtonPanel ourTextSearchPanel;
|
||||
private static NavigationButtonPanel ourNavigatePanel;
|
||||
|
||||
@Override
|
||||
protected ZLFile fileFromIntent(Intent intent) {
|
||||
String filePath = intent.getStringExtra(BOOK_PATH_KEY);
|
||||
|
@ -79,11 +76,11 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
);
|
||||
|
||||
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
|
||||
if (ourTextSearchPanel == null) {
|
||||
ourTextSearchPanel = new TextSearchButtonPanel(fbReader);
|
||||
if (fbReader.getPopupById(TextSearchPopup.ID) == null) {
|
||||
new TextSearchPopup(fbReader);
|
||||
}
|
||||
if (ourNavigatePanel == null) {
|
||||
ourNavigatePanel = new NavigationButtonPanel(fbReader);
|
||||
if (fbReader.getPopupById(NavigationPopup.ID) == null) {
|
||||
new NavigationPopup(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 Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
ourTextSearchPanel.initPosition();
|
||||
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
|
||||
final TextSearchPopup popup = (TextSearchPopup)fbReader.getPopupById(TextSearchPopup.ID);
|
||||
popup.initPosition();
|
||||
fbReader.TextSearchPatternOption.setValue(pattern);
|
||||
if (fbReader.getTextView().search(pattern, true, false, false, false) != 0) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ourTextSearchPanel.show(true);
|
||||
fbReader.showPopup(popup.getId());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
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()));
|
||||
}
|
||||
|
||||
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
|
||||
final RelativeLayout root = (RelativeLayout)findViewById(R.id.root_view);
|
||||
if (!ourTextSearchPanel.hasControlPanel()) {
|
||||
ourTextSearchPanel.createControlPanel(this, root, ControlPanel.Location.Bottom);
|
||||
}
|
||||
if (!ourNavigatePanel.hasControlPanel()) {
|
||||
ourNavigatePanel.createControlPanel(this, root, ControlPanel.Location.Bottom);
|
||||
}
|
||||
((PopupPanel)fbReader.getPopupById(TextSearchPopup.ID)).createControlPanel(this, root, PopupWindow.Location.Bottom);
|
||||
((PopupPanel)fbReader.getPopupById(NavigationPopup.ID)).createControlPanel(this, root, PopupWindow.Location.Bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -189,18 +184,12 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
sendBroadcast(new Intent(getApplicationContext(), KillerCallback.class));
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
ControlButtonPanel.restoreVisibilities(FBReaderApp.Instance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
ControlButtonPanel.saveVisibilities(FBReaderApp.Instance());
|
||||
super.onPause();
|
||||
PopupPanel.restoreVisibilities(FBReaderApp.Instance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
ControlButtonPanel.removeControlPanels(FBReaderApp.Instance());
|
||||
PopupPanel.removeAllWindows(FBReaderApp.Instance());
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -215,12 +204,14 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
@Override
|
||||
public boolean onSearchRequested() {
|
||||
final FBReaderApp fbreader = (FBReaderApp)FBReaderApp.Instance();
|
||||
ControlButtonPanel.saveVisibilities(fbreader);
|
||||
ControlButtonPanel.hideAllPendingNotify(fbreader);
|
||||
final FBReaderApp.PopupPanel popup = fbreader.getActivePopup();
|
||||
fbreader.hideActivePopup();
|
||||
final SearchManager manager = (SearchManager)getSystemService(SEARCH_SERVICE);
|
||||
manager.setOnCancelListener(new SearchManager.OnCancelListener() {
|
||||
public void onCancel() {
|
||||
ControlButtonPanel.restoreVisibilities(fbreader);
|
||||
if (popup != null) {
|
||||
fbreader.showPopup(popup.getId());
|
||||
}
|
||||
manager.setOnCancelListener(null);
|
||||
}
|
||||
});
|
||||
|
@ -263,7 +254,7 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
}
|
||||
|
||||
public void navigate() {
|
||||
ourNavigatePanel.runNavigation();
|
||||
((NavigationPopup)FBReaderApp.Instance().getPopupById(NavigationPopup.ID)).runNavigation();
|
||||
}
|
||||
|
||||
private void addMenuItem(Menu menu, String actionId, int iconId) {
|
||||
|
|
|
@ -34,55 +34,66 @@ import org.geometerplus.zlibrary.ui.android.R;
|
|||
|
||||
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;
|
||||
|
||||
NavigationButtonPanel(FBReaderApp fbReader) {
|
||||
NavigationPopup(FBReaderApp fbReader) {
|
||||
super(fbReader);
|
||||
}
|
||||
|
||||
public void runNavigation() {
|
||||
if (!getVisibility()) {
|
||||
if (myWindow.getVisibility() == View.GONE) {
|
||||
myIsInProgress = false;
|
||||
initPosition();
|
||||
show(true);
|
||||
Application.showPopup(ID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShow() {
|
||||
if (myControlPanel != null) {
|
||||
setupNavigation(myControlPanel);
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void show_() {
|
||||
super.show_();
|
||||
if (myWindow != null) {
|
||||
setupNavigation(myWindow);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStates() {
|
||||
super.updateStates();
|
||||
if (!myIsInProgress && myControlPanel != null) {
|
||||
setupNavigation(myControlPanel);
|
||||
protected void update() {
|
||||
if (!myIsInProgress && myWindow != null) {
|
||||
setupNavigation(myWindow);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createControlPanel(FBReader activity, RelativeLayout root, ControlPanel.Location location) {
|
||||
myControlPanel = new ControlPanel(activity, root, location, true);
|
||||
public void createControlPanel(FBReader activity, RelativeLayout root, PopupWindow.Location location) {
|
||||
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 TextView text = (TextView)layout.findViewById(R.id.book_position_text);
|
||||
|
||||
slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
private void gotoPage(int page) {
|
||||
final ZLTextView view = Reader.getTextView();
|
||||
final ZLTextView view = getReader().getTextView();
|
||||
if (page == 1) {
|
||||
view.gotoHome();
|
||||
} else {
|
||||
view.gotoPage(page);
|
||||
}
|
||||
Reader.getViewWidget().reset();
|
||||
Reader.getViewWidget().repaint();
|
||||
getReader().getViewWidget().reset();
|
||||
getReader().getViewWidget().repaint();
|
||||
}
|
||||
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
@ -109,12 +120,12 @@ final class NavigationButtonPanel extends ControlButtonPanel {
|
|||
public void onClick(View v) {
|
||||
final ZLTextWordCursor position = StartPosition;
|
||||
if (v == btnCancel && position != null) {
|
||||
Reader.getTextView().gotoPosition(position);
|
||||
getReader().getTextView().gotoPosition(position);
|
||||
} else if (v == btnOk) {
|
||||
storePosition();
|
||||
}
|
||||
StartPosition = null;
|
||||
hide(true);
|
||||
Application.hideActivePopup();
|
||||
}
|
||||
};
|
||||
btnOk.setOnClickListener(listener);
|
||||
|
@ -123,14 +134,14 @@ final class NavigationButtonPanel extends ControlButtonPanel {
|
|||
btnOk.setText(buttonResource.getResource("ok").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 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 pagesNumber = textView.computePageNumber();
|
||||
|
95
src/org/geometerplus/android/fbreader/PopupPanel.java
Normal file
95
src/org/geometerplus/android/fbreader/PopupPanel.java
Normal 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);
|
||||
}
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.geometerplus.android.fbreader;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.content.Context;
|
||||
|
@ -28,19 +29,22 @@ import android.widget.*;
|
|||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
public class ControlPanel extends LinearLayout {
|
||||
public class PopupWindow extends LinearLayout {
|
||||
public static enum Location {
|
||||
Bottom,
|
||||
Floating
|
||||
}
|
||||
|
||||
public ControlPanel(Context context, RelativeLayout root, Location location, boolean fillWidth) {
|
||||
super(context);
|
||||
private final Activity myActivity;
|
||||
|
||||
public PopupWindow(Activity activity, RelativeLayout root, Location location, boolean fillWidth) {
|
||||
super(activity);
|
||||
myActivity = activity;
|
||||
|
||||
setFocusable(false);
|
||||
|
||||
final LayoutInflater inflater =
|
||||
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
inflater.inflate(
|
||||
location == Location.Bottom
|
||||
? R.layout.control_panel_bottom : R.layout.control_panel_floating,
|
||||
|
@ -64,45 +68,20 @@ public class ControlPanel extends LinearLayout {
|
|||
return true;
|
||||
}
|
||||
|
||||
private interface VisibilityAction {
|
||||
int SHOW_ANIMATED = 0;
|
||||
int SHOW_INSTANTLY = 1;
|
||||
int HIDE_ANIMATED = 2;
|
||||
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:
|
||||
public void show() {
|
||||
myActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case VisibilityAction.HIDE_ANIMATED:
|
||||
fade(View.GONE, 1.0f, 0.0f);
|
||||
break;
|
||||
case VisibilityAction.HIDE_INSTANTLY:
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
myActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void show(boolean animate) {
|
||||
myVisibilityHandler.sendEmptyMessage(animate ? VisibilityAction.SHOW_ANIMATED : VisibilityAction.SHOW_INSTANTLY);
|
||||
}
|
||||
|
||||
public void hide(boolean animate) {
|
||||
myVisibilityHandler.sendEmptyMessage(animate ? VisibilityAction.HIDE_ANIMATED : VisibilityAction.HIDE_INSTANTLY);
|
||||
}
|
||||
|
||||
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) {
|
|
@ -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>();
|
||||
|
||||
TextSearchButtonPanel(FBReaderApp fbReader) {
|
||||
TextSearchPopup(FBReaderApp fbReader) {
|
||||
super(fbReader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHide() {
|
||||
Reader.getTextView().clearFindResults();
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createControlPanel(FBReader activity, RelativeLayout root, ControlPanel.Location location) {
|
||||
myControlPanel = new ControlPanel(activity, root, location, false);
|
||||
protected void hide_() {
|
||||
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.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) {
|
||||
final ActionButton button = new ActionButton(myControlPanel.getContext(), actionId, isCloseButton);
|
||||
final ActionButton button = new ActionButton(myWindow.getContext(), actionId, isCloseButton);
|
||||
button.setImageResource(imageId);
|
||||
myControlPanel.addView(button);
|
||||
myWindow.addView(button);
|
||||
button.setOnClickListener(this);
|
||||
myButtons.add(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStates() {
|
||||
protected void update() {
|
||||
for (ActionButton button : myButtons) {
|
||||
button.setEnabled(Reader.isActionEnabled(button.ActionId));
|
||||
button.setEnabled(Application.isActionEnabled(button.ActionId));
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
final ActionButton button = (ActionButton)view;
|
||||
Reader.doAction(button.ActionId);
|
||||
if (button.IsCloseButton && myControlPanel != null) {
|
||||
Application.doAction(button.ActionId);
|
||||
if (button.IsCloseButton) {
|
||||
storePosition();
|
||||
StartPosition = null;
|
||||
myControlPanel.hide(true);
|
||||
Application.hideActivePopup();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -75,14 +75,27 @@ public abstract class ZLApplication {
|
|||
if (myWindow != null) {
|
||||
myWindow.refreshMenu();
|
||||
}
|
||||
for (ButtonPanel panel : myPanels) {
|
||||
panel.updateStates();
|
||||
for (PopupPanel popup : popupPanels()) {
|
||||
popup.update();
|
||||
}
|
||||
}
|
||||
|
||||
public final void onViewChanged() {
|
||||
for (ButtonPanel panel : myPanels) {
|
||||
panel.hide();
|
||||
hideActivePopup();
|
||||
}
|
||||
|
||||
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 {
|
||||
void updateStates();
|
||||
void hide();
|
||||
public static abstract class PopupPanel {
|
||||
protected final ZLApplication Application;
|
||||
|
||||
protected PopupPanel(ZLApplication application) {
|
||||
application.myPopups.put(getId(), this);
|
||||
Application = application;
|
||||
}
|
||||
private final List<ButtonPanel> myPanels = new LinkedList<ButtonPanel>();
|
||||
public final List<ButtonPanel> buttonPanels() {
|
||||
return Collections.unmodifiableList(myPanels);
|
||||
|
||||
abstract public String getId();
|
||||
abstract protected void update();
|
||||
abstract protected void hide_();
|
||||
abstract protected void show_();
|
||||
}
|
||||
public final void registerButtonPanel(ButtonPanel panel) {
|
||||
myPanels.add(panel);
|
||||
|
||||
private final HashMap<String,PopupPanel> myPopups = new HashMap<String,PopupPanel>();
|
||||
private PopupPanel myActivePopup;
|
||||
public final Collection<PopupPanel> popupPanels() {
|
||||
return myPopups.values();
|
||||
}
|
||||
public final PopupPanel getActivePopup() {
|
||||
return myActivePopup;
|
||||
}
|
||||
public final PopupPanel getPopupById(String id) {
|
||||
return myPopups.get(id);
|
||||
}
|
||||
|
||||
public int getBatteryLevel() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue