mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
synchronization with 'selection' branch
This commit is contained in:
parent
4f7ddb3ae1
commit
6b81ed09e2
3 changed files with 156 additions and 42 deletions
73
src/org/geometerplus/android/fbreader/ButtonsPopupPanel.java
Normal file
73
src/org/geometerplus/android/fbreader/ButtonsPopupPanel.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (C) 2007-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 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<ActionButton> myButtons = new ArrayList<ActionButton>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
82
src/org/geometerplus/android/fbreader/SelectionPopup.java
Normal file
82
src/org/geometerplus/android/fbreader/SelectionPopup.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (C) 2007-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.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);
|
||||
}
|
||||
}
|
|
@ -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<ActionButton> myButtons = new ArrayList<ActionButton>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue