Kaydet (Commit) 514d6c6f authored tarafından Artur Dryomov's avatar Artur Dryomov Kaydeden (comit) Michael Meeks

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/2917Reviewed-by: 's avatarMichael Meeks <michael.meeks@suse.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@suse.com>
üst 1a843cc5
......@@ -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);
}
}
}
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment