Commit ac4bae2a authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko

#127 Changes in text

parent 48761453
......@@ -9,6 +9,10 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:allowBackup="true"
......
......@@ -3,23 +3,25 @@ package cz.nic.tablexia.android;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.PixelFormat;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.SurfaceView;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.flurry.android.FlurryAgent;
import java.io.File;
import java.io.FileOutputStream;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaBuildConfig;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.debug.BuildConfig;
import cz.nic.tablexia.android.camera.AndroidDeviceCameraController;
import cz.nic.tablexia.screen.loader.IConnectionManager;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.camera.CameraDemo;
import cz.nic.tablexia.util.camera.DeviceCameraControl;
public class AndroidLauncher extends AndroidApplication {
......@@ -27,22 +29,49 @@ public class AndroidLauncher extends AndroidApplication {
private Tablexia tablexia;
private int origWidth;
private int origHeight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(tablexia = new Tablexia(BuildConfig.BUILD_TYPE,
getResources().getConfiguration().locale,
SQL_CONNECTION_TYPE,
savedInstanceState == null), config);
if (TablexiaSettings.getInstance().getBuildType().isBugReport() && TablexiaBuildConfig.FLURRY_KEY != null) {
FlurryAgent.setLogEnabled(false);
FlurryAgent.setVersionName(TablexiaSettings.getInstance().getFullName());
FlurryAgent.init(this, TablexiaBuildConfig.FLURRY_KEY);
// initialize(tablexia = new Tablexia(BuildConfig.BUILD_TYPE,
// getResources().getConfiguration().locale,
// SQL_CONNECTION_TYPE,
// savedInstanceState == null), config);
//
// if (TablexiaSettings.getInstance().getBuildType().isBugReport() && TablexiaBuildConfig.FLURRY_KEY != null) {
// FlurryAgent.setLogEnabled(false);
// FlurryAgent.setVersionName(TablexiaSettings.getInstance().getFullName());
// FlurryAgent.init(this, TablexiaBuildConfig.FLURRY_KEY);
// }
// AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
// // we need to change the default pixel format - since it does not include an alpha channel
// // we need the alpha channel so the camera preview will be seen behind the GL scene
config.r = 8;
config.g = 8;
config.b = 8;
config.a = 8;
//
//
DeviceCameraControl cameraControl = new AndroidDeviceCameraController(this);
initialize(new CameraDemo(cameraControl), config);
//
Gdx.app.setLogLevel(Application.LOG_DEBUG);
if (graphics.getView() instanceof SurfaceView) {
SurfaceView glView = (SurfaceView) graphics.getView();
// glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
}
// // we don't want the screen to turn off during the long image saving process
graphics.getView().setKeepScreenOn(true);
//
origWidth = graphics.getWidth();
origHeight = graphics.getHeight();
Tablexia.connectionManager = new AndroidConnectionManager(getContext());
// Tablexia.connectionManager = new AndroidConnectionManager(getContext());
}
/**
......@@ -80,6 +109,26 @@ public class AndroidLauncher extends AndroidApplication {
});
}
public void post(Runnable r) {
handler.post(r);
}
public void setFixedSize(int width, int height) {
if (graphics.getView() instanceof SurfaceView) {
SurfaceView glView = (SurfaceView) graphics.getView();
glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
glView.getHolder().setFixedSize(width, height);
}
}
public void restoreFixedSize() {
if (graphics.getView() instanceof SurfaceView) {
SurfaceView glView = (SurfaceView) graphics.getView();
glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
glView.getHolder().setFixedSize(origWidth, origHeight);
}
}
private static class AndroidConnectionManager implements IConnectionManager {
private Context androidContext;
......
......@@ -63,6 +63,7 @@ allprojects {
guavaVersion = '18.0'
androidSupportV4Version = '22.0.0'
googlePlayServicesVersion = '8.3.+'
zxingVersion = '3.2.1'
}
repositories {
......@@ -361,6 +362,9 @@ project(":core") {
compile "net.engio:mbassador:$mbassadorVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "com.google.guava:guava:$guavaVersion"
// compile "com.google.zxing:core:$zxingVersion"
compile "com.google.zxing:javase:$zxingVersion"
testCompile "junit:junit:4.11"
......
......@@ -44,3 +44,5 @@ task writeTablexiaBuildConfig {
}
compileJava.dependsOn writeTablexiaBuildConfig
dependencies {
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.google.zxing.WriterException;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaApplication;
......@@ -18,7 +19,6 @@ import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.model.UserDAO;
import cz.nic.tablexia.shared.model.User;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.encyclopedia.EncyclopediaScreen;
import cz.nic.tablexia.screen.gamemenu.GameMenuAssets;
......@@ -27,8 +27,11 @@ import cz.nic.tablexia.screen.gamemenu.event.ShowGameMenuPageEvent;
import cz.nic.tablexia.screen.halloffame.HallOfFameScreen;
import cz.nic.tablexia.screen.profile.ProfileScreen;
import cz.nic.tablexia.screen.statistics.StatisticsScreen;
import cz.nic.tablexia.util.qrcode.QrCodeEncoder;
import cz.nic.tablexia.util.ui.ClickListenerWithSound;
import cz.nic.tablexia.util.ui.TablexiaNoBlendingImage;
import cz.nic.tablexia.util.ui.dialog.DialogFactory;
import cz.nic.tablexia.util.ui.dialog.TablexiaDialog;
/**
* Created by lhoracek on 3/4/15.
......@@ -211,6 +214,16 @@ public class OfficeMenuPage extends MenuPage {
hideAllActions();
toggleHelpOverlay();
try {
Image image = QrCodeEncoder.createQrCode("it's alive!");
TablexiaDialog dialog = DialogFactory.createFullSizeImageDialog(image);
dialog.show(getStage());
} catch (WriterException e) {
e.printStackTrace();
}
}
});
......
package cz.nic.tablexia.util.camera;
/*
* Copyright 2012 Johnny Lish (johnnyoneeyed@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import cz.nic.tablexia.util.Log;
// import com.badlogic.gdx.graphics.GL10;
public class CameraDemo implements ApplicationListener {
private PerspectiveCamera camera;
private Mode mode = Mode.normal;
private DeviceCameraControl deviceCameraControl;
public CameraDemo(DeviceCameraControl deviceCameraControl) {
this.deviceCameraControl = deviceCameraControl;
}
public enum Mode {
normal,
prepare,
preview,
takePicture,
waitForPictureReady,
done;
}
@Override
public void create() {
camera = new PerspectiveCamera(67.0f, 2.0f * Gdx.graphics.getWidth() / Gdx.graphics.getHeight(), 2.0f);
camera.far = 100.0f;
camera.near = 0.1f;
camera.position.set(2.0f, 2.0f, 2.0f);
camera.lookAt(0.0f, 0.0f, 0.0f);
if (mode == Mode.normal) {
if (deviceCameraControl != null) {
deviceCameraControl.prepareCameraAsync();
mode = Mode.prepare;
}
}
}
@Override
public void resize(int width, int height) {
camera = new PerspectiveCamera(67.0f, 2.0f * width / height, 2.0f);
camera.far = 100.0f;
camera.near = 0.1f;
camera.position.set(2.0f, 2.0f, 2.0f);
camera.lookAt(0.0f, 0.0f, 0.0f);
// TODO: 28.1.16 add restore state
}
@Override
public void render() {
if (Gdx.input.isTouched()) {
if (mode == Mode.preview) {
mode = Mode.takePicture;
}
}
if (mode == Mode.normal) {
Log.debug(getClass(), "From mode:" + mode.name());
mode = Mode.prepare;
Log.debug(getClass(), "To mode: " + mode.name());
if (deviceCameraControl != null) {
deviceCameraControl.prepareCameraAsync();
}
} else if (mode == Mode.takePicture) {
if (deviceCameraControl != null) {
deviceCameraControl.takePicture();
}
Log.debug(getClass(), "From mode:" + mode.name());
mode = Mode.waitForPictureReady;
Log.debug(getClass(), "To mode: " + mode.name());
} else if (mode == Mode.prepare) {
if (deviceCameraControl != null) {
if (deviceCameraControl.isReady()) {
deviceCameraControl.startPreviewAsync();
Log.debug(getClass(), "From mode:" + mode.name());
mode = Mode.preview;
Log.debug(getClass(), "To mode: " + mode.name());
}
}
}
// camera.update(true);
if (mode == Mode.waitForPictureReady) {
if (deviceCameraControl.getPictureData() != null) { // camera picture was actually taken
if (deviceCameraControl.isDecoded()) {
// decoded
Log.debug(getClass().getName(), "data decoded");
deviceCameraControl.stopPreviewAsync();
mode = Mode.done;
} else {
// not decoded - to initial state (+ dialog)
Log.debug(getClass(), mode.name());
mode = Mode.preview;
}
}
}
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}
\ No newline at end of file
package cz.nic.tablexia.util.camera;
/*
* Copyright 2012 Johnny Lish (johnnyoneeyed@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Pixmap;
public interface DeviceCameraControl {
// Synchronous interface
void prepareCamera();
void startPreview();
void stopPreview();
void takePicture();
byte[] getPictureData();
// Asynchronous interface - need when called from a non platform thread (GDX OpenGl thread)
void startPreviewAsync();
void stopPreviewAsync();
byte[] takePictureAsync(long timeout);
void saveAsJpeg(FileHandle jpgfile, Pixmap cameraPixmap);
boolean isReady();
boolean isDecoded();
void setDecoded(boolean state);
String getDecodedResult();
void prepareCameraAsync();
}
\ No newline at end of file
package cz.nic.tablexia.util.qrcode;
import com.badlogic.gdx.graphics.Pixmap;
import com.google.zxing.qrcode.QRCodeReader;
/**
* Created by Vitaliy Vashchenko on 26.1.16.
*/
public class QrCodeDecoder {
public static String decodeQrCode(Pixmap pixmap){
QRCodeReader reader = new QRCodeReader();
return "";
}
}
package cz.nic.tablexia.util.qrcode;
/**
* Created by Vitaliy Vashchenko on 26.1.16.
*/
public enum QrCodeDefinition {
CODE_1("24c8426b-c5fe-54fd-0e29-a1dd465d8bee");
private String code;
public String getCode() {
return code;
}
QrCodeDefinition(String code) {
this.code = code;
}
}
package cz.nic.tablexia.util.qrcode;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.util.Hashtable;
/**
* Created by Vitaliy Vashchenko on 26.1.16.
*/
public class QrCodeEncoder {
public static final int WIDTH = 250;
public static final int HEIGHT = 250;
public static Image createQrCode(String data) throws WriterException{
Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
QRCodeWriter writer = new QRCodeWriter();
BitMatrix matrix = writer.encode(data, BarcodeFormat.QR_CODE,WIDTH,HEIGHT);
Pixmap pixmap = new Pixmap(WIDTH,HEIGHT, Pixmap.Format.RGB888);
pixmap.setColor(Color.WHITE);
// pixmap.fillRectangle(0,0,matrix.getWidth(),matrix.getHeight());
pixmap.fill();
pixmap.setColor(Color.BLACK);
for(int i = 0; i < matrix.getWidth(); i++){
for (int j = 0; j< matrix.getHeight(); j++){
if(matrix.get(i,j)){
pixmap.drawPixel(i,j);
}
}
}
Image image = new Image(new Texture(pixmap));
return image;
}
}
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