mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +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
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue