mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
new style key options (VolumeKeyOption and InvertVolumeKeysOption have gone)
This commit is contained in:
parent
06db42f28c
commit
d8afa77319
7 changed files with 113 additions and 47 deletions
|
@ -346,24 +346,55 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
//final Screen tapZonesScreen = createPreferenceScreen("tapZones");
|
//final Screen tapZonesScreen = createPreferenceScreen("tapZones");
|
||||||
//tapZonesScreen.addOption(scrollingPreferences.TapZonesSchemeOption, "tapZonesScheme");
|
//tapZonesScreen.addOption(scrollingPreferences.TapZonesSchemeOption, "tapZonesScheme");
|
||||||
|
|
||||||
|
final ZLKeyBindings keyBindings = fbReader.keyBindings();
|
||||||
|
|
||||||
final Screen scrollingScreen = createPreferenceScreen("scrolling");
|
final Screen scrollingScreen = createPreferenceScreen("scrolling");
|
||||||
scrollingScreen.addOption(scrollingPreferences.FingerScrollingOption, "fingerScrolling");
|
scrollingScreen.addOption(scrollingPreferences.FingerScrollingOption, "fingerScrolling");
|
||||||
scrollingScreen.addOption(fbReader.EnableDoubleTapOption, "enableDoubleTapDetection");
|
scrollingScreen.addOption(fbReader.EnableDoubleTapOption, "enableDoubleTapDetection");
|
||||||
|
|
||||||
final ZLPreferenceSet volumeKeysPreferences = new ZLPreferenceSet();
|
final ZLPreferenceSet volumeKeysPreferences = new ZLPreferenceSet();
|
||||||
scrollingScreen.addPreference(new ZLBooleanPreference(
|
scrollingScreen.addPreference(new ZLCheckBoxPreference(
|
||||||
this, scrollingPreferences.VolumeKeysOption, scrollingScreen.Resource, "volumeKeys"
|
this, scrollingScreen.Resource, "volumeKeys"
|
||||||
) {
|
) {
|
||||||
|
{
|
||||||
|
setChecked(fbReader.hasActionForKey(KeyEvent.KEYCODE_VOLUME_UP, false));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
protected void onClick() {
|
||||||
super.onClick();
|
super.onClick();
|
||||||
|
if (isChecked()) {
|
||||||
|
keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_DOWN, false, ActionCode.VOLUME_KEY_SCROLL_FORWARD);
|
||||||
|
keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_UP, false, ActionCode.VOLUME_KEY_SCROLL_BACK);
|
||||||
|
} else {
|
||||||
|
keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_DOWN, false, FBReaderApp.NoAction);
|
||||||
|
keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_UP, false, FBReaderApp.NoAction);
|
||||||
|
}
|
||||||
volumeKeysPreferences.setEnabled(isChecked());
|
volumeKeysPreferences.setEnabled(isChecked());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
volumeKeysPreferences.add(scrollingScreen.addOption(
|
volumeKeysPreferences.add(scrollingScreen.addPreference(new ZLCheckBoxPreference(
|
||||||
scrollingPreferences.InvertVolumeKeysOption, "invertVolumeKeys"
|
this, scrollingScreen.Resource, "invertVolumeKeys"
|
||||||
));
|
) {
|
||||||
volumeKeysPreferences.setEnabled(scrollingPreferences.VolumeKeysOption.getValue());
|
{
|
||||||
|
setChecked(ActionCode.VOLUME_KEY_SCROLL_FORWARD.equals(
|
||||||
|
keyBindings.getBinding(KeyEvent.KEYCODE_VOLUME_UP, false)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onClick() {
|
||||||
|
super.onClick();
|
||||||
|
if (isChecked()) {
|
||||||
|
keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_DOWN, false, ActionCode.VOLUME_KEY_SCROLL_BACK);
|
||||||
|
keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_UP, false, ActionCode.VOLUME_KEY_SCROLL_FORWARD);
|
||||||
|
} else {
|
||||||
|
keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_DOWN, false, ActionCode.VOLUME_KEY_SCROLL_FORWARD);
|
||||||
|
keyBindings.bindKey(KeyEvent.KEYCODE_VOLUME_UP, false, ActionCode.VOLUME_KEY_SCROLL_BACK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
volumeKeysPreferences.setEnabled(fbReader.hasActionForKey(KeyEvent.KEYCODE_VOLUME_UP, false));
|
||||||
|
|
||||||
scrollingScreen.addOption(scrollingPreferences.AnimationOption, "animation");
|
scrollingScreen.addOption(scrollingPreferences.AnimationOption, "animation");
|
||||||
scrollingScreen.addPreference(new AnimationSpeedPreference(
|
scrollingScreen.addPreference(new AnimationSpeedPreference(
|
||||||
|
@ -402,20 +433,17 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
final Screen cancelMenuScreen = createPreferenceScreen("cancelMenu");
|
final Screen cancelMenuScreen = createPreferenceScreen("cancelMenu");
|
||||||
cancelMenuScreen.addOption(fbReader.ShowPreviousBookInCancelMenuOption, "previousBook");
|
cancelMenuScreen.addOption(fbReader.ShowPreviousBookInCancelMenuOption, "previousBook");
|
||||||
cancelMenuScreen.addOption(fbReader.ShowPositionsInCancelMenuOption, "positions");
|
cancelMenuScreen.addOption(fbReader.ShowPositionsInCancelMenuOption, "positions");
|
||||||
final ZLKeyBindings bindings = fbReader.keyBindings();
|
|
||||||
final String[] backKeyActions =
|
final String[] backKeyActions =
|
||||||
//{ ActionCode.EXIT, ActionCode.GO_BACK, ActionCode.SHOW_CANCEL_MENU };
|
|
||||||
{ ActionCode.EXIT, ActionCode.SHOW_CANCEL_MENU };
|
{ ActionCode.EXIT, ActionCode.SHOW_CANCEL_MENU };
|
||||||
cancelMenuScreen.addPreference(new ZLStringChoicePreference(
|
cancelMenuScreen.addPreference(new ZLStringChoicePreference(
|
||||||
this, cancelMenuScreen.Resource, "backKeyAction",
|
this, cancelMenuScreen.Resource, "backKeyAction",
|
||||||
bindings.getOption(KeyEvent.KEYCODE_BACK, false), backKeyActions
|
keyBindings.getOption(KeyEvent.KEYCODE_BACK, false), backKeyActions
|
||||||
));
|
));
|
||||||
final String[] backKeyLongPressActions =
|
final String[] backKeyLongPressActions =
|
||||||
//{ ActionCode.EXIT, ActionCode.GO_BACK, ActionCode.SHOW_CANCEL_MENU, FBReaderApp.NoAction };
|
|
||||||
{ ActionCode.EXIT, ActionCode.SHOW_CANCEL_MENU, FBReaderApp.NoAction };
|
{ ActionCode.EXIT, ActionCode.SHOW_CANCEL_MENU, FBReaderApp.NoAction };
|
||||||
cancelMenuScreen.addPreference(new ZLStringChoicePreference(
|
cancelMenuScreen.addPreference(new ZLStringChoicePreference(
|
||||||
this, cancelMenuScreen.Resource, "backKeyLongPressAction",
|
this, cancelMenuScreen.Resource, "backKeyLongPressAction",
|
||||||
bindings.getOption(KeyEvent.KEYCODE_BACK, true), backKeyLongPressActions
|
keyBindings.getOption(KeyEvent.KEYCODE_BACK, true), backKeyLongPressActions
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,22 +20,16 @@
|
||||||
package org.geometerplus.android.fbreader.preferences;
|
package org.geometerplus.android.fbreader.preferences;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.preference.CheckBoxPreference;
|
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.options.ZLBooleanOption;
|
import org.geometerplus.zlibrary.core.options.ZLBooleanOption;
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
class ZLBooleanPreference extends CheckBoxPreference implements ZLPreference {
|
class ZLBooleanPreference extends ZLCheckBoxPreference {
|
||||||
private final ZLBooleanOption myOption;
|
private final ZLBooleanOption myOption;
|
||||||
|
|
||||||
ZLBooleanPreference(Context context, ZLBooleanOption option, ZLResource rootResource, String resourceKey) {
|
ZLBooleanPreference(Context context, ZLBooleanOption option, ZLResource rootResource, String resourceKey) {
|
||||||
super(context);
|
super(context, rootResource, resourceKey);
|
||||||
myOption = option;
|
myOption = option;
|
||||||
|
|
||||||
ZLResource resource = rootResource.getResource(resourceKey);
|
|
||||||
setTitle(resource.getValue());
|
|
||||||
setSummaryOn(resource.getResource("summaryOn").getValue());
|
|
||||||
setSummaryOff(resource.getResource("summaryOff").getValue());
|
|
||||||
setChecked(option.getValue());
|
setChecked(option.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +38,4 @@ class ZLBooleanPreference extends CheckBoxPreference implements ZLPreference {
|
||||||
super.onClick();
|
super.onClick();
|
||||||
myOption.setValue(isChecked());
|
myOption.setValue(isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAccept() {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2009-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.preferences;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
|
abstract class ZLCheckBoxPreference extends CheckBoxPreference implements ZLPreference {
|
||||||
|
ZLCheckBoxPreference(Context context, ZLResource rootResource, String resourceKey) {
|
||||||
|
super(context);
|
||||||
|
|
||||||
|
ZLResource resource = rootResource.getResource(resourceKey);
|
||||||
|
setTitle(resource.getValue());
|
||||||
|
setSummaryOn(resource.getResource("summaryOn").getValue());
|
||||||
|
setSummaryOff(resource.getResource("summaryOff").getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onAccept() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,11 +37,6 @@ public class ScrollingPreferences {
|
||||||
public final ZLEnumOption<FingerScrolling> FingerScrollingOption =
|
public final ZLEnumOption<FingerScrolling> FingerScrollingOption =
|
||||||
new ZLEnumOption<FingerScrolling>("Scrolling", "Finger", FingerScrolling.byTapAndFlick);
|
new ZLEnumOption<FingerScrolling>("Scrolling", "Finger", FingerScrolling.byTapAndFlick);
|
||||||
|
|
||||||
public final ZLBooleanOption VolumeKeysOption =
|
|
||||||
new ZLBooleanOption("Scrolling", "VolumeKeys", true);
|
|
||||||
public final ZLBooleanOption InvertVolumeKeysOption =
|
|
||||||
new ZLBooleanOption("Scrolling", "InvertVolumeKeys", false);
|
|
||||||
|
|
||||||
public final ZLEnumOption<ZLView.Animation> AnimationOption =
|
public final ZLEnumOption<ZLView.Animation> AnimationOption =
|
||||||
new ZLEnumOption<ZLView.Animation>("Scrolling", "Animation", ZLView.Animation.slide);
|
new ZLEnumOption<ZLView.Animation>("Scrolling", "Animation", ZLView.Animation.slide);
|
||||||
public final ZLIntegerRangeOption AnimationSpeedOption =
|
public final ZLIntegerRangeOption AnimationSpeedOption =
|
||||||
|
|
|
@ -27,20 +27,10 @@ class VolumeKeyTurnPageAction extends FBAction {
|
||||||
myForward = forward;
|
myForward = forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return ScrollingPreferences.Instance().VolumeKeysOption.getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
final ScrollingPreferences preferences = ScrollingPreferences.Instance();
|
final ScrollingPreferences preferences = ScrollingPreferences.Instance();
|
||||||
|
|
||||||
boolean forward = myForward;
|
|
||||||
if (preferences.InvertVolumeKeysOption.getValue()) {
|
|
||||||
forward = !forward;
|
|
||||||
}
|
|
||||||
|
|
||||||
Reader.getViewWidget().startAnimatedScrolling(
|
Reader.getViewWidget().startAnimatedScrolling(
|
||||||
forward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
myForward ? FBView.PageIndex.next : FBView.PageIndex.previous,
|
||||||
preferences.HorizontalOption.getValue()
|
preferences.HorizontalOption.getValue()
|
||||||
? FBView.Direction.rightToLeft : FBView.Direction.up,
|
? FBView.Direction.rightToLeft : FBView.Direction.up,
|
||||||
preferences.AnimationSpeedOption.getValue()
|
preferences.AnimationSpeedOption.getValue()
|
||||||
|
|
|
@ -21,6 +21,10 @@ package org.geometerplus.zlibrary.core.application;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import org.geometerplus.fbreader.fbreader.ActionCode;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.options.ZLBooleanOption;
|
||||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||||
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
|
||||||
|
@ -42,16 +46,32 @@ public final class ZLKeyBindings {
|
||||||
new Reader(keys).readBindings();
|
new Reader(keys).readBindings();
|
||||||
Collections.sort(keys);
|
Collections.sort(keys);
|
||||||
myKeysOption = new ZLStringListOption(name, "KeyList", keys);
|
myKeysOption = new ZLStringListOption(name, "KeyList", keys);
|
||||||
// this code is here for migration from old versions;
|
|
||||||
// should be removed in FBReader 2.0
|
// this code is for migration from FBReader versions <= 1.1.2
|
||||||
ZLStringOption oldBackKeyOption = new ZLStringOption(name + ":" + ACTION, "<Back>", "");
|
ZLStringOption oldBackKeyOption = new ZLStringOption(myName + ":" + ACTION, "<Back>", "");
|
||||||
if (oldBackKeyOption.getValue() != null) {
|
if (!"".equals(oldBackKeyOption.getValue())) {
|
||||||
new ZLStringOption(name + ":" + ACTION, "4", oldBackKeyOption.getValue());
|
bindKey(KeyEvent.KEYCODE_BACK, false, oldBackKeyOption.getValue());
|
||||||
|
oldBackKeyOption.setValue("");
|
||||||
}
|
}
|
||||||
oldBackKeyOption = new ZLStringOption(name + ":" + LONG_PRESS_ACTION, "<Back>", "");
|
oldBackKeyOption = new ZLStringOption(myName + ":" + LONG_PRESS_ACTION, "<Back>", "");
|
||||||
if (oldBackKeyOption.getValue() != null) {
|
if (!"".equals(oldBackKeyOption.getValue())) {
|
||||||
new ZLStringOption(name + ":" + LONG_PRESS_ACTION, "4", oldBackKeyOption.getValue());
|
bindKey(KeyEvent.KEYCODE_BACK, true, oldBackKeyOption.getValue());
|
||||||
|
oldBackKeyOption.setValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ZLBooleanOption volumeKeysOption =
|
||||||
|
new ZLBooleanOption("Scrolling", "VolumeKeys", true);
|
||||||
|
final ZLBooleanOption invertVolumeKeysOption =
|
||||||
|
new ZLBooleanOption("Scrolling", "InvertVolumeKeys", false);
|
||||||
|
if (!volumeKeysOption.getValue()) {
|
||||||
|
bindKey(KeyEvent.KEYCODE_VOLUME_UP, false, ZLApplication.NoAction);
|
||||||
|
bindKey(KeyEvent.KEYCODE_VOLUME_DOWN, false, ZLApplication.NoAction);
|
||||||
|
} else if (invertVolumeKeysOption.getValue()) {
|
||||||
|
bindKey(KeyEvent.KEYCODE_VOLUME_UP, false, ActionCode.VOLUME_KEY_SCROLL_FORWARD);
|
||||||
|
bindKey(KeyEvent.KEYCODE_VOLUME_DOWN, false, ActionCode.VOLUME_KEY_SCROLL_BACK);
|
||||||
|
}
|
||||||
|
volumeKeysOption.setValue(true);
|
||||||
|
invertVolumeKeysOption.setValue(false);
|
||||||
// end of migration code
|
// end of migration code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -438,7 +438,10 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
|
||||||
myKeyUnderTracking = -1;
|
myKeyUnderTracking = -1;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
final ZLApplication application = ZLApplication.Instance();
|
||||||
|
return
|
||||||
|
application.hasActionForKey(keyCode, false) ||
|
||||||
|
application.hasActionForKey(keyCode, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue