Return-Path: X-Original-To: apmail-incubator-callback-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2FEDC92F9 for ; Tue, 24 Apr 2012 11:52:01 +0000 (UTC) Received: (qmail 88377 invoked by uid 500); 24 Apr 2012 11:52:00 -0000 Delivered-To: apmail-incubator-callback-dev-archive@incubator.apache.org Received: (qmail 88167 invoked by uid 500); 24 Apr 2012 11:52:00 -0000 Mailing-List: contact callback-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-dev@incubator.apache.org Received: (qmail 87907 invoked by uid 99); 24 Apr 2012 11:51:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Apr 2012 11:51:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Apr 2012 11:51:56 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 26D2F40C2A7 for ; Tue, 24 Apr 2012 11:51:35 +0000 (UTC) Date: Tue, 24 Apr 2012 11:51:35 +0000 (UTC) From: "Christopher Bailey (JIRA)" To: callback-dev@incubator.apache.org Message-ID: <69806669.9077.1335268295175.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1160906738.9940.1320737693650.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (CB-14) CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CB-14?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13260447#comment-13260447 ] Christopher Bailey commented on CB-14: -------------------------------------- @Joe. Sorry I think my confusion was due to the incorrect assignment of issue CB-193 being merged into this ticket. Essentially when Cordova or any app fires up the camera (regardless of FILE_URI or DATA_URL) then the OS can decide summarily to kill of the app as it's running in the background. This is the issue mentioned in CB-193. You can try this yourself by firing up the camera and then using the task switcher/home key to change to one or more memory intensive apps (e.g. browser) This issue was particularly prevalent with the camera app on my Galaxy S so I have implemented a workaround by extending CameraLauncher and saving it's state in my Activity's onSaveInstanceState(). I feel that DroidGap.java should be doing this itself so that it can recover from such an event. > CameraLauncher Plugin enhancement for loading big image files to avoid OutOfMemory exceptions > --------------------------------------------------------------------------------------------- > > Key: CB-14 > URL: https://issues.apache.org/jira/browse/CB-14 > Project: Apache Callback > Issue Type: Improvement > Components: Android > Affects Versions: 1.1.0 > Environment: Android SDK: 2.x & above > JDK: 1.6 > Eclipse: Helios > Reporter: Bright Zheng > Assignee: Joe Bowser > Priority: Critical > Labels: CameraLauncher, OutOfMemory, decodeStream > Fix For: 1.6.0 > > > Currently the CameraLauncher plugin of Phonegap (or Apache Callback) is using Android default API for stream decoding. > It will be very easy to get crash by throwing out the OutOfMemory exceptions while loading bigger image files. > So I add a new method called safeDecodeStream for better stream decoding. > {code:title=safeDecodeStream method|borderStyle=solid} > /** > * A safer decodeStream method > * rather than the one of {@link BitmapFactory} > * which will be easy to get OutOfMemory Exception > * while loading a big image file. > * > * @param uri > * @param width > * @param height > * @return > * @throws FileNotFoundException > */ > protected Bitmap safeDecodeStream(Uri uri, int width, int height) > throws FileNotFoundException{ > int scale = 1; > BitmapFactory.Options options = new BitmapFactory.Options(); > android.content.ContentResolver resolver = this.ctx.getContentResolver(); > > if(width>0 || height>0){ > // Decode image size without loading all data into memory > options.inJustDecodeBounds = true; > BitmapFactory.decodeStream( > new BufferedInputStream(resolver.openInputStream(uri), 16*1024), > null, > options); > > int w = options.outWidth; > int h = options.outHeight; > while (true) { > if ((width>0 && w/2 < width) > || (height>0 && h/2 < height)){ > break; > } > w /= 2; > h /= 2; > scale *= 2; > } > } > // Decode with inSampleSize option > options.inJustDecodeBounds = false; > options.inSampleSize = scale; > return BitmapFactory.decodeStream( > new BufferedInputStream(resolver.openInputStream(uri), 16*1024), > null, > options); > } > {code} > And then change all the codes which are invoking the Android decodeStream API directly to this method. > e.g. > {code:title=usage example|borderStyle=solid} > //Updated by Bright for safer decodeStream > //android.content.ContentResolver resolver = this.ctx.getContentResolver(); > //bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); > bitmap = safeDecodeStream(uri, this.targetWidth, this.targetHeight); > {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira