Example usage for android.util Base64 DEFAULT

List of usage examples for android.util Base64 DEFAULT

Introduction

In this page you can find the example usage for android.util Base64 DEFAULT.

Prototype

int DEFAULT

To view the source code for android.util Base64 DEFAULT.

Click Source Link

Document

Default values for encoder/decoder flags.

Usage

From source file:com.sogrey.sinaweibo.utils.FileUtil.java

/**
 * ?Base64/*from   ww w. j a v  a 2s. c  o  m*/
 * 
 * @author Sogrey
 * @date 2015723
 * @param path
 * @return
 */
public static String getBase64FromPath(String path) {
    String base64 = "";
    try {
        File file = new File(path);
        byte[] buffer = new byte[(int) file.length() + 100];
        @SuppressWarnings("resource")
        int length = new FileInputStream(file).read(buffer);
        base64 = Base64.encodeToString(buffer, 0, length, Base64.DEFAULT);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return base64;
}

From source file:ch.ethz.twimight.net.opportunistic.ScanningService.java

/**
 * Creates content values for a User from a JSON object TODO: Move this to
 * where it belongs/*from  w ww .  ja va2s .  co  m*/
 * 
 * @param o
 * @return
 * @throws JSONException
 */
protected ContentValues getUserCV(JSONObject o) throws JSONException {

    // create the content values for the user
    ContentValues cv = new ContentValues();
    String screenName = null;

    if (o.has(TwitterUsers.COL_SCREEN_NAME)) {
        screenName = o.getString(TwitterUsers.COL_SCREEN_NAME);
        cv.put(TwitterUsers.COL_SCREEN_NAME, o.getString(TwitterUsers.COL_SCREEN_NAME));
    }

    if (o.has(TwitterUsers.JSON_FIELD_PROFILE_IMAGE) && screenName != null) {
        InternalStorageHelper helper = new InternalStorageHelper(getBaseContext());
        byte[] image = Base64.decode(o.getString(TwitterUsers.JSON_FIELD_PROFILE_IMAGE), Base64.DEFAULT);
        helper.writeImage(image, screenName);
        String profileImageUri = Uri.fromFile(new File(getFilesDir(), screenName)).toString();
        Log.d(TAG, "storing profile image at: " + profileImageUri);
        cv.put(TwitterUsers.COL_PROFILE_IMAGE_URI, profileImageUri);
    }

    if (o.has(Tweets.COL_USER_TID)) {
        cv.put(TwitterUsers.COL_TWITTER_USER_ID, o.getLong(Tweets.COL_USER_TID));

    }
    cv.put(TwitterUsers.COL_IS_DISASTER_PEER, 1);

    return cv;
}

From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java

private String encodeBitmap(Bitmap bitmap) {
    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    BufferedOutputStream out = new BufferedOutputStream(bytesOut);
    bitmap.compress(CompressFormat.JPEG, 50, out);
    return Base64.encodeToString(bytesOut.toByteArray(), Base64.DEFAULT);
}

From source file:com.vkassin.mtrade.Common.java

public static void putOrder(final Context ctx, Quote quote) {

    final Instrument it = Common.selectedInstrument;// adapter.getItem(selectedRowId);

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.order_dialog);
    dialog.setTitle(R.string.OrderDialogTitle);

    datetxt = (EditText) dialog.findViewById(R.id.expdateedit);
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dat1 = new Date();
    datetxt.setText(sdf.format(dat1));/*from  w  w w  .j  a va  2  s  .c  o  m*/
    mYear = dat1.getYear() + 1900;
    mMonth = dat1.getMonth();
    mDay = dat1.getDate();
    final Date dat = new GregorianCalendar(mYear, mMonth, mDay).getTime();

    datetxt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i(TAG, "Show DatePickerDialog");
            DatePickerDialog dpd = new DatePickerDialog(ctx, mDateSetListener, mYear, mMonth, mDay);
            dpd.show();
        }
    });

    TextView itext = (TextView) dialog.findViewById(R.id.instrtext);
    itext.setText(it.symbol);

    final Spinner aspinner = (Spinner) dialog.findViewById(R.id.acc_spinner);
    List<String> list = new ArrayList<String>(Common.getAccountList());
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(Common.app_ctx,
            android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    aspinner.setAdapter(dataAdapter);

    final EditText pricetxt = (EditText) dialog.findViewById(R.id.priceedit);
    final EditText quanttxt = (EditText) dialog.findViewById(R.id.quantedit);

    final Button buttonpm = (Button) dialog.findViewById(R.id.buttonPriceMinus);
    buttonpm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                double price = Double.valueOf(pricetxt.getText().toString());
                price -= 0.01;
                if (price < 0)
                    price = 0;
                pricetxt.setText(twoDForm.format(price));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final Button buttonpp = (Button) dialog.findViewById(R.id.buttonPricePlus);
    buttonpp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                double price = Double.valueOf(pricetxt.getText().toString());
                price += 0.01;
                pricetxt.setText(twoDForm.format(price));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final Button buttonqm = (Button) dialog.findViewById(R.id.buttonQtyMinus);
    buttonqm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                long qty = Long.valueOf(quanttxt.getText().toString());
                qty -= 1;
                if (qty < 0)
                    qty = 0;
                quanttxt.setText(String.valueOf(qty));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final Button buttonqp = (Button) dialog.findViewById(R.id.buttonQtyPlus);
    buttonqp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                long qty = Long.valueOf(quanttxt.getText().toString());
                qty += 1;
                quanttxt.setText(String.valueOf(qty));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.radio0);
    final RadioButton bu1 = (RadioButton) dialog.findViewById(R.id.radio1);

    if (quote != null) {

        // pricetxt.setText(quote.price.toString());
        pricetxt.setText(quote.getPriceS());
        if (quote.qtyBuy > 0) {

            quanttxt.setText(quote.qtyBuy.toString());
            bu1.setChecked(true);
            bu0.setChecked(false);

        } else {

            quanttxt.setText(quote.qtySell.toString());
            bu1.setChecked(false);
            bu0.setChecked(true);

        }
    }

    Button customDialog_Cancel = (Button) dialog.findViewById(R.id.cancelbutt);
    customDialog_Cancel.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.dismiss();
        }

    });

    Button customDialog_Put = (Button) dialog.findViewById(R.id.putorder);
    customDialog_Put.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            Double price = new Double(0);
            Long qval = new Long(0);

            try {

                price = Double.valueOf(pricetxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
                return;
            }
            try {

                qval = Long.valueOf(quanttxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
                return;
            }

            if (dat.compareTo(new GregorianCalendar(mYear, mMonth, mDay).getTime()) > 0) {

                Toast.makeText(ctx, R.string.CorrectDate, Toast.LENGTH_SHORT).show();

                return;

            }

            JSONObject msg = new JSONObject();
            try {

                msg.put("objType", Common.CREATE_REMOVE_ORDER);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("device", "Android");
                msg.put("instrumId", Long.valueOf(it.id));
                msg.put("price", price);
                msg.put("qty", qval);
                msg.put("ordType", 1);
                msg.put("side", bu0.isChecked() ? 0 : 1);
                msg.put("code", String.valueOf(aspinner.getSelectedItem()));
                msg.put("orderNum", ++ordernum);
                msg.put("action", "CREATE");
                boolean b = (((mYear - 1900) == dat.getYear()) && (mMonth == dat.getMonth())
                        && (mDay == dat.getDate()));
                if (!b)
                    msg.put("expired", String.format("%02d.%02d.%04d", mDay, mMonth + 1, mYear));

                if (isSSL) {

                    //                ? ?:    newOrder-orderNum-instrumId-side-price-qty-code-ordType
                    //               :                  newOrder-16807-20594623-0-1150-13-1027700451-1
                    String forsign = "newOrder-" + ordernum + "-" + msg.getString("instrumId") + "-"
                            + msg.getString("side") + "-"
                            + JSONObject.numberToString(Double.valueOf(msg.getDouble("price"))) + "-"
                            + msg.getString("qty") + "-" + msg.getString("code") + "-"
                            + msg.getString("ordType");
                    byte[] signed = Common.signText(Common.signProfile, forsign.getBytes(), true);
                    String gsign = Base64.encodeToString(signed, Base64.DEFAULT);
                    msg.put("gostSign", gsign);
                }
                mainActivity.writeJSONMsg(msg);

            } catch (Exception e) {

                e.printStackTrace();
                Log.e(TAG, "Error! Cannot create JSON order object", e);
            }

            dialog.dismiss();
        }

    });

    dialog.show();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    dialog.getWindow().setAttributes(lp);

}

