<commit_before>package com.artursworld.reactiontest.view.games;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.CountDownTimer;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.artursworld.reactiontest.R;
import com.artursworld.reactiontest.controller.helper.GameStatus;
import com.artursworld.reactiontest.controller.util.UtilsRG;
import com.artursworld.reactiontest.view.UserManagement;

import java.util.Random;

public class GoGameView extends AppCompatActivity {

    private Activity activity;
    private GameStatus statusOfGame;
    private TextView countDownText;
    private int countDown_sec = 4;
    private int minWaitTimeAtStartUp_sec = 2;
    private int maxWaitTimeAtStartUp_sec = 4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_go_game);
        activity = this;
        statusOfGame = GameStatus.WAITING;

        UtilsRG.info("received message="+getIntentMessage(UserManagement.EXTRA_MESSAGE));

        hideActionBar(getSupportActionBar());
        setBackGroundColor(activity, R.color.goGameBlue);
        runCountDown();
    }

    private void runCountDown() {
        countDownText = (TextView) findViewById(R.id.gogamecountdown);
        new CountDownTimer(countDown_sec * 1000, 1000) {

            public void onTick(long millisUntilFinished) {
                if(countDownText != null)
                    countDownText.setText("" + millisUntilFinished / 1000);
            }

            public void onFinish() {
                onCountDownFinish();
            }
        }.start();
    }

    private void onCountDownFinish() {
        waitAndChangeStatusToClick(minWaitTimeAtStartUp_sec * 1000, maxWaitTimeAtStartUp_sec * 1000);
        if(countDownText != null)
            countDownText.setText(R.string.attention);
    }

    private String getIntentMessage(String messageKey){
        Intent intent = getIntent();
        String message = intent.getStringExtra(messageKey);
        return message;
    }

    private void hideActionBar(ActionBar actionBar){
        actionBar.hide();
    }

    private void setBackGroundColor(Activity activity, int colorId){
        try {
            int color = ContextCompat.getColor(activity.getApplicationContext(), colorId);
            activity.getWindow().getDecorView().setBackgroundColor(color);
            UtilsRG.info("background color set to: " +color);
        }
        catch (Exception e){
            String message = "Could not set background color.";
            UtilsRG.error(message + "\n" + e.getLocalizedMessage());
        }
    }

    private int getRandomNumberInRange(int min, int max){
        Random r = new Random();
        int random =  r.nextInt(max - min + 1) + min;
        UtilsRG.info("Waiting random number=" +random);
        return random;
    }

    private void waitAndChangeStatusToClick(int minWaitTimeInMilliSeconds, int maxWaitTimeInMilliSeconds){
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                onChangeStatusToClick();
            }
        }, getRandomNumberInRange(minWaitTimeInMilliSeconds,maxWaitTimeInMilliSeconds));
    }

    private void onChangeStatusToClick() {
        UtilsRG.info("set different color");
        if(countDownText != null)
            countDownText.setText(R.string.click);
        setBackGroundColor(activity, R.color.goGameGreen);
        statusOfGame = GameStatus.CLICK;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event){
        if(event.getAction() == MotionEvent.ACTION_DOWN){
            //String text = "x = " + event.getX() + ", y = " + event.getY();
            //Toast.makeText(this, text, Toast.LENGTH_LONG).show();
            if(statusOfGame == GameStatus.CLICK){
                onCorrectTouch();
            }
            else{
                UtilsRG.info("to early");
            }
        }
        return super.onTouchEvent(event);
    }

    private void onCorrectTouch() {
        UtilsRG.info("User touched at correct moment");
        setBackGroundColor(this, R.color.goGameBlue);
        statusOfGame = GameStatus.WAITING;
        runCountDown();
    }
}
<commit_msg>add max reaction time for user in go game<commit_after>package com.artursworld.reactiontest.view.games;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.CountDownTimer;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.artursworld.reactiontest.R;
import com.artursworld.reactiontest.controller.helper.GameStatus;
import com.artursworld.reactiontest.controller.util.UtilsRG;
import com.artursworld.reactiontest.view.UserManagement;

import java.util.Random;

public class GoGameView extends AppCompatActivity {

    private Activity activity;
    private GameStatus statusOfGame;
    private TextView countDownText;

