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

Rotate Screen, Zoom In, Zoom Out items have been added to the menu

A problem with %-escaped file names inside ePubs has been fixed


git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1281 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Nikolay Pultsin 2010-04-25 09:56:06 +00:00
parent 9370fd9d57
commit df4601c51c
19 changed files with 562 additions and 406 deletions

View file

@ -10,6 +10,9 @@
<item id="preferences"/>
<item id="preferences-old"/>
<item id="bookInfo"/>
<item id="rotate"/>
<item id="increaseFont"/>
<item id="decreaseFont"/>
<submenu id="navigate">
<item id="gotoHome"/>
<item id="gotoSectionStart"/>

View file

@ -107,10 +107,10 @@
<node name="clearSelection" value="Clear"/>
</node>
<node name="search" value="Search"/>
<node name="view" value="View">
<node name="rotate" value="Rotate Screen"/>
<node name="toggleFullscreen" value="Full Screen"/>
</node>
<node name="rotate" value="Rotate screen"/>
<node name="increaseFont" value="Zoom in" />
<node name="decreaseFont" value="Zoom out" />
<node name="toggleFullscreen" value="Full Screen"/>
<node name="bookmarks" value="Bookmarks"/>
</node>
<node name="dialog">

View file

@ -108,10 +108,10 @@
<node name="clearSelection" value="Effacer"/>
</node>
<node name="search" value="Rechercher"/>
<node name="view" value="Vue">
<node name="rotate" value="Orienter l'écran"/>
<node name="toggleFullscreen" value="Plein écran"/>
</node>
<node name="rotate" value="Orienter l'écran"/>
<node name="increaseFont" toBeTranslated="true" value="Zoom in" />
<node name="decreaseFont" toBeTranslated="true" value="Zoom out" />
<node name="toggleFullscreen" value="Plein écran"/>
<node name="bookmarks" value="Marque-pages"/>
</node>
<node name="dialog">

View file

@ -107,10 +107,10 @@
<node name="clearSelection" value="Убрать пометку"/>
</node>
<node name="search" value="Поиск"/>
<node name="view" value="Изображение">
<node name="rotate" value="Повернуть"/>
<node name="toggleFullscreen" value="На весь экран"/>
</node>
<node name="rotate" value="Повернуть"/>
<node name="increaseFont" value="Увеличить шрифта" />
<node name="decreaseFont" value="Уменьшить шрифта" />
<node name="toggleFullscreen" value="На весь экран"/>
<node name="bookmarks" value="Закладки"/>
</node>
<node name="dialog">

View file

@ -108,10 +108,10 @@
<node name="clearSelection" value="清除" />
</node>
<node name="search" value="查找" />
<node name="view" value="视图">
<node name="rotate" value="翻转屏幕" />
<node name="toggleFullscreen" value="全屏" />
</node>
<node name="rotate" value="翻转屏幕" />
<node name="increaseFont" value="字体加大" />
<node name="decreaseFont" value="字体缩小" />
<node name="toggleFullscreen" value="全屏" />
<node name="bookmarks" value="书签" />
</node>
<node name="dialog">

View file

