Android Open Source - Android-Print-SDK Prints Print Job






From Project

Back to project page Android-Print-SDK.

License

The source code is released under:

MIT License

If you think the Android project Android-Print-SDK 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 ly.kite.print;
//w  w  w. j av a 2  s  .com
import android.os.Parcel;
import android.os.Parcelable;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by deonbotha on 09/02/2014.
 */
class PrintsPrintJob extends PrintJob {

    private static final long serialVersionUID = 0L;

    private ProductType productType;
    private List<Asset> assets;

    public PrintsPrintJob(ProductType productType, List<Asset> assets) {
        this.productType = productType;
        this.assets = assets;
    }

    @Override
    public BigDecimal getCost() {
        // TODO: don't do this in the final public API, look up dynamically!
        switch (productType) {
            case MAGNETS: {
                BigDecimal cost = new BigDecimal("12.50");
                int numOrders = (assets.size() + 21) / 22;
                return cost.multiply(new BigDecimal(numOrders));
            }
            case POLAROIDS:
            case SQUARES: {
                BigDecimal cost = new BigDecimal("12.50");
                int numOrders = (assets.size() + 19) / 20;
                return cost.multiply(new BigDecimal(numOrders));
            }
            case MINI_POLAROIDS:
            case MINI_SQUARES: {
                BigDecimal cost = new BigDecimal("11.50");
                int numOrders = (assets.size() + 43) / 44;
                return cost.multiply(new BigDecimal(numOrders));
            }
            default:
                throw new AssertionError("Oops");
        }
    }

    @Override
    public ProductType getProductType() {
        return productType;
    }

    @Override
    public int getQuantity() {
        return assets.size();
    }

    @Override
    List<Asset> getAssetsForUploading() {
        return assets;
    }

    @Override
    public String getTemplateName() {
        return productType.defaultTemplate;
    }

    @Override
    JSONObject getJSONRepresentation() {
        JSONArray assets = new JSONArray();
        for (Asset a : this.assets) {
            assets.put("" + a.getId());
        }

        JSONObject json = new JSONObject();
        try {
            json.put("template_id", productType.defaultTemplate);
            json.put("assets", assets);
            json.put("frame_contents", new JSONObject());
        } catch (JSONException ex) {
            throw new RuntimeException(ex); // this should NEVER happen :)
        }
        return json;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeString(productType.defaultTemplate);
        parcel.writeTypedList(assets);
    }

    private PrintsPrintJob(Parcel parcel) {
        this.productType = ProductType.productTypeFromTemplate(parcel.readString());
        this.assets = new ArrayList<Asset>();
        parcel.readTypedList(assets, Asset.CREATOR);
    }

    public static final Parcelable.Creator<PrintsPrintJob> CREATOR
            = new Parcelable.Creator<PrintsPrintJob>() {
        public PrintsPrintJob createFromParcel(Parcel in) {
            return new PrintsPrintJob(in);
        }

        public PrintsPrintJob[] newArray(int size) {
            return new PrintsPrintJob[size];
        }
    };

    private void writeObject(java.io.ObjectOutputStream out) throws IOException {
        out.writeObject(productType.defaultTemplate);
        out.writeInt(assets.size());
        for (Asset a : assets) {
            out.writeObject(a);
        }
    }

    private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
        productType = ProductType.productTypeFromTemplate((String) in.readObject());
        int numAssets = in.readInt();
        assets = new ArrayList<Asset>(numAssets);
        for (int i = 0; i < numAssets; ++i) {
            assets.add((Asset) in.readObject());
        }
    }

}




Java Source Code List

co.oceanlabs.sample.MainActivity.java
ly.kite.address.AddressBookActivity.java
ly.kite.address.AddressEditActivity.java
ly.kite.address.AddressSearchActivity.java
ly.kite.address.AddressSearchRequestListener.java
ly.kite.address.AddressSearchRequest.java
ly.kite.address.Address.java
ly.kite.address.Country.java
ly.kite.checkout.CheckoutActivity.java
ly.kite.checkout.OrderReceiptActivity.java
ly.kite.checkout.PaymentActivity.java
ly.kite.checkout.PrintOrderSummaryListAdapter.java
ly.kite.payment.CheckPromoCodeRequestListener.java
ly.kite.payment.CheckPromoRequest.java
ly.kite.payment.PayPalCardChargeListener.java
ly.kite.payment.PayPalCardVaultStorageListener.java
ly.kite.payment.PayPalCard.java
ly.kite.print.ApplyPromoCodeListener.java
ly.kite.print.AssetGetBytesLengthListener.java
ly.kite.print.AssetGetBytesListener.java
ly.kite.print.AssetUploadRequestListener.java
ly.kite.print.AssetUploadRequest.java
ly.kite.print.Asset.java
ly.kite.print.BaseRequest.java
ly.kite.print.KitePrintSDKException.java
ly.kite.print.KitePrintSDK.java
ly.kite.print.PrintJob.java
ly.kite.print.PrintOrderSubmissionListener.java
ly.kite.print.PrintOrder.java
ly.kite.print.PrintsPrintJob.java
ly.kite.print.ProductType.java
ly.kite.print.SubmitPrintOrderRequestListener.java
ly.kite.print.SubmitPrintOrderRequest.java