    private int countDown_sec = 4;
    private int minWaitTimeAtStartUp_sec = 2;
    private int maxWaitTimeAtStartUp_sec = 4;
    private int usersMaxAcceptedClickTime = 5;

    private long startTimeOfGame;
    private long stopTimeOfGame;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_go_game);
        activity = this;
        statusOfGame = GameStatus.WAITING;

        UtilsRG.info("received message="+getIntentMessage(UserManagement.EXTRA_MESSAGE));

        hideActionBar(getSupportActionBar());
        setBackGroundColor(activity, R.color.goGameBlue);
        runCountDown();
    }

    private void runCountDown() {
        countDownText = (TextView) findViewById(R.id.gogamecountdown);
        new CountDownTimer(countDown_sec * 1000, 1000) {

            public void onTick(long millisUntilFinished) {
                if(countDownText != null)
                    countDownText.setText("" + millisUntilFinished / 1000);
            }

            public void onFinish() {
                onCountDownFinish();
            }
        }.start();
    }

    private void onCountDownFinish() {
        waitAndChangeStatusToClick(minWaitTimeAtStartUp_sec * 1000, maxWaitTimeAtStartUp_sec * 1000);
        if(countDownText != null)
            countDownText.setText(R.string.attention);
    }

    private String getIntentMessage(String messageKey){
        Intent intent = getIntent();
        String message = intent.getStringExtra(messageKey);
        return message;
    }

    private void hideActionBar(ActionBar actionBar){
        actionBar.hide();
    }

    private void setBackGroundColor(Activity activity, int colorId){
        try {
            int color = ContextCompat.getColor(activity.getApplicationContext(), colorId);
            activity.getWindow().getDecorView().setBackgroundColor(color);
            UtilsRG.info("background color set to: " +color);
        }
        catch (Exception e){
            String message = "Could not set background color.";
            UtilsRG.error(message + "\n" + e.getLocalizedMessage());
        }
    }

    private int getRandomNumberInRange(int min, int max){
        Random r = new Random();
        int random =  r.nextInt(max - min + 1) + min;
        UtilsRG.info("Waiting random number=" +random);
        return random;
    }

    private void waitAndChangeStatusToClick(int minWaitTimeInMilliSeconds, int maxWaitTimeInMilliSeconds){
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                onChangeStatusToClick();
            }
        }, getRandomNumberInRange(minWaitTimeInMilliSeconds,maxWaitTimeInMilliSeconds));
    }

    private void onChangeStatusToClick() {
        UtilsRG.info("Now user should tap on phone. It's time!");
        if(countDownText != null)
            countDownText.setText(R.string.click);
        setBackGroundColor(activity, R.color.goGameGreen);
        this.startTimeOfGame = System.currentTimeMillis();
        statusOfGame = GameStatus.CLICK;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event){
        if(event.getAction() == MotionEvent.ACTION_DOWN){
            //String text = "x = " + event.getX() + ", y = " + event.getY();
            //Toast.makeText(this, text, Toast.LENGTH_LONG).show();
            if(statusOfGame == GameStatus.CLICK){
                onCorrectTouch();
            }
            else{
                UtilsRG.info("to early");
            }
        }
        return super.onTouchEvent(event);
    }

    private void onCorrectTouch() {
        this.stopTimeOfGame = System.currentTimeMillis();
        double usersClickTime = (this.stopTimeOfGame - this.startTimeOfGame) /  1000.0;

        setBackGroundColor(this, R.color.goGameBlue);
        statusOfGame = GameStatus.WAITING;
        boolean userHasDoneThreeTrials = false;

        if(usersMaxAcceptedClickTime < usersClickTime){
            UtilsRG.info("User was to slow touching on the screen.");
            runCountDown();
        }
        else if(!userHasDoneThreeTrials){
            UtilsRG.info("User touched at correct moment.");
            //TODO: add trial to trialList
            runCountDown();
        }
        else{
            UtilsRG.info("User finished the GO-Game seuccessfully.");
            //TODO: add trial to trialList
            // TODO: go to next view
        }

        Toast.makeText(this, usersClickTime + " s", Toast.LENGTH_LONG).show();
    }
}

{'fraction_non_alphanumeric': 0.09660548648115255, 'fraction_numerical': 0.005920663114268798, 'mean_word_length': 2.708379070618368, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '380417', 'n_tokens_mistral': 2903, 'n_tokens_neox': 2743, 'n_words': 575}