Skip to content
Snippets Groups Projects
Commit 18aa1798 authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko
Browse files

#318 Fixed not recognizing qr code after merge with V3.3 branch

parent b66c6ea9
Branches
Tags
No related merge requests found
...@@ -10,8 +10,6 @@ import android.view.ViewGroup; ...@@ -10,8 +10,6 @@ import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent; import android.view.ViewParent;
import com.badlogic.gdx.Gdx;
import cz.nic.tablexia.android.AndroidLauncher; import cz.nic.tablexia.android.AndroidLauncher;
import cz.nic.tablexia.util.Log; import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.camera.CameraCallback; import cz.nic.tablexia.util.camera.CameraCallback;
...@@ -32,8 +30,6 @@ public class AndroidDeviceCameraController implements DeviceCameraControl, Camer ...@@ -32,8 +30,6 @@ public class AndroidDeviceCameraController implements DeviceCameraControl, Camer
private boolean previewReady = false; private boolean previewReady = false;
int mWidth, mHeight, mLeft, mTop, mAreaWidth, mAreaHeight;
private class ScreenOrientationListener extends OrientationEventListener { private class ScreenOrientationListener extends OrientationEventListener {
public ScreenOrientationListener(Context context, int rate) { public ScreenOrientationListener(Context context, int rate) {
...@@ -80,7 +76,6 @@ public class AndroidDeviceCameraController implements DeviceCameraControl, Camer ...@@ -80,7 +76,6 @@ public class AndroidDeviceCameraController implements DeviceCameraControl, Camer
cameraSurface.getCamera().startPreview(); cameraSurface.getCamera().startPreview();
screenOrientationListener.enable(); screenOrientationListener.enable();
previewReady = true; previewReady = true;
setArea();
} else { } else {
prepareCamera(); prepareCamera();
} }
...@@ -168,17 +163,8 @@ public class AndroidDeviceCameraController implements DeviceCameraControl, Camer ...@@ -168,17 +163,8 @@ public class AndroidDeviceCameraController implements DeviceCameraControl, Camer
@Override @Override
public void onPreviewFrame(byte[] bytes, Camera camera) { public void onPreviewFrame(byte[] bytes, Camera camera) {
if (cameraCallback != null && !cameraCallback.hasDataToProceed()) { if (cameraCallback != null && !cameraCallback.hasDataToProceed()) {
cameraCallback.scanPreviewData(bytes); cameraCallback.scanPreviewData(bytes, getPreviewWidth(), getPreviewHeight());
} }
} }
public void setArea() {
// TODO: 10.3.16 set size to fit new texture
mWidth = Gdx.graphics.getWidth();
mHeight = Gdx.graphics.getHeight();
mLeft = mWidth / 4;
mTop = mHeight / 4;
mAreaHeight = mHeight / 2;
mAreaWidth = mWidth / 2;
}
} }
\ No newline at end of file
package cz.nic.tablexia.screen.camera; package cz.nic.tablexia.screen.camera;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
...@@ -24,21 +23,11 @@ import cz.nic.tablexia.bus.ApplicationBus; ...@@ -24,21 +23,11 @@ import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.loader.application.ApplicationTextManager; import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.user.UserMenu; import cz.nic.tablexia.menu.user.UserMenu;
import cz.nic.tablexia.screen.AbstractTablexiaScreen; import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.shared.model.User;
import cz.nic.tablexia.sync.RestSynchronizationService;
import cz.nic.tablexia.sync.work.DownloadUser;
import cz.nic.tablexia.sync.work.SyncWork;
import cz.nic.tablexia.util.Log; import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.camera.CameraCallback; import cz.nic.tablexia.util.camera.CameraCallback;
import cz.nic.tablexia.util.camera.DeviceCameraControl; import cz.nic.tablexia.util.camera.DeviceCameraControl;
import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialog; import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialog;
import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialogFactory; import cz.nic.tablexia.util.ui.dialog.TablexiaComponentDialogFactory;
import cz.nic.tablexia.util.ui.dialog.components.BackButtonHideComponent;
import cz.nic.tablexia.util.ui.dialog.components.CenterPositionDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.CloseButtonContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.FixedSpaceContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.ResizableSpaceContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog.components.TextContentDialogComponent;
/** /**
* Created by Vitaliy Vashchenko on 7.3.16. * Created by Vitaliy Vashchenko on 7.3.16.
...@@ -66,13 +55,13 @@ public class CameraScreen extends AbstractTablexiaScreen<Void> implements Camera ...@@ -66,13 +55,13 @@ public class CameraScreen extends AbstractTablexiaScreen<Void> implements Camera
public enum Mode { public enum Mode {
prepare, prepare,
preview, preview,
done; done
} }
@Override @Override
public void scanPreviewData(byte[] data) { public void scanPreviewData(byte[] data, int width, int height) {
hasData = true; hasData = true;
setArea(); setArea(width, height);
LuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, left, top, innerWidth, innerHeight, false); //set searching area in the middle of the screen LuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, left, top, innerWidth, innerHeight, false); //set searching area in the middle of the screen
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result; Result result;
...@@ -155,7 +144,6 @@ public class CameraScreen extends AbstractTablexiaScreen<Void> implements Camera ...@@ -155,7 +144,6 @@ public class CameraScreen extends AbstractTablexiaScreen<Void> implements Camera
if (deviceCameraControl.isPreviewReady()) { if (deviceCameraControl.isPreviewReady()) {
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
drawRectangle();
} }
break; break;
case prepare: case prepare:
...@@ -186,14 +174,6 @@ public class CameraScreen extends AbstractTablexiaScreen<Void> implements Camera ...@@ -186,14 +174,6 @@ public class CameraScreen extends AbstractTablexiaScreen<Void> implements Camera
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y); super.clicked(event, x, y);
Log.debug(getClass(), "Decoded: "+ decodedData); Log.debug(getClass(), "Decoded: "+ decodedData);
DownloadUser syncWork = new DownloadUser(decodedData);
syncWork.registerListener(new SyncWork.RestSyncListener() {
@Override
public void onSuccess(User user) {
ApplicationBus.getInstance().post(new UserMenu.RefreshUserMenu()).asynchronously();
}
});
RestSynchronizationService.doSyncWork(syncWork);
backToMenu(); backToMenu();
} }
}, },
...@@ -203,46 +183,10 @@ public class CameraScreen extends AbstractTablexiaScreen<Void> implements Camera ...@@ -203,46 +183,10 @@ public class CameraScreen extends AbstractTablexiaScreen<Void> implements Camera
super.clicked(event, x, y); super.clicked(event, x, y);
resetState(); resetState();
} }
}); });
dialog.show(DIALOG_WIDTH, DIALOG_HEIGHT); dialog.show(DIALOG_WIDTH, DIALOG_HEIGHT);
} }
private void syncUser(String userId) {
DownloadUser syncWork = new DownloadUser(userId);
syncWork.registerListener(new SyncWork.RestSyncListener() {
@Override
public void onSuccess(User user) {
ApplicationBus.getInstance().post(new UserMenu.RefreshUserMenu()).asynchronously();
ApplicationBus.getInstance().post(new Tablexia.ChangeScreenEvent(CameraScreen.class, TablexiaApplication.ScreenTransaction.FADE)).asynchronously();
}
@Override
public void onFailure(Throwable t) {
TablexiaComponentDialogFactory.getInstance().createDialog(
// TODO: 11.3.16 repeat cancel dialog
new CenterPositionDialogComponent(),
new TextContentDialogComponent(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYNC_REQUEST_ERROR_DIALOG_TEXT)),
new ResizableSpaceContentDialogComponent(),
new CloseButtonContentDialogComponent(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYSTEM_EXIT)),
new FixedSpaceContentDialogComponent(),
new BackButtonHideComponent()
).show(DIALOG_WIDTH, DIALOG_HEIGHT);
super.onFailure(t);
}
});
RestSynchronizationService.doSyncWork(syncWork);
}
private void drawRectangle() {
setArea();
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(Color.RED);
shapeRenderer.rect(left, top, innerWidth, innerHeight);
shapeRenderer.end();
}
private void resetState(){ private void resetState(){
hasData = false; hasData = false;
decodedData = null; decodedData = null;
...@@ -251,14 +195,14 @@ public class CameraScreen extends AbstractTablexiaScreen<Void> implements Camera ...@@ -251,14 +195,14 @@ public class CameraScreen extends AbstractTablexiaScreen<Void> implements Camera
mode = Mode.prepare; mode = Mode.prepare;
} }
private void setArea() { private void setArea(int width, int height) {
if (!sizeIsSet) { if (!sizeIsSet) {
width = Gdx.graphics.getWidth(); this.width = width;
height = Gdx.graphics.getHeight(); this.height = height;
innerWidth = width / 3; innerWidth = width/2;
innerHeight = height / 2; innerHeight = height/2;
left = width / 3; left = width/4;
top = height / 4; top = height/4;
sizeIsSet = true; sizeIsSet = true;
} }
} }
......
...@@ -4,7 +4,7 @@ package cz.nic.tablexia.util.camera; ...@@ -4,7 +4,7 @@ package cz.nic.tablexia.util.camera;
* Created by Vitaliy Vashchenko on 15.3.16. * Created by Vitaliy Vashchenko on 15.3.16.
*/ */
public interface CameraCallback { public interface CameraCallback {
void scanPreviewData(byte[] data); void scanPreviewData(byte[] data, int width, int height);
boolean scanFinished(); boolean scanFinished();
boolean hasDataToProceed(); boolean hasDataToProceed();
} }
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