<commit_before>package br.com.ema.activities.student;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Vibrator;
import android.speech.tts.TextToSpeech;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;

import br.com.ema.R;
import br.com.ema.dialogs.EndGameDialog;
import br.com.ema.dialogs.FinishGameDialog;
import br.com.ema.dialogs.NoWordsRegisteredDialog;
import br.com.ema.entities.AppConfiguration;
import br.com.ema.entities.Challenge;
import br.com.ema.entities.PlayStats;
import br.com.ema.entities.Student;
import br.com.ema.services.Speaker;

import io.realm.Realm;

public class StudentGameActivity extends Activity implements View.OnClickListener, View.OnTouchListener {
        private static final String TAG = "StudentGameActivity";
        private Vibrator vibrator;
        private final int CHECK_CODE = 0x1;
        private String word = "";
        private List<Challenge> wordList;
        private Random generator = new Random();
        private String answerString = "";
        private EditText answerText;
        private LinearLayout scrambledLayout;
        private MediaPlayer correctSound = null;
        private MediaPlayer wrongSound = null;
        private Button nextButton;
        private ImageButton clearButton;
        private Student student;
        private int counter = 0;
        private static int points = 0;
        private PlayStats activityStats;
        private boolean help;
        private Realm realm;
        private Speaker speaker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        realm = Realm.getDefaultInstance();
        super.onCreate(savedInstanceState);
        //start speaker
        speaker = new Speaker(getApplicationContext());
        setContentView(R.layout.activity_student_game);
        vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        Intent intent = getIntent();
        String studentId = intent.getStringExtra("studentId");
        student = realm.where(Student.class).equalTo("id", studentId).findFirst();
        Log.i(TAG,"Student "+ student.getNickname()+", ID = "+studentId );
        Log.i(TAG,"With "+student.getChallenges().size()+" challenges.");
        nextButton = (Button) findViewById(R.id.nextButton);
        nextButton.setOnClickListener(this);
        clearButton = (ImageButton) findViewById(R.id.backspaceBtn);
        clearButton.setOnClickListener(this);
        answerText = (EditText) findViewById(R.id.awnser);
        AppConfiguration appConfiguration = realm.where(AppConfiguration.class).findFirst();
        if(appConfiguration.getSound()){
            correctSound = MediaPlayer.create(getApplicationContext(), R.raw.correct);
            wrongSound = MediaPlayer.create(getApplicationContext(), R.raw.wrongsound);
        }
        AppConfiguration config = realm.where(AppConfiguration.class).findFirst();
        //set space button
        Button spaceButton = (Button)findViewById(R.id.spaceBtn);
        spaceButton.setOnTouchListener(this);
        spaceButton.setOnClickListener(this);
        //---
        this.help = config.getShowWord();
        this.wordList = student.getChallenges();
        if(wordList.size() > 0){
           startWord();
           Log.d(TAG, "creating activity stats...");
           activityStats = new PlayStats();
           activityStats.setStart(new Date());
           activityStats.setTotalPoints(0);
           Log.d(TAG, "created.");
        }else{
             //alert informing that the student does not have any words registered for him.
             NoWordsRegisteredDialog wordsRegisteredDialog = new NoWordsRegisteredDialog();
             FragmentManager fm = getFragmentManager();
             wordsRegisteredDialog.show(fm,"no words");
        }
    }

    @Override
    protected void onDestroy(){
        super.onDestroy();
        if(speaker != null) {
            speaker.destroy();
        }
        realm.close();
    }

    @Override
    protected void onPause(){
        super.onPause();
        if(speaker != null){
            speaker.destroy();
        }
    }

    /**
     * Method to setup the screen to type the word
     */
    public void startWord(){
        clearButton.setEnabled(Boolean.FALSE);
        Challenge challenge = getNewWord();
        if(challenge == null){
            //End of the game.
            realm = Realm.getDefaultInstance();
            EndGameDialog endGameDialog = new EndGameDialog();
            FragmentManager fm = getFragmentManager();
            realm.executeTransaction(new Realm.Transaction() {
                @Override
                public void execute(Realm realm) {
                    activityStats.setEnd(new Date());
                    realm.insertOrUpdate(activityStats);
                }
            });
            endGameDialog.show(fm,"end");
        }else {
            word = challenge.getText();
            if(help){
                TextView helpText = (TextView) findViewById(R.id.tip);
                helpText.setText(word.toUpperCase());
            }
            String scrambledWord = scramble(word);
            scrambledLayout = (LinearLayout) findViewById(R.id.keyboardLayout);<commit_msg>Set tip text to blank when the tip configuration is set as false.<commit_after>package br.com.ema.activities.student;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Vibrator;
import android.speech.tts.TextToSpeech;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;

import br.com.ema.R;
import br.com.ema.dialogs.EndGameDialog;
import br.com.ema.dialogs.FinishGameDialog;
import br.com.ema.dialogs.NoWordsRegisteredDialog;
import br.com.ema.entities.AppConfiguration;
import br.com.ema.entities.Challenge;
import br.com.ema.entities.PlayStats;
import br.com.ema.entities.Student;
import br.com.ema.services.Speaker;

import io.realm.Realm;

public class StudentGameActivity extends Activity implements View.OnClickListener, View.OnTouchListener {
        private static final String TAG = "StudentGameActivity";
        private Vibrator vibrator;
        private final int CHECK_CODE = 0x1;
        private String word = "";
        private List<Challenge> wordList;
        private Random generator = new Random();
        private String answerString = "";
        private EditText answerText;
        private LinearLayout scrambledLayout;
        private MediaPlayer correctSound = null;
        private MediaPlayer wrongSound = null;
        private Button nextButton;
        private ImageButton clearButton;
        private Student student;
        private int counter = 0;
        private static int points = 0;
        private PlayStats activityStats;
        private boolean help;
        private Realm realm;
        private Speaker speaker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        realm = Realm.getDefaultInstance();
        super.onCreate(savedInstanceState);
        //start speaker
        speaker = new Speaker(getApplicationContext());
        setContentView(R.layout.activity_student_game);
        vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        Intent intent = getIntent();
        String studentId = intent.getStringExtra("studentId");
        student = realm.where(Student.class).equalTo("id", studentId).findFirst();
        Log.i(TAG,"Student "+ student.getNickname()+", ID = "+studentId );
        Log.i(TAG,"With "+student.getChallenges().size()+" challenges.");
        nextButton = (Button) findViewById(R.id.nextButton);
        nextButton.setOnClickListener(this);
        clearButton = (ImageButton) findViewById(R.id.backspaceBtn);
        clearButton.setOnClickListener(this);
        answerText = (EditText) findViewById(R.id.awnser);
        AppConfiguration config = realm.where(AppConfiguration.class).findFirst();
        if(config.getSound()){
            correctSound = MediaPlayer.create(getApplicationContext(), R.raw.correct);
            wrongSound = MediaPlayer.create(getApplicationContext(), R.raw.wrongsound);
        }

        //set space button
        Button spaceButton = (Button)findViewById(R.id.spaceBtn);
        spaceButton.setOnTouchListener(this);
        spaceButton.setOnClickListener(this);
        //---
        this.help = config.getShowWord();
        this.wordList = student.getChallenges();
        if(wordList.size() > 0){
           startWord();
           Log.d(TAG, "creating activity stats...");
           activityStats = new PlayStats();
           activityStats.setStart(new Date());
           activityStats.setTotalPoints(0);
           Log.d(TAG, "created.");
        }else{
             //alert informing that the student does not have any words registered for him.
             NoWordsRegisteredDialog wordsRegisteredDialog = new NoWordsRegisteredDialog();
             FragmentManager fm = getFragmentManager();
             wordsRegisteredDialog.show(fm,"no words");
        }
    }

    @Override
    protected void onDestroy(){
        super.onDestroy();
        if(speaker != null) {
            speaker.destroy();
        }
        realm.close();
    }

    @Override
    protected void onPause(){
        super.onPause();
        if(speaker != null){
            speaker.destroy();
        }
    }

    /**
     * Method to setup the screen to type the word
     */
    public void startWord(){
        clearButton.setEnabled(Boolean.FALSE);
        Challenge challenge = getNewWord();
        if(challenge == null){
            //End of the game.
            realm = Realm.getDefaultInstance();
            EndGameDialog endGameDialog = new EndGameDialog();
            FragmentManager fm = getFragmentManager();
            realm.executeTransaction(new Realm.Transaction() {
                @Override
                public void execute(Realm realm) {
                    activityStats.setEnd(new Date());
                    realm.insertOrUpdate(activityStats);
                }
            });
            endGameDialog.show(fm,"end");
        }else {
            word = challenge.getText();
            if(help){
                TextView helpText = (TextView) findViewById(R.id.tip);
                helpText.setText(word.toUpperCase());
            }else{
                TextView helpText = (TextView) findViewById(R.id.tip);
                helpText.setText("");
            }
            String scrambledWord = scramble(word);
            scrambledLayout = (LinearLayout) findViewById(R.id.keyboardLayout);
{'fraction_non_alphanumeric': 0.10246871829556983, 'fraction_numerical': 0.0010145417653026716, 'mean_word_length': 2.6919475655430714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '260114', 'n_tokens_mistral': 3121, 'n_tokens_neox': 3030, 'n_words': 692}