List of usage examples for android.graphics BitmapFactory decodeFile
public static Bitmap decodeFile(String pathName)
From source file:com.intel.xdk.camera.Camera.java
private void savePicture(final String outputFile, final int quality, final boolean isPNG) { //busy could be false if activity had been stopped busy = true;// w w w . j a va 2 s . co m try { String dir = pictureDir(); File dirFile = new File(dir); if (!dirFile.exists()) dirFile.mkdirs(); String baseName = getNextPictureFile(isPNG); String filePath = String.format("%1$s/%2$s", dir, baseName); try { if (debug) System.out.println("AppMobiCamera.takePicture: file = " + filePath); OutputStream out = new BufferedOutputStream(new FileOutputStream(filePath), 0x8000); Bitmap bitMap = BitmapFactory.decodeFile(outputFile); if (bitMap == null || !bitMap .compress((isPNG ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG), 70, out)) { throw new IOException("Error converting to PNG"); } bitMap.recycle(); out.close(); fireJSEvent("camera.internal.picture.add", true, null, new String[] { String.format("ev.filename='%1$s';", baseName) }); fireJSEvent("camera.picture.add", true, null, new String[] { String.format("ev.filename='%1$s';", baseName) }); callbackContext.success(""); } catch (IOException e) { postAddError(baseName); if (debug) System.out.println("AppMobiCamera.takePicture err: " + e.getMessage()); } finally { callbackContext = null; busy = false; } } catch (Exception e) { //sometimes a NPE occurs after resuming, catch it here but do nothing if (Debug.isDebuggerConnected()) Log.e("[intel.xdk]", "handled camera resume NPE:\n" + e.getMessage(), e); } }
From source file:com.mercandalli.android.apps.files.main.Config.java
public static Bitmap getUserProfilePicture(Activity activity) { File file = new File(activity.getFilesDir() + "/file_" + getUserIdFileProfilePicture()); if (file.exists()) { return BitmapFactory.decodeFile(file.getPath()); } else if (NetUtils.isInternetConnection(activity)) { FileModel.FileModelBuilder fileModelBuilder = new FileModel.FileModelBuilder(); fileModelBuilder.id(getUserIdFileProfilePicture()); new TaskGetDownloadImage(activity, fileModelBuilder.build(), 100_000, new IBitmapListener() { @Override//www . j av a 2 s .c o m public void execute(Bitmap bitmap) { //TODO photo profile } }).execute(); } return null; }
From source file:com.miloisbadboy.net.Utility.java
public static String openUrl(Context context, String url, String method, RequestParameters params, String file) throws RequestException { String result = ""; try {/*from ww w. j a v a 2 s . c om*/ HttpClient client = getNewHttpClient(context); HttpUriRequest request = null; ByteArrayOutputStream bos = null; if (method.equals("GET")) { url = url + "?" + encodeUrl(params); HttpGet get = new HttpGet(url); request = get; } else if (method.equals("POST")) { HttpPost post = new HttpPost(url); byte[] data = null; bos = new ByteArrayOutputStream(1024 * 50); if (!TextUtils.isEmpty(file)) { Utility.paramToUpload(bos, params); post.setHeader("Content-Type", MULTIPART_FORM_DATA + "; boundary=" + BOUNDARY); Bitmap bf = BitmapFactory.decodeFile(file); Utility.imageContentToUpload(bos, bf); } else { post.setHeader("Content-Type", "application/x-www-form-urlencoded"); String postParam = encodeParameters(params); data = postParam.getBytes("UTF-8"); bos.write(data); } data = bos.toByteArray(); bos.close(); // UrlEncodedFormEntity entity = getPostParamters(params); ByteArrayEntity formEntity = new ByteArrayEntity(data); post.setEntity(formEntity); request = post; } else if (method.equals("DELETE")) { request = new HttpDelete(url); } setHeader(method, request, params, url); HttpResponse response = client.execute(request); StatusLine status = response.getStatusLine(); int statusCode = status.getStatusCode(); if (statusCode != 200) { result = read(response); throw new RequestException(String.format(status.toString()), statusCode); } // parse content stream from response result = read(response); return result; } catch (IOException e) { throw new RequestException(e); } }
From source file:com.mifos.mifosxdroid.online.ClientDetailsFragment.java
/** * A service to upload the image of the client. * * @param pngFile - PNG images supported at the moment *///w w w .ja v a2 s.co m private void uploadImage(File pngFile) { final String imagePath = pngFile.getAbsolutePath(); pb_imageProgressBar.setVisibility(VISIBLE); App.apiManager.uploadClientImage(clientId, new TypedFile("image/png", pngFile), new Callback<Response>() { @Override public void success(Response response, Response response2) { Toaster.show(rootView, R.string.client_image_updated); iv_clientImage.setImageBitmap(BitmapFactory.decodeFile(imagePath)); pb_imageProgressBar.setVisibility(GONE); } @Override public void failure(RetrofitError retrofitError) { Toaster.show(rootView, "Failed to update image"); imageLoadingAsyncTask = new ImageLoadingAsyncTask(); imageLoadingAsyncTask.execute(clientId); } }); }
From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java
private Bitmap getIconBitmap(Context context, String iconUrl) { try {/*from ww w.ja va 2 s . c o m*/ URL uRL = new URL(iconUrl); HttpURLConnection connection = (HttpURLConnection) uRL.openConnection(); String cookie = CookieManager.getInstance().getCookie(iconUrl); if (null != cookie) { connection.setRequestProperty(SM.COOKIE, cookie); } connection.connect(); if (200 == connection.getResponseCode()) { InputStream input = connection.getInputStream(); if (input != null) { Environment.getDownloadCacheDirectory(); File ecd = context.getExternalCacheDir(); File file = new File(ecd, "pushIcon.png"); OutputStream outStream = new FileOutputStream(file); byte buf[] = new byte[8 * 1024]; while (true) { int numread = input.read(buf); if (numread == -1) { break; } outStream.write(buf, 0, numread); } Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); return bitmap; } } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.roamprocess1.roaming4world.ui.messages.MessageAdapter.java
@SuppressLint("SdCardPath") @Override/*w ww .j a v a 2s . c om*/ public void bindView(View view, Context context, Cursor cursor) { System.out.println("MessageAdapter.java in bindView() "); final MessageListItemViews tagView = (MessageListItemViews) view.getTag(); v = view; this.context = context; SipMessage msg = new SipMessage(cursor); // System.out.println("msg:"+msg); System.out.println("Cursor row count:" + cursor.getCount()); String number = msg.getRemoteNumber(); long date = msg.getDate(); String message = msg.getBodyContent(); subject = message; System.out.println("subject--" + subject); if (message.contains("[Offline message -") && !number.equals("sip:registrar@kamailio.org")) { System.out.println("offline message"); String[] finalMessage = message.split("]"); subject = finalMessage[finalMessage.length - 1]; } else { subject = message; } String errorTxt = msg.getErrorContent(); String mimeType = msg.getMimeType(); int type = msg.getType(); Log.setLogLevel(6); Log.d("Col count", cursor.getColumnCount() + " @"); String[] columnname = cursor.getColumnNames(); for (int i = 0; i < columnname.length; i++) { Log.d("columnname " + i, columnname[i] + " @"); Log.d(columnname[i], cursor.getString(cursor.getColumnIndex(columnname[i])) + " @"); } tv_msg_info = (TextView) view.findViewById(R.id.tv_msg_info); pb_uploading = (ProgressBar) view.findViewById(R.id.pb_uploading); String timestamp = ""; if (System.currentTimeMillis() - date > 1000 * 60 * 60 * 24) { // If it was recieved one day ago or more display relative // timestamp - SMS like behavior int flags = DateUtils.FORMAT_ABBREV_RELATIVE; timestamp = (String) DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags); } else { // If it has been recieved recently show time of reception - IM // like behavior timestamp = dateFormatter.format(new Date(date)); } tagView.dateView.setText(timestamp); // Delivery state if (type == SipMessage.MESSAGE_TYPE_QUEUED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.error_watch_not_send); tagView.deliveredIndicator.setContentDescription(""); } else if (type == SipMessage.MESSAGE_TYPE_FAILED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.error_watch_not_send); tagView.deliveredIndicator.setContentDescription(""); } else { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.todo_send); tagView.deliveredIndicator.setContentDescription(""); } if (TextUtils.isEmpty(errorTxt)) { tagView.errorView.setVisibility(View.GONE); } else { tagView.errorView.setVisibility(View.GONE); tagView.errorView.setText(errorTxt); } // Subject tagView.contentView.setText(formatMessage(number, subject, mimeType)); if (msg.isOutgoing()) { setPhotoSide(tagView, ArrowPosition.LEFT); LinearLayout linerLayout = (LinearLayout) view.findViewById(R.id.message_block); linerLayout.setBackgroundResource(R.drawable.chatedittextdesign); text_view = (TextView) view.findViewById(R.id.text_view); text_view.setTextColor(Color.BLACK); // Photo tagView.quickContactView.assignContactUri(personalInfo.contactContentUri); /* ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, R.drawable.ic_contact_picture_holo_dark); */ System.out.println("msg adp out - 0"); String path = "/sdcard/R4W/ProfilePic/ProfilePic.png"; File user_imageFile = new File(path); if (user_imageFile.exists()) { try { if (bm != null) { // bm = null; } bm = BitmapFactory.decodeFile(path); bm = ImageHelperCircular.getRoundedCornerBitmap(bm, bm.getWidth()); tagView.quickContactView.getImageView().setImageBitmap(bm); } catch (Exception e) { // TODO: handle exception try { tagView.quickContactView.getImageView().setImageURI(Uri.parse(path)); } catch (Exception e2) { ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, R.drawable.ic_contact_picture_holo_dark); // TODO: handle exception } } } else { ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, R.drawable.ic_contact_picture_holo_dark); } outgoingImage(number); } else { setPhotoSide(tagView, ArrowPosition.RIGHT); LinearLayout linerLayout = (LinearLayout) view.findViewById(R.id.message_block); linerLayout.setBackgroundResource(R.drawable.messagebodyleft); // Contact CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, msg.getFullFrom()); text_view = (TextView) view.findViewById(R.id.text_view); text_view.setTextColor(Color.BLACK); pb_uploading.setVisibility(ProgressBar.GONE); // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); /* ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); */ System.out.println("msg adp in - 1"); String nu = stripNumber(number); String path = "/sdcard/R4W/ProfilePic/" + nu + ".png"; System.out.println("msg adp out - path=" + path); File user_imageFile = new File(path); if (user_imageFile.exists()) { try { if (bm != null) { // bm = null; } bm = BitmapFactory.decodeFile(path); bm = ImageHelperCircular.getRoundedCornerBitmap(bm, bm.getWidth()); tagView.quickContactView.getImageView().setImageBitmap(bm); } catch (Exception e) { // TODO: handle exception try { tagView.quickContactView.getImageView().setImageURI(Uri.parse(path)); } catch (Exception e2) { ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); // TODO: handle exception } } } else { ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); } incomingImage(); } }
From source file:com.eastedge.readnovel.weibo.net.Utility.java
public static String openUrl(Context context, String url, String method, WeiboParameters params, String file, Token token) throws WeiboException { String result = ""; try {/* w ww . ja v a2 s . c o m*/ HttpClient client = getNewHttpClient(context); HttpUriRequest request = null; ByteArrayOutputStream bos = null; if (method.equals("GET")) { url = url + "?" + encodeUrl(params); HttpGet get = new HttpGet(url); request = get; } else if (method.equals("POST")) { HttpPost post = new HttpPost(url); byte[] data = null; bos = new ByteArrayOutputStream(1024 * 50); if (!TextUtils.isEmpty(file)) { Utility.paramToUpload(bos, params); post.setHeader("Content-Type", MULTIPART_FORM_DATA + "; boundary=" + BOUNDARY); Bitmap bf = BitmapFactory.decodeFile(file); Utility.imageContentToUpload(bos, bf); } else { post.setHeader("Content-Type", "application/x-www-form-urlencoded"); String postParam = encodeParameters(params); data = postParam.getBytes("UTF-8"); bos.write(data); } data = bos.toByteArray(); bos.close(); // UrlEncodedFormEntity entity = getPostParamters(params); ByteArrayEntity formEntity = new ByteArrayEntity(data); post.setEntity(formEntity); request = post; } else if (method.equals("DELETE")) { request = new HttpDelete(url); } setHeader(method, request, params, url, token); HttpResponse response = client.execute(request); StatusLine status = response.getStatusLine(); int statusCode = status.getStatusCode(); if (statusCode != 200) { result = read(response); throw new WeiboException(String.format(status.toString()), statusCode); } // parse content stream from response result = read(response); return result; } catch (IOException e) { throw new WeiboException(e); } }
From source file:com.viettel.view.MainHome.SelectEventPlace.java
public Bitmap getBitmapPlaceIcon(String urlIcon) { Bitmap bm = BitmapFactory.decodeFile(urlIcon); return bm; }
From source file:it.iziozi.iziozi.gui.IOBoardFragment.java
private View buildView(boolean editMode) { this.homeRows.clear(); final List<IOSpeakableImageButton> mButtons = new ArrayList<IOSpeakableImageButton>(); List<IOSpeakableImageButton> configButtons = this.mBoard.getButtons(); ViewGroup mainView = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.table_main_layout, null);/* ww w.j ava2 s . com*/ LinearLayout tableContainer = new LinearLayout(getActivity()); LinearLayout.LayoutParams mainParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); tableContainer.setLayoutParams(mainParams); tableContainer.setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < this.mBoard.getRows(); i++) { LinearLayout rowLayout = new LinearLayout(getActivity()); LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.f); rowLayout.setLayoutParams(rowParams); rowLayout.setOrientation(LinearLayout.HORIZONTAL); Random color = new Random(); rowLayout.setBackgroundColor(Color.WHITE); tableContainer.addView(rowLayout); this.homeRows.add(rowLayout); } for (int j = 0; j < this.homeRows.size(); j++) { LinearLayout homeRow = this.homeRows.get(j); for (int i = 0; i < this.mBoard.getCols(); i++) { LinearLayout btnContainer = new LinearLayout(getActivity()); LinearLayout.LayoutParams btnContainerParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1.f); btnContainer.setLayoutParams(btnContainerParams); btnContainer.setOrientation(LinearLayout.VERTICAL); btnContainer.setGravity(Gravity.CENTER); homeRow.addView(btnContainer); final IOSpeakableImageButton imgButton = (configButtons.size() > 0 && configButtons.size() > mButtons.size()) ? configButtons.get(mButtons.size()) : new IOSpeakableImageButton(getActivity()); imgButton.setmContext(getActivity()); imgButton.setShowBorder(IOConfiguration.getShowBorders()); if (IOGlobalConfiguration.isEditing) imgButton.setImageDrawable(getResources().getDrawable(R.drawable.logo_org)); else imgButton.setImageDrawable(null); imgButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imgButton.setBackgroundColor(Color.TRANSPARENT); if (imgButton.getmImageFile() != null && imgButton.getmImageFile().length() > 0) { if (!new File(imgButton.getmImageFile()).exists()) { if (mAlertDialog == null || !mAlertDialog.isShowing()) { mAlertDialog = new AlertDialog.Builder(getActivity()).setCancelable(true) .setTitle(getString(R.string.image_missing)) .setMessage(getString(R.string.image_missing_text)) .setNegativeButton(getString(R.string.continue_string), null).create(); mAlertDialog.show(); } //download image if (isExternalStorageReadable()) { File baseFolder = new File(Environment.getExternalStorageDirectory() + "/" + IOApplication.APPLICATION_FOLDER + "/pictograms"); Character pictoChar = imgButton.getmImageFile() .charAt(imgButton.getmImageFile().lastIndexOf("/") + 1); File pictoFolder = new File(baseFolder + "/" + pictoChar + "/"); if (isExternalStorageWritable()) { pictoFolder.mkdirs(); //download it AsyncHttpClient client = new AsyncHttpClient(); client.get(imgButton.getmUrl(), new FileAsyncHttpResponseHandler(new File(imgButton.getmImageFile())) { @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, File file) { Toast.makeText(getActivity(), getString(R.string.download_error) + file.toString(), Toast.LENGTH_LONG).show(); } @Override public void onSuccess(int statusCode, Header[] headers, File downloadedFile) { if (new File(imgButton.getmImageFile()).exists()) { imgButton.setImageBitmap( BitmapFactory.decodeFile(imgButton.getmImageFile())); } else { Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_SHORT).show(); } } }); } else { Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_SHORT) .show(); } } else imgButton.setImageBitmap(BitmapFactory.decodeFile(imgButton.getmImageFile())); } ViewGroup parent = (ViewGroup) imgButton.getParent(); if (parent != null) parent.removeAllViews(); btnContainer.addView(imgButton); mButtons.add(imgButton); imgButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int index = mButtons.indexOf(v); if (mListener != null) mListener.tapOnSpeakableButton(mButtons.get(index), mBoardLevel); } }); } } this.mBoard.setButtons(mButtons.size() > configButtons.size() ? mButtons : configButtons); return tableContainer; }
From source file:com.weibo.net.Utility.java
public static String openUrl(Context context, String url, String method, WeiboParameters params, String file, Token token) throws WeiboException { String result = ""; try {/*from www .jav a 2 s . c o m*/ HttpClient client = getNewHttpClient(context); HttpUriRequest request = null; ByteArrayOutputStream bos = null; if (method.equals("GET")) { url = url + "?" + encodeUrl(params); HttpGet get = new HttpGet(url); request = get; } else if (method.equals("POST")) { HttpPost post = new HttpPost(url); byte[] data = null; bos = new ByteArrayOutputStream(1024 * 50); if (!TextUtils.isEmpty(file)) { Utility.paramToUpload(bos, params); post.setHeader("Content-Type", MULTIPART_FORM_DATA + "; boundary=" + BOUNDARY); Bitmap bf = BitmapFactory.decodeFile(file); Utility.imageContentToUpload(bos, bf); } else { post.setHeader("Content-Type", "application/x-www-form-urlencoded"); String postParam = encodeParameters(params); data = postParam.getBytes("UTF-8"); bos.write(data); } data = bos.toByteArray(); bos.close(); // UrlEncodedFormEntity entity = getPostParamters(params); ByteArrayEntity formEntity = new ByteArrayEntity(data); post.setEntity(formEntity); request = post; } else if (method.equals("DELETE")) { request = new HttpDelete(url); } setHeader(method, request, params, url, token); HttpResponse response = client.execute(request); StatusLine status = response.getStatusLine(); int statusCode = status.getStatusCode(); if (statusCode != 200) { result = read(response); String err = null; int errCode = 0; try { JSONObject json = new JSONObject(result); err = json.getString("error"); errCode = json.getInt("error_code"); } catch (JSONException e) { e.printStackTrace(); } throw new WeiboException(String.format(err), errCode); } // parse content stream from response result = read(response); return result; } catch (IOException e) { throw new WeiboException(e); } }