diff --git a/src/org/geometerplus/android/fbreader/ButtonsPopupPanel.java b/src/org/geometerplus/android/fbreader/ButtonsPopupPanel.java new file mode 100644 index 000000000..0ea6a358d --- /dev/null +++ b/src/org/geometerplus/android/fbreader/ButtonsPopupPanel.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2007-2011 Geometer Plus + * + * 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.ArrayList; + +import org.geometerplus.fbreader.fbreader.FBReaderApp; + +import android.content.Context; +import android.view.View; +import android.widget.RelativeLayout; +import android.widget.ZoomButton; + +abstract class ButtonsPopupPanel extends PopupPanel implements View.OnClickListener { + class ActionButton extends ZoomButton { + final String ActionId; + final boolean IsCloseButton; + + ActionButton(Context context, String actionId, boolean isCloseButton) { + super(context); + ActionId = actionId; + IsCloseButton = isCloseButton; + } + } + + private final ArrayList myButtons = new ArrayList(); + + ButtonsPopupPanel(FBReaderApp fbReader) { + super(fbReader); + } + + protected void addButton(String actionId, boolean isCloseButton, int imageId) { + final ActionButton button = new ActionButton(myWindow.getContext(), actionId, isCloseButton); + button.setImageResource(imageId); + myWindow.addView(button); + button.setOnClickListener(this); + myButtons.add(button); + } + + @Override + protected void update() { + for (ActionButton button : myButtons) { + button.setEnabled(Application.isActionEnabled(button.ActionId)); + } + } + + public void onClick(View view) { + final ActionButton button = (ActionButton)view; + Application.doAction(button.ActionId); + if (button.IsCloseButton) { + storePosition(); + StartPosition = null; + Application.hideActivePopup(); + } + } +} diff --git a/src/org/geometerplus/android/fbreader/SelectionPopup.java b/src/org/geometerplus/android/fbreader/SelectionPopup.java new file mode 100644 index 000000000..dfee9a319 --- /dev/null +++ b/src/org/geometerplus/android/fbreader/SelectionPopup.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2007-2011 Geometer Plus + * + * 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.widget.RelativeLayout; + +import org.geometerplus.fbreader.fbreader.ActionCode; +import org.geometerplus.fbreader.fbreader.FBReaderApp; +import org.geometerplus.zlibrary.ui.android.R; + +class SelectionPopup extends ButtonsPopupPanel { + final static String ID = "SelectionPopup"; + + SelectionPopup(FBReaderApp fbReader) { + super(fbReader); + } + + @Override + public String getId() { + return ID; + } + + @Override + public void createControlPanel(FBReader activity, RelativeLayout root, PopupWindow.Location location) { + if (myWindow != null) { + return; + } + + myWindow = new PopupWindow(activity, root, location, false); + + addButton(ActionCode.SELECTION_COPY_TO_CLIPBOARD, true, R.drawable.selection_copy); + addButton(ActionCode.SELECTION_SHARE, true, R.drawable.selection_share); + addButton(ActionCode.SELECTION_OPEN_IN_DICTIONARY, true, R.drawable.selection_dictionary); + addButton(ActionCode.SELECTION_ADD_BOOKMARK, true, R.drawable.selection_bookmark); + addButton(ActionCode.SELECTION_CLEAR, true, R.drawable.selection_close); + } + + public void move(int selectionStartY, int selectionEndY) { + if (myWindow == null) { + return; + } + + RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( + RelativeLayout.LayoutParams.WRAP_CONTENT, + RelativeLayout.LayoutParams.WRAP_CONTENT + ); + layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL); + + final int verticalPosition; + final int screenHeight = ((View)myWindow.getParent()).getHeight(); + final int diffTop = screenHeight - selectionEndY; + final int diffBottom = selectionStartY; + if (diffTop > diffBottom) { + verticalPosition = diffTop > myWindow.getHeight() + 10 + ? RelativeLayout.ALIGN_PARENT_BOTTOM : RelativeLayout.CENTER_VERTICAL; + } else { + verticalPosition = diffBottom > myWindow.getHeight() + 10 + ? RelativeLayout.ALIGN_PARENT_TOP : RelativeLayout.CENTER_VERTICAL; + } + + layoutParams.addRule(verticalPosition); + myWindow.setLayoutParams(layoutParams); + } +} diff --git a/src/org/geometerplus/android/fbreader/TextSearchPopup.java b/src/org/geometerplus/android/fbreader/TextSearchPopup.java index 3d2d202e0..aeff13ddc 100644 --- a/src/org/geometerplus/android/fbreader/TextSearchPopup.java +++ b/src/org/geometerplus/android/fbreader/TextSearchPopup.java @@ -21,32 +21,16 @@ package org.geometerplus.android.fbreader; import java.util.ArrayList; -import android.content.Context; -import android.view.View; import android.widget.RelativeLayout; -import android.widget.ZoomButton; import org.geometerplus.zlibrary.ui.android.R; import org.geometerplus.fbreader.fbreader.ActionCode; import org.geometerplus.fbreader.fbreader.FBReaderApp; -class ActionButton extends ZoomButton { - final String ActionId; - final boolean IsCloseButton; - - ActionButton(Context context, String actionId, boolean isCloseButton) { - super(context); - ActionId = actionId; - IsCloseButton = isCloseButton; - } -} - -final class TextSearchPopup extends PopupPanel implements View.OnClickListener { +final class TextSearchPopup extends ButtonsPopupPanel { final static String ID = "TextSearchPopup"; - private final ArrayList myButtons = new ArrayList(); - TextSearchPopup(FBReaderApp fbReader) { super(fbReader); } @@ -74,29 +58,4 @@ final class TextSearchPopup extends PopupPanel implements View.OnClickListener { addButton(ActionCode.CLEAR_FIND_RESULTS, true, R.drawable.text_search_close); addButton(ActionCode.FIND_NEXT, false, R.drawable.text_search_next); } - - private void addButton(String actionId, boolean isCloseButton, int imageId) { - final ActionButton button = new ActionButton(myWindow.getContext(), actionId, isCloseButton); - button.setImageResource(imageId); - myWindow.addView(button); - button.setOnClickListener(this); - myButtons.add(button); - } - - @Override - protected void update() { - for (ActionButton button : myButtons) { - button.setEnabled(Application.isActionEnabled(button.ActionId)); - } - } - - public void onClick(View view) { - final ActionButton button = (ActionButton)view; - Application.doAction(button.ActionId); - if (button.IsCloseButton) { - storePosition(); - StartPosition = null; - Application.hideActivePopup(); - } - } }