Skip to content
Snippets Groups Projects
Commit fec2273a authored by Drahomír Karchňák's avatar Drahomír Karchňák
Browse files

#361 Dialog for user synchronization shouldn't be getting covered by virtual keyboard anymore...

parent 2deb5070
Branches
Tags
No related merge requests found
package cz.nic.tablexia;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.Color;
......@@ -537,4 +538,11 @@ public class TablexiaSettings {
public static float getActorSceneVerticalCenter(Stage stage, Actor actor) {
return getViewportHeight(stage) / 2f - actor.getHeight() / 2f + getViewportBottomY(stage);
}
//////////////////////////// DEVICE INFO
public boolean isRunningOnMobileDevice() {
return Gdx.app.getType() == Application.ApplicationType.Android ||
Gdx.app.getType() == Application.ApplicationType.iOS;
}
}
\ No newline at end of file
......@@ -4,11 +4,13 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.FocusListener;
import net.engio.mbassy.listener.Handler;
......@@ -17,6 +19,7 @@ import java.util.List;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.event.DeleteUserSynchronizationEvent;
import cz.nic.tablexia.bus.event.MenuControlEvent;
......@@ -31,6 +34,7 @@ import cz.nic.tablexia.sync.work.DownloadUser;
import cz.nic.tablexia.sync.work.PushDataToServer;
import cz.nic.tablexia.sync.work.SyncWork;
import cz.nic.tablexia.util.ui.ClickListenerWithSound;
import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialog;
import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialogFactory;
import cz.nic.tablexia.util.ui.dialog.components.AdaptiveSizeDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.BackButtonHideComponent;
......@@ -148,12 +152,12 @@ public class UserMenu extends AbstractMenu {
public void performAction() {
final TextFiledDialogComponent textFiledDialogComponent = new TextFiledDialogComponent(SYNC_REQUEST_DIALOG_MAXIMUM_LENGTH, SYNC_REQUEST_DIALOG_PLACEHOLDER_TEXT);
textFiledDialogComponent.setTextFieldWidthPercent(DOWNLOAD_DIALOG_INPUT_WIDTH_PERCENT);
TablexiaComponentDialogFactory.getInstance().createDialog(
final TablexiaComponentDialog dialog = TablexiaComponentDialogFactory.getInstance().createDialog(
new CenterPositionDialogComponent(),
new DimmerDialogComponent(),
new ViewportMaximumSizeComponent(),
new AdaptiveSizeDialogComponent(),
new ResizableSpaceContentDialogComponent(),
new TextContentDialogComponent(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYNC_REQUEST_DIALOG_TEXT)),
new ResizableSpaceContentDialogComponent(),
......@@ -171,12 +175,33 @@ public class UserMenu extends AbstractMenu {
}
});
RestSynchronizationService.doSyncWork(syncWork);
//Prevents keyboard getting stuck
Gdx.input.setOnscreenKeyboardVisible(false);
}
},
new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
//Prevents keyboard getting stuck
Gdx.input.setOnscreenKeyboardVisible(false);
}
},
PositiveNegativeButtonContentDialogComponent.PositiveNegativeButtonType.CONFIRM_DECLINE),
new FixedSpaceContentDialogComponent(),
new BackButtonHideComponent()
).show(SYNC_REQUEST_DIALOG_WIDTH, SYNC_REQUEST_DIALOG_HEIGHT);
);
dialog.show(SYNC_REQUEST_DIALOG_WIDTH, SYNC_REQUEST_DIALOG_HEIGHT);
if(TablexiaSettings.getInstance().isRunningOnMobileDevice()) {
textFiledDialogComponent.getTextField().addListener(new FocusListener() {
@Override
public void keyboardFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
if(focused) repositionDialog(dialog);
}
});
}
}
@Override
......@@ -198,6 +223,16 @@ public class UserMenu extends AbstractMenu {
layoutContainer.setActor(container);
}
private void repositionDialog(TablexiaComponentDialog dialog) {
Stage stage;
if(dialog == null || (stage = dialog.getStage()) == null) return;
dialog.setPosition(
TablexiaSettings.getViewportLeftX(stage) + TablexiaSettings.getViewportWidth(stage) / 2f - dialog.getInnerWidth()/2f,
TablexiaSettings.getViewportBottomY(stage) + TablexiaSettings.getViewportHeight(stage) - dialog.getOutterHeight()
);
}
@Override
public void dispose() {
ApplicationBus.getInstance().unsubscribe(this);
......
......@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.Align;
......@@ -32,7 +33,7 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
private ApplicationFontManager.FontType_NEW actualFontType;
private float textFieldWidthPercent = DEFAULT_TEXT_FIELD_WIDTH_PERCENT;
private TextFieldWithPlaceholder uuidTextField;
private TextFieldWithPlaceholder textField;
private Cell content;
public TextFiledDialogComponent() {
......@@ -53,10 +54,12 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
this.actualFontType = fontType;
this.fontColor = fontColor;
this.maximumLength = maximumLength;
textField = prepareTextField(placeholderText);
}
public String getText() {
return uuidTextField.getText();
return textField.getText();
}
public float getTextFieldWidthPercent() {
......@@ -70,9 +73,8 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
@Override
public void prepareContent(Cell content) {
this.content = content;
uuidTextField = prepareTextField(placeholderText);
content.width(getDialog().getWidth() * getTextFieldWidthPercent());
content.setActor(uuidTextField);
content.setActor(textField);
}
@Override
......@@ -88,7 +90,7 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
isScaled = false;
}
}
uuidTextField.setTablexiaTextFieldStyle(prepareTextFieldStyle());
textField.setTablexiaTextFieldStyle(prepareTextFieldStyle());
content.width(getDialog().getWidth() * getTextFieldWidthPercent());
}
......@@ -105,6 +107,10 @@ public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
return new TextFieldWithPlaceholder.TablexiaTextFieldStyle(actualFontType, fontColor, createCursorForTextField(), null, null);
}
public TextField getTextField() {
return textField;
}
private Drawable createCursorForTextField() {
Texture texture = ApplicationAtlasManager.getInstance().getColorTexture(Color.BLACK);
return new Image(texture).getDrawable();
......
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