mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +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:
parent
2461d39fca
commit
24c113d281
4 changed files with 229 additions and 139 deletions
164
src/org/geometerplus/android/fbreader/ControlButtonPanel.java
Normal file
164
src/org/geometerplus/android/fbreader/ControlButtonPanel.java
Normal 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() {}
|
||||
}
|
|
@ -57,7 +57,6 @@ public class ControlPanel extends LinearLayout implements View.OnClickListener {
|
|||
final LayoutInflater inflater =
|
||||
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
inflater.inflate(R.layout.control_panel, this, true);
|
||||
|
||||
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) {
|
||||
preparePanel();
|
||||
myVisibilityHandler.sendEmptyMessage(animate ? VisibilityAction.SHOW_ANIMATED : VisibilityAction.SHOW_INSTANTLY);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
package org.geometerplus.android.fbreader;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import android.app.SearchManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.RelativeLayout;
|
||||
|
@ -49,69 +49,36 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
|
||||
private int myFullScreenFlag;
|
||||
|
||||
private static class ControlButtonPanel implements ZLApplication.ButtonPanel {
|
||||
boolean Visible;
|
||||
ControlPanel ControlPanel;
|
||||
private static class NavigationButtonPanel extends ControlButtonPanel {
|
||||
public volatile boolean NavigateDragging;
|
||||
public ZLTextPosition StartPosition;
|
||||
|
||||
public void hide() {
|
||||
Visible = false;
|
||||
if (ControlPanel != null) {
|
||||
ControlPanel.hide(false);
|
||||
@Override
|
||||
public void onShow() {
|
||||
if (FBReader.Instance != null) {
|
||||
FBReader.Instance.setupNavigation(myControlPanel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStates() {
|
||||
if (ControlPanel != null) {
|
||||
ControlPanel.updateStates();
|
||||
super.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
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
@ -129,11 +96,11 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
WindowManager.LayoutParams.FLAG_FULLSCREEN, myFullScreenFlag
|
||||
);
|
||||
if (myTextSearchPanel == null) {
|
||||
myTextSearchPanel = new ControlButtonPanel();
|
||||
myTextSearchPanel = new TextSearchButtonPanel();
|
||||
myTextSearchPanel.register();
|
||||
}
|
||||
if (myNavigatePanel == null) {
|
||||
myNavigatePanel = new ControlButtonPanel();
|
||||
myNavigatePanel = new NavigationButtonPanel();
|
||||
myNavigatePanel.register();
|
||||
}
|
||||
}
|
||||
|
@ -151,19 +118,21 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
}
|
||||
|
||||
final RelativeLayout root = (RelativeLayout)FBReader.this.findViewById(R.id.root_view);
|
||||
if (myTextSearchPanel.ControlPanel == null) {
|
||||
myTextSearchPanel.ControlPanel = new ControlPanel(this);
|
||||
if (!myTextSearchPanel.hasControlPanel()) {
|
||||
final ControlPanel panel = new ControlPanel(this);
|
||||
|
||||
myTextSearchPanel.ControlPanel.addButton(ActionCode.FIND_PREVIOUS, false, R.drawable.text_search_previous);
|
||||
myTextSearchPanel.ControlPanel.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_PREVIOUS, false, R.drawable.text_search_previous);
|
||||
panel.addButton(ActionCode.CLEAR_FIND_RESULTS, true, R.drawable.text_search_close);
|
||||
panel.addButton(ActionCode.FIND_NEXT, false, R.drawable.text_search_next);
|
||||
|
||||
myTextSearchPanel.registerControlPanel(root, false);
|
||||
myTextSearchPanel.setControlPanel(panel, root, false);
|
||||
}
|
||||
if (myNavigatePanel.ControlPanel == null) {
|
||||
myNavigatePanel.ControlPanel = new NavigationControlPanel(this);
|
||||
createNavigation();
|
||||
myNavigatePanel.registerControlPanel(root, true);
|
||||
if (!myNavigatePanel.hasControlPanel()) {
|
||||
final ControlPanel panel = new ControlPanel(this);
|
||||
final View layout = getLayoutInflater().inflate(R.layout.navigate, panel, false);
|
||||
createNavigation(layout);
|
||||
panel.setExtension(layout);
|
||||
myNavigatePanel.setControlPanel(panel, root, true);
|
||||
}
|
||||
|
||||
findViewById(R.id.main_view).setOnLongClickListener(new View.OnLongClickListener() {
|
||||
|
@ -182,8 +151,7 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
myTextSearchPanel.restoreVisibility();
|
||||
myNavigatePanel.restoreVisibility();
|
||||
ControlButtonPanel.restoreVisibilities();
|
||||
if (ZLAndroidApplication.Instance().DontTurnScreenOffOption.getValue()) {
|
||||
myWakeLock =
|
||||
((PowerManager)getSystemService(POWER_SERVICE)).
|
||||
|
@ -199,27 +167,21 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
if (myWakeLock != null) {
|
||||
myWakeLock.release();
|
||||
}
|
||||
myTextSearchPanel.saveVisibility();
|
||||
myNavigatePanel.saveVisibility();
|
||||
ControlButtonPanel.saveVisibilities();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
final RelativeLayout root = (RelativeLayout)FBReader.this.findViewById(R.id.root_view);
|
||||
myTextSearchPanel.destroyControlPanel(root);
|
||||
myNavigatePanel.destroyControlPanel(root);
|
||||
ControlButtonPanel.removeControlPanels();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
void showTextSearchControls(boolean show) {
|
||||
if (myTextSearchPanel.ControlPanel != null) {
|
||||
if (show) {
|
||||
ZLApplication.Instance().hideAllPanels();
|
||||
myTextSearchPanel.ControlPanel.show(true);
|
||||
} else {
|
||||
myTextSearchPanel.ControlPanel.hide(false);
|
||||
}
|
||||
if (show) {
|
||||
myTextSearchPanel.show(true);
|
||||
} else {
|
||||
myTextSearchPanel.hide(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,14 +193,13 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
|
||||
@Override
|
||||
public boolean onSearchRequested() {
|
||||
final boolean textSearchVisible = myTextSearchPanel.getVisibility();
|
||||
final boolean navigateVisible = myNavigatePanel.getVisibility();
|
||||
ZLApplication.Instance().hideAllPanels();
|
||||
final LinkedList<Boolean> visibilities = new LinkedList<Boolean>();
|
||||
ControlButtonPanel.saveVisibilitiesTo(visibilities);
|
||||
ControlButtonPanel.hideAllPendingNotify();
|
||||
final SearchManager manager = (SearchManager)getSystemService(SEARCH_SERVICE);
|
||||
manager.setOnCancelListener(new SearchManager.OnCancelListener() {
|
||||
public void onCancel() {
|
||||
myTextSearchPanel.setVisibility(textSearchVisible);
|
||||
myNavigatePanel.setVisibility(navigateVisible);
|
||||
ControlButtonPanel.restoreVisibilitiesFrom(visibilities);
|
||||
manager.setOnCancelListener(null);
|
||||
}
|
||||
});
|
||||
|
@ -249,41 +210,14 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
}
|
||||
|
||||
|
||||
private static ZLTextPosition myPosition;
|
||||
|
||||
public void navigate() {
|
||||
if (myNavigatePanel.ControlPanel != null) {
|
||||
final ZLTextView textView = (ZLTextView) ZLApplication.Instance().getCurrentView();
|
||||
if (myTextSearchPanel.ControlPanel.getVisibility() == View.VISIBLE) {
|
||||
textView.clearFindResults();
|
||||
}
|
||||
myPosition = new ZLTextFixedPosition(textView.getStartCursor());
|
||||
ZLApplication.Instance().hideAllPanels();
|
||||
setupNavigation();
|
||||
myNavigatePanel.ControlPanel.show(true);
|
||||
}
|
||||
final ZLTextView textView = (ZLTextView) ZLApplication.Instance().getCurrentView();
|
||||
myNavigatePanel.NavigateDragging = false;
|
||||
myNavigatePanel.StartPosition = new ZLTextFixedPosition(textView.getStartCursor());
|
||||
myNavigatePanel.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() {
|
||||
final org.geometerplus.fbreader.fbreader.FBReader fbreader =
|
||||
|
@ -296,10 +230,7 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
&& fbreader.Model.Book != null;
|
||||
}
|
||||
|
||||
private final void createNavigation() {
|
||||
final ControlPanel panel = myNavigatePanel.ControlPanel;
|
||||
|
||||
final View layout = getLayoutInflater().inflate(R.layout.navigate, panel, false);
|
||||
private final void createNavigation(View layout) {
|
||||
final SeekBar slider = (SeekBar) layout.findViewById(R.id.book_position_slider);
|
||||
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) {
|
||||
myNavigateDragging = false;
|
||||
myNavigatePanel.NavigateDragging = false;
|
||||
}
|
||||
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
myNavigateDragging = true;
|
||||
myNavigatePanel.NavigateDragging = true;
|
||||
}
|
||||
|
||||
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);
|
||||
View.OnClickListener listener = new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (v == btnCancel && myPosition != null) {
|
||||
((ZLTextView) ZLApplication.Instance().getCurrentView()).gotoPosition(myPosition);
|
||||
final ZLTextPosition position = myNavigatePanel.StartPosition;
|
||||
myNavigatePanel.StartPosition = null;
|
||||
if (v == btnCancel && position != null) {
|
||||
((ZLTextView) ZLApplication.Instance().getCurrentView()).gotoPosition(position);
|
||||
}
|
||||
myPosition = null;
|
||||
panel.hide(true);
|
||||
myNavigatePanel.hide(true);
|
||||
}
|
||||
};
|
||||
btnOk.setOnClickListener(listener);
|
||||
|
@ -351,13 +283,9 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button");
|
||||
btnOk.setText(buttonResource.getResource("ok").getValue());
|
||||
btnCancel.setText(buttonResource.getResource("cancel").getValue());
|
||||
|
||||
panel.setExtension(layout);
|
||||
}
|
||||
|
||||
private final void setupNavigation() {
|
||||
final ControlPanel panel = myNavigatePanel.ControlPanel;
|
||||
|
||||
private final void setupNavigation(ControlPanel panel) {
|
||||
final SeekBar slider = (SeekBar) panel.findViewById(R.id.book_position_slider);
|
||||
final TextView text = (TextView) panel.findViewById(R.id.book_position_text);
|
||||
|
||||
|
|
|
@ -35,6 +35,9 @@ abstract class SearchActivity extends Activity {
|
|||
|
||||
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();
|
||||
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
||||
final String pattern = intent.getStringExtra(SearchManager.QUERY);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue