Example usage for android.graphics BitmapFactory decodeByteArray

List of usage examples for android.graphics BitmapFactory decodeByteArray

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeByteArray.

Prototype

public static Bitmap decodeByteArray(byte[] data, int offset, int length) 

Source Link

Document

Decode an immutable bitmap from the specified byte array.

Usage

From source file:com.download.cache.image.UrlImageDownloader.java

@Override
protected Bitmap download(String key, WeakReference<ImageView> imageViewRef) {
    URL url;//  w w  w  .j a  v  a2 s .co m

    try {
        url = new URL(key);
    } catch (MalformedURLException e) {
        Log.e(TAG, "url is malformed: " + key, e);
        return null;
    }

    HttpURLConnection urlConnection;
    try {
        urlConnection = (HttpURLConnection) url.openConnection();
    } catch (IOException e) {
        Log.e(TAG, "error while opening connection", e);
        return null;
    }

    Bitmap bitmap = null;
    InputStream httpStream = null;
    int contentLength;
    int bytesDownloaded = 0;
    try {

        contentLength = urlConnection.getContentLength();
        if (contentLength != -1) {

            httpStream = new FlushedInputStream(urlConnection.getInputStream());

            ByteArrayBuffer baf = new ByteArrayBuffer(BYTE_ARRAY_BUFFER_INCREMENTAL_SIZE);
            byte[] buffer = new byte[BYTE_ARRAY_BUFFER_INCREMENTAL_SIZE];
            while (!isCancelled(imageViewRef)) {
                int incrementalRead = httpStream.read(buffer);
                if (incrementalRead == -1) {
                    break;
                }
                bytesDownloaded += incrementalRead;
                if (contentLength > 0 || (bytesDownloaded > 0 && bytesDownloaded == contentLength)) {
                    int progress = bytesDownloaded * 100 / contentLength;
                    publishProgress(progress, imageViewRef);
                }
                baf.append(buffer, 0, incrementalRead);
            }

            if (isCancelled(imageViewRef))
                return null;

            bitmap = BitmapFactory.decodeByteArray(baf.toByteArray(), 0, baf.length());
        } else { // steam 
            //             byte[] imageBuf;
            //             byte[] buf = new byte[BYTE_ARRAY_BUFFER_INCREMENTAL_SIZE];
            //              int bufferLeft = buf.length;
            //              int offset = 0;
            //              int result = 0;
            //              
            //              BufferedInputStream bis = new BufferedInputStream(url.openStream());
            //              
            //              InputStream is = url.openStream();
            //              outer: do {
            //                  while (bufferLeft > 0) {
            //                      result = is.read(buf, offset, bufferLeft);
            //                      if (result < 0) {
            //                          // we're done
            //                          break outer;
            //                      }
            //                      offset += result;
            //                      bufferLeft -= result;
            //                   }
            //                   // resize
            //                   bufferLeft = BYTE_ARRAY_BUFFER_INCREMENTAL_SIZE;
            //                   int newSize = buf.length + BYTE_ARRAY_BUFFER_INCREMENTAL_SIZE;
            //                   byte[] newBuf = new byte[newSize];
            //                   System.arraycopy(buf, 0, newBuf, 0, buf.length);
            //                   buf = newBuf;
            //               } while (true);
            //               imageBuf = new byte[offset];
            //               System.arraycopy(buf, 0, imageBuf, 0, offset);
            //               
            //               bitmap = BitmapFactory.decodeByteArray(imageBuf, 0, imageBuf.length);
        }

    } catch (IOException e) {
        Log.e(TAG, "error creating InputStream", e);
    } finally {
        if (urlConnection != null)
            urlConnection.disconnect();
        if (httpStream != null) {
            try {
                httpStream.close();
            } catch (IOException e) {
                Log.e(TAG, "IOException while closing http stream", e);
            }
        }
    }

    return bitmap;
}

From source file:com.hector.invoice.views.LieferscheinExportView.java

/**
 * //from w  w w .j  a  v a  2  s.c om
 * init data for screen
 * 
 * @return: void
 * @throws:
 * @author: HaiTC3
 * @date: Nov 3, 2012
 */
public void initData() {
    // show logo
    if (this.companyInfo.logo != null && this.companyInfo.logo.length > 0) {
        Bitmap bm = BitmapFactory.decodeByteArray(this.companyInfo.logo, 0, this.companyInfo.logo.length);
        ivLogo.setImageBitmap(bm);
    }

    // show content 1
    StringBuffer strContent1 = new StringBuffer();
    strContent1.append("Firma \n");
    strContent1.append((invoiceInfo.invoiceOrder.contactInvoice.contactName != null
            ? invoiceInfo.invoiceOrder.contactInvoice.contactName
            : " ") + "\n");
    if (invoiceInfo.invoiceOrder.contactInvoice.sex == ContactDTO.SEX_MALE) {
        strContent1.append("Herr " + (invoiceInfo.invoiceOrder.contactInvoice.firstName != null
                ? invoiceInfo.invoiceOrder.contactInvoice.firstName
                : " ") + "\n");
    } else {
        strContent1.append("Frau " + (invoiceInfo.invoiceOrder.contactInvoice.firstName != null
                ? invoiceInfo.invoiceOrder.contactInvoice.firstName
                : " ") + "\n");
    }
    strContent1.append((invoiceInfo.invoiceOrder.contactInvoice.contactAddress != null
            ? invoiceInfo.invoiceOrder.contactInvoice.contactAddress
            : " ") + "\n");
    strContent1.append((invoiceInfo.invoiceOrder.contactInvoice.contactPLZ != null
            ? (invoiceInfo.invoiceOrder.contactInvoice.contactPLZ + " ")
            : ""));
    strContent1.append((invoiceInfo.invoiceOrder.contactInvoice.contactStadt != null
            ? invoiceInfo.invoiceOrder.contactInvoice.contactStadt
            : ""));

    tvContent1.setText(strContent1.toString());

    // content 2
    StringBuffer strContent2 = new StringBuffer();
    strContent2.append((companyInfo.companyName != null ? companyInfo.companyName : " ") + "\n");
    strContent2.append((companyInfo.companyAddress != null ? companyInfo.companyAddress : " ") + "\n");
    strContent2.append((companyInfo.companyPLZ != null ? companyInfo.companyPLZ : " ") + " "
            + (companyInfo.companyCity != null ? companyInfo.companyCity : " ") + "\n\n");
    strContent2.append("lhre Ansprechpartner/in \n");
    if (companyInfo.sex == ContactDTO.SEX_MALE) {
        strContent2.append("Herr "
                + (companyInfo.certificateOfOrigin != null ? companyInfo.certificateOfOrigin : " ") + "\n");
    } else {
        strContent2.append("Frau "
                + (companyInfo.certificateOfOrigin != null ? companyInfo.certificateOfOrigin : " ") + "\n");
    }
    strContent2
            .append("Tel: " + (this.companyInfo.telephone != null ? this.companyInfo.telephone : " ") + "\n");
    strContent2.append("Fax: " + (this.companyInfo.fax != null ? this.companyInfo.fax : " ") + "\n");
    strContent2.append("Email: " + (this.companyInfo.email != null ? this.companyInfo.email : " ") + "\n");
    tvContent2.setText(strContent2.toString());

    // content 3
    StringBuffer strContent3 = new StringBuffer();
    strContent3.append("Bestellt am: " + (invoiceInfo.invoiceOrder.invoiceOrderInfo.orderedOn != null
            ? invoiceInfo.invoiceOrder.invoiceOrderInfo.orderedOn
            : " ") + "\n");
    strContent3.append("Lieferdatum: " + (invoiceInfo.invoiceOrder.invoiceOrderInfo.delivery != null
            ? invoiceInfo.invoiceOrder.invoiceOrderInfo.delivery
            : " ") + "\n");
    strContent3.append("Kunden-Nr.: " + (invoiceInfo.invoiceOrder.invoiceOrderInfo.customerNumber != null
            ? invoiceInfo.invoiceOrder.invoiceOrderInfo.customerNumber
            : " ") + "\n");
    strContent3.append("Lieferschein-Nr: " + fileName.substring(0, fileName.length() - 4) + "\n");
    tvContent3.setText(strContent3.toString());

    for (int i = 0, size = this.invoiceInfo.listOrderDetail.size(); i < size; i++) {
        InvoiceOrderDetailDTO dto = this.invoiceInfo.listOrderDetail.get(i);

        DisplayItemOrderNumberRow rowOrder = new DisplayItemOrderNumberRow(parentActivity, tblListOrderNumber,
                2);
        rowOrder.etPos.setText(dto.pos);
        rowOrder.etPos.setEnabled(false);
        rowOrder.etMenge.setText(dto.quantity);
        rowOrder.etMenge.setEnabled(false);
        rowOrder.etArtNr.setText(dto.art_nr);
        rowOrder.etArtNr.setEnabled(false);
        rowOrder.etBezeichnung.setText(dto.designation);
        rowOrder.etBezeichnung.setEnabled(false);
        rowOrder.etEinze.setVisibility(View.GONE);
        rowOrder.etGesamt.setVisibility(View.GONE);

        tblListOrderNumber.addView(rowOrder);
    }
}

