1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 19:42:17 +02:00

Control panels layer has been rewritten

git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1600 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Vasiliy Bout 2010-07-15 09:10:41 +00:00
parent 2461d39fca
commit 24c113d281
4 changed files with 229 additions and 139 deletions

View file

@ -0,0 +1,164 @@
/*
* Copyright (C) 2010 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 java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import org.geometerplus.zlibrary.core.application.ZLApplication;
class ControlButtonPanel implements ZLApplication.ButtonPanel {
private boolean myVisible;
protected ControlPanel myControlPanel;
private static LinkedList<ControlButtonPanel> ourPanels = new LinkedList<ControlButtonPanel>();
public final void hide() {
hide(false);
}
public void updateStates() {
if (myControlPanel != null) {
myControlPanel.updateStates();
}
}
public final void register() {
ZLApplication.Instance().registerButtonPanel(this);
ourPanels.add(this);
}
public final boolean hasControlPanel() {
return myControlPanel != null;
}
public final void setControlPanel(ControlPanel panel, RelativeLayout root, boolean fillWidth) {
myControlPanel = panel;
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
fillWidth ? ViewGroup.LayoutParams.FILL_PARENT : ViewGroup.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
p.addRule(RelativeLayout.CENTER_HORIZONTAL);
myControlPanel.setVisibility(View.GONE);
root.addView(myControlPanel, p);
}
private final void removeControlPanel() {
if (myControlPanel != null) {
ViewGroup root = (ViewGroup) myControlPanel.getParent();
myControlPanel.hide(false);
root.removeView(myControlPanel);
myControlPanel = null;
}
}
public static void removeControlPanels() {
for (ControlButtonPanel panel: ourPanels) {
panel.removeControlPanel();
}
}
public static void restoreVisibilities() {
for (ControlButtonPanel panel: ourPanels) {
panel.setVisibility(panel.myVisible);
}
}
public static void saveVisibilities() {
for (ControlButtonPanel panel: ourPanels) {
panel.myVisible = panel.getVisibility();
}
}
public static void restoreVisibilitiesFrom(List<Boolean> buffer) {
Iterator<Boolean> it = buffer.iterator();
for (ControlButtonPanel panel: ourPanels) {
panel.setVisibility(it.next());
}
}
public static void saveVisibilitiesTo(List<Boolean> buffer) {
buffer.clear();
for (ControlButtonPanel panel: ourPanels) {
buffer.add(panel.getVisibility());
}
}
public static void hideAllPendingNotify() {
for (ControlButtonPanel panel: ourPanels) {
if (panel.myControlPanel != null && panel.getVisibility()) {
panel.myControlPanel.hide(false);
}
}
}
public final boolean getVisibility() {
if (myControlPanel != null) {
return myControlPanel.getVisibility() == View.VISIBLE;
}
return false;
}
public final void setVisibility(boolean visible) {
if (visible) {
show(false);
} else {
hide(false);
}
}
private void hideOthers() {
for (ControlButtonPanel panel: ourPanels) {
if (panel != this) {
panel.hide(false);
}
}
}
public final void show(boolean animate) {
if (myControlPanel != null && !getVisibility()) {
myVisible = true;
hideOthers();
onShow();
myControlPanel.show(animate);
}
}
public final void hide(boolean animate) {
myVisible = false;
if (myControlPanel != null && getVisibility()) {
onHide();
myControlPanel.hide(animate);
}
}
// callback methods
public void onShow() {}
public void onHide() {}
}

View file

@ -57,7 +57,6 @@ public class ControlPanel extends LinearLayout implements View.OnClickListener {
final LayoutInflater inflater = final LayoutInflater inflater =
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.control_panel, this, true); inflater.inflate(R.layout.control_panel, this, true);
myPlateLayout = (LinearLayout)findViewById(R.id.tools_plate); myPlateLayout = (LinearLayout)findViewById(R.id.tools_plate);
} }
@ -108,11 +107,7 @@ public class ControlPanel extends LinearLayout implements View.OnClickListener {
} }
}; };
public void preparePanel() {
}
public void show(boolean animate) { public void show(boolean animate) {
preparePanel();
myVisibilityHandler.sendEmptyMessage(animate ? VisibilityAction.SHOW_ANIMATED : VisibilityAction.SHOW_INSTANTLY); myVisibilityHandler.sendEmptyMessage(animate ? VisibilityAction.SHOW_ANIMATED : VisibilityAction.SHOW_INSTANTLY);
} }

View file

@ -19,13 +19,13 @@
package org.geometerplus.android.fbreader; package org.geometerplus.android.fbreader;
import java.util.LinkedList;
import android.app.SearchManager; import android.app.SearchManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager; import android.os.PowerManager;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
@ -49,69 +49,36 @@ public final class FBReader extends ZLAndroidActivity {
private int myFullScreenFlag; private int myFullScreenFlag;
private static class ControlButtonPanel implements ZLApplication.ButtonPanel { private static class NavigationButtonPanel extends ControlButtonPanel {
boolean Visible; public volatile boolean NavigateDragging;
ControlPanel ControlPanel; public ZLTextPosition StartPosition;
public void hide() { @Override
Visible = false; public void onShow() {
if (ControlPanel != null) { if (FBReader.Instance != null) {
ControlPanel.hide(false); FBReader.Instance.setupNavigation(myControlPanel);
} }
} }
@Override
public void updateStates() { public void updateStates() {
if (ControlPanel != null) { super.updateStates();
ControlPanel.updateStates(); if (!NavigateDragging && FBReader.Instance != null) {
FBReader.Instance.setupNavigation(myControlPanel);
} }
} }
public void register() {
ZLApplication.Instance().registerButtonPanel(this);
}
public void registerControlPanel(RelativeLayout root, boolean fillWidth) {
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
fillWidth ? ViewGroup.LayoutParams.FILL_PARENT : ViewGroup.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
p.addRule(RelativeLayout.CENTER_HORIZONTAL);
root.addView(ControlPanel, p);
ControlPanel.requestLayout();
}
public void destroyControlPanel(RelativeLayout root) {
if (ControlPanel != null) {
ControlPanel.hide(false);
root.removeView(ControlPanel);
ControlPanel = null;
}
}
public boolean getVisibility() {
if (ControlPanel != null) {
return ControlPanel.getVisibility() == View.VISIBLE;
}
return false;
}
public void setVisibility(boolean visibility) {
if (ControlPanel != null) {
ControlPanel.setVisibility(visibility ? View.VISIBLE : View.GONE);
}
}
public void restoreVisibility() {
setVisibility(Visible);
}
public void saveVisibility() {
Visible = getVisibility();
}
} }
private static ControlButtonPanel myTextSearchPanel;
private static ControlButtonPanel myNavigatePanel; private static class TextSearchButtonPanel extends ControlButtonPanel {
@Override
public void onHide() {
final ZLTextView textView = (ZLTextView) ZLApplication.Instance().getCurrentView();
textView.clearFindResults();
}
}
private static TextSearchButtonPanel myTextSearchPanel;
private static NavigationButtonPanel myNavigatePanel;
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
@ -129,11 +96,11 @@ public final class FBReader extends ZLAndroidActivity {
WindowManager.LayoutParams.FLAG_FULLSCREEN, myFullScreenFlag WindowManager.LayoutParams.FLAG_FULLSCREEN, myFullScreenFlag
); );
if (myTextSearchPanel == null) { if (myTextSearchPanel == null) {
myTextSearchPanel = new ControlButtonPanel(); myTextSearchPanel = new TextSearchButtonPanel();
myTextSearchPanel.register(); myTextSearchPanel.register();
} }
if (myNavigatePanel == null) { if (myNavigatePanel == null) {
myNavigatePanel = new ControlButtonPanel(); myNavigatePanel = new NavigationButtonPanel();
myNavigatePanel.register(); myNavigatePanel.register();
} }
} }
@ -151,19 +118,21 @@ public final class FBReader extends ZLAndroidActivity {
} }
final RelativeLayout root = (RelativeLayout)FBReader.this.findViewById(R.id.root_view); final RelativeLayout root = (RelativeLayout)FBReader.this.findViewById(R.id.root_view);
if (myTextSearchPanel.ControlPanel == null) { if (!myTextSearchPanel.hasControlPanel()) {
myTextSearchPanel.ControlPanel = new ControlPanel(this); final ControlPanel panel = new ControlPanel(this);
myTextSearchPanel.ControlPanel.addButton(ActionCode.FIND_PREVIOUS, false, R.drawable.text_search_previous); panel.addButton(ActionCode.FIND_PREVIOUS, false, R.drawable.text_search_previous);
myTextSearchPanel.ControlPanel.addButton(ActionCode.CLEAR_FIND_RESULTS, true, R.drawable.text_search_close); panel.addButton(ActionCode.CLEAR_FIND_RESULTS, true, R.drawable.text_search_close);
myTextSearchPanel.ControlPanel.addButton(ActionCode.FIND_NEXT, false, R.drawable.text_search_next); panel.addButton(ActionCode.FIND_NEXT, false, R.drawable.text_search_next);
myTextSearchPanel.registerControlPanel(root, false); myTextSearchPanel.setControlPanel(panel, root, false);
} }
if (myNavigatePanel.ControlPanel == null) { if (!myNavigatePanel.hasControlPanel()) {
myNavigatePanel.ControlPanel = new NavigationControlPanel(this); final ControlPanel panel = new ControlPanel(this);
createNavigation(); final View layout = getLayoutInflater().inflate(R.layout.navigate, panel, false);
myNavigatePanel.registerControlPanel(root, true); createNavigation(layout);
panel.setExtension(layout);
myNavigatePanel.setControlPanel(panel, root, true);
} }
findViewById(R.id.main_view).setOnLongClickListener(new View.OnLongClickListener() { findViewById(R.id.main_view).setOnLongClickListener(new View.OnLongClickListener() {
@ -182,8 +151,7 @@ public final class FBReader extends ZLAndroidActivity {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
myTextSearchPanel.restoreVisibility(); ControlButtonPanel.restoreVisibilities();
myNavigatePanel.restoreVisibility();
if (ZLAndroidApplication.Instance().DontTurnScreenOffOption.getValue()) { if (ZLAndroidApplication.Instance().DontTurnScreenOffOption.getValue()) {
myWakeLock = myWakeLock =
((PowerManager)getSystemService(POWER_SERVICE)). ((PowerManager)getSystemService(POWER_SERVICE)).
@ -199,27 +167,21 @@ public final class FBReader extends ZLAndroidActivity {
if (myWakeLock != null) { if (myWakeLock != null) {
myWakeLock.release(); myWakeLock.release();
} }
myTextSearchPanel.saveVisibility(); ControlButtonPanel.saveVisibilities();
myNavigatePanel.saveVisibility();
super.onPause(); super.onPause();
} }
@Override @Override
public void onStop() { public void onStop() {
final RelativeLayout root = (RelativeLayout)FBReader.this.findViewById(R.id.root_view); ControlButtonPanel.removeControlPanels();
myTextSearchPanel.destroyControlPanel(root);
myNavigatePanel.destroyControlPanel(root);
super.onStop(); super.onStop();
} }
void showTextSearchControls(boolean show) { void showTextSearchControls(boolean show) {
if (myTextSearchPanel.ControlPanel != null) { if (show) {
if (show) { myTextSearchPanel.show(true);
ZLApplication.Instance().hideAllPanels(); } else {
myTextSearchPanel.ControlPanel.show(true); myTextSearchPanel.hide(false);
} else {
myTextSearchPanel.ControlPanel.hide(false);
}
} }
} }
@ -231,14 +193,13 @@ public final class FBReader extends ZLAndroidActivity {
@Override @Override
public boolean onSearchRequested() { public boolean onSearchRequested() {
final boolean textSearchVisible = myTextSearchPanel.getVisibility(); final LinkedList<Boolean> visibilities = new LinkedList<Boolean>();
final boolean navigateVisible = myNavigatePanel.getVisibility(); ControlButtonPanel.saveVisibilitiesTo(visibilities);
ZLApplication.Instance().hideAllPanels(); ControlButtonPanel.hideAllPendingNotify();
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() {
myTextSearchPanel.setVisibility(textSearchVisible); ControlButtonPanel.restoreVisibilitiesFrom(visibilities);
myNavigatePanel.setVisibility(navigateVisible);
manager.setOnCancelListener(null); manager.setOnCancelListener(null);
} }
}); });
@ -249,41 +210,14 @@ public final class FBReader extends ZLAndroidActivity {
} }
private static ZLTextPosition myPosition;
public void navigate() { public void navigate() {
if (myNavigatePanel.ControlPanel != null) { final ZLTextView textView = (ZLTextView) ZLApplication.Instance().getCurrentView();
final ZLTextView textView = (ZLTextView) ZLApplication.Instance().getCurrentView(); myNavigatePanel.NavigateDragging = false;
if (myTextSearchPanel.ControlPanel.getVisibility() == View.VISIBLE) { myNavigatePanel.StartPosition = new ZLTextFixedPosition(textView.getStartCursor());
textView.clearFindResults(); myNavigatePanel.show(true);
}
myPosition = new ZLTextFixedPosition(textView.getStartCursor());
ZLApplication.Instance().hideAllPanels();
setupNavigation();
myNavigatePanel.ControlPanel.show(true);
}
} }
private boolean myNavigateDragging;
private class NavigationControlPanel extends ControlPanel {
public NavigationControlPanel(Context context) {
super(context);
}
@Override
public void preparePanel() {
setupNavigation();
}
@Override
public void updateStates() {
super.updateStates();
if (!myNavigateDragging) {
setupNavigation();
}
}
}
public final boolean canNavigate() { public final boolean canNavigate() {
final org.geometerplus.fbreader.fbreader.FBReader fbreader = final org.geometerplus.fbreader.fbreader.FBReader fbreader =
@ -296,10 +230,7 @@ public final class FBReader extends ZLAndroidActivity {
&& fbreader.Model.Book != null; && fbreader.Model.Book != null;
} }
private final void createNavigation() { private final void createNavigation(View layout) {
final ControlPanel panel = myNavigatePanel.ControlPanel;
final View layout = getLayoutInflater().inflate(R.layout.navigate, panel, 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);
@ -318,11 +249,11 @@ public final class FBReader extends ZLAndroidActivity {
} }
public void onStopTrackingTouch(SeekBar seekBar) { public void onStopTrackingTouch(SeekBar seekBar) {
myNavigateDragging = false; myNavigatePanel.NavigateDragging = false;
} }
public void onStartTrackingTouch(SeekBar seekBar) { public void onStartTrackingTouch(SeekBar seekBar) {
myNavigateDragging = true; myNavigatePanel.NavigateDragging = true;
} }
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@ -339,11 +270,12 @@ public final class FBReader extends ZLAndroidActivity {
final Button btnCancel = (Button) layout.findViewById(android.R.id.button3); final Button btnCancel = (Button) layout.findViewById(android.R.id.button3);
View.OnClickListener listener = new View.OnClickListener() { View.OnClickListener listener = new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
if (v == btnCancel && myPosition != null) { final ZLTextPosition position = myNavigatePanel.StartPosition;
((ZLTextView) ZLApplication.Instance().getCurrentView()).gotoPosition(myPosition); myNavigatePanel.StartPosition = null;
if (v == btnCancel && position != null) {
((ZLTextView) ZLApplication.Instance().getCurrentView()).gotoPosition(position);
} }
myPosition = null; myNavigatePanel.hide(true);
panel.hide(true);
} }
}; };
btnOk.setOnClickListener(listener); btnOk.setOnClickListener(listener);
@ -351,13 +283,9 @@ public final class FBReader extends ZLAndroidActivity {
final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button"); final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button");
btnOk.setText(buttonResource.getResource("ok").getValue()); btnOk.setText(buttonResource.getResource("ok").getValue());
btnCancel.setText(buttonResource.getResource("cancel").getValue()); btnCancel.setText(buttonResource.getResource("cancel").getValue());
panel.setExtension(layout);
} }
private final void setupNavigation() { private final void setupNavigation(ControlPanel panel) {
final ControlPanel panel = myNavigatePanel.ControlPanel;
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);

View file

@ -35,6 +35,9 @@ abstract class SearchActivity extends Activity {
Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this)); Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
final SearchManager manager = (SearchManager)getSystemService(SEARCH_SERVICE);
manager.setOnCancelListener(null);
final Intent intent = getIntent(); final Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
final String pattern = intent.getStringExtra(SearchManager.QUERY); final String pattern = intent.getStringExtra(SearchManager.QUERY);