Exemple #1
0
  /** UPDATE GRAPH WITH SELECTED when results are returned */
  private void updateGraphWithSelected(String results) {

    ndb = new NutritionDatabaseHelper(this);

    if (selectedItems != null || quantities != null) {
      selectedItems.clear();
      quantities.clear();
    } else {
      selectedItems = new ArrayList<Item>();
      quantities = new ArrayList<Integer>();
    }

    int position = -1;
    for (int i = 0; i < ccartList.getCount(); i++) {
      String tempItemName = ccartList.getItem(i);
      int pos = tempItemName.indexOf(" ");
      String compare = tempItemName.substring(pos + 1);

      if (compare.equals(results)) {
        position = i;
        break;
      } else {
        continue;
      }
    }

    Item selectedItem = ndb.getItem(results);
    ndb.close();

    selectedItems.add(selectedItem);
    String itemOne;

    if (selectedItems.get(0).getItemName().length() > 20) {
      itemOne = selectedItems.get(0).getItemName().substring(0, 20) + "...";
    } else {
      itemOne = selectedItems.get(0).getItemName();
    }

    String one = "<font color='#7EAD1A'>" + itemOne + "</font> SELECTED";
    added.setText(Html.fromHtml(one));

    for (GroceryItem gItem : ccart) {
      if (gItem.getItemName().equals(results)) {
        quantities.add(gItem.getQuantity());
        Log.d("CartActivity: ", "Name: " + gItem.getItemName() + quantities.get(0));
      }
    }

    Log.d("CartActivity", "Position: " + position);
    sd_list.setItemChecked(position, true);

    graph.passSelectedItems(selectedItems);
    graph.passSelectedQuantities(quantities);

    graph.postInvalidate();

    graphLabels.setDays(days);
    graphLabels.postInvalidate();
  }
Exemple #2
0
  /** UPDATE BASE GRAPH with new Cart totals */
  private void updateBaseGraph() {
    // get an updated version of the adb on resume each time
    adb = new AccountDatabaseHelper(this);
    ccart = adb.getAllGroceryItemsOf(currentUsername);
    int groceryCount = adb.getGroceryCountFor(currentUsername);
    if (groceryCount == 1) {
      added.setText(groceryCount + " ITEM IN CART");
    } else if (groceryCount == 0 || groceryCount > 1) {
      added.setText(groceryCount + " ITEMS IN CART");
    }
    adb.close();

    if (ccart != null) {
      setupItemDrawer();
    }

    passedIntent = getIntent();

    results = passedIntent.getStringExtra("results");
    int check = passedIntent.getIntExtra("check", 0);
    if (check == 1) {
      Log.d("CartActivity", "This is results " + results);
      if (results != null && !results.equals("e")) {
        updateGraphWithSelected(results);
      } else {
        Toast noData =
            Toast.makeText(
                CartActivity.this,
                "Sorry, we couldn't find the nutrition data for this item",
                Toast.LENGTH_LONG);
        noData.show();
      }
    }

    ccartTotals = getCartTotalsFor(currentUsername);
    totalRDV = getRDVTotalsFor(currentUsername);

    if (pcart.getCalories() != 0.0f) {
      graph.getRatiosWithPCart(ccartTotals, totalRDV, pcart);
    } else {
      graph.getRatiosWithoutPCart(ccartTotals, totalRDV);
    }
    graph.postInvalidate();

    graphLabels.setDays(days);
    graphLabels.postInvalidate();
  }
Exemple #3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cart);

    // From the intent, read the number of days
    Intent passedIntent = getIntent();

    if (passedIntent != null) {
      // retrieve the account
      Account tempAccount = passedIntent.getParcelableExtra("account");

      if (tempAccount != null) {
        act = tempAccount;
        currentUsername = act.getName();
        int tdays = tempAccount.getDays();
        if (tdays != 0) {
          days = tdays;
        } else {
          // set days equal to 1 to prevent crashing
          days = 1;
        }
      } else {
        throw new RuntimeException("CartActivity: account passed was null");
      }
    }

    // ActionBar
    actionBar = (ActionBar) findViewById(R.id.actionbar);
    actionBar.setTitle("Your Grocery Cart");
    actionBar.setHomeAction(new backToDashboardAction());
    actionBar.addAction(new toDaysAction());
    actionBar.addAction(new toPeopleAction());
    actionBar.addAction(new toCheckoutAction());

    // start the db
    adb = new AccountDatabaseHelper(this);
    ndb = new NutritionDatabaseHelper(this);

    // Set the number of days and start the graph view!
    graph = (GraphView) this.findViewById(R.id.graphview);
    graph.setDays(days);

    // Start the graph label view
    graphLabels = (GraphLabelView) this.findViewById(R.id.graphlabelview);

    // Start the nutrition advisor
    advisor = new NutritionAdvisor();

    added = (TextView) findViewById(R.id.tv_added);
    peopleDays = (TextView) findViewById(R.id.tv_cart_peopledays);

    // start the peopledays goal reminder
    int peopleNumber = adb.getPersonCountFor(currentUsername);
    if (days == 1) {
      peopleDays.setText("You're shopping for " + days + " day ");
    } else if (days > 1) {
      peopleDays.setText("You're shopping for " + days + " days ");
    }
    if (peopleNumber == 1) {
      peopleDays.append("and " + peopleNumber + " person");
    } else if (peopleNumber > 1) {
      peopleDays.append("and " + peopleNumber + " people.");
    }

    // initiates the listview within the drawer
    sd_list = (ListView) findViewById(R.id.sd_list);
    sd_itemlist = (SlidingDrawer) findViewById(R.id.sd_itemlist);
    handle = (Button) findViewById(R.id.btn_handle);

    pcart = adb.getPreviousHistoryFor(currentUsername);
    adb.close();

    // Handles the PLU code
    searchItem = (Button) findViewById(R.id.btn_search);
    deleteItem = (Button) findViewById(R.id.btn_delete_item);
    quantityItem = (Button) findViewById(R.id.btn_quantity);

    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    inputsContext = getApplicationContext();

    searchItem.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            // opens up activity with a text entry and numpad
            Intent openSearchItemScreen = new Intent(CartActivity.this, InputSearchActivity.class);
            openSearchItemScreen.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            openSearchItemScreen.putExtra("account", act);
            startActivity(openSearchItemScreen);
          }
        }); // end searchItem

    // Handles the Barcode Scanning activity
    scanItem = (Button) findViewById(R.id.btn_scan);
    scanItem.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            // start a scanner intent, using zxing library
            // refer back to PACKAGE settings
            Intent scanIntent = new Intent(SCANNER);
            scanIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            scanIntent.setPackage(PACKAGE);
            scanIntent.addCategory(Intent.CATEGORY_DEFAULT);
            scanIntent.putExtra("SCAN_FORMATS", SCAN_FORMATS);
            scanIntent.putExtra("SCAN_MODE", SCAN_MODE);
            try {
              startActivityForResult(scanIntent, REQUEST_CODE);
            } catch (ActivityNotFoundException e) {
              Toast eToast =
                  Toast.makeText(CartActivity.this, "Activity Not Found!", Toast.LENGTH_LONG);
              eToast.setGravity(Gravity.TOP, 25, 400);
              eToast.show();
            }
          }
        }); // end scanBarcode onClickListener
  }