summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Dryomov <artur.dryomov@gmail.com>2013-03-22 23:03:32 +0300
committerMichael Meeks <michael.meeks@suse.com>2013-03-25 11:09:57 +0000
commit4ef4046419a3bc351a2ae06362ff5049cd120f96 (patch)
tree0377f2a4143186444bc675aa6673aa664a629531
parent1f2dac0d945b8f1636ee203ec55cf7f21390e32e (diff)
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 <michael.meeks@suse.com> Tested-by: Michael Meeks <michael.meeks@suse.com> Signed-off-by: Michael Meeks <michael.meeks@suse.com>
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java23
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java47
2 files changed, 26 insertions, 44 deletions
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<byte[]> mPreviewImages = new SparseArray<byte[]>();
+ private SparseArray<Bitmap> mPreviews = new SparseArray<Bitmap>();
private SparseArray<String> mNotes = new SparseArray<String>();
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) {