Saturday, December 6, 2014

SMS bid app


Use cases:
1) User creates offline list of items that will be used in an auction, example:
- sofa, pale blue, heavily used #sofa001
- mountain bike, barely used (I am developer not a sportsman) #bike002
- HTC ONE, Android phone, still working, AT&T #phone003
2) User distributes the list of bid items to FFF (family, friends and fools) by mailing, posting, etc.
3) User enters the bid items into the app
4) User enters the bid deadline per item into the app
6) User enters a minimum bid price per item into the app
7) FFF send SMS messages with bid in format:

bid #bike002 $30

8) The app tally up the highest bid and replies to FFF

- Minimum bid for item #bike002 is $30
- These is a higher bid for #bike002 in amount of $31

9) User can monitor the winning bids in the app

No bids

#bike002 minimum bid $30
- $31 from 6508151234
- $30 from 6508151432

10) there are many additional features you can add to this application

Step 1) Copy appSMS

We will use the previous app we wrote as a starting point.
Synch the class GIT repo:
- git fetch
- git add -all
- git commit -m "my previous changes xyz"
- git rebase
- git push
You can copy the version committed by the instructor to your desktop and then "Import Module" in AndroidStudio
Name it appSMSBid

Step 2) Rename the app in res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
    <string name="app_name">"SMS Auction"</string>
    <string name="action_settings">Settings</string>

Step 3) Change the package name (app unique identifier)

<manifest xmlns:android=""

Step 4) Move classes

  • Create new package bid
  • Move classes to package

Step 5) Run the app

adb shell 'pm list packages -f' | grep /data/app/

Step 6) see what class apps you have running

$ adb shell 'pm list packages -f' | grep /data/app/


Step 7) Create a new Java class

  •  private String description;
  •  private String itemID;
  •  private double minBidPrice;

  • Generate Getters and Setters methods

    Add constructor:

       BidItem(String itemID, double minBidPrice, String description) {

    Override default toString method:

       public String toString() {
          StringBuffer output = new StringBuffer(150);
          output.append("itemID: " + getItemID() + ", ");
          output.append("description: " + getDescription() + ", ");
          output.append("minBidPrice: $" + getMinBidPrice());
          return output.toString();

    Step 8: Create Java class Bid


       Bid(String bidID, double bidAmount, String personNumber) {

    Step 9: Create class BidEngine

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
     * Created by uki on 12/6/14.
    public class BidEngine {
       /** A collection of BidItems indexed by itemID **/
       private Map<String, BidItem> bidItems;
       private List<Bid> bids;
       BidEngine() {
       //TODO public void addItem(BidItem)
       //TODO public void removeItem(BidItem)
       //TODO public void changeItem(BidItem);
       public Map getBidItems() {
          return this.bidItems;
       private void createMockBidItems() {
          bidItems = new HashMap<String, BidItem>();
          BidItem sofa = new BidItem("sofa001", 15.00, "sofa, pale blue, heavily used");
          bidItems.put(sofa.getItemID(), sofa);
          BidItem bike = new BidItem("bike002", 50.00, "mountain bike, barely used (I am developer not a sportsman)");
          bidItems.put(bike.getItemID(), bike);
          BidItem phone = new BidItem("phone003", 30.00, "HTC ONE, Android phone, still working, AT&T");
          bidItems.put(phone.getItemID(), phone);
       private void createMockBids() {
          bids = new ArrayList<Bid>();
          Bid sofa1 = new Bid("sofa001", 15.00, "6508151234");
          Bid sofa2 = new Bid("sofa001", 16.00, "6508151232");
          Bid sofa3 = new Bid("sofa001", 17.00, "6508151234");
       public String printMyBidItems() {
          StringBuffer output = new StringBuffer();
          for (BidItem item : bidItems.values()) {
             output.append(item.toString() + "\n");
          return output.toString();

    Step 10: Create initial UI