コード例 #1
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

      View oldView;

      // Make sure we habe a view to work with(may have been given false)
      View itemView = convertView;

      if (itemView == null) {
        itemView = getActivity().getLayoutInflater().inflate(R.layout.da_items, parent, false);
      }

      // find the product to work with

      sparkFun currentProduct = itemsList.get(position);
      Log.d("tagname", "in list view");

      //	if(currentProduct.getKaand().equals("green")){

      // Fill the view

      ImageView imageView = (ImageView) itemView.findViewById(R.id.item_icon);
      imageView.setImageResource(currentProduct.getIconID());

      // ProductName :
      TextView productNameText = (TextView) itemView.findViewById(R.id.item_Nametv);
      // doing juggad for the app again , don't know why the f*****g changes in the app are not
      // working.
      // My mapping is
      // Levi's Jeans - oreo
      // Wrogn shirt(Puma cap) -  jam
      // Arrow shirt(Nike Tshirt) - sauce
      // Leee shirt  - milk
      // changing the pics and doing jugaad.
      // like changing oreo image to levi's jeans.

      if (currentProduct.getProductname().contains("oreo")) {
        juggadName = "Levi's Tshirt";
        //          	if(WifiBroadcastReceiver.SNotificationSentLevis){
        //         	juggadDiscount ="Discount =30%";
        //         	productPrice = (Double.parseDouble(currentProduct.getProductprice()))*(1-0.3);
        //          	productPrice = (double)Math.round(productPrice * 10d) / 10d;
        //          	}else{
        juggadDiscount = "";
        productPrice = Double.parseDouble(currentProduct.getProductprice());
        //        	}

      }
      if (currentProduct.getProductname().contains("jam")) {
        //  	juggadName = "Wrogn Tshirt";
        juggadName = "Puma Cap";
        if (WifiBroadcastReceiver.SNotificationSentPuma) {
          juggadDiscount = "Discount =10%";
          productPrice = (Double.parseDouble(currentProduct.getProductprice())) * (1 - 0.1);
          productPrice = (double) Math.round(productPrice * 10d) / 10d;
        } else {
          juggadDiscount = "";
          productPrice = Double.parseDouble(currentProduct.getProductprice());
        }
        //           	juggadDiscount = "Discount =10%";
        //          	productPrice = Double.parseDouble(currentProduct.getProductprice());

      }
      if (currentProduct.getProductname().contains("sauce")) {
        //   	juggadName = "Arrow Tshirt";
        juggadName = "Nike Tshirt";
        if (WifiBroadcastReceiver.SNotificationSentNike) {
          juggadDiscount = "Discount =30%";
          productPrice = (Double.parseDouble(currentProduct.getProductprice())) * (1 - 0.3);
          productPrice = (double) Math.round(productPrice * 10d) / 10d;
        } else {
          juggadDiscount = "";
          productPrice = Double.parseDouble(currentProduct.getProductprice());
        }
      }
      if (currentProduct.getProductname().contains("milk")) {
        juggadName = "Lee Tshirt";
        juggadDiscount = "";
        productPrice = Double.parseDouble(currentProduct.getProductprice());
      }

      productNameText.setText(" " + juggadName);

      // Discount :
      TextView productWeightText = (TextView) itemView.findViewById(R.id.item_Weighttv);
      productWeightText.setText(" " + juggadDiscount);

      // ProductPrice :
      TextView productPriceText = (TextView) itemView.findViewById(R.id.item_Pricetv);
      productPriceText.setText("Rs." + productPrice);

      // ProductWeight :
      // TextView productWeightText = (TextView)
      // findViewById(R.id.item_Nametv);
      // productWeightText.setText(""+currentProduct.getProductname());

      // ProductName :
      // TextView productKaandText = (TextView)
      // findViewById(R.id.item_Weighttv);
      // productKaandText.setText(currentProduct.getKaand());
      // total = total
      // + Double.parseDouble(currentProduct.getProductprice());

      // myCartTv.setText("My Cart");
      // myCartTv.append("(" + currentProduct.getNoOfItems() + ")");
      noOfProducts = currentProduct.getNoOfItems();

      return itemView;
    }
