/**
   * Computes score and proceeds by either viewing the next image, or invoking ScoreActivity to view
   * results.
   *
   * @param view The button which was clicked.
   */
  public void onClick(View view) {

    person = list.get(current);
    ++current;

    if (person.getName().equalsIgnoreCase(input.getText().toString())) {
      correct++;
    }
    if (view.getId() == R.id.showScore) {
      total = current - 1;
      startScore();
    } else if (current >= total) {
      startScore();
    } else {
      score.setText(correct + "");
      imagesLeft.setText((total - current) + "");
      input.setText("");

      person = list.get(current);

      Uri uri = Uri.parse(person.getUriString());
      try {
        InputStream stream = ApplicationUtils.fetchImage(getApplicationContext(), uri);
        image.setImageBitmap(BitmapFactory.decodeStream(stream));
      } catch (Exception e) {
        throw new Error(e);
      }
    }
  }
  /**
   * Renders the view, shuffles the list of persons and shows the first person in the shuffled list.
   *
   * @param savedInstanceState Information of this activity's previously frozen state.
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_learn);

    myDB = new ApplicationDatabase(this, null, null, 1);
    list = myDB.fetchAll();

    total = list.size();
    if (total <= 0) {
      Intent resumeMain = new Intent(LearnActivity.this, MainActivity.class);
      resumeMain.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
      startActivity(resumeMain);
      return;
    } else {
      ApplicationUtils.shuffle(list);
      current = 0;

      imagesLeft = (TextView) findViewById(R.id.imagesLeft);
      imagesLeft.setText(total + "");

      score = (TextView) findViewById(R.id.learnScore);
      score.setText(correct + "");

      person = list.get(current);

      image = (ImageView) findViewById(R.id.imageView);
      Uri uri = Uri.parse(person.getUriString());
      try {
        InputStream stream = ApplicationUtils.fetchImage(getApplicationContext(), uri);
        image.setImageBitmap(BitmapFactory.decodeStream(stream));
      } catch (Exception e) {
        throw new Error(e);
      }
      input = (EditText) findViewById(R.id.learnEditText);
    }
  }