Android Open Source - AndroidCouponAssistant Android Barcode View






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.activities;
//from w  ww  . jav  a  2  s.co m
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.view.View;

import com.onbarcode.barcode.android.AndroidColor;
import com.onbarcode.barcode.android.AndroidFont;
import com.onbarcode.barcode.android.IBarcode;
import com.onbarcode.barcode.android.UPCA;

public class AndroidBarcodeView extends View {

    private String upc;

    public AndroidBarcodeView(Context context, String upc) {
        super(context);
        this.upc = upc;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        try {
            androidUPC(canvas);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void androidUPC(Canvas canvas) throws Exception {
        UPCA barcode = new UPCA();

        /*
           UPC-A Valid data char set:
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (Digits)

           UPC-A Valid data length: 11 digits only, excluding the last checksum digit
        */
        barcode.setData(upc);

        // for UPC-A with supplement data (2 or 5 digits)
        /*
        barcode.setSupData("12");
        // supplement bar height vs bar height ratio
        barcode.setSupHeight(0.8f);
        // space between barcode and supplement barcode (in pixel)
        barcode.setSupSpace(15);
        */

        // Unit of Measure, pixel, cm, or inch
        barcode.setUom(IBarcode.UOM_PIXEL);
        // barcode bar module width (X) in pixel
        barcode.setX(1f);
        // barcode bar module height (Y) in pixel
        barcode.setY(45f);

        // barcode image margins
        barcode.setLeftMargin(10f);
        barcode.setRightMargin(10f);
        barcode.setTopMargin(10f);
        barcode.setBottomMargin(10f);

        // barcode image resolution in dpi
        barcode.setResolution(72);

        // disply barcode encoding data below the barcode
        barcode.setShowText(true);
        // barcode encoding data font style
        barcode.setTextFont(new AndroidFont("Arial", Typeface.NORMAL, 10));
        // space between barcode and barcode encoding data
        barcode.setTextMargin(6);
        barcode.setTextColor(AndroidColor.black);

        // barcode bar color and background color in Android device
        barcode.setForeColor(AndroidColor.black);
        barcode.setBackColor(AndroidColor.white);

        /*
        specify your barcode drawing area
      */
        RectF bounds = new RectF(50, 30, 0, 0);
        barcode.drawBarcode(canvas, bounds);
    }
}




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