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

code simplification

This commit is contained in:
Nikolay Pultsin 2014-01-01 19:57:10 +00:00
parent 80ef9dd290
commit 73b564f436
4 changed files with 14 additions and 13 deletions

View file

@ -426,7 +426,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
this, scrollingScreen.Resource, "volumeKeys"
) {
{
setChecked(fbReader.hasActionForKey(KeyEvent.KEYCODE_VOLUME_UP, false));
setChecked(keyBindings.hasBinding(KeyEvent.KEYCODE_VOLUME_UP, false));
}
@Override
@ -463,7 +463,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
}
}
}));
volumeKeysPreferences.setEnabled(fbReader.hasActionForKey(KeyEvent.KEYCODE_VOLUME_UP, false));
volumeKeysPreferences.setEnabled(keyBindings.hasBinding(KeyEvent.KEYCODE_VOLUME_UP, false));
scrollingScreen.addOption(pageTurningOptions.Animation, "animation");
scrollingScreen.addPreference(new AnimationSpeedPreference(

View file

@ -152,11 +152,6 @@ public abstract class ZLApplication {
//may be protected
abstract public ZLKeyBindings keyBindings();
public final boolean hasActionForKey(int key, boolean longPress) {
final String actionId = keyBindings().getBinding(key, longPress);
return actionId != null && !NoAction.equals(actionId);
}
public final boolean runActionByKey(int key, boolean longPress) {
final String actionId = keyBindings().getBinding(key, longPress);
if (actionId != null) {

View file

@ -118,6 +118,10 @@ public final class ZLKeyBindings {
return getOption(key, longPress).getValue();
}
public boolean hasBinding(int key, boolean longPress) {
return !ZLApplication.NoAction.equals(getBinding(key, longPress));
}
private class Reader extends ZLXMLReaderAdapter {
private final Set<String> myKeySet;

View file

@ -25,6 +25,7 @@ import android.util.AttributeSet;
import android.view.*;
import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.zlibrary.core.application.ZLKeyBindings;
import org.geometerplus.zlibrary.core.view.ZLView;
import org.geometerplus.zlibrary.core.view.ZLViewWidget;
@ -414,9 +415,10 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
final ZLApplication application = ZLApplication.Instance();
final ZLKeyBindings bindings = application.keyBindings();
if (application.hasActionForKey(keyCode, true) ||
application.hasActionForKey(keyCode, false)) {
if (bindings.hasBinding(keyCode, true) ||
bindings.hasBinding(keyCode, false)) {
if (myKeyUnderTracking != -1) {
if (myKeyUnderTracking == keyCode) {
return true;
@ -424,7 +426,7 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
myKeyUnderTracking = -1;
}
}
if (application.hasActionForKey(keyCode, true)) {
if (bindings.hasBinding(keyCode, true)) {
myKeyUnderTracking = keyCode;
myTrackingStartTime = System.currentTimeMillis();
return true;
@ -447,10 +449,10 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
myKeyUnderTracking = -1;
return true;
} else {
final ZLApplication application = ZLApplication.Instance();
final ZLKeyBindings bindings = ZLApplication.Instance().keyBindings();
return
application.hasActionForKey(keyCode, false) ||
application.hasActionForKey(keyCode, true);
bindings.hasBinding(keyCode, false) ||
bindings.hasBinding(keyCode, true);
}
}