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

new screen orientation logic

This commit is contained in:
Nikolay Pultsin 2011-12-31 07:25:58 +00:00
parent 8ea49e9f6a
commit 8085944581
14 changed files with 141 additions and 167 deletions

View file

@ -8,6 +8,7 @@
* Image in image view can be scaled using pinch (Android 2+) * Image in image view can be scaled using pinch (Android 2+)
* Full-screen cover images * Full-screen cover images
* An exception in *.mobi file reading has been fixed * An exception in *.mobi file reading has been fixed
* New screen orientation option; keeps screen orientation between starts
===== 1.2.6 (Dec 19, 2011) ===== ===== 1.2.6 (Dec 19, 2011) =====
* Android 3.*, 4.*: bottom buttons are hidden during book reading * Android 3.*, 4.*: bottom buttons are hidden during book reading

View file

@ -252,6 +252,12 @@
</node> </node>
<node name="search" value="Search"/> <node name="search" value="Search"/>
<node name="rotate" value="Rotate screen"/> <node name="rotate" value="Rotate screen"/>
<node name="screenOrientation" value="Screen orientation"/>
<node name="screenOrientationAuto" value="Auto"/>
<node name="screenOrientationPortrait" value="Portrait"/>
<node name="screenOrientationLandscape" value="Landscape"/>
<node name="screenOrientationReversePortrait" value="Reverse portrait"/>
<node name="screenOrientationReverseLandscape" value="Reverse landscape"/>
<node name="increaseFont" value="Zoom in"/> <node name="increaseFont" value="Zoom in"/>
<node name="decreaseFont" value="Zoom out"/> <node name="decreaseFont" value="Zoom out"/>
<node name="toggleFullscreen" value="Full Screen"/> <node name="toggleFullscreen" value="Full Screen"/>
@ -301,6 +307,13 @@
</node> </node>
<node name="appearance" value="Appearance"> <node name="appearance" value="Appearance">
<node name="summary" value="Rotation, status bar"/> <node name="summary" value="Rotation, status bar"/>
<node name="screenOrientation" value="Screen orientation">
<node name="auto" value="Auto"/>
<node name="portrait" value="Portrait"/>
<node name="landscape" value="Landscape"/>
<node name="reversePortrait" value="Reverse portrait"/>
<node name="reverseLandscape" value="Reverse landscape"/>
</node>
<node name="autoOrientation" value="Automatic rotation"> <node name="autoOrientation" value="Automatic rotation">
<node name="summaryOn" value="The display will rotate when user moves the device"/> <node name="summaryOn" value="The display will rotate when user moves the device"/>
<node name="summaryOff" value="The display will not rotate when user moves the device"/> <node name="summaryOff" value="The display will not rotate when user moves the device"/>

View file

@ -30,6 +30,7 @@ import android.view.WindowManager;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.library.ZLibrary;
import org.geometerplus.zlibrary.text.view.ZLTextView; import org.geometerplus.zlibrary.text.view.ZLTextView;
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator; import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
@ -102,7 +103,7 @@ public final class FBReader extends ZLAndroidActivity {
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLAndroidLibrary.Instance(); final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLibrary.Instance();
myFullScreenFlag = myFullScreenFlag =
zlibrary.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN; zlibrary.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setFlags( getWindow().setFlags(
@ -141,11 +142,19 @@ public final class FBReader extends ZLAndroidActivity {
fbReader.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, fbReader)); fbReader.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, fbReader));
fbReader.addAction(ActionCode.SHOW_CANCEL_MENU, new ShowCancelMenuAction(this, fbReader)); fbReader.addAction(ActionCode.SHOW_CANCEL_MENU, new ShowCancelMenuAction(this, fbReader));
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_AUTO, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_AUTO));
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_PORTRAIT, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_PORTRAIT));
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_LANDSCAPE, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_LANDSCAPE));
if (ZLibrary.Instance().supportsAllOrientations()) {
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_REVERSE_PORTRAIT, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_REVERSE_PORTRAIT));
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_REVERSE_LANDSCAPE, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_REVERSE_LANDSCAPE));
}
} }
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLAndroidLibrary.Instance(); final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLibrary.Instance();
if (!zlibrary.ShowStatusBarOption.getValue() && if (!zlibrary.ShowStatusBarOption.getValue() &&
zlibrary.ShowStatusBarWhenMenuIsActiveOption.getValue()) { zlibrary.ShowStatusBarWhenMenuIsActiveOption.getValue()) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
@ -156,7 +165,7 @@ public final class FBReader extends ZLAndroidActivity {
@Override @Override
public void onOptionsMenuClosed(Menu menu) { public void onOptionsMenuClosed(Menu menu) {
super.onOptionsMenuClosed(menu); super.onOptionsMenuClosed(menu);
final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLAndroidLibrary.Instance(); final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLibrary.Instance();
if (!zlibrary.ShowStatusBarOption.getValue() && if (!zlibrary.ShowStatusBarOption.getValue() &&
zlibrary.ShowStatusBarWhenMenuIsActiveOption.getValue()) { zlibrary.ShowStatusBarWhenMenuIsActiveOption.getValue()) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
@ -204,7 +213,7 @@ public final class FBReader extends ZLAndroidActivity {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLAndroidLibrary.Instance(); final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLibrary.Instance();
final int fullScreenFlag = final int fullScreenFlag =
zlibrary.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN; zlibrary.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
@ -213,6 +222,8 @@ public final class FBReader extends ZLAndroidActivity {
startActivity(new Intent(this, getClass())); startActivity(new Intent(this, getClass()));
} }
SetScreenOrientationAction.setOrientation(this, zlibrary.OrientationOption.getValue());
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance(); final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
final RelativeLayout root = (RelativeLayout)findViewById(R.id.root_view); final RelativeLayout root = (RelativeLayout)findViewById(R.id.root_view);
((PopupPanel)fbReader.getPopupById(TextSearchPopup.ID)).createControlPanel(this, root, PopupWindow.Location.Bottom); ((PopupPanel)fbReader.getPopupById(TextSearchPopup.ID)).createControlPanel(this, root, PopupWindow.Location.Bottom);
@ -368,7 +379,14 @@ public final class FBReader extends ZLAndroidActivity {
addMenuItem(menu, ActionCode.SEARCH, R.drawable.ic_menu_search); addMenuItem(menu, ActionCode.SEARCH, R.drawable.ic_menu_search);
addMenuItem(menu, ActionCode.SHOW_PREFERENCES); addMenuItem(menu, ActionCode.SHOW_PREFERENCES);
addMenuItem(menu, ActionCode.SHOW_BOOK_INFO); addMenuItem(menu, ActionCode.SHOW_BOOK_INFO);
addMenuItem(menu, ActionCode.ROTATE); final Menu subMenu = menu.addSubMenu("Screen orientation");
addMenuItem(subMenu, ActionCode.SET_SCREEN_ORIENTATION_AUTO);
addMenuItem(subMenu, ActionCode.SET_SCREEN_ORIENTATION_PORTRAIT);
addMenuItem(subMenu, ActionCode.SET_SCREEN_ORIENTATION_LANDSCAPE);
if (ZLibrary.Instance().supportsAllOrientations()) {
addMenuItem(subMenu, ActionCode.SET_SCREEN_ORIENTATION_REVERSE_PORTRAIT);
addMenuItem(subMenu, ActionCode.SET_SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}
addMenuItem(menu, ActionCode.INCREASE_FONT); addMenuItem(menu, ActionCode.INCREASE_FONT);
addMenuItem(menu, ActionCode.DECREASE_FONT); addMenuItem(menu, ActionCode.DECREASE_FONT);
addMenuItem(menu, ActionCode.SHOW_NAVIGATION); addMenuItem(menu, ActionCode.SHOW_NAVIGATION);

View file

@ -0,0 +1,55 @@
/*
* Copyright (C) 2007-2012 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.app.Activity;
import android.content.pm.ActivityInfo;
import org.geometerplus.zlibrary.core.library.ZLibrary;
import org.geometerplus.fbreader.fbreader.FBReaderApp;
class SetScreenOrientationAction extends FBAndroidAction {
static void setOrientation(Activity activity, String optionValue) {
int orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
if (ZLibrary.SCREEN_ORIENTATION_PORTRAIT.equals(optionValue)) {
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} else if (ZLibrary.SCREEN_ORIENTATION_LANDSCAPE.equals(optionValue)) {
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else if (ZLibrary.SCREEN_ORIENTATION_REVERSE_PORTRAIT.equals(optionValue)) {
orientation = 9;
} else if (ZLibrary.SCREEN_ORIENTATION_REVERSE_LANDSCAPE.equals(optionValue)) {
orientation = 8;
}
activity.setRequestedOrientation(orientation);
}
private final String myOptionValue;
SetScreenOrientationAction(FBReader baseActivity, FBReaderApp fbreader, String optionValue) {
super(baseActivity, fbreader);
myOptionValue = optionValue;
}
@Override
protected void run(Object ... params) {
setOrientation(BaseActivity, myOptionValue);
ZLibrary.Instance().OrientationOption.setValue(myOptionValue);
}
}

View file

@ -58,7 +58,10 @@ public class PreferenceActivity extends ZLPreferenceActivity {
final ZLPreferenceSet statusBarPreferences = new ZLPreferenceSet(); final ZLPreferenceSet statusBarPreferences = new ZLPreferenceSet();
final Screen appearanceScreen = createPreferenceScreen("appearance"); final Screen appearanceScreen = createPreferenceScreen("appearance");
appearanceScreen.addOption(androidLibrary.AutoOrientationOption, "autoOrientation"); appearanceScreen.addPreference(new ZLStringChoicePreference(
this, appearanceScreen.Resource, "screenOrientation",
androidLibrary.OrientationOption, androidLibrary.allOrientations()
));
appearanceScreen.addPreference( appearanceScreen.addPreference(
new ZLBooleanPreference( new ZLBooleanPreference(
this, androidLibrary.ShowStatusBarOption, appearanceScreen.Resource, "showStatusBar" this, androidLibrary.ShowStatusBarOption, appearanceScreen.Resource, "showStatusBar"

View file

@ -55,7 +55,12 @@ public interface ActionCode {
String EXIT = "exit"; String EXIT = "exit";
String SHOW_CANCEL_MENU = "cancelMenu"; String SHOW_CANCEL_MENU = "cancelMenu";
String ROTATE = "rotate"; String SET_SCREEN_ORIENTATION_AUTO = "screenOrientationAuto";
String SET_SCREEN_ORIENTATION_PORTRAIT = "screenOrientationPortrait";
String SET_SCREEN_ORIENTATION_LANDSCAPE = "screenOrientationLandscape";
String SET_SCREEN_ORIENTATION_REVERSE_PORTRAIT = "screenOrientationReversePortrait";
String SET_SCREEN_ORIENTATION_REVERSE_LANDSCAPE = "screenOrientationReverseLandscape";
String INCREASE_FONT = "increaseFont"; String INCREASE_FONT = "increaseFont";
String DECREASE_FONT = "decreaseFont"; String DECREASE_FONT = "decreaseFont";

View file

@ -109,7 +109,6 @@ public final class FBReaderApp extends ZLApplication {
addAction(ActionCode.INCREASE_FONT, new ChangeFontSizeAction(this, +2)); addAction(ActionCode.INCREASE_FONT, new ChangeFontSizeAction(this, +2));
addAction(ActionCode.DECREASE_FONT, new ChangeFontSizeAction(this, -2)); addAction(ActionCode.DECREASE_FONT, new ChangeFontSizeAction(this, -2));
addAction(ActionCode.ROTATE, new RotateAction(this));
addAction(ActionCode.FIND_NEXT, new FindNextAction(this)); addAction(ActionCode.FIND_NEXT, new FindNextAction(this));
addAction(ActionCode.FIND_PREVIOUS, new FindPreviousAction(this)); addAction(ActionCode.FIND_PREVIOUS, new FindPreviousAction(this));

View file

@ -1,36 +0,0 @@
/*
* Copyright (C) 2007-2012 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(FBReaderApp fbreader) {
super(fbreader);
}
@Override
protected void run(Object ... params) {
Reader.rotateScreen();
}
@Override
public boolean isVisible() {
return Reader.canRotateScreen();
}
}

View file

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

View file

@ -40,9 +40,6 @@ abstract public class ZLApplicationWindow {
abstract protected ZLViewWidget getViewWidget(); abstract protected ZLViewWidget getViewWidget();
abstract protected void rotate();
abstract protected boolean canRotate();
abstract protected void close(); abstract protected void close();
abstract protected int getBatteryLevel(); abstract protected int getBatteryLevel();

View file

@ -22,6 +22,7 @@ package org.geometerplus.zlibrary.core.library;
import java.util.Collection; import java.util.Collection;
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile; import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
public abstract class ZLibrary { public abstract class ZLibrary {
public static ZLibrary Instance() { public static ZLibrary Instance() {
@ -30,6 +31,14 @@ public abstract class ZLibrary {
private static ZLibrary ourImplementation; private static ZLibrary ourImplementation;
public static final String SCREEN_ORIENTATION_AUTO = "auto";
public static final String SCREEN_ORIENTATION_PORTRAIT = "portrait";
public static final String SCREEN_ORIENTATION_LANDSCAPE = "landscape";
public static final String SCREEN_ORIENTATION_REVERSE_PORTRAIT = "reversePortrait";
public static final String SCREEN_ORIENTATION_REVERSE_LANDSCAPE = "reverseLandscape";
public final ZLStringOption OrientationOption = new ZLStringOption("LookNFeel", "Orientation", "auto");
protected ZLibrary() { protected ZLibrary() {
ourImplementation = this; ourImplementation = this;
} }
@ -43,4 +52,21 @@ public abstract class ZLibrary {
abstract public int getScreenBrightness(); abstract public int getScreenBrightness();
abstract public int getDisplayDPI(); abstract public int getDisplayDPI();
abstract public Collection<String> defaultLanguageCodes(); abstract public Collection<String> defaultLanguageCodes();
abstract public boolean supportsAllOrientations();
public String[] allOrientations() {
return supportsAllOrientations()
? new String[] {
SCREEN_ORIENTATION_AUTO,
SCREEN_ORIENTATION_PORTRAIT,
SCREEN_ORIENTATION_LANDSCAPE,
SCREEN_ORIENTATION_REVERSE_PORTRAIT,
SCREEN_ORIENTATION_REVERSE_LANDSCAPE
}
: new String[] {
SCREEN_ORIENTATION_AUTO,
SCREEN_ORIENTATION_PORTRAIT,
SCREEN_ORIENTATION_LANDSCAPE
};
}
} }

View file

@ -99,16 +99,6 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
return ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget(); return ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).getWidget();
} }
@Override
public void rotate() {
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).rotateScreen();
}
public boolean canRotate() {
final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLAndroidLibrary.Instance();
return zlibrary.AutoOrientationOption.getValue();
}
public void close() { public void close() {
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).finish(); ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).finish();
} }

View file

@ -41,13 +41,6 @@ public abstract class ZLAndroidActivity extends Activity {
private static final String REQUESTED_ORIENTATION_KEY = "org.geometerplus.zlibrary.ui.android.library.androidActiviy.RequestedOrientation"; private static final String REQUESTED_ORIENTATION_KEY = "org.geometerplus.zlibrary.ui.android.library.androidActiviy.RequestedOrientation";
private static final String ORIENTATION_CHANGE_COUNTER_KEY = "org.geometerplus.zlibrary.ui.android.library.androidActiviy.ChangeCounter"; private static final String ORIENTATION_CHANGE_COUNTER_KEY = "org.geometerplus.zlibrary.ui.android.library.androidActiviy.ChangeCounter";
@Override
protected void onSaveInstanceState(Bundle state) {
super.onSaveInstanceState(state);
state.putInt(REQUESTED_ORIENTATION_KEY, myOrientation);
state.putInt(ORIENTATION_CHANGE_COUNTER_KEY, myChangeCounter);
}
private void setScreenBrightnessAuto() { private void setScreenBrightnessAuto() {
final WindowManager.LayoutParams attrs = getWindow().getAttributes(); final WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.screenBrightness = -1.0f; attrs.screenBrightness = -1.0f;
@ -89,12 +82,8 @@ public abstract class ZLAndroidActivity extends Activity {
@Override @Override
public void onCreate(Bundle state) { public void onCreate(Bundle state) {
super.onCreate(state); super.onCreate(state);
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(this));
if (state != null) { Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(this));
myOrientation = state.getInt(REQUESTED_ORIENTATION_KEY, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
myChangeCounter = state.getInt(ORIENTATION_CHANGE_COUNTER_KEY);
}
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
if (getLibrary().DisableButtonLightsOption.getValue()) { if (getLibrary().DisableButtonLightsOption.getValue()) {
@ -117,28 +106,6 @@ public abstract class ZLAndroidActivity extends Activity {
ZLApplication.Instance().getViewWidget().repaint(); ZLApplication.Instance().getViewWidget().repaint();
} }
@Override
public void onStart() {
super.onStart();
if (getLibrary().AutoOrientationOption.getValue()) {
setAutoRotationMode();
} else {
switch (myOrientation) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
if (getRequestedOrientation() != myOrientation) {
setRequestedOrientation(myOrientation);
myChangeCounter = 0;
}
break;
default:
setAutoRotationMode();
break;
}
}
}
private PowerManager.WakeLock myWakeLock; private PowerManager.WakeLock myWakeLock;
private boolean myWakeLockToCreate; private boolean myWakeLockToCreate;
private boolean myStartTimer; private boolean myStartTimer;
@ -234,61 +201,6 @@ public abstract class ZLAndroidActivity extends Activity {
return ((view != null) && view.onKeyUp(keyCode, event)) || super.onKeyUp(keyCode, event); return ((view != null) && view.onKeyUp(keyCode, event)) || super.onKeyUp(keyCode, event);
} }
private int myChangeCounter;
private int myOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
private void setAutoRotationMode() {
myOrientation = getLibrary().AutoOrientationOption.getValue() ?
ActivityInfo.SCREEN_ORIENTATION_SENSOR : ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
setRequestedOrientation(myOrientation);
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;
} else if (myChangeCounter++ > 0) {
setAutoRotationMode();
}
break;
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
if (config.orientation != Configuration.ORIENTATION_LANDSCAPE) {
myChangeCounter = 0;
} else if (myChangeCounter++ > 0) {
setAutoRotationMode();
}
break;
}
}
void rotate() {
View view = findViewById(R.id.main_view);
if (view != null) {
switch (getRequestedOrientation()) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
myOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
break;
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
myOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
break;
default:
if (view.getWidth() > view.getHeight()) {
myOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} else {
myOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
}
setRequestedOrientation(myOrientation);
myChangeCounter = 0;
}
}
BroadcastReceiver myBatteryInfoReceiver = new BroadcastReceiver() { BroadcastReceiver myBatteryInfoReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
final int level = intent.getIntExtra("level", 100); final int level = intent.getIntExtra("level", 100);

View file

@ -21,10 +21,12 @@ package org.geometerplus.zlibrary.ui.android.library;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import java.lang.reflect.Field;
import android.app.Application; import android.app.Application;
import android.content.res.AssetFileDescriptor;
import android.content.Context; import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.AssetFileDescriptor;
import android.os.Build; import android.os.Build;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.format.DateFormat; import android.text.format.DateFormat;
@ -40,7 +42,6 @@ import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.ui.android.view.ZLAndroidWidget; import org.geometerplus.zlibrary.ui.android.view.ZLAndroidWidget;
public final class ZLAndroidLibrary extends ZLibrary { public final class ZLAndroidLibrary extends ZLibrary {
public final ZLBooleanOption AutoOrientationOption = new ZLBooleanOption("LookNFeel", "AutoOrientation", false);
public final ZLBooleanOption ShowStatusBarOption = new ZLBooleanOption("LookNFeel", "ShowStatusBar", hasNoHardwareMenuButton()); public final ZLBooleanOption ShowStatusBarOption = new ZLBooleanOption("LookNFeel", "ShowStatusBar", hasNoHardwareMenuButton());
public final ZLBooleanOption ShowStatusBarWhenMenuIsActiveOption = new ZLBooleanOption("LookNFeel", "ShowStatusBarWithMenu", true); public final ZLBooleanOption ShowStatusBarWhenMenuIsActiveOption = new ZLBooleanOption("LookNFeel", "ShowStatusBarWithMenu", true);
public final ZLIntegerRangeOption BatteryLevelToTurnScreenOffOption = new ZLIntegerRangeOption("LookNFeel", "BatteryLevelToTurnScreenOff", 0, 100, 50); public final ZLIntegerRangeOption BatteryLevelToTurnScreenOffOption = new ZLIntegerRangeOption("LookNFeel", "BatteryLevelToTurnScreenOff", 0, 100, 50);
@ -69,12 +70,6 @@ public final class ZLAndroidLibrary extends ZLibrary {
myWidget = null; myWidget = null;
} }
public void rotateScreen() {
if (myActivity != null) {
myActivity.rotate();
}
}
public void finish() { public void finish() {
if ((myActivity != null) && !myActivity.isFinishing()) { if ((myActivity != null) && !myActivity.isFinishing()) {
myActivity.finish(); myActivity.finish();
@ -165,6 +160,15 @@ public final class ZLAndroidLibrary extends ZLibrary {
return set; return set;
} }
@Override
public boolean supportsAllOrientations() {
try {
return ActivityInfo.class.getField("SCREEN_ORIENTATION_REVERSE_PORTRAIT") != null;
} catch (NoSuchFieldException e) {
return false;
}
}
private final class AndroidAssetsFile extends ZLResourceFile { private final class AndroidAssetsFile extends ZLResourceFile {
private final AndroidAssetsFile myParent; private final AndroidAssetsFile myParent;