Skip to content

Commit

Permalink
New method for flashing text on display implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Wilson committed May 23, 2017
1 parent 233ad29 commit f6a078f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
25 changes: 23 additions & 2 deletions audition/app/src/main/java/com/audition/DisplayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.app.Activity;
import android.widget.TextView;

import java.util.Timer;
import java.util.TimerTask;

public class DisplayHandler extends VendingMachine {

Activity activity;
Expand Down Expand Up @@ -51,12 +54,30 @@ public void updateDisplay(float currentTotal){
//is money in machine?

if (currentTotal > 0.0f) { //If no coins inserted
setDisplayText(String.valueOf(currentTotal));
setDisplayText("$" + String.format("%.2f", currentTotal));
return;
}

setDisplayText(INSERT_COIN);
}


// TODO - Make Generic Method to handle multiple input cases
public void flashMessage(String flashMsg){
final String resetMsg = getDisplayText(); //Get current display contents

setDisplayText(flashMsg); //Write temporary message to display

Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
setDisplayText(resetMsg); //Restore original display contents
}
});
}
}, 1000);
}
}
7 changes: 5 additions & 2 deletions audition/app/src/main/java/com/audition/ProductHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
Expand All @@ -18,11 +19,13 @@
public class ProductHandler extends VendingMachine {

Activity activity;
DatabaseHandler db;

ArrayList<Product> listDispensedProducts;

ProductHandler(Activity activity){
ProductHandler(Activity activity, DatabaseHandler db){
this.activity = activity;
this.db = db;

initialize();
}
Expand All @@ -31,7 +34,7 @@ private void initialize(){
listDispensedProducts = new ArrayList<Product>();
}

public boolean isProductAvailable(int productID, DatabaseHandler db){
public boolean isProductAvailable(int productID){
int qty = db.getQuantityOfProduct(productID);

return (qty > 0);
Expand Down
10 changes: 5 additions & 5 deletions audition/app/src/main/java/com/audition/VendingMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ protected void onCreate(Bundle savedInstanceState) {

private void initialize(){
// buttonHandler = new ButtonHandler(this);
displayHandler = new DisplayHandler(this);
databaseHandler = new DatabaseHandler(this);
displayHandler = new DisplayHandler(this);
changeHandler = new ChangeHandler(this);
productHandler = new ProductHandler(this);
productHandler = new ProductHandler(this, databaseHandler);
}


Expand All @@ -44,13 +44,13 @@ public void onProductButtonClicked(int productID){
float currentTotal = changeHandler.getSumOfInsertedCoins();

//Check Product Availability
if (!productHandler.isProductAvailable(productID, databaseHandler)) { //If sold out
//Flash SOLD OUT
if (productHandler.isProductAvailable(productID)) { //If sold out
displayHandler.flashMessage(displayHandler.SOLD_OUT);
return;
}

//Check if enough money inserted
// if(!isProductPaidFor(productID)){ //If not enough
// if(!productHandler.getProductCost(productID)){ //If not enough
// lcdController.flashMessage(productPrice, currentTotal);
// return;
// }
Expand Down

0 comments on commit f6a078f

Please sign in to comment.