From source file:com.bitfable.ammocache.download.UrlImageDownloader.java

@Override
protected Bitmap download(String key, WeakReference<ImageView> imageViewRef) {
    URL url;//from w ww  . ja v  a2  s  .  co  m

    try {
        url = new URL(key);
    } catch (MalformedURLException e) {
        Log.e(TAG, "url is malformed: " + key, e);
        return null;
    }

    HttpURLConnection urlConnection;
    try {
        urlConnection = (HttpURLConnection) url.openConnection();
    } catch (IOException e) {
        Log.e(TAG, "error while opening connection", e);
        return null;
    }

    Bitmap bitmap = null;
    InputStream httpStream = null;
    int contentLength;
    int bytesDownloaded = 0;
    try {
        contentLength = urlConnection.getContentLength();
        httpStream = new FlushedInputStream(urlConnection.getInputStream());
        ByteArrayBuffer baf = new ByteArrayBuffer(BYTE_ARRAY_BUFFER_INCREMENTAL_SIZE);
        byte[] buffer = new byte[BYTE_ARRAY_BUFFER_INCREMENTAL_SIZE];
        while (!isCancelled(imageViewRef)) {
            int incrementalRead = httpStream.read(buffer);
            if (incrementalRead == -1) {
                break;
            }
            bytesDownloaded += incrementalRead;
            if (contentLength > 0 || (bytesDownloaded > 0 && bytesDownloaded == contentLength)) {
                int progress = bytesDownloaded * 100 / contentLength;
                publishProgress(progress, imageViewRef);
            }
            baf.append(buffer, 0, incrementalRead);
        }

        if (isCancelled(imageViewRef))
            return null;

        bitmap = BitmapFactory.decodeByteArray(baf.toByteArray(), 0, baf.length());
    } catch (IOException e) {
        Log.e(TAG, "error creating InputStream", e);
    } finally {
        if (urlConnection != null)
            urlConnection.disconnect();
        if (httpStream != null) {
            try {
                httpStream.close();
            } catch (IOException e) {
                Log.e(TAG, "IOException while closing http stream", e);
            }
        }
    }

    return bitmap;
}

From source file:com.hector.invoice.views.AngebotExportView.java

public void initData() {
    // show logo//from  w ww .jav a2s  .  com
    if (this.companyInfo.logo != null && this.companyInfo.logo.length > 0) {
        Bitmap bm = BitmapFactory.decodeByteArray(this.companyInfo.logo, 0, this.companyInfo.logo.length);
        ivLogo.setImageBitmap(bm);
    }

    // show content 1
    StringBuffer strContent1 = new StringBuffer();
    strContent1.append("Firma \n");
    strContent1.append((invoiceInfo.invoiceOrder.contactInvoice.contactName != null
            ? invoiceInfo.invoiceOrder.contactInvoice.contactName
            : " ") + "\n");
    if (invoiceInfo.invoiceOrder.contactInvoice.sex == ContactDTO.SEX_MALE) {
        String nameCus = (invoiceInfo.invoiceOrder.contactInvoice.firstName != null
                ? invoiceInfo.invoiceOrder.contactInvoice.firstName
                : " ")
                + (invoiceInfo.invoiceOrder.contactInvoice.lastName != null
                        ? invoiceInfo.invoiceOrder.contactInvoice.lastName
                        : "")
                + "\n";
        strContent1.append("Herr " + nameCus);
    } else {
        String nameCus = (invoiceInfo.invoiceOrder.contactInvoice.firstName != null
                ? invoiceInfo.invoiceOrder.contactInvoice.firstName
                : " ")
                + (invoiceInfo.invoiceOrder.contactInvoice.lastName != null
                        ? invoiceInfo.invoiceOrder.contactInvoice.lastName
                        : "")
                + "\n";
        strContent1.append("Frau " + nameCus);
    }
    strContent1.append((invoiceInfo.invoiceOrder.contactInvoice.contactAddress != null
            ? invoiceInfo.invoiceOrder.contactInvoice.contactAddress
            : " ") + "\n");
    strContent1.append((invoiceInfo.invoiceOrder.contactInvoice.contactPLZ != null
            ? (invoiceInfo.invoiceOrder.contactInvoice.contactPLZ + " ")
            : ""));
    strContent1.append((invoiceInfo.invoiceOrder.contactInvoice.contactStadt != null
            ? invoiceInfo.invoiceOrder.contactInvoice.contactStadt
            : " "));

    tvContent1.setText(strContent1.toString());

    // content 2
    StringBuffer strContent2 = new StringBuffer();
    strContent2.append((companyInfo.companyName != null ? companyInfo.companyName : " ") + "\n");
    strContent2.append((companyInfo.companyAddress != null ? companyInfo.companyAddress : " ") + "\n");
    strContent2.append((companyInfo.companyPLZ != null ? companyInfo.companyPLZ : " ") + " "
            + (companyInfo.companyCity != null ? companyInfo.companyCity : " ") + "\n \n");
    strContent2.append("lhre Ansprechpartner/in \n");
    if (companyInfo.sex == ContactDTO.SEX_MALE) {
        strContent2.append("Herr "
                + (companyInfo.certificateOfOrigin != null ? companyInfo.certificateOfOrigin : " ") + "\n");
    } else {
        strContent2.append("Frau "
                + (companyInfo.certificateOfOrigin != null ? companyInfo.certificateOfOrigin : " ") + "\n");
    }
    strContent2
            .append("Tel: " + (this.companyInfo.telephone != null ? this.companyInfo.telephone : " ") + "\n");
    strContent2.append("Fax: " + (this.companyInfo.fax != null ? this.companyInfo.fax : " ") + "\n");
    strContent2.append("Email: " + (this.companyInfo.email != null ? this.companyInfo.email : " ") + "\n");
    tvContent2.setText(strContent2.toString());

    // content 3
    StringBuffer strContent3 = new StringBuffer();
    Date currentDateTime = new Date();
    SimpleDateFormat format = null;
    format = new SimpleDateFormat("dd.MM.yyyy");
    String line = "Datum: " + format.format(currentDateTime);
    strContent3.append(line + "\n");
    strContent3.append("Angebotsnr.: " + fileName.substring(0, fileName.length() - 4) + "\n");
    tvContent3.setText(strContent3.toString());

    // table
    double total = 0;
    for (int i = 0, size = this.invoiceInfo.listOrderDetail.size(); i < size; i++) {
        InvoiceOrderDetailDTO dto = this.invoiceInfo.listOrderDetail.get(i);

        DisplayItemOrderNumberRow rowOrder = new DisplayItemOrderNumberRow(parentActivity, tblListOrderNumber,
                1);
        rowOrder.etPos.setText(dto.pos);
        rowOrder.etPos.setEnabled(false);
        rowOrder.etBezeichnung.setText(dto.designation);
        rowOrder.etBezeichnung.setEnabled(false);
        rowOrder.etMenge.setText(dto.quantity);
        rowOrder.etMenge.setEnabled(false);
        rowOrder.etEinze.setText(dto.single_price + " " + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " ");
        rowOrder.etEinze.setEnabled(false);
        total += Double.valueOf(dto.total);
        rowOrder.etGesamt.setText(dto.total + " " + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " ");
        rowOrder.etGesamt.setEnabled(false);
        rowOrder.etArtNr.setVisibility(View.GONE);

        tblListOrderNumber.addView(rowOrder);
    }
    // content 4
    StringBuffer strContent4 = new StringBuffer();
    strContent4.append("Zwischensumme      " + GlobalUtil.getInstance().convertFormatNumberOrder(total) + " "
            + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " " + "\n");
    float vatValue = 0;
    if (!StringUtil.isNullOrEmpty(companyInfo.vatValue)) {
        vatValue = Float.valueOf(companyInfo.vatValue);
    }

    double newTotal = (vatValue * total) / 100;
    // strContent4.append((companyInfo.vatText != null ? companyInfo.vatText
    // : "0 ") + " von " + total + "   " + String.valueOf(newTotal));
    strContent4.append("Mehrwertsteuer " + (companyInfo.vatValue != null ? companyInfo.vatValue : "0 ")
            + "%    von    " + GlobalUtil.getInstance().convertFormatNumberOrder(total) + " "
            + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " " + "   "
            + GlobalUtil.getInstance().convertFormatNumberOrder(newTotal) + " "
            + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " ");
    tvContent4.setText(strContent4.toString());

    // content 5
    StringBuffer strContent5 = new StringBuffer();
    strContent5
            .append("Gesamtsumme:      " + GlobalUtil.getInstance().convertFormatNumberOrder(total + newTotal)
                    + " " + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " ");
    tvContent5.setText(strContent5.toString());
}

From source file:com.ogunwale.android.app.yaps.ui.PhotosSimpleCursorAdapter.java

private void setViewImage(ImageView v, byte[] value) {
    v.setImageBitmap(BitmapFactory.decodeByteArray(value, 0, value.length));
}

From source file:com.librelio.activity.StartupActivity.java

private void loadAndShowAdvertising() {
    AsyncHttpClient client = new AsyncHttpClient();
    client.setTimeout(2000);/*  ww  w.j ava 2 s .  co  m*/
    client.get(getAdvertisingImageURL(), new BinaryHttpResponseHandler() {
        @Override
        public void onSuccess(byte[] bytes) {
            super.onSuccess(bytes);
            EasyTracker.getTracker()
                    .sendView("Interstitial/" + FilenameUtils.getName(getAdvertisingImageURL()));
            if (bytes != null) {
                Bitmap adImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                if (adImage != null) {
                    advertisingImage.setImageBitmap(adImage);
                    if (isFirstImage) {
                        applyRotation(0, 90);
                        isFirstImage = !isFirstImage;
                    } else {
                        applyRotation(0, -90);
                        isFirstImage = !isFirstImage;
                    }
                }
            }
            loadAdvertisingLink();
        }

        @Override
        public void onFailure(Throwable throwable, byte[] bytes) {
            onStartMagazine(DEFAULT_ADV_DELAY);
        }
    });
}

From source file:de.luhmer.owncloudnewsreader.async_tasks.GetImageThreaded.java

@Override
public void run() {
    try {//from   www .  j  a v a2s.c  o  m
        File cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath);

        DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(cont);
        Feed feed = dbConn.getFeedById(ThreadId);
        if (!cacheFile.isFile() || feed.getAvgColour() == null) {
            File dir = new File(rootPath);
            dir.mkdirs();
            cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath);
            //cacheFile.createNewFile();

            /* Open a connection to that URL. */
            URLConnection urlConn = WEB_URL_TO_FILE.openConnection();

            urlConn.setRequestProperty("User-Agent",
                    "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");

            /*
             * Define InputStreams to read from the URLConnection.
             */
            InputStream is = urlConn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);

            /*
             * Read bytes to the Buffer until there is nothing more to read(-1).
             */
            ByteArrayBuffer baf = new ByteArrayBuffer(50);
            int current;
            while ((current = bis.read()) != -1) {
                baf.append((byte) current);
            }

            //If the file is not empty
            if (baf.length() > 0) {
                bmp = BitmapFactory.decodeByteArray(baf.toByteArray(), 0, baf.length());

                FileOutputStream fos = new FileOutputStream(cacheFile);
                fos.write(baf.toByteArray());
                fos.close();
            }
        }
        //return cacheFile.getPath();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    //return bmp;

    if (imageDownloadFinished != null)
        imageDownloadFinished.DownloadFinished(ThreadId, bmp);

    super.run();
}

From source file:com.hector.invoice.views.RechnungExportView.java

public void initData() {
    // show logo//from   ww w . java 2 s .  c  o m
    if (this.companyInfo.logo != null && this.companyInfo.logo.length > 0) {
        Bitmap bm = BitmapFactory.decodeByteArray(this.companyInfo.logo, 0, this.companyInfo.logo.length);
        ivLogo.setImageBitmap(bm);
    }

    // show content 1
    StringBuffer strContent1 = new StringBuffer();
    strContent1.append("Firma \n");
    if (!StringUtil.isNullOrEmpty(invoiceInfo.invoiceOrder.contactInvoice.contactName)) {
        strContent1.append(invoiceInfo.invoiceOrder.contactInvoice.contactName + "\n");
    } else {
        strContent1.append("" + "\n");
    }

    if (invoiceInfo.invoiceOrder.contactInvoice.sex == ContactDTO.SEX_MALE) {
        if (!StringUtil.isNullOrEmpty(invoiceInfo.invoiceOrder.contactInvoice.firstName)) {
            strContent1.append("Herr " + invoiceInfo.invoiceOrder.contactInvoice.firstName + "\n");

        } else {
            strContent1.append("Herr " + " " + "\n");
        }
    } else {
        if (!StringUtil.isNullOrEmpty(invoiceInfo.invoiceOrder.contactInvoice.firstName)) {
            strContent1.append("Frau " + invoiceInfo.invoiceOrder.contactInvoice.firstName + "\n");
        } else {
            strContent1.append("Frau " + " " + "\n");
        }
    }
    if (!StringUtil.isNullOrEmpty(invoiceInfo.invoiceOrder.contactInvoice.contactAddress)) {
        strContent1.append(invoiceInfo.invoiceOrder.contactInvoice.contactAddress + "\n");
    } else {
        strContent1.append(" " + "\n");
    }
    if (!StringUtil.isNullOrEmpty(invoiceInfo.invoiceOrder.contactInvoice.contactPLZ)) {
        strContent1.append(invoiceInfo.invoiceOrder.contactInvoice.contactPLZ);
    } else {
        strContent1.append(" ");
    }
    if (!StringUtil.isNullOrEmpty(invoiceInfo.invoiceOrder.contactInvoice.contactStadt)) {
        strContent1.append(" " + invoiceInfo.invoiceOrder.contactInvoice.contactStadt);
    } else {
        strContent1.append(" ");
    }

    tvContent1.setText(strContent1.toString());

    // content 2
    StringBuffer strContent2 = new StringBuffer();
    if (!StringUtil.isNullOrEmpty(companyInfo.companyName)) {
        strContent2.append(companyInfo.companyName + "\n");
    } else {
        strContent2.append(" " + "\n");
    }
    strContent2.append((companyInfo.companyAddress != null ? companyInfo.companyAddress : " ") + "\n");
    String tmp = companyInfo.companyPLZ != null ? companyInfo.companyPLZ : "";
    if (!StringUtil.isNullOrEmpty(companyInfo.companyCity)) {
        tmp += " " + companyInfo.companyCity != null ? companyInfo.companyCity : "";
    }
    tmp += "\n\n";
    strContent2.append(tmp);
    strContent2.append("lhre Ansprechpartner/in \n");
    if (companyInfo.sex == ContactDTO.SEX_MALE) {
        strContent2.append("Herr "
                + (companyInfo.certificateOfOrigin != null ? companyInfo.certificateOfOrigin : " ") + "\n");
    } else {
        strContent2.append("Frau "
                + (companyInfo.certificateOfOrigin != null ? companyInfo.certificateOfOrigin : " ") + "\n");
    }
    strContent2
            .append("Tel: " + (this.companyInfo.telephone != null ? this.companyInfo.telephone : " ") + "\n");
    strContent2.append("Fax: " + (this.companyInfo.fax != null ? this.companyInfo.fax : " ") + "\n");
    strContent2.append("Email: " + (this.companyInfo.email != null ? this.companyInfo.email : " ") + "\n");
    strContent2.append((this.companyInfo.unitedStatesT != null ? this.companyInfo.unitedStatesT : " ") + "\n");
    tvContent2.setText(strContent2.toString());

    // content 3
    StringBuffer strContent3 = new StringBuffer();
    Date currentDateTime = new Date();
    SimpleDateFormat format = null;
    format = new SimpleDateFormat("dd.MM.yyyy");
    String line = "Datum: " + format.format(currentDateTime);
    strContent3.append(line + "\n");
    strContent3.append("Rechnungsnr: " + fileName.substring(0, fileName.length() - 4) + "\n");
    tvContent3.setText(strContent3.toString());

    // table
    double total = 0;
    for (int i = 0, size = this.invoiceInfo.listOrderDetail.size(); i < size; i++) {
        InvoiceOrderDetailDTO dto = this.invoiceInfo.listOrderDetail.get(i);

        DisplayItemOrderNumberRow rowOrder = new DisplayItemOrderNumberRow(parentActivity, tblListOrderNumber,
                2);
        rowOrder.etPos.setText(dto.pos);
        rowOrder.etPos.setEnabled(false);
        rowOrder.etBezeichnung.setText(dto.designation);
        rowOrder.etBezeichnung.setEnabled(false);
        rowOrder.etMenge.setText(dto.quantity);
        rowOrder.etMenge.setEnabled(false);
        rowOrder.etEinze.setText(dto.single_price + " " + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " ");
        rowOrder.etEinze.setEnabled(false);
        total += Double.valueOf(dto.total);
        rowOrder.etGesamt.setText(dto.total + " " + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " ");
        rowOrder.etGesamt.setEnabled(false);
        rowOrder.etArtNr.setVisibility(View.GONE);

        tblListOrderNumber.addView(rowOrder);
    }

    // content 4
    StringBuffer strContent4 = new StringBuffer();
    strContent4.append("Zwischensumme      " + GlobalUtil.getInstance().convertFormatNumberOrder(total) + " "
            + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " " + "\n");
    float vatValue = 0;
    if (!StringUtil.isNullOrEmpty(companyInfo.vatValue)) {
        vatValue = Float.valueOf(companyInfo.vatValue);
    }
    double newTotal = (vatValue * total) / 100;
    strContent4.append((companyInfo.vatText != null ? companyInfo.vatText : " ") + "      "
            + GlobalUtil.getInstance().convertFormatNumberOrder(newTotal) + " "
            + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " ");
    tvContent4.setText(strContent4.toString());

    // content 5
    StringBuffer strContent5 = new StringBuffer();
    strContent5
            .append("Gesamtsumme:      " + GlobalUtil.getInstance().convertFormatNumberOrder(total + newTotal)
                    + " " + StringUtil.getString(R.string.TEXT_USD_GERMAN) + " ");
    tvContent5.setText(strContent5.toString());

    // content 6
    StringBuffer strContent6 = new StringBuffer();
    strContent6.append((companyInfo.bankCompanyName != null ? companyInfo.bankCompanyName : " "));
    tvContent6.setText(strContent6.toString());

    // content 7
    StringBuffer strContent7 = new StringBuffer();
    strContent7.append("BLZ: " + (companyInfo.bankBLZ != null ? companyInfo.bankBLZ : " ") + "\n");
    strContent7.append("Konto-Nr: " + (companyInfo.bankAcctnum != null ? companyInfo.bankAcctnum : " ") + "\n");
    strContent7.append("Bank: " + (companyInfo.bankName != null ? companyInfo.bankName : " ") + "\n\n");
    strContent7.append(StringUtil.getString(R.string.TEXT5) + "\n\n");
    strContent7.append(StringUtil.getString(R.string.TEXT6) + "\n\n\n\n");
    strContent7.append((companyInfo.staffSale != null ? companyInfo.staffSale : " ") + "\n");
    tvContent7.setText(strContent7.toString());

}

From source file:com.ogunwale.android.app.yaps.ui.PhotosSimpleCursorAdapter.java

private void setLayoutBackground(Context context, RelativeLayout v, byte[] value) {
    Bitmap bitmap = BitmapFactory.decodeByteArray(value, 0, value.length);
    v.setBackground(new BitmapDrawable(v.getContext().getResources(), bitmap));
}

From source file:com.cydroid.coreframe.web.img.fetcher.ImageFetcher.java

public Bitmap getImage(String path) throws Exception {
    URL url = new URL(path);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(10 * 1000);// www  .  j  a  v a 2 s .com
    conn.setConnectTimeout(10 * 1000);
    conn.setRequestMethod("GET");
    InputStream is = null;
    if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
        is = conn.getInputStream();
    } else {
        is = null;
    }
    if (is == null) {
        throw new RuntimeException("stream is null");
    } else {
        try {
            byte[] data = readStream(is);
            if (data != null) {
                Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                return bitmap;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        is.close();
        return null;
    }
}