コード例 #1
0
  public AuctionCreateScreen(Card card, Bitmap cardthumb) {
    super(null);
    add(new ColorLabelField(""));
    this.card = card;
    SettingsBean _instance = SettingsBean.getSettings();
    _instance.created = false;
    SettingsBean.saveSettings(_instance);
    Font _font = getFont();
    _font = _font.derive(Const.TYPE, Const.FONT);
    setFont(_font);

    bgManager.setStatusHeight(exit.getContentHeight());

    exit.setChangeListener(this);
    auction.setChangeListener(this);

    // cardfield = new CardField(card, cardthumb);
    cardfield = new ThumbnailField(card);
    // add(cardfield);
    add(cardfield);
    add(lblOpeningBid);
    int val = 0;
    try {
      val = Integer.parseInt(card.getValue());
    } catch (Exception e) {
      val = 0;
    }
    openingBid.setText("" + val);
    buyNowPrice.setText("" + (2 * val));
    auctionDuration.setText("5");

    add(openingBid);
    add(lblBuyNowPrice);
    add(buyNowPrice);
    add(lblAuctionDuration);
    add(auctionDuration);

    addButton(auction);
    addButton(empty);
    addButton(exit);

    invalidate();
    setDisplaying(true);
  }
コード例 #2
0
  public void fieldChanged(Field f, int i) {
    if (f == exit) {
      screen = null;
      UiApplication.getUiApplication().popScreen(this);
    } else if (f == auction && created == false) {
      if (!confirm) {
        if (valid()) {
          created = false;
          SettingsBean _instance = SettingsBean.getSettings();
          _instance.created = false;
          SettingsBean.saveSettings(_instance);
          confirm = true;

          // when i auction
          /*
           * created = true, instance.created = true
           */
          synchronized (UiApplication.getEventLock()) {
            try {

              this.delete(cardfield);
              this.delete(openingBid);
              this.delete(buyNowPrice);
              this.delete(auctionDuration);

              lblBuyNowPrice.setText("");
              lblAuctionDuration.setText("");
              int val = 0;
              int buynow = 0;
              try {
                buynow = Integer.parseInt(buyNowPrice.getText());
              } catch (Exception e) {
                buynow = 0;
              }
              int bid = 0;
              try {
                bid = Integer.parseInt(openingBid.getText());
              } catch (Exception e) {
                bid = 0;
              }
              val = bid;
              if (buynow > bid) {
                val = buynow;
              }
              val = (int) ((double) val / 10);
              if (val < 5) {
                val = 5;
              }

              lblOpeningBid.setColor(Color.RED);
              lblOpeningBid.setText(
                  "Are you sure you want to auction "
                      + card.getDesc()
                      + "? It will cost you "
                      + val
                      + " credits.");
              // lblOpeningBid.setColor(Const.FONTCOLOR);

              add(
                  new AuctionField(
                      new Auction(
                          -1,
                          card.getId(),
                          1,
                          card.getDesc(),
                          card.getThumburl(),
                          openingBid.getText(),
                          buyNowPrice.getText(),
                          "",
                          "You",
                          auctionDuration.getText() + " days left",
                          ""),
                      cardfield.getThumbnail()));

              // this.removeButton(auction);
              // addButton(new FixedButtonField(""));
            } catch (Exception e) {

            }
          }
          // doConnect(Const.createauction+"&cardid="+card.getId()+"&bid="+openingBid.getText()+"&buynow="+buyNowPrice.getText()+"&days="+auctionDuration.getText());
        }
      } else {
        if (valid()) {
          created = true;
          SettingsBean _instance = SettingsBean.getSettings();
          _instance.created = true;
          SettingsBean.saveSettings(_instance);

          synchronized (UiApplication.getEventLock()) {
            try {
              lblOpeningBid.setColor(Color.RED);
              lblOpeningBid.setText("Attempting to create auction...");

              auction.setChangeListener(null);
              auction.empty = true;
              auction.setLabel("");
              // removeButton(auction);

            } catch (Exception e) {

            }
          }
          doConnect(
              Const.createauction
                  + "&cardid="
                  + card.getId()
                  + "&bid="
                  + openingBid.getText()
                  + "&buynow="
                  + buyNowPrice.getText()
                  + "&days="
                  + auctionDuration.getText());
        }
      }
    }
  }