Commit 5978fe61 authored by Drahomír Karchňák's avatar Drahomír Karchňák

#625 WIP Edited user sync dialog. Dialog now includes little qr magnifier...

#625 WIP Edited user sync dialog. Dialog now includes little qr magnifier icon, which opens QR Code scanner on devices, which support it.
parent 8d43b77f
......@@ -243,6 +243,7 @@ user_rank_10=Rozumbrada
user_rank_11=Vrchní rada
sync_request_dialog_text=Zadej číslo průkazu:
sync_request_qr_dialog_text=Zadej číslo průkazu nebo naskenuj QR kód, který nalezneš ve svém profilu.
sync_request_button=Synchronizovat uživatele
sync_request_wrong_id=Špatně zadaný kód.
sync_request_error=Synchronizace se nezdařila, zkuste to prosím později.
......
......@@ -243,6 +243,7 @@ user_rank_10=Besserwisser
user_rank_11=Oberrat
sync_request_dialog_text=Trage deine Ausweisnummer ein:
sync_request_qr_dialog_text=[DE]Zadej číslo průkazu nebo naskenuj QR kód, který nalezneš ve svém profilu.[DE]
sync_request_button=Account synchronisieren
sync_request_wrong_id=Falsch geschriebener Code.
sync_request_error=Die synchronisierung ist fehlgeschlagen, bitte versuche es später noch einmal.
......
......@@ -246,6 +246,7 @@ user_rank_10=Rozumbrada
user_rank_11=Šefmajster
sync_request_dialog_text=Zadaj číslo preukazu:
sync_request_qr_dialog_text=[DE]Zadej číslo průkazu nebo naskenuj QR kód, který nalezneš ve svém profilu.[DE]
sync_request_button=Synchronizovať užívateľa
sync_request_wrong_id=Zle zadaný kód.
sync_request_error=Synchronizácia sa nepodarila, skúste to prosím neskôr.
......
Subproject commit fc4a4521a08566e4981de7ba2c0c74466597762c
Subproject commit 2b79a59f433541a3aeef9e26b49cf307e7dbc0fd
......@@ -129,6 +129,7 @@ public class ApplicationAtlasManager extends TablexiaAtlasManager implements IAp
public static final String UI_PATH = "ui/";
public static final String BACK_BUTTON = UI_PATH + "back_button";
public static final String BACK_BUTTON_PRESSED = UI_PATH + "back_button_pressed";
public static final String QR_MAGNIFIER_ICON = UI_PATH + "qr_magnifier_icon";
public static final String DIALOG_PATH = "dialog/";
public static final String DIALOG_BUBBLE_CLASSIC = DIALOG_PATH + "bubble_classic";
......@@ -141,6 +142,7 @@ public class ApplicationAtlasManager extends TablexiaAtlasManager implements IAp
public static final String DIALOG_SQUARE = DIALOG_PATH + "dialog_square";
public static final String DIALOG_SQUARE_BORDER_LINES = DIALOG_PATH + "dialog_square_borderlines";
public static final String DIALOG_BADGE_BOARD = DIALOG_PATH + "dialog_badgeboard";
public static final String DIALOG_THIN_BORDER = DIALOG_PATH + "thin_border";
public static final String DIALOG_BUBBLE_ARROW_BOTTOM = DIALOG_PATH + "bubble_arrow_bottom";
public static final String DIALOG_BUBBLE_ARROW_TOP = DIALOG_PATH + "bubble_arrow_top";
......
......@@ -127,6 +127,7 @@ public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> impl
public static final String SOUND_MUTED_GAME_QUESTION = "sound_muted_game_question";
public static final String SYNC_REQUEST_DIALOG_TEXT = "sync_request_dialog_text";
public static final String SYNC_REQUEST_QR_DIALOG_TEXT = "sync_request_qr_dialog_text";
public static final String SYNC_REQUEST_BUTTON = "sync_request_button";
public static final String SYNC_REQUEST_WRONG_ID = "sync_request_wrong_id";
public static final String SYNC_REQUEST_ERROR = "sync_request_error";
......
......@@ -128,6 +128,10 @@ public class TextFieldWithPlaceholder extends TextField {
}
}
public void setPlaceHolderLabelStyle(TablexiaLabel.TablexiaLabelStyle style) {
if(placeholder != null) placeholder.setTablexiaLabelStyle(style);
}
public void refreshPlaceholderState() {
if (placeholder != null) {
placeholder.setVisible(getText() == null || getText().toString().isEmpty());
......
package cz.nic.tablexia.util.ui.dialog.components;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.util.ui.ClickListenerWithSound;
import cz.nic.tablexia.util.ui.ComponentScaleUtil;
import cz.nic.tablexia.util.ui.QRCodeScanner;
import cz.nic.tablexia.util.ui.TablexiaLabel;
import cz.nic.tablexia.util.ui.TextFieldWithPlaceholder;
public class UserUuidSyncDialogComponent extends TablexiaDialogComponentAdapter {
public static final String UUID_CODE_REGEX = "((?:(?:[0-9]|[a-f]){8})-(?:(?:[0-9]|[a-f]){4})-(?:(?:[0-9]|[a-f]){4})-(?:(?:[0-9]|[a-f]){4})-(?:(?:[0-9]|[a-f]){12}))";
private static final ApplicationFontManager.FontType_NEW TEXT_FIELD_FONT = ApplicationFontManager.FontType_NEW.REGULAR_18;
private static final ApplicationFontManager.FontType_NEW TEXT_FIELD_FONT_THRESHOLD = ApplicationFontManager.FontType_NEW.REGULAR_26;
private static final float COMPONENT_WIDTH = 0.9f;
private static final float COMPONENT_HEIGHT = 50f;
private static final float TEXT_FIELD_WIDTH = 0.96f;
private static final float TEXT_FIELD_WIDTH_QR = 0.85f;
private static final float TEXT_FIELD_BORDER_OFFSET = 4;
private static final float TEXT_FIELD_HEIGHT = 0.5f * COMPONENT_HEIGHT;
private static final Color TEXT_FIELD_FONT_COLOR = Color.BLACK;
private static final Color TEXT_FIELD_PLACEHOLDER_FONT_COLOR = Color.GRAY;
private static final String TEXT_FIELD_PLACEHOLDER_TEXT = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
private static final int TEXT_FIELD_MAXIMUM_LENGTH = 36;
private final ClickListenerWithSound qrCodeListenerFinal = new ClickListenerWithSound() {
@Override
public void onClick(InputEvent event, float x, float y) {
//Close if qr code scanner is active
if(!Tablexia.hasQRCodeScanner() || Tablexia.getQRCodeScanner().isCameraPreviewActive()) return;
Tablexia.getQRCodeScanner().setQRCodeListener(new QRCodeScanner.QRCodeListener() {
@Override
public void onCodeScanned(final String data) {
Tablexia.getQRCodeScanner().disableScanning();
Pattern pattern = Pattern.compile(UUID_CODE_REGEX);
Matcher matcher = pattern.matcher(data);
if(matcher.find()) {
String uuid = matcher.group(1);
textField.setText(uuid);
}
else {
if(wrongQRScannedCallback != null) wrongQRScannedCallback.run();
}
Tablexia.getQRCodeScanner().stopCameraPreview();
Tablexia.getQRCodeScanner().removeQRCodeListener();
}
});
Tablexia.getQRCodeScanner().enableScanning();
Tablexia.getQRCodeScanner().startCameraPreview();
}
};
private final boolean hasQRCodeScanner;
private final Runnable wrongQRScannedCallback;
private Group group;
private Image textFieldCursor;
private TextFieldWithPlaceholder textField;
private Image textFieldBorder;
private Image qrScannerButton;
//Add QRCodeScanner as a parameter...
public UserUuidSyncDialogComponent(boolean hasQRCodeScanner, String syncUUID, Runnable wrongQRScannedCallback) {
this.hasQRCodeScanner = hasQRCodeScanner;
this.wrongQRScannedCallback = wrongQRScannedCallback;
group = new Group();
textFieldBorder = new Image(ApplicationAtlasManager.getInstance().getPatch(ApplicationAtlasManager.DIALOG_THIN_BORDER));
textFieldCursor = new Image(ApplicationAtlasManager.getInstance().getColorTexture(TEXT_FIELD_FONT_COLOR));
qrScannerButton = new Image(ApplicationAtlasManager.getInstance().getTextureRegion(ApplicationAtlasManager.QR_MAGNIFIER_ICON));
textField = initializeTextField(syncUUID);
}
private TextFieldWithPlaceholder initializeTextField(String initialText) {
TextFieldWithPlaceholder textFieldWithPlaceholder = new TextFieldWithPlaceholder(
initialText,
new TextFieldWithPlaceholder.TablexiaTextFieldStyle(
ComponentScaleUtil.isUnderThreshold() ? TEXT_FIELD_FONT_THRESHOLD : TEXT_FIELD_FONT,
TEXT_FIELD_FONT_COLOR,
textFieldCursor.getDrawable(),
null,
null
),
TEXT_FIELD_PLACEHOLDER_TEXT
);
textFieldWithPlaceholder.setPlaceHolderLabelStyle(new TablexiaLabel.TablexiaLabelStyle(
ComponentScaleUtil.isUnderThreshold() ? TEXT_FIELD_FONT_THRESHOLD : TEXT_FIELD_FONT,
TEXT_FIELD_PLACEHOLDER_FONT_COLOR
));
textFieldWithPlaceholder.setMaxLength(TEXT_FIELD_MAXIMUM_LENGTH);
return textFieldWithPlaceholder;
}
public String getText() {
return textField.getText();
}
public boolean hasQRCodeScanner() {
return hasQRCodeScanner;
}
@Override
public void prepareContent(Cell content) {
content.setActor(group);
}
@Override
public void adaptiveSizeThresholdChanged() {
group.clear();
group.setSize(getDialog().getInnerWidth() * COMPONENT_WIDTH, COMPONENT_HEIGHT);
if(hasQRCodeScanner) {
textField.setSize(group.getWidth() * TEXT_FIELD_WIDTH_QR, TEXT_FIELD_HEIGHT);
textField.setPosition(TEXT_FIELD_BORDER_OFFSET, (group.getHeight() - textField.getHeight()) / 2f);
qrScannerButton.setSize(COMPONENT_HEIGHT, COMPONENT_HEIGHT);
qrScannerButton.setPosition(group.getWidth() - qrScannerButton.getWidth(), (group.getHeight() - qrScannerButton.getHeight()) / 2f);
qrScannerButton.addListener(qrCodeListenerFinal);
group.addActor(qrScannerButton);
} else {
textField.setSize(group.getWidth() * TEXT_FIELD_WIDTH, TEXT_FIELD_HEIGHT);
textField.setPosition((group.getWidth() - textField.getWidth()) / 2f, (group.getHeight() - textField.getHeight()) / 2f);
}
group.addActor(textField);
textFieldBorder.setSize(textField.getWidth() + TEXT_FIELD_BORDER_OFFSET * 2, textField.getHeight() + TEXT_FIELD_BORDER_OFFSET * 2);
textFieldBorder.setPosition(textField.getX() - TEXT_FIELD_BORDER_OFFSET, textField.getY() - TEXT_FIELD_BORDER_OFFSET);
textFieldBorder.setTouchable(Touchable.disabled);
group.addActor(textFieldBorder);
}
}
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