From source file:org.cryptsecure.Utility.java

/**
 * Convert BASE64 to string./*w  w w .  j ava  2 s  . c o  m*/
 * 
 * @param encodedString
 *            the encoded string
 * @return the string
 */
public static String convertBASE64ToString(String encodedString) {
    return new String(Base64.decode(encodedString.getBytes(), Base64.DEFAULT));
}

From source file:org.cryptsecure.Utility.java

/**
 * Convert string to BASE64//from   w  ww  .  java  2  s. com
 * 
 * @param originalString
 *            the original string
 * @return the string
 */
public static String convertStringToBASE64(String originalString) {
    return Base64.encodeToString(originalString.getBytes(), Base64.DEFAULT);
}

From source file:com.annanovas.bestprice.DashBoardEditActivity.java

public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality) {
    ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
    image.compress(compressFormat, quality, byteArrayOS);
    return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT);
}

From source file:org.cryptsecure.Utility.java

/**
 * Gets the resized image as BASE64 string.
 * /*from w  ww  . j a  va 2s .  c  o m*/
 * @param context
 *            the context
 * @param attachmentPath
 *            the attachment path
 * @param maxWidth
 *            the max width
 * @param maxHeight
 *            the max height
 * @param quality
 *            the quality
 * @return the resized image as bas e64 string
 */
