From 514d6c6fb61437a2e4f6c94abb4bfea22936f86c Mon Sep 17 00:00:00 2001 From: Artur Dryomov Date: Fri, 22 Mar 2013 23:03:32 +0300 Subject: fdo#62591 - change Impress remote slide previews building * Store bitmaps directly instead of byte arrays. * Store bitmaps with shadows instead of one set with shadows and another without them. This change should optimize memory usage a bit. Change-Id: Ied7ce57a660438a06167e8984d16a6f26ebd8c23 Reviewed-on: https://gerrit.libreoffice.org/2917 Reviewed-by: Michael Meeks Tested-by: Michael Meeks --- .../impressremote/PresentationFragment.java | 23 +---------- .../impressremote/communication/SlideShow.java | 47 ++++++++++++---------- 2 files changed, 26 insertions(+), 44 deletions(-) (limited to 'android') diff --git a/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java b/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java index 0aab5a640df5..8f1ba7de6584 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java @@ -21,10 +21,7 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.res.Configuration; import android.graphics.Bitmap; -import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.RectF; import android.os.Bundle; import android.os.IBinder; import android.support.v4.content.LocalBroadcastManager; @@ -38,7 +35,6 @@ import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ImageView; import android.widget.TextView; - import com.actionbarsherlock.app.SherlockFragment; public class PresentationFragment extends SherlockFragment { @@ -306,24 +302,7 @@ public class PresentationFragment extends SherlockFragment { @Override protected Bitmap createBitmap(int position) { - Bitmap aBitmap = mSlideShow.getImage(position); - final int borderWidth = 8; - - Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); - p.setShadowLayer(borderWidth, 0, 0, Color.BLACK); - - RectF aRect = new RectF(borderWidth, borderWidth, borderWidth - + aBitmap.getWidth(), borderWidth - + aBitmap.getHeight()); - Bitmap aOut = Bitmap.createBitmap(aBitmap.getWidth() + 2 - * borderWidth, aBitmap.getHeight() + 2 - * borderWidth, aBitmap.getConfig()); - Canvas canvas = new Canvas(aOut); - canvas.drawColor(getResources().getColor(R.color.light_grey)); - canvas.drawRect(aRect, p); - canvas.drawBitmap(aBitmap, null, aRect, null); - - return aOut; + return mSlideShow.getImage(position); } } } diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java index 3925fe258fa7..8b7a8e1979fc 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java @@ -9,17 +9,20 @@ package org.libreoffice.impressremote.communication; import org.libreoffice.impressremote.R; -import org.libreoffice.impressremote.Globals; -import android.util.Log; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.RectF; import android.util.SparseArray; + public class SlideShow { - private SparseArray mPreviewImages = new SparseArray(); + private SparseArray mPreviews = new SparseArray(); private SparseArray mNotes = new SparseArray(); private int mSize = 0; @@ -47,28 +50,28 @@ public class SlideShow { } protected void putImage(int aSlide, byte[] aImage) { - mPreviewImages.put(aSlide, aImage); + Bitmap aBitmap = BitmapFactory.decodeByteArray(aImage, 0, aImage.length); + final int borderWidth = 8; + + Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); + p.setShadowLayer(borderWidth, 0, 0, Color.BLACK); + + RectF aRect = new RectF(borderWidth, borderWidth, borderWidth + + aBitmap.getWidth(), borderWidth + + aBitmap.getHeight()); + Bitmap aOut = Bitmap.createBitmap(aBitmap.getWidth() + 2 + * borderWidth, aBitmap.getHeight() + 2 + * borderWidth, aBitmap.getConfig()); + Canvas canvas = new Canvas(aOut); + canvas.drawColor(mContext.getResources().getColor(R.color.light_grey)); + canvas.drawRect(aRect, p); + canvas.drawBitmap(aBitmap, null, aRect, null); + + mPreviews.put(aSlide, aOut); } public Bitmap getImage(int aSlide) { - byte[] aImage = mPreviewImages.get(aSlide); - if (aImage == null) { - return BitmapFactory.decodeResource(mContext.getResources(), - R.drawable.image_loading); - } - Bitmap aBitmap = null; - try { - aBitmap = BitmapFactory.decodeByteArray(aImage, 0, aImage.length); - } catch (OutOfMemoryError e) { - Log.e(Globals.TAG, "Bitmap decoding error byte length: " + aImage.length + - "first 4 bytes: " + aImage[0] + " " + aImage[1] + " " + aImage[2] + " " + aImage[3] + - "Exception " + e); - } - if (aBitmap == null) { - return BitmapFactory.decodeResource(mContext.getResources(), - R.drawable.image_loading); - } - return aBitmap; + return mPreviews.get(aSlide); } protected void putNotes(int aSlide, String aNotes) { -- cgit