<commit_before>package lt.vumifps.undzenastest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;

import org.json.JSONException;
import org.json.JSONObject;

public class ExamConfigActivity extends Activity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {

    private static final int DEFAULT_NUM_QUESTIONS = 20;
    private Quiz filteredQuiz;
    private CheckBox shouldRandomizeCheckBox;
    private EditText questionsCountEditText;
    private CheckBox showAllCheckBox;
    private String oldQuestionsCountValue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.exam_config);

        Intent intent = getIntent();
        String quizJsonString= intent.getStringExtra(MainActivity.QUIZ_JSON_KEY);

        try {
            filteredQuiz = new Quiz(new JSONObject(quizJsonString), -1);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        shouldRandomizeCheckBox = (CheckBox) findViewById(R.id.randomizeCheckBox);
        showAllCheckBox = (CheckBox) findViewById(R.id.showAllCheckBox);
        showAllCheckBox.setOnCheckedChangeListener(this);
        questionsCountEditText = (EditText) findViewById(R.id.questionsCountEditText);
        questionsCountEditText.setText(String.valueOf(DEFAULT_NUM_QUESTIONS));


        Button startExamButton = (Button) findViewById(R.id.startButton);
        startExamButton.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        boolean shouldRandomize = shouldRandomizeCheckBox.isChecked();

        if (shouldRandomize) {
            filteredQuiz.shuffleQuestions();
        }

        if (!showAllCheckBox.isChecked()) {
            int questionsCount = DEFAULT_NUM_QUESTIONS;

            if (questionsCountEditText.getText() != null) {
                String questionsCountString = questionsCountEditText.getText().toString();

                try {<commit_msg>Exam preferences now remembers previous exam questions count selected<commit_after>package lt.vumifps.undzenastest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;

import org.json.JSONException;
import org.json.JSONObject;

public class ExamConfigActivity extends Activity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {

    private static final int DEFAULT_NUM_QUESTIONS = 20;
    private static final String EXAM_QUESTIONS_COUNT_KEY = "exam_questions_count";

    private SharedPreferencesHelper sharedPreferencesHelper;

    private Quiz filteredQuiz;
    private CheckBox shouldRandomizeCheckBox;
    private EditText questionsCountEditText;
    private CheckBox showAllCheckBox;
    private String oldQuestionsCountValue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.exam_config);

        sharedPreferencesHelper = new SharedPreferencesHelper(this);

        Intent intent = getIntent();
        String quizJsonString= intent.getStringExtra(MainActivity.QUIZ_JSON_KEY);

        try {
            filteredQuiz = new Quiz(new JSONObject(quizJsonString), -1);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        shouldRandomizeCheckBox = (CheckBox) findViewById(R.id.randomizeCheckBox);
        showAllCheckBox = (CheckBox) findViewById(R.id.showAllCheckBox);
        showAllCheckBox.setOnCheckedChangeListener(this);
        questionsCountEditText = (EditText) findViewById(R.id.questionsCountEditText);
        questionsCountEditText.setText(String.valueOf(DEFAULT_NUM_QUESTIONS));

        String savedQuestionsCount = sharedPreferencesHelper.loadString(EXAM_QUESTIONS_COUNT_KEY);
        if (savedQuestionsCount.length() > 0) {
            questionsCountEditText.setText(savedQuestionsCount);
        }

        Button startExamButton = (Button) findViewById(R.id.startButton);
        startExamButton.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        boolean shouldRandomize = shouldRandomizeCheckBox.isChecked();

        if (shouldRandomize) {
            filteredQuiz.shuffleQuestions();
        }

        if (!showAllCheckBox.isChecked()) {
            int questionsCount = DEFAULT_NUM_QUESTIONS;

            if (questionsCountEditText.getText() != null) {
                String questionsCountString = questionsCountEditText.getText().toString();

                sharedPreferencesHelper.saveString(EXAM_QUESTIONS_COUNT_KEY, questionsCountString);

                try {
{'fraction_non_alphanumeric': 0.0783517121300058, 'fraction_numerical': 0.0013542271232346683, 'mean_word_length': 3.674502712477396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6274294', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1307, 'n_words': 261}