public static String getResizedImageAsBASE64String(Context context, Bitmap bitmap, int maxWidth, int maxHeight,
        int quality, boolean clipped) {
    // byte[] bytes = Utility.getFile(attachmentPath);
    // Bitmap bitmap = Utility.getBitmapFromBytes(bytes);
    Bitmap resizedBitmap = Utility.getResizedImage(bitmap, maxWidth, maxHeight, false, clipped);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    resizedBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
    byte[] byteArray = stream.toByteArray();
    String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
    return encoded;
}

From source file:org.cryptsecure.Utility.java

/**
 * Reads a file and encodes the bytes with BASE64 for transmission.
 * //from   www. j  a  va  2s .c o  m
 * @param attachmentPath
 *            the attachment path
 * @return the encoded image
 */
public static String getEncodedFile(String attachmentPath) {
    try {
        byte[] bytes = getFile(attachmentPath);
        String encodedFile = Base64.encodeToString(bytes, Base64.DEFAULT);
        return encodedFile;
    } catch (Exception e) {
        // Ignore, return null
        e.printStackTrace();
    }
    return null;
}

From source file:com.colorchen.qbase.utils.FileUtil.java

public static String file2Base64(String filePath) {
    FileInputStream fis = null;//from   w  w w  .  ja v  a  2s.  c  o  m
    String base64String = "";
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        fis = new FileInputStream(filePath);
        byte[] buffer = new byte[1024 * 100];
        int count = 0;
        while ((count = fis.read(buffer)) != -1) {
            bos.write(buffer, 0, count);
        }
        fis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    base64String = Base64.encodeToString(bos.toByteArray(), Base64.DEFAULT);
    return base64String;

}