Android Open Source - AndroidCouponAssistant Php Wrapper






From Project

Back to project page AndroidCouponAssistant.

License

The source code is released under:

MIT License

If you think the Android project AndroidCouponAssistant listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.corylucasjeffery.couponassistant;
/*from   ww w.j  a  va  2s  .c o  m*/
import android.app.Activity;
import android.app.ListActivity;
import android.util.Log;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

public class PhpWrapper {

    public static final int SUCCESS_VALUE = 1;

    private final String TAG = "PHP";
    boolean connected;
    UserInfo user;

    public PhpWrapper() {
        if(user == null)
            user = new UserInfo("user1", "pass1", "name", "name");
        connected = true;
    }

    public void disconnect() { connected = false; }
    public void connect() { connected = true; }

    public Boolean submitItem(String upc) {
        boolean result = false;
        if(connected) {
            DbSubmitItem db = new DbSubmitItem(user.getUserName(), user.getPass(), upc);

            try {
                result = db.execute().get();
            } catch (InterruptedException ie) {
                ie.printStackTrace();
            } catch (ExecutionException ee) {
                ee.printStackTrace();
            }
        }

        return result;
    }

    public Boolean submitCoupon(String upc, String exp_date, String image) {
        boolean result = false;

        if (connected) {
            DbSubmitCoupon db = new DbSubmitCoupon(user.getUserName(), user.getPass(), upc, exp_date, image);

            try {
                result = db.execute().get();
            } catch (InterruptedException ie) {
                Log.v(TAG, "Interrupted Exception");
            } catch (ExecutionException ee) {
                Log.v(TAG, "Execution Exception");
            }
        }
        return result;
    }

    public ArrayList<Coupon> getCoupons(String itemUpc, ListActivity activity) {
        ArrayList<Coupon> coupons = new ArrayList<Coupon>();
        if (connected) {
            DbGetCoupons db = new DbGetCoupons(user.getUserName(), user.getPass(), itemUpc, activity);
            try {
                Log.v(TAG, "execute getCoupons");
                coupons = db.execute().get();
            } catch (InterruptedException ie) {
                ie.printStackTrace();
            } catch (ExecutionException ee) {
                ee.printStackTrace();
            }
        }
        else {
            String fakeExp = "2013-12-31";
            String fakeDescription = "db is disconnected";
            Coupon c = new Coupon(itemUpc, fakeExp, fakeDescription);
            coupons.add(c);
            coupons.add(c);
        }

        return coupons;
    }

    public Statistics getStatistics(Activity activity) {
        Statistics stats;
        if (connected) {
            DbUserStats db = new DbUserStats(user.getUserName(), user.getPass(), activity);
            try {
                Log.v(TAG, "execute getStats");
                stats = db.execute().get();
                Log.v("STAT", "post stat");
            } catch (InterruptedException ie) {
                String fakeBought = "0";
                String fakeTotal = "0";
                String fakeDay = "0";
                String fakeWeek = "0";
                String fakeMonth = "0";
                String fakeYear = "0";
                stats = new Statistics(fakeBought, fakeTotal, fakeDay, fakeWeek, fakeMonth, fakeYear);
                ie.printStackTrace();
            } catch (ExecutionException ee) {
                String fakeBought = "0";
                String fakeTotal = "0";
                String fakeDay = "0";
                String fakeWeek = "0";
                String fakeMonth = "0";
                String fakeYear = "0";
                stats = new Statistics(fakeBought, fakeTotal, fakeDay, fakeWeek, fakeMonth, fakeYear);
                ee.printStackTrace();
            }
        }
        else {
            String fakeBought = "0";
            String fakeTotal = "0";
            String fakeDay = "0";
            String fakeWeek = "0";
            String fakeMonth = "0";
            String fakeYear = "0";
            stats = new Statistics(fakeBought, fakeTotal, fakeDay, fakeWeek, fakeMonth, fakeYear);

        }

        return stats;
    }

    public void getItems(String couponUPC) {
        //TODO implement getItems()
        Log.v(TAG, "getItems() not implemented yet");
    }

    public boolean submitLogin(String user, String pass, String first, String last) {
        DbUserRegister db = new DbUserRegister(user, pass, first, last);
        boolean result = false;
        try {
            result = db.execute().get();
        } catch (InterruptedException ie) {
            Log.v(TAG, "Interrupted Exception");
        } catch (ExecutionException ee) {
            Log.v(TAG, "Execution Exception");
        }
        return result;
    }

    public boolean purchaseItem(String item_code, String coupon_code, String exp_date) {
        DbPurchaseItem db = new DbPurchaseItem(user.getUserName(), user.getPass(), item_code, coupon_code, exp_date);
        boolean result = false;
        try {
            result = db.execute().get();
        } catch (InterruptedException ie) {
            Log.v(TAG, "Interrupted Exception");
        } catch (ExecutionException ee) {
            Log.v(TAG, "Execution Exception");
        }
        return result;
    }
}




Java Source Code List

com.corylucasjeffery.couponassistant.BMPtoBlob.java
com.corylucasjeffery.couponassistant.BarcodeGenerator.java
com.corylucasjeffery.couponassistant.BlobtoBMP.java
com.corylucasjeffery.couponassistant.CameraPreview.java
com.corylucasjeffery.couponassistant.CouponAdapter.java
com.corylucasjeffery.couponassistant.Coupon.java
com.corylucasjeffery.couponassistant.DateChooserDialog.java
com.corylucasjeffery.couponassistant.DbGetCoupons.java
com.corylucasjeffery.couponassistant.DbPurchaseItem.java
com.corylucasjeffery.couponassistant.DbSubmitCoupon.java
com.corylucasjeffery.couponassistant.DbSubmitItem.java
com.corylucasjeffery.couponassistant.DbUserRegister.java
com.corylucasjeffery.couponassistant.DbUserStats.java
com.corylucasjeffery.couponassistant.GlobalCart.java
com.corylucasjeffery.couponassistant.Item.java
com.corylucasjeffery.couponassistant.ManualEntryDialog.java
com.corylucasjeffery.couponassistant.ParseUPC.java
com.corylucasjeffery.couponassistant.PhpWrapper.java
com.corylucasjeffery.couponassistant.ProgressBarHelper.java
com.corylucasjeffery.couponassistant.Statistics.java
com.corylucasjeffery.couponassistant.UserInfo.java
com.corylucasjeffery.couponassistant.ValueCodeDict.java
com.corylucasjeffery.couponassistant.activities.AndroidBarcodeView.java
com.corylucasjeffery.couponassistant.activities.CheckoutActivity.java
com.corylucasjeffery.couponassistant.activities.LoginActivity.java
com.corylucasjeffery.couponassistant.activities.MainActivity.java
com.corylucasjeffery.couponassistant.activities.SettingsActivity.java
com.corylucasjeffery.couponassistant.activities.ShowCouponsActivity.java
com.corylucasjeffery.couponassistant.activities.StatisticsActivity.java
com.google.zxing.integration.android.IntentIntegrator.java
com.google.zxing.integration.android.IntentResult.java