
package com.uwetrottmann.shopr.eval;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.Menu;
import android.widget.TextView;

import com.uwetrottmann.shopr.R;
import com.uwetrottmann.shopr.provider.ShoprContract.Stats;

/**
 * Displays the given stats and allows to start a new task.
 */
public class ResultsActivity extends Activity {

    public interface InitBundle {
        String STATS_ID = "stats_id";
    }

    private int mStatId;

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

        // extract stat id
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            finish();
            return;
        }
        mStatId = extras.getInt(InitBundle.STATS_ID);

        setupViews();
    }

    private void setupViews() {
        TextView textViewUserName = (TextView) findViewById(R.id.textViewResultsUsername);
        TextView textViewTaskType = (TextView) findViewById(R.id.textViewResultsTaskType);
        TextView textViewDuration = (TextView) findViewById(R.id.textViewResultsDuration);
        TextView textViewCycles = (TextView) findViewById(R.id.textViewResultsCycles);

        final Cursor query = getContentResolver().query(Stats.buildStatUri(mStatId), new String[] {
                Stats._ID, Stats.USERNAME, Stats.TASK_TYPE, Stats.DURATION, Stats.CYCLE_COUNT
        }, null, null, null);
        if (query != null) {
            if (query.moveToFirst()) {
                textViewUserName.setText(query.getString(1));
                textViewTaskType.setText(query.getString(2));
                long duration = query.getLong(3) / DateUtils.SECOND_IN_MILLIS;
                textViewDuration.setText(String.format("%dh:%02dm:%02ds", duration / 3600,
                        (duration % 3600) / 60, (duration % 60)));
                textViewCycles.setText(query.getString(4));
            }
            query.close();
        }
    }

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

}

@@ -61,16 +61,47 @@
 tivity;%0A
+import android.content.Intent;%0A
 import a
@@ -214,16 +214,46 @@
 w.Menu;%0A
+import android.view.MenuItem;%0A
 import a
@@ -2398,10 +2398,466 @@
 %0A    %7D%0A%0A
+    @Override%0A    public boolean onOptionsItemSelected(MenuItem item) %7B%0A        switch (item.getItemId()) %7B%0A            case R.id.action_restart:%0A                // go back to setup activity%0A                startActivity(new Intent(this, TestSetupActivity.class)%0A                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));%0A                return true;%0A            default:%0A                return super.onOptionsItemSelected(item);%0A        %7D%0A    %7D%0A%0A
 %7D%0A

Implement start over button for task.