コード例 #2
0
  public void updateDisplay() {

    // sparkFun SparkFun = null;

    // noOfProducts = SparkFun.getNoOfItems();

    // update list view only when no of products have increased

    // if (SparkFun.getNoOfItems() > noOfProducts) {
    // populateListView();
    // }

    kaand = "green";
    total = 0;
    int i = 0;
    // sparkFun SparkFun = new sparkFun();

    // SparkFun.getNoOfItems();
    // Log.d("tagname", SparkFun.getProductname());
    if (itemsList != null) {
      // Log.d("tagname", "in total");
      for (sparkFun SparkFun : itemsList) {
        // tvData.append(SparkFun.getTest1() + "\n");
        if (SparkFun.getKaand().equals("green")) {
          i++;
          if ((SparkFun.getProductname().contains("jam"))
              && (WifiBroadcastReceiver.SNotificationSentPuma)) {
            total = total + (Double.parseDouble(SparkFun.getProductprice())) * (1 - 0.1);

          } else if ((SparkFun.getProductname().contains("sauce"))
              && (WifiBroadcastReceiver.SNotificationSentNike)) {
            total = total + (Double.parseDouble(SparkFun.getProductprice())) * (1 - 0.3);
          } else {
            total = total + Double.parseDouble(SparkFun.getProductprice());
          }

          populateListView();
        }
        // grandTotalValueTv.setText("Rs ");
        // grandTotalValueTv.append("" + total);
        // grandTotalValueTv.setText(total);
        if (SparkFun.getKaand().equals("red")) {
          kaand = "red";
          query = false;
          checkoutButton.setEnabled(false);
          checkoutButton.setBackgroundColor(Color.RED);
          Toast.makeText(
                  getActivity(),
                  "Something is wrong, please proceed to manual checkout",
                  Toast.LENGTH_LONG)
              .show();
        }
      }
    }
    Log.d("tagname", "in update display");
    // if(query){
    // populateListView();
    // }

    // tvData.setText("");
    /*
     * List<String> where = new ArrayList<String>(); int i = 0; String data;
     * double total = 0;
     *
     * if (itemsList != null) { for (sparkFun SparkFun : itemsList) { if
     * (SparkFun.getPhonenumber().equals(showNumber())) { data =
     * SparkFun.getProductname() + "               " +
     * SparkFun.getProductprice(); total = total +
     * Double.parseDouble(SparkFun.getProductprice()); where.add(i, data);
     * kaand = SparkFun.getKaand(); if (kaand.equals("red")) {
     * Toast.makeText( MainActivity.this,
     * "Something is wrong, please proceed to manual checkout",
     * 10000).show(); checkoutButton.setEnabled(false);
     * checkoutButton.setBackgroundColor(Color.RED); query = false; }
     *
     * i++; }
     *
     * // where.add(i, SparkFun.getProductname());
     *
     * // tvData.append(SparkFun.getTest1() + "\n"); } }
     *
     * String[] simpleArray = new String[where.size()];
     * where.toArray(simpleArray);
     *
     * // Build Adapter
     *
     * // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, //
     * R.layout.da_items, simpleArray);
     *
     * ArrayAdapter<String> adapter1 = new MyListAdapter();
     *
     * // Configure the list view.
     *
     * ListView list = (ListView) findViewById(R.id.listViewMain); if
     * (!query) { list.setBackgroundColor(Color.RED); //
     * list.setBackground(Color.RED);
     *
     * } // list.setAdapter(adapter);
     *
     * grandTotalTv.setText("Grand Total: ");
     *
     * DecimalFormat df = new DecimalFormat("#,###.##");
     *
     * // to display principalInvested //
     * principalInvestedTextViewDisplay.setText
     * (""+df.format(principalInvested)); grandTotalValueTv.setText("Rs ");
     * grandTotalValueTv.append("" + df.format(total)); //
     */
    // if(kaand.equals("green")){ checkoutButton.setVisibility(0);
    // }

    myCartTv.setText("My Cart");
    myCartTv.append("(" + i + ")");
    grandTotalTv.setText("Grand Total: ");
    checkoutButton.setVisibility(View.VISIBLE);
    DecimalFormat df = new DecimalFormat("#,###.##");
    grandTotalValueTv.setText("Rs ");
    grandTotalValueTv.append("" + df.format(total));
    Log.d("tagname", "finisehd printing");

    if (query) {
      final Handler handler = new Handler();
      handler.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              // Do something after 10s = 10000ms
              // Toast.makeText(MainActivity.this, "Starting query",
              // Toast.LENGTH_SHORT).show();

              // getData(etPollingIntervalValue,
              // "http://data.sparkfun.com/output/VGYDordaJJf7VGxaMyYK.json?page=1");
              Log.d("tagname", "in handler");
              // getData(etPollingIntervalValue,
              // "http://192.168.1.6:8080/output/RDpqP47p35Sw3x47zlgdFzZL70e.json");
              // getData(etPollingIntervalValue,
              // "http://10.196.64.81:8080/output/go0Kyy7Dxzh6dwArbqMbH0eenP0.json");

              getData(
                  etPollingIntervalValue,
                  "http://10.77.133.24:8080/output/qdLPqJ1QmKHAG136Z1Alhle2bg3J.json");
            }
          },
          100);
    }

    // getData(etPollingIntervalValue,
    // "http://data.sparkfun.com/output/VGYDordaJJf7VGxaMyYK.json?page=1");

  }