2016-08-16 19:25:28 +02:00
|
|
|
package com.rubenvandeven.emotionhero;
|
|
|
|
|
|
|
|
import android.Manifest;
|
2016-08-19 13:38:59 +02:00
|
|
|
import android.annotation.TargetApi;
|
2016-09-08 00:32:28 +02:00
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.DialogInterface;
|
2016-08-20 22:28:05 +02:00
|
|
|
import android.content.Intent;
|
2016-08-16 19:25:28 +02:00
|
|
|
import android.content.pm.PackageManager;
|
2016-09-09 14:00:41 +02:00
|
|
|
import android.graphics.Typeface;
|
2016-08-19 13:38:59 +02:00
|
|
|
import android.media.AudioAttributes;
|
|
|
|
import android.media.AudioManager;
|
|
|
|
import android.media.SoundPool;
|
|
|
|
import android.os.Build;
|
2016-08-16 19:25:28 +02:00
|
|
|
import android.support.v4.app.ActivityCompat;
|
2016-09-08 00:32:28 +02:00
|
|
|
import android.support.v4.app.DialogFragment;
|
|
|
|
import android.support.v7.app.AlertDialog;
|
2016-08-16 19:25:28 +02:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.SurfaceView;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2016-08-19 18:28:51 +02:00
|
|
|
import android.view.WindowManager;
|
2016-08-17 19:21:16 +02:00
|
|
|
import android.widget.Button;
|
2016-08-16 19:25:28 +02:00
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.affectiva.android.affdex.sdk.Frame;
|
|
|
|
import com.affectiva.android.affdex.sdk.detector.CameraDetector;
|
|
|
|
import com.affectiva.android.affdex.sdk.detector.Detector;
|
|
|
|
import com.affectiva.android.affdex.sdk.detector.Face;
|
|
|
|
|
2016-08-19 13:38:59 +02:00
|
|
|
import java.util.HashMap;
|
2016-08-16 19:25:28 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2016-09-01 15:23:30 +02:00
|
|
|
|
2016-08-16 19:25:28 +02:00
|
|
|
/**
|
|
|
|
* An example full-screen activity that shows and hides the system UI (i.e.
|
|
|
|
* status bar and navigation/system bar) with user interaction.
|
|
|
|
*/
|
|
|
|
public class GamingActivity extends AppCompatActivity implements Detector.ImageListener, CameraDetector.CameraEventListener, Detector.FaceListener {
|
|
|
|
|
2016-08-20 22:28:05 +02:00
|
|
|
public final static String INTENT_EXTRA_SCENARIO = "com.rubenvandeven.emotionhero.LEVEL";
|
|
|
|
|
2016-08-17 13:17:04 +02:00
|
|
|
final static String LOG_TAG = "EmotionHero";
|
2016-08-16 19:25:28 +02:00
|
|
|
|
|
|
|
final int PERMISSIONS_REQUEST_CAMERA = 1;
|
|
|
|
|
|
|
|
private TextView mContentView;
|
|
|
|
|
|
|
|
private CameraDetector detector;
|
|
|
|
|
|
|
|
SurfaceView cameraPreview;
|
|
|
|
|
|
|
|
int previewWidth = 0;
|
|
|
|
int previewHeight = 0;
|
|
|
|
|
|
|
|
Scenario currentScenario;
|
2016-08-17 19:21:16 +02:00
|
|
|
ScenarioView scenarioView;
|
2016-08-16 19:25:28 +02:00
|
|
|
|
|
|
|
boolean has_camera_permission = false;
|
|
|
|
|
2016-08-19 13:38:59 +02:00
|
|
|
public SoundPool sound;
|
|
|
|
public HashMap<Integer, Integer> soundIds = new HashMap<>();
|
|
|
|
|
|
|
|
final static int SOUND_SCORE = 1;
|
2016-09-15 16:23:38 +02:00
|
|
|
final static int SOUND_BONUS = 2;
|
2016-08-19 13:38:59 +02:00
|
|
|
|
2016-08-22 16:47:35 +02:00
|
|
|
protected Player player;
|
2016-08-19 13:38:59 +02:00
|
|
|
|
2016-09-08 00:32:28 +02:00
|
|
|
protected boolean isStarted = false;
|
|
|
|
|
2016-08-16 19:25:28 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2016-08-19 18:28:51 +02:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
2016-10-05 15:25:05 +02:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); // kiosk mode
|
2016-08-22 22:39:19 +02:00
|
|
|
if(getSupportActionBar() != null) {
|
|
|
|
getSupportActionBar().hide();
|
|
|
|
}
|
2016-08-16 19:25:28 +02:00
|
|
|
|
|
|
|
setContentView(R.layout.activity_gaming);
|
|
|
|
|
2016-08-22 16:47:35 +02:00
|
|
|
player = Player.getInstance(getApplicationContext());
|
|
|
|
|
2016-08-20 22:28:05 +02:00
|
|
|
Intent intent = getIntent();
|
|
|
|
// first level is the default to load, if none is given to intent
|
|
|
|
int scenarioLvlId = intent.getIntExtra(INTENT_EXTRA_SCENARIO, Scenario.SCENARIOS.get(0));
|
|
|
|
|
2016-08-16 19:25:28 +02:00
|
|
|
mContentView = (TextView) findViewById(R.id.fullscreen_content);
|
|
|
|
RelativeLayout videoLayout = (RelativeLayout) findViewById(R.id.video_layout);
|
2016-09-10 16:59:10 +02:00
|
|
|
TextView titleText = (TextView) findViewById(R.id.titleText);
|
2016-08-16 19:25:28 +02:00
|
|
|
|
|
|
|
//We create a custom SurfaceView that resizes itself to match the aspect ratio of the incoming camera frames
|
|
|
|
cameraPreview = new SurfaceView(this) {
|
|
|
|
@Override
|
|
|
|
public void onMeasure(int widthSpec, int heightSpec) {
|
|
|
|
int measureWidth = MeasureSpec.getSize(widthSpec);
|
|
|
|
int measureHeight = MeasureSpec.getSize(heightSpec);
|
2016-09-08 00:32:28 +02:00
|
|
|
int maxWidth = GamingActivity.this.getWindow().getDecorView().getWidth();
|
|
|
|
int maxHeight = GamingActivity.this.getWindow().getDecorView().getHeight();
|
2016-08-16 19:25:28 +02:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
if (previewHeight == 0 || previewWidth == 0) {
|
|
|
|
width = measureWidth;
|
|
|
|
height = measureHeight;
|
|
|
|
} else {
|
|
|
|
float viewAspectRatio = (float)measureWidth/measureHeight;
|
|
|
|
float cameraPreviewAspectRatio = (float) previewWidth/previewHeight;
|
|
|
|
|
|
|
|
if (cameraPreviewAspectRatio > viewAspectRatio) {
|
|
|
|
width = measureWidth;
|
|
|
|
height =(int) (measureWidth / cameraPreviewAspectRatio);
|
|
|
|
} else {
|
|
|
|
width = (int) (measureHeight * cameraPreviewAspectRatio);
|
|
|
|
height = measureHeight;
|
|
|
|
}
|
|
|
|
}
|
2016-09-08 00:32:28 +02:00
|
|
|
|
|
|
|
// make sure we fill the screen!
|
|
|
|
if(width < maxWidth) {
|
|
|
|
float ratio = (float)maxWidth/width;
|
|
|
|
width = maxWidth;
|
|
|
|
height = (int) (ratio * height);
|
|
|
|
}
|
|
|
|
if(height < maxHeight) {
|
|
|
|
float ratio = (float)maxHeight/height;
|
|
|
|
width = (int) (ratio * width);
|
|
|
|
height = maxHeight;
|
|
|
|
}
|
2016-08-16 19:25:28 +02:00
|
|
|
setMeasuredDimension(width,height);
|
2016-08-19 13:38:59 +02:00
|
|
|
// setMeasuredDimension(1,1); // this DOES increase performance....
|
2016-08-16 19:25:28 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2016-08-17 19:21:16 +02:00
|
|
|
// RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(1,1);
|
2016-08-16 19:25:28 +02:00
|
|
|
params.addRule(RelativeLayout.CENTER_IN_PARENT,RelativeLayout.TRUE);
|
2016-08-30 19:06:18 +02:00
|
|
|
// 10% margin:
|
2016-09-08 00:32:28 +02:00
|
|
|
// params.leftMargin = (int) 120;
|
|
|
|
// params.rightMargin = params.leftMargin;
|
2016-08-16 19:25:28 +02:00
|
|
|
cameraPreview.setLayoutParams(params);
|
|
|
|
videoLayout.addView(cameraPreview,0);
|
|
|
|
|
2016-08-17 13:17:04 +02:00
|
|
|
|
2016-08-20 22:28:05 +02:00
|
|
|
// currentScenario = new ScenarioAnger(this);
|
|
|
|
currentScenario = new Scenario(scenarioLvlId, this);
|
2016-08-22 16:47:35 +02:00
|
|
|
|
2016-09-10 16:59:10 +02:00
|
|
|
|
2016-08-20 23:58:32 +02:00
|
|
|
currentScenario.init(); // "start the clock"...
|
2016-08-16 19:25:28 +02:00
|
|
|
|
2016-08-17 13:17:04 +02:00
|
|
|
scenarioView = new ScenarioView(this, currentScenario);
|
2016-09-08 00:32:28 +02:00
|
|
|
scenarioView.drawOverlay = true;
|
2016-08-17 13:17:04 +02:00
|
|
|
RelativeLayout.LayoutParams scenarioViewParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
|
videoLayout.addView(scenarioView, 1, scenarioViewParams);
|
|
|
|
|
2016-08-19 13:38:59 +02:00
|
|
|
createSoundPool(); // instantiate SoundPool in sound
|
|
|
|
soundIds.put(SOUND_SCORE, sound.load(this, R.raw.score2, 1));
|
2016-09-15 16:23:38 +02:00
|
|
|
soundIds.put(SOUND_BONUS, sound.load(this, R.raw.scorebonus, 1));
|
2016-08-17 13:17:04 +02:00
|
|
|
|
2016-09-11 23:35:38 +02:00
|
|
|
// StoryDialogFragment storyDialog = new StoryDialogFragment();
|
|
|
|
// storyDialog.show(getSupportFragmentManager(), "StoryDialog");
|
2016-09-08 00:32:28 +02:00
|
|
|
|
2016-09-09 14:00:41 +02:00
|
|
|
Typeface font = Typeface.createFromAsset(getAssets(), "unifont-9.0.02.ttf");
|
|
|
|
mContentView.setTypeface(font);
|
|
|
|
|
2016-09-11 23:35:38 +02:00
|
|
|
titleText.setText(currentScenario.toString());
|
2016-09-10 16:59:10 +02:00
|
|
|
titleText.setTypeface(font);
|
2016-09-11 23:35:38 +02:00
|
|
|
|
|
|
|
startGame();
|
2016-09-08 00:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void startGame() {
|
|
|
|
isStarted = true;
|
|
|
|
startDetector();
|
2016-08-16 19:25:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2016-09-08 00:32:28 +02:00
|
|
|
if(isStarted)
|
|
|
|
startDetector();
|
2016-08-25 16:10:28 +02:00
|
|
|
// should resume 'on face detection started'
|
2016-08-16 19:25:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
stopDetector();
|
2016-08-25 16:10:28 +02:00
|
|
|
currentScenario.pause();
|
2016-08-16 19:25:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void startDetector() {
|
|
|
|
if (detector == null || !detector.isRunning()) {
|
|
|
|
// check permission
|
|
|
|
String permission = "android.permission.CAMERA";
|
|
|
|
int res = getApplicationContext().checkCallingOrSelfPermission(permission);
|
|
|
|
if (res == PackageManager.PERMISSION_GRANTED) {
|
2016-08-22 16:47:35 +02:00
|
|
|
Log.i(LOG_TAG, "Has camera permission");
|
2016-08-16 19:25:28 +02:00
|
|
|
has_camera_permission = true;
|
|
|
|
} else {
|
2016-08-22 16:47:35 +02:00
|
|
|
Log.i(LOG_TAG, "No camera permission");
|
2016-08-16 19:25:28 +02:00
|
|
|
ActivityCompat.requestPermissions(this,
|
|
|
|
new String[]{Manifest.permission.CAMERA},
|
|
|
|
PERMISSIONS_REQUEST_CAMERA);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(has_camera_permission)
|
|
|
|
{
|
|
|
|
if(detector == null)
|
|
|
|
{
|
|
|
|
// SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
|
2016-08-19 13:38:59 +02:00
|
|
|
|
|
|
|
detector = new CameraDetector(this, CameraDetector.CameraType.CAMERA_FRONT, cameraPreview, 1, Detector.FaceDetectorMode.LARGE_FACES);
|
|
|
|
|
2016-08-16 19:25:28 +02:00
|
|
|
detector.setDetectAllEmotions(true);
|
2016-09-08 00:32:28 +02:00
|
|
|
detector.setDetectAllAppearances(true);
|
2016-08-17 19:21:16 +02:00
|
|
|
detector.setDetectAllEmojis(false);
|
2016-09-03 19:22:18 +02:00
|
|
|
detector.setDetectAllExpressions(true);
|
2016-09-08 00:32:28 +02:00
|
|
|
detector.setMaxProcessRate(12);
|
2016-08-17 19:21:16 +02:00
|
|
|
|
2016-08-16 19:25:28 +02:00
|
|
|
detector.setImageListener(this);
|
|
|
|
detector.setOnCameraEventListener(this);
|
2016-08-17 19:21:16 +02:00
|
|
|
detector.setFaceListener(this);
|
2016-08-16 19:25:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
detector.start();
|
2016-08-19 13:38:59 +02:00
|
|
|
setText("STARTING...");
|
2016-08-16 19:25:28 +02:00
|
|
|
Log.d(LOG_TAG, Boolean.toString(detector.isRunning()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void stopDetector() {
|
|
|
|
if (detector != null && detector.isRunning()) {
|
|
|
|
detector.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
/**
|
2016-08-20 23:58:32 +02:00
|
|
|
* Detector callback gives the faces found so we can match their hits to the given scenario.
|
2016-08-16 19:25:28 +02:00
|
|
|
*/
|
|
|
|
public void onImageResults(List<Face> list, Frame frame, float timestamp) {
|
2016-08-19 13:38:59 +02:00
|
|
|
// frame.getOriginalBitmapFrame()
|
2016-08-16 19:25:28 +02:00
|
|
|
// Log.e(LOG_TAG, "RESULT! faces: " + Integer.toString(list.size()) + " t: " + Float.toString(timestamp) + "s" );
|
2016-08-19 13:38:59 +02:00
|
|
|
// if(!currentScenario.isWithinTime(timestamp))
|
|
|
|
if(currentScenario.isFinished())
|
2016-08-16 19:25:28 +02:00
|
|
|
{
|
2016-08-20 18:22:01 +02:00
|
|
|
finishLevel();
|
2016-08-16 19:25:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (list == null)
|
|
|
|
return;
|
|
|
|
if (list.size() == 0) {
|
2016-08-30 19:06:18 +02:00
|
|
|
setText("No face found...");
|
2016-08-19 13:38:59 +02:00
|
|
|
// mContentView.setText("NO FACE FOUND"); // this happens in onFaceDetectionStopped
|
2016-08-16 19:25:28 +02:00
|
|
|
} else {
|
2016-08-19 13:38:59 +02:00
|
|
|
hideText(); // hide textView as we want as few elements as possible.
|
2016-08-16 19:25:28 +02:00
|
|
|
Face face = list.get(0);
|
2016-09-20 18:23:49 +02:00
|
|
|
currentScenario.setCurrentFaceAndFrame(face, (Frame.ByteArrayFrame) frame);
|
2016-08-17 19:21:16 +02:00
|
|
|
scenarioView.setCurrentAttributeScoresForFace(face);
|
2016-08-16 19:25:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
/**
|
|
|
|
* For CameraDetector.CameraEventListener
|
|
|
|
* Used to scale video preview output
|
|
|
|
*/
|
|
|
|
public void onCameraSizeSelected(int width, int height, Frame.ROTATE rotate) {
|
|
|
|
if (rotate == Frame.ROTATE.BY_90_CCW || rotate == Frame.ROTATE.BY_90_CW) {
|
|
|
|
previewWidth = height;
|
|
|
|
previewHeight = width;
|
|
|
|
} else {
|
|
|
|
previewHeight = height;
|
|
|
|
previewWidth = width;
|
|
|
|
}
|
|
|
|
cameraPreview.requestLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode,
|
|
|
|
String permissions[], int[] grantResults) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case PERMISSIONS_REQUEST_CAMERA: {
|
|
|
|
// If request is cancelled, the result arrays are empty.
|
|
|
|
if (grantResults.length > 0
|
|
|
|
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
has_camera_permission = true;
|
|
|
|
startDetector();
|
|
|
|
} else {
|
|
|
|
has_camera_permission = false;
|
|
|
|
Toast errorMsg = Toast.makeText(this, R.string.camera_required, Toast.LENGTH_LONG);
|
|
|
|
errorMsg.show();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// other 'case' lines to check for other
|
|
|
|
// permissions this app might request
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFaceDetectionStarted()
|
|
|
|
{
|
2016-08-19 13:38:59 +02:00
|
|
|
setText("START!");
|
2016-09-16 19:04:01 +02:00
|
|
|
currentScenario.lostFace = false;
|
2016-09-08 00:32:28 +02:00
|
|
|
|
|
|
|
if(isStarted)
|
|
|
|
currentScenario.start();
|
2016-08-16 19:25:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFaceDetectionStopped()
|
|
|
|
{
|
2016-08-19 13:38:59 +02:00
|
|
|
currentScenario.pause();
|
2016-09-16 19:04:01 +02:00
|
|
|
currentScenario.lostFace = true;
|
2016-08-19 13:38:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setText(String text)
|
|
|
|
{
|
|
|
|
mContentView.setVisibility(View.VISIBLE);
|
|
|
|
mContentView.setText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hideText()
|
|
|
|
{
|
|
|
|
mContentView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// http://stackoverflow.com/a/27552576
|
|
|
|
protected void createSoundPool() {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
createNewSoundPool();
|
|
|
|
} else {
|
|
|
|
createOldSoundPool();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// http://stackoverflow.com/a/27552576
|
|
|
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
|
protected void createNewSoundPool(){
|
|
|
|
AudioAttributes attributes = new AudioAttributes.Builder()
|
|
|
|
.setUsage(AudioAttributes.USAGE_GAME)
|
|
|
|
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
|
|
|
.build();
|
|
|
|
sound = new SoundPool.Builder()
|
2016-09-15 16:23:38 +02:00
|
|
|
.setMaxStreams(6) // allow sounds to ring while another is started
|
2016-08-19 13:38:59 +02:00
|
|
|
.setAudioAttributes(attributes)
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
// http://stackoverflow.com/a/27552576
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
protected void createOldSoundPool(){
|
|
|
|
sound = new SoundPool(5, AudioManager.STREAM_MUSIC,0);
|
2016-08-16 19:25:28 +02:00
|
|
|
}
|
2016-08-20 18:22:01 +02:00
|
|
|
|
|
|
|
public void finishLevel() {
|
|
|
|
stopDetector();
|
2016-08-20 22:28:05 +02:00
|
|
|
|
2016-08-22 16:47:35 +02:00
|
|
|
PlayerInfo playerInfo = player.getPlayerInfo();
|
2016-09-06 15:35:40 +02:00
|
|
|
// ScoreList scores = playerInfo.getScoresForLevel(currentScenario.id);
|
|
|
|
// Score score = currentScenario.getScore();
|
|
|
|
//
|
|
|
|
// if(score.score == currentScenario.getMaxScore()) {
|
|
|
|
// // Maximum SCORE!!
|
|
|
|
// // You nailed it!
|
|
|
|
// } if(scores.isEmpty()) {
|
|
|
|
// // First play! Nice :-)
|
|
|
|
// }
|
|
|
|
// else if(scores.isHighest(score)) {
|
|
|
|
// // HIGHSCORE!!!!!
|
|
|
|
// } else {
|
|
|
|
// // Better luck next time
|
|
|
|
// }
|
2016-08-20 18:22:01 +02:00
|
|
|
|
2016-08-22 16:47:35 +02:00
|
|
|
// check whether this is the highest reached level by the player
|
|
|
|
// ... used by 'continue' button in main menu
|
2016-09-12 01:00:26 +02:00
|
|
|
|
2016-09-16 19:04:01 +02:00
|
|
|
currentScenario.game.checkAchievements(player);
|
|
|
|
|
|
|
|
if(currentScenario.minimumScore < currentScenario.game.score + currentScenario.game.bonus) {
|
2016-09-12 01:00:26 +02:00
|
|
|
if(currentScenario.isFinalLevel()) {
|
|
|
|
playerInfo.completedAll = true;
|
|
|
|
} else {
|
|
|
|
Scenario nextScenario = new Scenario(currentScenario.getNextLevelId(), this);
|
|
|
|
if(nextScenario.isHigherThen(playerInfo.reachedLevelId)) {
|
|
|
|
// allow player to continue to next level :-)
|
|
|
|
playerInfo.reachedLevelId = nextScenario.id;
|
|
|
|
}
|
|
|
|
}
|
2016-08-22 16:47:35 +02:00
|
|
|
}
|
|
|
|
|
2016-09-06 15:35:40 +02:00
|
|
|
// scores.add(score);
|
2016-08-22 16:47:35 +02:00
|
|
|
player.savePlayerInfo(playerInfo);
|
2016-08-20 22:28:05 +02:00
|
|
|
|
2016-08-23 01:35:33 +02:00
|
|
|
|
|
|
|
finish();
|
2016-09-03 19:22:18 +02:00
|
|
|
GameOpenHelper gameHelper = new GameOpenHelper(getApplicationContext());
|
|
|
|
gameHelper.insertGame(currentScenario.game);
|
|
|
|
|
2016-09-04 01:03:22 +02:00
|
|
|
|
|
|
|
Intent intent = new Intent(this, ReviewActivity.class);
|
|
|
|
intent.putExtra(ReviewActivity.INTENT_EXTRA_GAME_ID, currentScenario.game.id);
|
|
|
|
intent.putExtra(ReviewActivity.INTENT_EXTRA_FROM_GAME, true);
|
2016-08-23 01:35:33 +02:00
|
|
|
startActivity(intent);
|
2016-08-20 18:22:01 +02:00
|
|
|
}
|
2016-10-05 15:25:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For kioskmode
|
|
|
|
* @param hasFocus
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onWindowFocusChanged(boolean hasFocus) {
|
|
|
|
super.onWindowFocusChanged(hasFocus);
|
|
|
|
if(!hasFocus) {
|
|
|
|
// Close every kind of system dialog
|
|
|
|
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
|
|
|
sendBroadcast(closeDialog);
|
|
|
|
}
|
|
|
|
}
|
2016-08-16 19:25:28 +02:00
|
|
|
}
|