
package com.uwetrottmann.shopr.eval;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import com.uwetrottmann.shopr.R;
import com.uwetrottmann.shopr.settings.AppSettings;
import com.uwetrottmann.shopr.ui.MainActivity;

import java.util.Random;

public class TestSetupActivity extends Activity {

    private static final String TAG = "Test Setup";

    private EditText mNameEditText;
    private CheckBox mDiversityCheckBox;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_setup);

        setupViews();
    }

    private void setupViews() {
        View startButton = findViewById(R.id.buttonTestSetupStart);
        startButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onStartTest();
            }
        });

        mNameEditText = (EditText) findViewById(R.id.editTextTestSetupName);
        mNameEditText.setText("thisis" + new Random().nextInt(999999));

        mDiversityCheckBox = (CheckBox) findViewById(R.id.checkBoxTestSetupDiversity);
    }

    protected void onStartTest() {
        if (TextUtils.isEmpty(mNameEditText.getText())) {
            Toast.makeText(this, "Please supply a name or pseudonym.", Toast.LENGTH_LONG).show();
            return;
        }

        // set diversity on or off
        PreferenceManager.getDefaultSharedPreferences(this).edit()
                .putBoolean(AppSettings.KEY_USING_DIVERSITY, mDiversityCheckBox.isChecked())
                .commit();
        Log.d(TAG, "Setting diversity to : " + (mDiversityCheckBox.isChecked() ? "ON" : "OFF"));

        // record name, time and type, start task
        Statistics.get().startTask(mNameEditText.getText().toString(),
                mDiversityCheckBox.isChecked());

        // start the task
        startActivity(new Intent(this, MainActivity.class));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.test_setup, menu);
        return true;
    }

}

@@ -245,16 +245,46 @@
 w.Menu;%0A
+import android.view.MenuItem;%0A
 import a
@@ -301,16 +301,16 @@
 w.View;%0A
-
 import a
@@ -568,16 +568,67 @@
 ctivity;
+%0Aimport com.uwetrottmann.shopr.ui.SettingsActivity;
 %0A%0Aimport
@@ -1551,16 +1551,101 @@
 rsity);%0A
+        mDiversityCheckBox.setChecked(AppSettings.isUsingDiversity(this));%0A        ;%0A
     %7D%0A%0A 
@@ -2657,16 +2657,16 @@
  menu);%0A
-
         
@@ -2685,10 +2685,355 @@
 %0A    %7D%0A%0A
+    @Override%0A    public boolean onOptionsItemSelected(MenuItem item) %7B%0A        switch (item.getItemId()) %7B%0A            case R.id.action_settings:%0A                startActivity(new Intent(this, SettingsActivity.class));%0A                return true;%0A            default:%0A                return super.onOptionsItemSelected(item);%0A        %7D%0A    %7D%0A%0A
 %7D%0A

Enable settings action, load current diversity setting.