@ -25,7 +25,6 @@ import android.os.Bundle;
import android.os.PowerManager;
import android.view.View;
import android.view.WindowManager;
import android.content.pm.ActivityInfo;
import android.widget.RelativeLayout;
import org.geometerplus.zlibrary.core.application.ZLApplication;
@ -91,11 +90,6 @@ public class FBReader extends ZLAndroidActivity {
startActivity(new Intent(this, this.getClass()));
finish();
}
setRequestedOrientation(
application.AutoOrientationOption.getValue() ?
ActivityInfo.SCREEN_ORIENTATION_SENSOR :
ActivityInfo.SCREEN_ORIENTATION_NOSENSOR
);
if (myPanel.ControlPanel == null) {
myPanel.ControlPanel = new ControlPanel(this);

View file

@ -44,6 +44,7 @@ public interface ActionCode {
String SCROLL_TO_START_OF_TEXT = "gotoSectionStart";
String SCROLL_TO_END_OF_TEXT = "gotoSectionEnd";
String CANCEL = "cancel";
String ROTATE = "rotate";
String INCREASE_FONT = "increaseFont";
String DECREASE_FONT = "decreaseFont";
String TOGGLE_FULLSCREEN = "toggleFullscreen";

View file

@ -80,6 +80,7 @@ public final class FBReader extends ZLApplication {
addAction(ActionCode.INCREASE_FONT, new ChangeFontSizeAction(this, +2));
addAction(ActionCode.DECREASE_FONT, new ChangeFontSizeAction(this, -2));
addAction(ActionCode.ROTATE, new RotateAction(this));
addAction(ActionCode.SHOW_LIBRARY, new ShowLibraryAction(this));
addAction(ActionCode.SHOW_OPTIONS, new ShowOptionsDialogAction(this));

View file

@ -0,0 +1,30 @@
/*
* Copyright (C) 2007-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.fbreader.fbreader;
class RotateAction extends FBAction {
RotateAction(FBReader fbreader) {
super(fbreader);
}
public void run() {
Reader.rotateScreen();
}
}

View file

@ -190,8 +190,9 @@ class OEBBookReader extends ZLXMLReaderAdapter implements XMLNamespace {
myState = READ_TOUR;
} else if ((myState == READ_MANIFEST) && (ITEM == tag)) {
final String id = xmlattributes.getValue("id");
final String href = xmlattributes.getValue("href");
String href = xmlattributes.getValue("href");
if ((id != null) && (href != null)) {
href = MiscUtil.decodeHtmlReference(href);
myIdToHref.put(id, href);
}
} else if ((myState == READ_SPINE) && (ITEMREF == tag)) {
@ -205,8 +206,9 @@ class OEBBookReader extends ZLXMLReaderAdapter implements XMLNamespace {
} else if ((myState == READ_GUIDE) && (REFERENCE == tag)) {
final String type = xmlattributes.getValue("type");
final String title = xmlattributes.getValue("title");
final String href = xmlattributes.getValue("href");
String href = xmlattributes.getValue("href");
if (href != null) {
href = MiscUtil.decodeHtmlReference(href);
if (title != null) {
myGuideTOC.add(new Reference(title, href));
}
@ -220,8 +222,9 @@ class OEBBookReader extends ZLXMLReaderAdapter implements XMLNamespace {
}
} else if ((myState == READ_TOUR) && (SITE == tag)) {
final String title = xmlattributes.getValue("title");
final String href = xmlattributes.getValue("href");
String href = xmlattributes.getValue("href");
if ((title != null) && (href != null)) {
href = MiscUtil.decodeHtmlReference(href);
myTourTOC.add(new Reference(title, href));
}
}

View file

@ -37,4 +37,32 @@ public class MiscUtil {
final int index = fullPath.lastIndexOf(':');
return (index >= 2) ? fullPath.substring(index + 1) : fullPath;
}
private static boolean isHexDigit(char ch) {
return
(ch >= '0' && ch <= '9') ||
(ch >= 'a' && ch <= 'f') ||
(ch >= 'A' && ch <= 'F');
}
public static String decodeHtmlReference(String name) {
int index = 0;
while (true) {
index = name.indexOf('%', index);
if (index == -1 || index >= name.length() - 2) {
break;
}
if (isHexDigit(name.charAt(index + 1)) &&
isHexDigit(name.charAt(index + 2))) {
char c = 0;
try {
c = (char)Integer.decode("0x" + name.substring(index + 1, index + 3)).intValue();
} catch (NumberFormatException e) {
}
name = name.substring(0, index) + c + name.substring(index + 3);
}
index = index + 1;
}
return name;
}
}

View file

@ -134,6 +134,7 @@ public class XHTMLReader extends ZLXMLReaderAdapter {
}
public final String getFileAlias(String fileName) {
fileName = MiscUtil.decodeHtmlReference(fileName);
Integer num = myFileNumbers.get(fileName);
if (num == null) {
num = myFileNumbers.size();

View file

@ -150,6 +150,12 @@ public abstract class ZLApplication {
return false;
}
public void rotateScreen() {
if (myWindow != null) {
myWindow.rotate();
}
}
public boolean closeWindow() {
onWindowClosing();
if (myWindow != null) {

View file

@ -45,5 +45,7 @@ abstract public class ZLApplicationWindow {
abstract protected void scrollViewTo(int viewPage, int shift);
abstract protected void startViewAutoScrolling(int viewPage);
abstract protected void rotate();
abstract protected void close();
}

View file

@ -836,6 +836,10 @@ public abstract class ZLTextView extends ZLTextViewBase {
myCurrentPage.moveStartCursor(paragraphIndex, wordIndex, charIndex);
myPreviousPage.reset();
myNextPage.reset();
preparePaintInfo(myCurrentPage);
if (myCurrentPage.isEmptyPage()) {
scrollPage(true, ScrollingMode.NO_OVERLAPPING, 0);
}
}
}

View file

@ -119,6 +119,10 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
getViewWidget().startAutoScrolling(viewPage);
}
public void rotate() {
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).rotateScreen();
}
public void close() {
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).finish();
}

View file

@ -25,6 +25,8 @@ import android.net.Uri;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.view.*;
import org.geometerplus.zlibrary.core.application.ZLApplication;
@ -40,6 +42,7 @@ public abstract class ZLAndroidActivity extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(this));
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
@ -67,6 +70,21 @@ public abstract class ZLAndroidActivity extends Activity {
ZLApplication.Instance().repaintView();
}
@Override
public void onStart() {
super.onStart();
switch (ourOrientation) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
setRequestedOrientation(ourOrientation);
myChangeCounter = 0;
break;
default:
setAutoRotationMode();
break;
}
}
@Override
public void onPause() {
ZLApplication.Instance().onWindowClosing();
@ -114,4 +132,58 @@ public abstract class ZLAndroidActivity extends Activity {
View view = findViewById(R.id.main_view);
return ((view != null) && view.onKeyUp(keyCode, event)) || super.onKeyUp(keyCode, event);
}
private int myChangeCounter = 0;
private static int ourOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
private void setAutoRotationMode() {
final ZLAndroidApplication application = ZLAndroidApplication.Instance();
setRequestedOrientation(
application.AutoOrientationOption.getValue() ?
ActivityInfo.SCREEN_ORIENTATION_SENSOR :
ActivityInfo.SCREEN_ORIENTATION_NOSENSOR
);
myChangeCounter = 0;
}
@Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
switch (getRequestedOrientation()) {
default:
break;
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
if (config.orientation == Configuration.ORIENTATION_PORTRAIT && myChangeCounter++ > 0) {
setAutoRotationMode();
}
break;
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE && myChangeCounter++ > 0) {
setAutoRotationMode();
}
break;
}
}
void rotate() {
View view = findViewById(R.id.main_view);
if (view != null) {
switch (getRequestedOrientation()) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
ourOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
break;
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
ourOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
break;
default:
if (view.getWidth() > view.getHeight()) {
ourOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} else {
ourOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
}
setRequestedOrientation(ourOrientation);
myChangeCounter = 0;
}
}
}

View file

@ -25,6 +25,7 @@ import android.app.Application;
import android.content.res.Resources;
import android.content.res.AssetFileDescriptor;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import org.geometerplus.zlibrary.core.library.ZLibrary;
@ -56,6 +57,12 @@ public final class ZLAndroidLibrary extends ZLibrary {
myWidget = null;
}
public void rotateScreen() {
if (myActivity != null) {
myActivity.rotate();
}
}
public void finish() {
if ((myActivity != null) && !myActivity.isFinishing()) {
myActivity.finish();