List of usage examples for java.lang OutOfMemoryError printStackTrace
public void printStackTrace()
From source file:cl.ipp.katbag.fragment.Player.java
@SuppressWarnings("deprecation") public void setPictureBackground(String type_world, int scaleFactor, long id_world) { // Get the dimensions of the View int targetW = playerView.getWidth(); int targetH = playerView.getHeight(); // Get the dimensions of the bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image if (scaleFactor == -1) { if (photoW != 0 && targetW != 0 && photoH != 0 && targetH != 0) scaleFactor = Math.min(photoW / targetW, photoH / targetH); else/*w w w .j a v a 2s. c o m*/ scaleFactor = 1; mainActivity.katbagHandler.updateWorld(id_world, type_world, mCurrentPhotoPath, scaleFactor); } // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true; Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); try { bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath); } catch (OutOfMemoryError e2) { e2.printStackTrace(); // handle gracefully. } } BitmapDrawable background = new BitmapDrawable(mainActivity.context.getResources(), bitmap); playerView.setBackgroundDrawable(background); }
From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedPost.java
private void downloadThumbnail(final Context context, final int widthPixels, final CacheManager cm, final int listId, final boolean highRes) { final String uriStr = highRes ? imageUrl : thumbnailUrl; final URI uri = General.uriFromString(uriStr); final int priority = highRes ? Constants.Priority.IMAGE_PRECACHE : Constants.Priority.THUMBNAIL; final int fileType = highRes ? Constants.FileType.IMAGE : Constants.FileType.THUMBNAIL; final RedditAccount anon = RedditAccountManager.getAnon(); cm.makeRequest(new CacheRequest(uri, anon, null, priority, listId, CacheRequest.DownloadType.IF_NECESSARY, fileType, false, false, false, context) { @Override/*from ww w . j a v a2 s. c om*/ protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { } @Override protected void onCallbackException(final Throwable t) { // TODO handle -- internal error throw new RuntimeException(t); } @Override protected void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { } @Override protected void onProgress(final long bytesRead, final long totalBytes) { } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, final long timestamp, final UUID session, final boolean fromCache, final String mimetype) { // The lock avoids using too much memory synchronized (singleImageDecodeLock) { if (gotHighResThumb && !highRes) return; try { final Bitmap data = BitmapFactory.decodeStream(cacheFile.getInputStream()); if (data == null) return; thumbnailCache = ThumbnailScaler.scale(data, widthPixels); if (thumbnailCache != data) data.recycle(); if (highRes) gotHighResThumb = true; if (thumbnailCallback != null) thumbnailCallback.betterThumbnailAvailable(thumbnailCache, usageId); } catch (OutOfMemoryError e) { // TODO handle this better - disable caching of images Log.e("RedditPreparedPost", "Out of memory trying to download image"); e.printStackTrace(); return; } catch (Throwable t) { // Just ignore it. } } } }); }
From source file:de.baumann.browser.Browser_right.java
private void screenshot() { shareFile = helper_main.newFile(mWebView); try {/*from w w w .j a v a 2s . c o m*/ mWebView.measure( View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); mWebView.layout(0, 0, mWebView.getMeasuredWidth(), mWebView.getMeasuredHeight()); mWebView.setDrawingCacheEnabled(true); mWebView.buildDrawingCache(); bitmap = Bitmap.createBitmap(mWebView.getMeasuredWidth(), mWebView.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); int iHeight = bitmap.getHeight(); canvas.drawBitmap(bitmap, 0, iHeight, paint); mWebView.draw(canvas); } catch (OutOfMemoryError e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_screenshot_failed, Snackbar.LENGTH_SHORT).show(); } if (bitmap != null) { try { OutputStream fOut; fOut = new FileOutputStream(shareFile); bitmap.compress(Bitmap.CompressFormat.PNG, 50, fOut); fOut.flush(); fOut.close(); bitmap.recycle(); Snackbar snackbar = Snackbar .make(mWebView, getString(R.string.context_saveImage_toast) + " " + shareFile.getName() + ". " + getString(R.string.app_open), Snackbar.LENGTH_LONG) .setAction(getString(R.string.toast_yes), new View.OnClickListener() { @Override public void onClick(View view) { helper_main.switchToActivity(Browser_right.this, Popup_files.class, "", false); } }); snackbar.show(); Uri uri = Uri.fromFile(shareFile); Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri); sendBroadcast(intent); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } } }
From source file:org.lol.reddit.reddit.prepared.RedditPreparedPost.java
private void downloadThumbnail(final Context context, final int widthPixels, final CacheManager cm, final int listId, final boolean highRes) { final String uriStr = highRes ? imageUrl : thumbnailUrl; final URI uri = General.uriFromString(uriStr); final int priority = highRes ? Constants.Priority.IMAGE_PRECACHE : Constants.Priority.THUMBNAIL; final int fileType = highRes ? Constants.FileType.IMAGE : Constants.FileType.THUMBNAIL; final RedditAccount anon = RedditAccountManager.getAnon(); cm.makeRequest(new CacheRequest(uri, anon, null, priority, listId, CacheRequest.DownloadType.IF_NECESSARY, fileType, false, false, false, context) { @Override//from w w w . j ava2s. c om protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { } @Override protected void onCallbackException(final Throwable t) { // TODO handle -- internal error throw new RuntimeException(t); } @Override protected void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { } @Override protected void onProgress(final long bytesRead, final long totalBytes) { } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, final long timestamp, final UUID session, final boolean fromCache, final String mimetype) { if (gotHighResThumb && !highRes) return; try { synchronized (singleImageDecodeLock) { BitmapFactory.Options justDecodeBounds = new BitmapFactory.Options(); justDecodeBounds.inJustDecodeBounds = true; BitmapFactory.decodeStream(cacheFile.getInputStream(), null, justDecodeBounds); final int width = justDecodeBounds.outWidth; final int height = justDecodeBounds.outHeight; int factor = 1; while (width / (factor + 1) > widthPixels && height / (factor + 1) > widthPixels) factor *= 2; BitmapFactory.Options scaledOptions = new BitmapFactory.Options(); scaledOptions.inSampleSize = factor; final Bitmap data = BitmapFactory.decodeStream(cacheFile.getInputStream(), null, scaledOptions); if (data == null) return; thumbnailCache = ThumbnailScaler.scale(data, widthPixels); if (thumbnailCache != data) data.recycle(); } if (highRes) gotHighResThumb = true; if (thumbnailCallback != null) thumbnailCallback.betterThumbnailAvailable(thumbnailCache, usageId); } catch (OutOfMemoryError e) { // TODO handle this better - disable caching of images Log.e("RedditPreparedPost", "Out of memory trying to download image"); e.printStackTrace(); } catch (Throwable t) { // Just ignore it. } } }); }
From source file:de.baumann.browser.Browser_left.java
private void screenshot() { shareFile = helper_main.newFile(mWebView); try {/*w w w. ja v a 2s. c o m*/ mWebView.measure( View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); mWebView.layout(0, 0, mWebView.getMeasuredWidth(), mWebView.getMeasuredHeight()); mWebView.setDrawingCacheEnabled(true); mWebView.buildDrawingCache(); bitmap = Bitmap.createBitmap(mWebView.getMeasuredWidth(), mWebView.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); int iHeight = bitmap.getHeight(); canvas.drawBitmap(bitmap, 0, iHeight, paint); mWebView.draw(canvas); } catch (OutOfMemoryError e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_screenshot_failed, Snackbar.LENGTH_SHORT).show(); } if (bitmap != null) { try { OutputStream fOut; fOut = new FileOutputStream(shareFile); bitmap.compress(Bitmap.CompressFormat.PNG, 50, fOut); fOut.flush(); fOut.close(); bitmap.recycle(); Snackbar snackbar = Snackbar .make(mWebView, getString(R.string.context_saveImage_toast) + " " + shareFile.getName() + ". " + getString(R.string.app_open), Snackbar.LENGTH_LONG) .setAction(getString(R.string.toast_yes), new View.OnClickListener() { @Override public void onClick(View view) { helper_main.switchToActivity(Browser_left.this, Popup_files.class, "", false); } }); snackbar.show(); Uri uri = Uri.fromFile(shareFile); Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri); sendBroadcast(intent); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } } }
From source file:org.egov.android.view.activity.CreateComplaintActivity.java
public String compressImage(String fromfilepath, String tofilepath) { Bitmap scaledBitmap = null;//from w w w.j a v a2s . co m BitmapFactory.Options options = new BitmapFactory.Options(); // by setting this field as true, the actual bitmap pixels are not loaded in the memory. Just the bounds are loaded. If // you try the use the bitmap here, you will get null. options.inJustDecodeBounds = true; Bitmap bmp = BitmapFactory.decodeFile(fromfilepath, options); int actualHeight = options.outHeight; int actualWidth = options.outWidth; // max Height and width values of the compressed image is taken as 816x612 float maxHeight = 816.0f; float maxWidth = 612.0f; float imgRatio = actualWidth / actualHeight; float maxRatio = maxWidth / maxHeight; // width and height values are set maintaining the aspect ratio of the image if (actualHeight > maxHeight || actualWidth > maxWidth) { if (imgRatio < maxRatio) { imgRatio = maxHeight / actualHeight; actualWidth = (int) (imgRatio * actualWidth); actualHeight = (int) maxHeight; } else if (imgRatio > maxRatio) { imgRatio = maxWidth / actualWidth; actualHeight = (int) (imgRatio * actualHeight); actualWidth = (int) maxWidth; } else { actualHeight = (int) maxHeight; actualWidth = (int) maxWidth; } } // setting inSampleSize value allows to load a scaled down version of the original image options.inSampleSize = calculateInSampleSize(options, actualWidth, actualHeight); // inJustDecodeBounds set to false to load the actual bitmap options.inJustDecodeBounds = false; // this options allow android to claim the bitmap memory if it runs low on memory options.inPurgeable = true; options.inInputShareable = true; options.inTempStorage = new byte[16 * 1024]; try { // load the bitmap from its path bmp = BitmapFactory.decodeFile(tofilepath, options); } catch (OutOfMemoryError exception) { exception.printStackTrace(); } try { scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.ARGB_8888); } catch (OutOfMemoryError exception) { exception.printStackTrace(); } float ratioX = actualWidth / (float) options.outWidth; float ratioY = actualHeight / (float) options.outHeight; float middleX = actualWidth / 2.0f; float middleY = actualHeight / 2.0f; Matrix scaleMatrix = new Matrix(); scaleMatrix.setScale(ratioX, ratioY, middleX, middleY); Canvas canvas = new Canvas(scaledBitmap); canvas.setMatrix(scaleMatrix); canvas.drawBitmap(bmp, middleX - bmp.getWidth() / 2, middleY - bmp.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG)); String attrLatitute = null; String attrLatituteRef = null; String attrLONGITUDE = null; String attrLONGITUDEREf = null; // check the rotation of the image and display it properly ExifInterface exif; try { exif = new ExifInterface(fromfilepath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); Log.d("EXIF", "Exif: " + orientation); Matrix matrix = new Matrix(); if (orientation == 6) { matrix.postRotate(90); Log.d("EXIF", "Exif: " + orientation); } else if (orientation == 3) { matrix.postRotate(180); Log.d("EXIF", "Exif: " + orientation); } else if (orientation == 8) { matrix.postRotate(270); Log.d("EXIF", "Exif: " + orientation); } attrLatitute = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); attrLatituteRef = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF); attrLONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); attrLONGITUDEREf = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF); scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true); } catch (IOException e) { e.printStackTrace(); } FileOutputStream out = null; try { out = new FileOutputStream(tofilepath); // write the compressed bitmap at the destination specified by filename. scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 80, out); ExifInterface exif2 = new ExifInterface(tofilepath); if (attrLatitute != null) { exif2.setAttribute(ExifInterface.TAG_GPS_LATITUDE, attrLatitute); exif2.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, attrLONGITUDE); } if (attrLatituteRef != null) { exif2.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, attrLatituteRef); exif2.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, attrLONGITUDEREf); } exif2.saveAttributes(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return tofilepath; }
From source file:org.quantumbadger.redreader.reddit.prepared.RedditPreparedPost.java
private void downloadThumbnail(final Context context, final int widthPixels, final CacheManager cm, final int listId) { final String uriStr = thumbnailUrl; final URI uri = General.uriFromString(uriStr); final int priority = Constants.Priority.THUMBNAIL; final int fileType = Constants.FileType.THUMBNAIL; final RedditAccount anon = RedditAccountManager.getAnon(); cm.makeRequest(new CacheRequest(uri, anon, null, priority, listId, CacheRequest.DownloadType.IF_NECESSARY, fileType, false, false, false, context) { @Override// w w w. j a v a 2s . c o m protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { } @Override protected void onCallbackException(final Throwable t) { // TODO handle -- internal error throw new RuntimeException(t); } @Override protected void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { } @Override protected void onProgress(final boolean authorizationInProgress, final long bytesRead, final long totalBytes) { } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, final long timestamp, final UUID session, final boolean fromCache, final String mimetype) { try { synchronized (singleImageDecodeLock) { BitmapFactory.Options justDecodeBounds = new BitmapFactory.Options(); justDecodeBounds.inJustDecodeBounds = true; BitmapFactory.decodeStream(cacheFile.getInputStream(), null, justDecodeBounds); final int width = justDecodeBounds.outWidth; final int height = justDecodeBounds.outHeight; int factor = 1; while (width / (factor + 1) > widthPixels && height / (factor + 1) > widthPixels) factor *= 2; BitmapFactory.Options scaledOptions = new BitmapFactory.Options(); scaledOptions.inSampleSize = factor; final Bitmap data = BitmapFactory.decodeStream(cacheFile.getInputStream(), null, scaledOptions); if (data == null) return; thumbnailCache = ThumbnailScaler.scale(data, widthPixels); if (thumbnailCache != data) data.recycle(); } if (thumbnailCallback != null) thumbnailCallback.betterThumbnailAvailable(thumbnailCache, usageId); } catch (OutOfMemoryError e) { // TODO handle this better - disable caching of images Log.e("RedditPreparedPost", "Out of memory trying to download image"); e.printStackTrace(); } catch (Throwable t) { // Just ignore it. } } }); }
From source file:com.kjsaw.alcosys.ibacapp.IBAC.java
private Bitmap readPhotos() { String localPath = getApplicationContext().getFilesDir().getAbsolutePath() + "/photos/"; String fileName = localPath + "Test.jpg"; BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*from w w w .ja va 2 s . c om*/ BitmapFactory.decodeFile(fileName, options); options.inSampleSize = computeSampleSize(options, -1, 128 * 128); options.inJustDecodeBounds = false; try { return BitmapFactory.decodeFile(fileName, options); } catch (OutOfMemoryError err) { err.printStackTrace(); } return null; }
From source file:de.baumann.browser.Browser.java
private void screenshot() { shareFile = helper_main.newFile();//w ww. j a v a 2s.c om try { mWebView.measure( View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); mWebView.layout(0, 0, mWebView.getMeasuredWidth(), mWebView.getMeasuredHeight()); mWebView.setDrawingCacheEnabled(true); mWebView.buildDrawingCache(); bitmap = Bitmap.createBitmap(mWebView.getMeasuredWidth(), mWebView.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); int iHeight = bitmap.getHeight(); canvas.drawBitmap(bitmap, 0, iHeight, paint); mWebView.draw(canvas); } catch (OutOfMemoryError e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_screenshot_failed, Snackbar.LENGTH_SHORT).show(); } if (bitmap != null) { try { OutputStream fOut; fOut = new FileOutputStream(shareFile); bitmap.compress(Bitmap.CompressFormat.PNG, 50, fOut); fOut.flush(); fOut.close(); bitmap.recycle(); Snackbar snackbar = Snackbar .make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName() + ". " + getString(R.string.app_open), Snackbar.LENGTH_LONG) .setAction(getString(R.string.toast_yes), new View.OnClickListener() { @Override public void onClick(View view) { String startDir = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .getPath(); helper_main.openFilePicker(Browser.this, mWebView, startDir); } }); snackbar.show(); Uri uri = Uri.fromFile(shareFile); Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri); sendBroadcast(intent); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } } }
From source file:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedPost.java
private void downloadThumbnail(final Context context, final int widthPixels, final CacheManager cm, final int listId) { final String uriStr = src.getThumbnailUrl(); final URI uri = General.uriFromString(uriStr); final int priority = Constants.Priority.THUMBNAIL; final int fileType = Constants.FileType.THUMBNAIL; final RedditAccount anon = RedditAccountManager.getAnon(); cm.makeRequest(new CacheRequest(uri, anon, null, priority, listId, DownloadStrategyIfNotCached.INSTANCE, fileType, CacheRequest.DOWNLOAD_QUEUE_IMMEDIATE, false, false, context) { @Override/*w ww . j a v a 2s . c om*/ protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { } @Override protected void onCallbackException(final Throwable t) { // TODO handle -- internal error throw new RuntimeException(t); } @Override protected void onFailure(final @CacheRequest.RequestFailureType int type, final Throwable t, final Integer status, final String readableMessage) { } @Override protected void onProgress(final boolean authorizationInProgress, final long bytesRead, final long totalBytes) { } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, final long timestamp, final UUID session, final boolean fromCache, final String mimetype) { try { synchronized (singleImageDecodeLock) { BitmapFactory.Options justDecodeBounds = new BitmapFactory.Options(); justDecodeBounds.inJustDecodeBounds = true; BitmapFactory.decodeStream(cacheFile.getInputStream(), null, justDecodeBounds); final int width = justDecodeBounds.outWidth; final int height = justDecodeBounds.outHeight; int factor = 1; while (width / (factor + 1) > widthPixels && height / (factor + 1) > widthPixels) factor *= 2; BitmapFactory.Options scaledOptions = new BitmapFactory.Options(); scaledOptions.inSampleSize = factor; final Bitmap data = BitmapFactory.decodeStream(cacheFile.getInputStream(), null, scaledOptions); if (data == null) return; thumbnailCache = ThumbnailScaler.scale(data, widthPixels); if (thumbnailCache != data) data.recycle(); } if (thumbnailCallback != null) thumbnailCallback.betterThumbnailAvailable(thumbnailCache, usageId); } catch (OutOfMemoryError e) { // TODO handle this better - disable caching of images Log.e("RedditPreparedPost", "Out of memory trying to download image"); e.printStackTrace(); } catch (Throwable t) { // Just ignore it. } } }); }