Commit 641ad96c authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko

#712 Added input listener for additional controls on desktop.

parent 286c6b0d
......@@ -50,6 +50,7 @@ public class AndroidLauncher extends AndroidApplication {
private static final int MULTI_SAMPLING_2X = 2;
private static final boolean HAS_SOFT_BACK_BUTTON = false;
private static final boolean HAS_ALTERNATIVE_CONTROLS = false;
protected Tablexia tablexia;
private AndroidCameraOpener cameraOpener;
......@@ -83,6 +84,7 @@ public class AndroidLauncher extends AndroidApplication {
qrCodeScanner,
getResources().getString(R.string.sentry_dsn),
HAS_SOFT_BACK_BUTTON,
HAS_ALTERNATIVE_CONTROLS,
savedInstanceState == null,
Build.SERIAL), config);
}
......
......@@ -131,14 +131,15 @@ public class Tablexia extends TablexiaApplication {
}
}
public Tablexia(String buildType, Locale systemLocale, SQLConnectionType sqlConnectionType, IConnectionManager connManager, CameraOpener cameraOpener, IFileSystemManager fileSystemManager, QRCodeScanner qrCodeScanner, String sentryDSN, boolean hasSoftBackButton, boolean reset, String hwSerial) {
public Tablexia(String buildType, Locale systemLocale, SQLConnectionType sqlConnectionType, IConnectionManager connManager, CameraOpener cameraOpener, IFileSystemManager fileSystemManager,
QRCodeScanner qrCodeScanner, String sentryDSN, boolean hasSoftBackButton, boolean supportAlternativeControls, boolean reset, String hwSerial) {
this.reset = reset;
this.connectionManager = validateConnectionManager(connManager);
this.fileSystemManager = validateFileSystemManager(fileSystemManager);
this.qrCodeScanner = qrCodeScanner;
this.sqlConnectionType = sqlConnectionType;
this.cameraOpener = cameraOpener;
TablexiaSettings.init(buildType, systemLocale, hasSoftBackButton, hwSerial);
TablexiaSettings.init(buildType, systemLocale, hasSoftBackButton, supportAlternativeControls, hwSerial);
if(TablexiaSettings.getInstance().getBuildType().isBugReport()) {
@SuppressWarnings("ConstantConditions")
......
......@@ -60,19 +60,15 @@ import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.AbstractMenu;
import cz.nic.tablexia.menu.MenuController;
import cz.nic.tablexia.menu.main.MainMenu;
import cz.nic.tablexia.menu.user.UserAvatarDefinition;
import cz.nic.tablexia.model.CustomAvatarDAO;
import cz.nic.tablexia.model.UserDAO;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.AbstractTablexiaScreen.ScreenLoadingListener;
import cz.nic.tablexia.shared.model.User;
import cz.nic.tablexia.sync.RestSynchronizationService;
import cz.nic.tablexia.sync.work.DeleteUser;
import cz.nic.tablexia.sync.work.DownloadAvatar;
import cz.nic.tablexia.sync.work.DownloadUser;
import cz.nic.tablexia.sync.work.PushDataToServer;
import cz.nic.tablexia.sync.work.UpdateAvatar;
import cz.nic.tablexia.sync.work.UploadAvatar;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ui.AnimatedImage;
import cz.nic.tablexia.util.ui.ComponentScaleUtil;
......@@ -166,6 +162,7 @@ public abstract class TablexiaApplication implements ApplicationListener {
public void dispose() {
disposePreloader();
ApplicationBus.getInstance().unsubscribe(screenDimmer);
inputMultiplexer.removeProcessor(alternativeControlsInputProcessor);
inputMultiplexer.removeProcessor(backButtonInputProcessor);
inputMultiplexer.removeProcessor(stage);
if (debugInfo != null) {
......@@ -200,6 +197,7 @@ public abstract class TablexiaApplication implements ApplicationListener {
stage = new Stage(new XFillViewport());
inputMultiplexer = new InputMultiplexer(stage);
inputMultiplexer.addProcessor(backButtonInputProcessor);
inputMultiplexer.addProcessor(alternativeControlsInputProcessor);
Gdx.input.setCatchBackKey(true);
Gdx.input.setInputProcessor(inputMultiplexer);
prepareBackButtonLayer();
......@@ -267,7 +265,18 @@ public abstract class TablexiaApplication implements ApplicationListener {
return false;
}
};
//////////////////////////// ALTERNATIVE CONTROLS HANDLER
InputAdapter alternativeControlsInputProcessor = new InputAdapter() {
@Override
public boolean keyDown(int keycode) {
if (keycode == Input.Keys.ESCAPE) {
ApplicationBus.getInstance().publishAsync(new EscButtonPressed());
}
return false;
}
};
//////////////////////////// SCREEN DIMMER
......@@ -1034,7 +1043,7 @@ public abstract class TablexiaApplication implements ApplicationListener {
private int processWithPriority = 0;
protected BackButtonPressed() {
public BackButtonPressed() {
}
......@@ -1046,4 +1055,12 @@ public abstract class TablexiaApplication implements ApplicationListener {
this.processWithPriority = processWithPriority;
}
}
public static class EscButtonPressed implements ApplicationBus.ApplicationEvent {
public EscButtonPressed(){
}
}
}
......@@ -75,6 +75,7 @@ public class TablexiaSettings {
private Platform PLATFORM;
private final BuildType BUILD_TYPE;
private final boolean HAS_SOFT_BACK_BUTTON;
private final boolean SUPPORT_ALTERNATIVE_CONTROLS;
private static String HW_SERIAL_NUMBER;
private Preferences preferences;
......@@ -212,10 +213,11 @@ public class TablexiaSettings {
//////////////////////////// SETTINGS SINGLETON
private static TablexiaSettings instance;
private TablexiaSettings(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton) {
private TablexiaSettings(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton, boolean supportAlternativeControls) {
BUILD_TYPE = buildType;
HAS_SOFT_BACK_BUTTON = hasSoftBackButton;
SUPPORT_ALTERNATIVE_CONTROLS = supportAlternativeControls;
this.systemLocale = LocaleDefinition.getLocaleDefinitionForLocale(systemLocale);
languageChosen = selectedLocale == LocaleDefinition.FALLBACK_VARIANT || languageChosen;
}
......@@ -228,18 +230,19 @@ public class TablexiaSettings {
return instance;
}
static void init(String buildTypeKey, Locale systemLocale, boolean hasSoftBackButton, String hwSerial) {
TablexiaSettings.init(BuildType.getBuildTypeForKey(buildTypeKey), systemLocale, hasSoftBackButton, hwSerial);
static void init(String buildTypeKey, Locale systemLocale, boolean hasSoftBackButton, boolean supportAlternativeControls, String hwSerial) {
TablexiaSettings.init(BuildType.getBuildTypeForKey(buildTypeKey), systemLocale, hasSoftBackButton, supportAlternativeControls, hwSerial);
}
static void init(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton, String hwSerialNumber) {
static void init(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton, boolean supportAlternativeControls, String hwSerialNumber) {
if (instance != null) {
String exceptionMessage = "Tablexia settings already initialized!";
Log.err(TablexiaSettings.class, exceptionMessage);
return;
}
instance = new TablexiaSettings(buildType, systemLocale, hasSoftBackButton);
instance = new TablexiaSettings(buildType, systemLocale, hasSoftBackButton, supportAlternativeControls);
TablexiaSettings.HW_SERIAL_NUMBER = hwSerialNumber;
}
......@@ -304,6 +307,10 @@ public class TablexiaSettings {
public boolean hasSoftBackButton() {
return HAS_SOFT_BACK_BUTTON;
}
public boolean hasAlternativeControls() {
return SUPPORT_ALTERNATIVE_CONTROLS;
}
public String getHwSerialNumber() {
return HW_SERIAL_NUMBER;
......
......@@ -827,6 +827,16 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
return TablexiaSettings.getInstance().hasSoftBackButton();
}
public boolean hasAlternativeControls() {
return TablexiaSettings.getInstance().hasAlternativeControls();
}
@Handler
public void escButtonPressed(TablexiaApplication.EscButtonPressed event){
if (hasAlternativeControls())
ApplicationBus.getInstance().publishAsync(new TablexiaApplication.BackButtonPressed());
}
//////////////////////////// ASSETS ACCESS
public Animation getAnimationForAtlas(String atlasName, String regionName, int framesCount, float frameDuration) {
......
......@@ -50,6 +50,7 @@ public class DesktopLauncher extends Application {
private static final String BUILD_VARIANT_MANIFEST_ATTRIBUTE = "Build-Type";
private static final String SENTRY_DSN_KEY_MANIFEST_ATTRIBUTE = "Sentry-DSN";
private static final boolean HAS_SOFT_BACK_BUTTON = true;
private static final boolean HAS_ALTERNATIVE_CONTROLS = true;
private static final String DESKTOP_ICON_PATH = "icon/";
......@@ -121,6 +122,7 @@ public class DesktopLauncher extends Application {
null,
sentryDSN,
HAS_SOFT_BACK_BUTTON,
HAS_ALTERNATIVE_CONTROLS,
true,
null);
......
......@@ -50,6 +50,7 @@ public class IOSLauncher extends IOSApplication.Delegate {
public static final Tablexia.SQLConnectionType SQL_CONNECTION_TYPE = new Tablexia.SQLConnectionType("SQLite.JDBCDriver", "jdbc:sqlite:");
private static final boolean HAS_SOFT_BACK_BUTTON = true;
private static final boolean HAS_ALTERNATIVE_CONTROLS = false;
private static final String FALLBACK_CONNECTION_CHECK_HOST = "nic.cz";
private static final Integer FALLBACK_CONNECTION_CHECK_PORT = 80;
......@@ -83,6 +84,7 @@ public class IOSLauncher extends IOSApplication.Delegate {
new IOSQRCodeScanner(),
sentryDSN,
HAS_SOFT_BACK_BUTTON,
HAS_ALTERNATIVE_CONTROLS,
false,
null), config) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment