コード例 #1
0
  private String getIngredientList(String[][] array) {
    String ingredientList = "";

    String measurement = "";

    for (int i = 0; i < array.length; i++) {

      measurement = array[i][MEASUREMENT];
      // adds the plural's' to the end of measurement
      if (nutrition.amountToFloat(array[i][AMOUNT]) > 1) measurement += "s";

      // screens the possibility that no unit is needed
      if (measurement.equalsIgnoreCase("no unit") || measurement.equalsIgnoreCase("no units"))
        measurement = "";
      else measurement += " of";

      ingredientList +=
          "> "
              + array[i][AMOUNT]
              + " "
              + measurement
              + " "
              + array[i][DESCRIPTION]
              + " "
              + array[i][INGREDIENTNAME]
              + "\n";
    }

    return ingredientList;
  }
コード例 #2
0
  @Override
  public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    tempArray = stringCopy(ingredientArray, ingredientNum);

    // inc progress b/c we dont want it to be 0
    progress++;

    if (progress > 0) {

      txtServings.setText(Integer.toString(progress));
      for (int i = 0; i < tempArray.length; i++) {
        float am = nutrition.amountToFloat(tempArray[i][AMOUNT]);
        float serv = progress / Float.valueOf(servings);
        // Log.d("seekbar in for", "am= "+am+", serv="+serv);
        tempArray[i][AMOUNT] = nutrition.amountToString(am * serv);
      }

      txtIngredientList.setText(getIngredientList(tempArray));
    }
  }
コード例 #3
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case R.id.menuHome:
        Intent i = new Intent(getApplicationContext(), MainScreenActivity.class);
        // Closing all previous activities
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);
        return true;

      case R.id.share: // 					market://details?id=com.example.android.jetboy
        String message =
            firstName
                + " "
                + getString(R.string.likes)
                + " '"
                + recipeName
                + "' "
                + getString(R.string.from)
                + " "
                + getString(R.string.app_name)
                + " @ http://bit.ly/Y6SR2b";
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("text/plain");
        share.putExtra(Intent.EXTRA_TEXT, message);
        // share.putExtra(Intent.EXTRA_SUBJECT, message);

        startActivity(Intent.createChooser(share, getString(R.string.howShare)));
        return true;

      case R.id.nutritionInfo:
        Map<String, Float> info = new HashMap<String, Float>();

        float sumProtein = 0.0f;
        float sumFat = 0.0f;
        float sumCalorie = 0.0f;
        float sumCarbs = 0.0f;
        for (int n = 0; n < tempArray.length; n++) {
          info =
              nutrition.getIngredientFacts(
                  tempArray[n][MEASUREMENT],
                  tempArray[n][TYPE],
                  tempArray[n][AMOUNT],
                  tempArray[n][CALORIES],
                  tempArray[n][FAT],
                  tempArray[n][CARBS],
                  tempArray[n][PROTEIN]);

          sumCalorie += info.get(TAG_CALORIES);
          sumFat += info.get(TAG_FAT);
          sumProtein += info.get(TAG_PROTEIN);
          sumCarbs += info.get(TAG_CARBS);
          Log.d(
              "recipeView, getNut",
              "sumCalorie:"
                  + sumCalorie
                  + ", sumFat:"
                  + sumFat
                  + ", sumProtein:"
                  + sumProtein
                  + ", sumCarbs:"
                  + sumCarbs);
        }

        String serv = txtServings.getText().toString();

        Intent intent = new Intent(getApplicationContext(), NutritionInfoActivity.class);
        intent.putExtra("calories", sumCalorie);
        intent.putExtra("fat", sumFat);
        intent.putExtra("protein", sumProtein);
        intent.putExtra("servings", serv);
        intent.putExtra("carbs", sumCarbs);
        startActivity(intent);
        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }